/// "use strict"; 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; }; /** * * @param fileStringArg * @param fileTypeArg * @returns {any|any} */ exports.toObject = function (fileStringArg, fileTypeArg) { return SmartfileInterpreter(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 (fileArg, optionsArg) { var done = plugins.q.defer(); //function checks to abort if needed if (!fileArg || !optionsArg || !(typeof optionsArg.fileName === "string")) throw new Error("expected a valid arguments"); if (!(typeof optionsArg.filePath === "string")) optionsArg.filePath = "/"; var filePath = plugins.path.join(optionsArg.filePath, optionsArg.fileName); var fileString; if (fileArg instanceof plugins.vinyl) { fileString = exports.toStringSync(fileArg); } else if (typeof fileArg === "string") { fileString = fileArg; } plugins.fs.writeFile(filePath, fileString, "utf8", done.resolve); return done.promise; }; exports.toFsSync = function (fileArg, optionsArg) { //function checks to abort if needed if (!fileArg || !optionsArg || !(typeof optionsArg.fileName === "string")) throw new Error("expected a valid arguments"); if (!(typeof optionsArg.filePath === "string")) optionsArg.filePath = "/"; var filePath = plugins.path.join(optionsArg.filePath, optionsArg.fileName); var fileString; 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,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNtYXJ0ZmlsZS5tZW1vcnkudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsNENBQTRDOztBQUU1QyxJQUFPLE9BQU8sV0FBVyxxQkFBcUIsQ0FBQyxDQUFDO0FBQ2hELElBQU8sb0JBQW9CLFdBQVcseUJBQXlCLENBQUMsQ0FBQztBQUNqRSxJQUFJLFFBQVEsR0FBRyxPQUFPLENBQUMsUUFBUSxDQUFDLENBQUMsUUFBUSxDQUFDO0FBQzFDOzs7Ozs7R0FNRztBQUNRLG9CQUFZLEdBQUcsVUFBUyxPQUFxRCxFQUFDLE9BQW9CO0lBQXBCLHVCQUFvQix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