129 lines
16 KiB
JavaScript
129 lines
16 KiB
JavaScript
"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 (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;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNtYXJ0ZmlsZS5tZW1vcnkudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sZ0JBQWdCLENBQUMsQ0FBQTtBQUV4QixJQUFPLE9BQU8sV0FBVyxxQkFBcUIsQ0FBQyxDQUFDO0FBQ2hELElBQU8sb0JBQW9CLFdBQVcseUJBQXlCLENBQUMsQ0FBQztBQUNqRSxJQUFJLFFBQVEsR0FBRyxPQUFPLENBQUMsUUFBUSxDQUFDLENBQUMsUUFBUSxDQUFDO0FBQzFDOzs7Ozs7R0FNRztBQUNRLG9CQUFZLEdBQUcsVUFBUyxPQUFxRCxFQUFDLE9BQW9CO0lBQXBCLHVCQUFvQixHQUFwQixhQUFvQjtJQUN6RyxJQUFJLFNBQVMsR0FBRyxFQUFFLENBQUM7SUFFbkIsRUFBRSxDQUFBLENBQUMsT0FBTyxPQUFPLEtBQUssUUFBUSxJQUFJLE9BQU8sWUFBWSxPQUFPLENBQUMsS0FBSyxDQUFDLENBQUEsQ0FBQztRQUNoRSxTQUFTLENBQUMsSUFBSSxDQUFDLE9BQU8sQ0FBQyxDQUFDO0lBQzVCLENBQUM7SUFBQyxJQUFJLENBQUMsRUFBRSxDQUFDLENBQUMsS0FBSyxDQUFDLE9BQU8sQ0FBQyxPQUFPLENBQUMsQ0FBQyxDQUFBLENBQUM7UUFDL0IsU0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