"use strict"; require("typings-global"); var plugins = require("./smartfile.plugins"); var SmartfileInterpreter = require("./smartfile.interpreter"); var Readable = require("stream").Readable; /** * allows you to create a gulp stream * from String, from an Array of Strings, from Vinyl File, from an Array of VinylFiles * @param fileArg * @returns stream.Readable * @TODO: make it async; */ exports.toGulpStream = function (fileArg, baseArg) { if (baseArg === void 0) { baseArg = "/"; } var fileArray = []; if (typeof fileArg === "string" || fileArg instanceof plugins.vinyl) { fileArray.push(fileArg); } else if (Array.isArray(fileArg)) { fileArray = fileArg; } else { throw new Error("fileArg has unknown format"); } var vinylFileArray = []; //we want to have an array of vinylFiles for (var fileIndexArg in fileArray) { var file = fileArray[fileIndexArg]; file instanceof plugins.vinyl ? vinylFileArray.push(file) : vinylFileArray.push(exports.toVinylFileSync(file, { filename: fileIndexArg, base: baseArg })); } ; var stream = new Readable({ objectMode: true }); for (var vinylFileIndexArg in vinylFileArray) { var vinylFile = vinylFileArray[vinylFileIndexArg]; stream.push(vinylFile); } ; stream.push(null); //signal end of stream; return stream; }; /** * converts file to Object * @param fileStringArg * @param fileTypeArg * @returns {any|any} */ exports.toObject = function (fileStringArg, fileTypeArg) { return SmartfileInterpreter.objectFile(fileStringArg, fileTypeArg); }; /** * takes a string and converts it to vinyl file * @param fileArg * @param optionsArg */ exports.toVinylFileSync = function (fileArg, optionsArg) { optionsArg ? void (0) : optionsArg = { filename: "vinylfile", base: "/" }; optionsArg.filename ? void (0) : optionsArg.filename = "vinylfile"; optionsArg.base ? void (0) : optionsArg.base = "/"; optionsArg.relPath ? void ("0") : optionsArg.relPath = ""; var vinylFile = new plugins.vinyl({ base: optionsArg.base, path: plugins.path.join(optionsArg.base, optionsArg.relPath, optionsArg.filename), contents: new Buffer(fileArg) }); return vinylFile; }; /** * takes a string array and some options and returns a vinylfile array * @param arrayArg * @param optionsArg */ exports.toVinylArraySync = function (arrayArg, optionsArg) { var vinylArray = []; for (var stringIndexArg in arrayArg) { var myString = arrayArg[stringIndexArg]; vinylArray.push(exports.toVinylFileSync(myString, optionsArg)); } return vinylArray; }; /** * takes a vinylFile object and converts it to String */ exports.toStringSync = function (fileArg) { return fileArg.contents.toString("utf8"); }; /** * writes string or vinyl file to disk. * @param fileArg * @param fileNameArg * @param fileBaseArg */ exports.toFs = function (fileContentArg, filePathArg) { var done = plugins.Q.defer(); //function checks to abort if needed if (!fileContentArg || !filePathArg) throw new Error("expected valid arguments"); // prepare actual write action var fileString; var filePath = filePathArg; if (fileContentArg instanceof plugins.vinyl) { fileString = exports.toStringSync(fileContentArg); } else if (typeof fileContentArg === "string") { fileString = fileContentArg; } plugins.fs.writeFile(filePath, fileString, "utf8", done.resolve); return done.promise; }; exports.toFsSync = function (fileArg, filePathArg) { //function checks to abort if needed if (!fileArg || !filePathArg) throw new Error("expected a valid arguments"); // prepare actual write action var fileString; var filePath = filePathArg; if (fileArg instanceof plugins.vinyl) { fileString = exports.toStringSync(fileArg); } else if (typeof fileArg === "string") { fileString = fileArg; } plugins.fs.writeFileSync(filePath, fileString, "utf8"); }; //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRmaWxlLm1lbW9yeS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0ZmlsZS5tZW1vcnkudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sZ0JBQWdCLENBQUMsQ0FBQTtBQUV4QixJQUFPLE9BQU8sV0FBVyxxQkFBcUIsQ0FBQyxDQUFDO0FBQ2hELElBQU8sb0JBQW9CLFdBQVcseUJBQXlCLENBQUMsQ0FBQztBQUVqRSxJQUFJLFFBQVEsR0FBRyxPQUFPLENBQUMsUUFBUSxDQUFDLENBQUMsUUFBUSxDQUFDO0FBQzFDOzs7Ozs7R0FNRztBQUNRLG9CQUFZLEdBQUcsVUFBUyxPQUFxRCxFQUFDLE9BQW9CO0lBQXBCLHVCQUFvQixHQUFwQixhQUFvQjtJQUN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