all files / smartfile/ index.js

92.31% Statements 60/65
80.95% Branches 17/21
94.12% Functions 16/17
92.06% Lines 58/63
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124                                                                                                                                   
#!/usr/bin/env node
 
/// <reference path="./index.ts" />
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 = {}));
/// <reference path="./index.ts" />
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 = {}));
/// <reference path="./index.ts" />
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) {
        Eif (fileTypeArg === void 0) { fileTypeArg = "undefined"; }
        var fileType;
        Eif (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 = {}));
/// <reference path="./index.ts" />
var SmartfileVinyl;
(function (SmartfileVinyl) {
    var readFileToVinyl = function (filePathArg, options) {
        Eif (options === void 0) { options = {}; }
        return plugins.vinylFile.readSync(filePathArg, options);
    };
    SmartfileVinyl.init = function (objectArg) {
        objectArg.readFileToVinyl = readFileToVinyl;
    };
})(SmartfileVinyl || (SmartfileVinyl = {}));
/// <reference path="./index.ts" />
var SmartfileRequire;
(function (SmartfileRequire) {
    var requireReload = function (path) {
        return plugins.requireReload(path);
    };
    SmartfileRequire.init = function (objectArg) {
        objectArg.requireReload = requireReload;
    };
})(SmartfileRequire || (SmartfileRequire = {}));
/// <reference path="./typings/main.d.ts" />
/// <reference path="./smartfile.plugins.ts" />
/// <reference path="./smartfile.check.ts" />
/// <reference path="./smartfile.simple.ts" />
/// <reference path="./smartfile.vinyl.ts" />
/// <reference path="./smartfile.require.ts" />
var plugins = SmartfilePlugins.init();
var smartfile = {};
SmartfileCheck.init(smartfile);
SmartfileSimple.init(smartfile);
SmartfileVinyl.init(smartfile);
SmartfileRequire.init(smartfile);
module.exports = smartfile;