#!/usr/bin/env node /// var SmartfilePlugins; (function (SmartfilePlugins) { SmartfilePlugins.init = function () { var plugins = { beautylog: require("beautylog"), fs: require("fs-extra"), path: require("path"), q: require("q"), vinyl: require("vinyl"), vinylFile: require("vinyl-file"), yaml: require("js-yaml"), requireReload: require("require-reload") }; return plugins; }; })(SmartfilePlugins || (SmartfilePlugins = {})); /// var SmartfileCheck; (function (SmartfileCheck) { var checks = { fileExistsSync: function (filePath) { var fileExistsBool = false; try { plugins.fs.readFileSync(filePath); fileExistsBool = true; } catch (err) { fileExistsBool = false; } return fileExistsBool; }, fileExists: function (filePath) { var done = plugins.q.defer(); plugins.fs.access(filePath, plugins.fs.R_OK, function (err) { err ? done.reject() : done.resolve(); }); return done.promise; } }; SmartfileCheck.init = function (objectArg) { objectArg.checks = checks; }; })(SmartfileCheck || (SmartfileCheck = {})); /// var SmartfileSimple; (function (SmartfileSimple) { /** * reads a file content to a String * @param filePath * @returns {string|Buffer|any} */ var readFileToString = function (filePath) { var fileString; fileString = plugins.fs.readFileSync(filePath, "utf8"); return fileString; }; var readFileToObject = function (filePath, fileTypeArg) { if (fileTypeArg === void 0) { fileTypeArg = "undefined"; } var fileType; if (fileTypeArg == "undefined") { fileType = plugins.path.extname(filePath); } else { fileType = fileTypeArg; } fileType = fileType.replace(/\.([a-z]*)/, "$1"); //remove . form fileType switch (fileType) { case "yml": case "yaml": try { return plugins.yaml.safeLoad(plugins.fs.readFileSync(filePath, 'utf8')); } catch (e) { plugins.beautylog.error("check that " + filePath.blue + " points to a valid file"); } break; case "json": return plugins.fs.readJsonSync(filePath, {}); break; } }; SmartfileSimple.init = function (objectArg) { objectArg.readFileToString = readFileToString; objectArg.readFileToObject = readFileToObject; }; })(SmartfileSimple || (SmartfileSimple = {})); /// var SmartfileVinyl; (function (SmartfileVinyl) { var readFileToVinyl = function (filePathArg, options) { if (options === void 0) { options = {}; } return plugins.vinylFile.readSync(filePathArg, options); }; SmartfileVinyl.init = function (objectArg) { objectArg.readFileToVinyl = readFileToVinyl; }; })(SmartfileVinyl || (SmartfileVinyl = {})); /// var SmartfileRequire; (function (SmartfileRequire) { var requireReload = function (path) { return plugins.requireReload(path); }; SmartfileRequire.init = function (objectArg) { objectArg.requireReload = requireReload; }; })(SmartfileRequire || (SmartfileRequire = {})); /// /// /// /// /// /// var plugins = SmartfilePlugins.init(); var smartfile = {}; SmartfileCheck.init(smartfile); SmartfileSimple.init(smartfile); SmartfileVinyl.init(smartfile); SmartfileRequire.init(smartfile); module.exports = smartfile;