137 lines
14 KiB
JavaScript
137 lines
14 KiB
JavaScript
|
"use strict";
|
||
|
require("typings-global");
|
||
|
var plugins = require("./smartfile.plugins");
|
||
|
var SmartfileInterpreter = require("./smartfile.interpreter");
|
||
|
/*===============================================================
|
||
|
============================ FS ACTIONS =========================
|
||
|
===============================================================*/
|
||
|
exports.copy = function (fromArg, toArg) {
|
||
|
var done = plugins.q.defer();
|
||
|
plugins.fs.copy(fromArg, toArg, {}, function () {
|
||
|
done.resolve();
|
||
|
});
|
||
|
return done.promise;
|
||
|
};
|
||
|
exports.copySync = function (fromArg, toArg) {
|
||
|
plugins.fs.copySync(fromArg, toArg);
|
||
|
return true;
|
||
|
};
|
||
|
exports.remove = function (pathArg) {
|
||
|
var done = plugins.q.defer();
|
||
|
plugins.fs.remove(pathArg, function () {
|
||
|
done.resolve();
|
||
|
});
|
||
|
return done.promise;
|
||
|
};
|
||
|
exports.removeSync = function (pathArg) {
|
||
|
plugins.fs.removeSync(pathArg);
|
||
|
return true;
|
||
|
};
|
||
|
/*===============================================================
|
||
|
============================ Write/Read =========================
|
||
|
===============================================================*/
|
||
|
exports.toFS = function (options, cb) {
|
||
|
if (cb === void 0) { cb = undefined; }
|
||
|
};
|
||
|
/**
|
||
|
*
|
||
|
* @param filePathArg
|
||
|
* @returns {*}
|
||
|
*/
|
||
|
exports.toGulpStreamSync = function (filePathArg) {
|
||
|
var stream = plugins.gulp.src(filePathArg);
|
||
|
return stream;
|
||
|
};
|
||
|
exports.toGulpDestSync = function (folderPathArg) {
|
||
|
return plugins.gulp.dest(folderPathArg);
|
||
|
};
|
||
|
/**
|
||
|
*
|
||
|
* @param filePathArg
|
||
|
* @param fileTypeArg
|
||
|
* @returns {any}
|
||
|
*/
|
||
|
exports.toObjectSync = function (filePathArg, fileTypeArg) {
|
||
|
var fileString = plugins.fs.readFileSync(filePathArg, 'utf8');
|
||
|
var fileType;
|
||
|
fileTypeArg ? fileType = fileTypeArg : fileType = SmartfileInterpreter.filetype(filePathArg);
|
||
|
return SmartfileInterpreter.objectFile(fileString, fileType);
|
||
|
};
|
||
|
/**
|
||
|
* reads a file content to a String
|
||
|
* @param filePath
|
||
|
* @returns {string|Buffer|any}
|
||
|
*/
|
||
|
exports.toStringSync = function (filePath) {
|
||
|
var fileString;
|
||
|
fileString = plugins.fs.readFileSync(filePath, "utf8");
|
||
|
return fileString;
|
||
|
};
|
||
|
/**
|
||
|
*
|
||
|
* @param filePathArg
|
||
|
* @param options
|
||
|
* @returns {number}
|
||
|
*/
|
||
|
exports.toVinylSync = function (filePathArg, options) {
|
||
|
if (options === void 0) { options = {}; }
|
||
|
return plugins.vinylFile.readSync(filePathArg, options);
|
||
|
};
|
||
|
/**
|
||
|
* lets you reload files hot.
|
||
|
* @param path
|
||
|
* @returns {any}
|
||
|
*/
|
||
|
exports.requireReload = function (path) {
|
||
|
return plugins.requireReload(path);
|
||
|
};
|
||
|
exports.foldersSync = function (pathArg) {
|
||
|
return plugins.fs.readdirSync(pathArg).filter(function (file) {
|
||
|
return plugins.fs.statSync(plugins.path.join(pathArg, file)).isDirectory();
|
||
|
});
|
||
|
};
|
||
|
exports.folders = function (pathArg) {
|
||
|
var done = plugins.q.defer();
|
||
|
var folderArray = plugins.fs.readdirSync(pathArg).filter(function (file) {
|
||
|
return plugins.fs.statSync(plugins.path.join(pathArg, file)).isDirectory();
|
||
|
});
|
||
|
done.resolve(folderArray);
|
||
|
return done.promise;
|
||
|
};
|
||
|
/**
|
||
|
*
|
||
|
* @param filePath
|
||
|
* @returns {boolean}
|
||
|
*/
|
||
|
exports.fileExistsSync = function (filePath) {
|
||
|
var fileExistsBool = false;
|
||
|
try {
|
||
|
plugins.fs.readFileSync(filePath);
|
||
|
fileExistsBool = true;
|
||
|
}
|
||
|
catch (err) {
|
||
|
fileExistsBool = false;
|
||
|
}
|
||
|
return fileExistsBool;
|
||
|
};
|
||
|
/**
|
||
|
*
|
||
|
* @param filePath
|
||
|
* @returns {any}
|
||
|
*/
|
||
|
exports.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;
|
||
|
};
|
||
|
exports.isDirectory = function (pathArg) {
|
||
|
return plugins.fs.statSync(pathArg).isDirectory();
|
||
|
};
|
||
|
exports.isFile = function (pathArg) {
|
||
|
return plugins.fs.statSync(pathArg).isFile();
|
||
|
};
|
||
|
|
||
|
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNtYXJ0ZmlsZS5mcy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsUUFBTyxnQkFBZ0IsQ0FBQyxDQUFBO0FBRXhCLElBQU8sT0FBTyxXQUFXLHFCQUFxQixDQUFDLENBQUM7QUFDaEQsSUFBTyxvQkFBb0IsV0FBVyx5QkFBeUIsQ0FBQyxDQUFDO0FBRWpFOztpRUFFaUU7QUFFdEQsWUFBSSxHQUFHLFVBQVMsT0FBYyxFQUFFLEtBQVk7SUFDbkQsSUFBSSxJQUFJLEdBQUcsT0FBTyxDQUFDLENBQUMsQ0FBQyxLQUFLLEVBQUUsQ0FBQztJQUM3QixPQUFPLENBQUMsRUFBRSxDQUFDLElBQUksQ0FBQyxPQUFPLEVBQUMsS0FBSyxFQUFDLEVBQUUsRUFBQztRQUM3QixJQUFJLENBQUMsT0FBTyxFQUFFLENBQUM7SUFDbkIsQ0FBQyxDQUFDLENBQUM7SUFDSCxNQUFNLENBQUMsSUFBSSxDQUFDLE9BQU8sQ0FBQztBQUN4QixDQUFDLENBQUM7QUFFUyxnQkFBUSxHQUFHLFVBQVMsT0FBYyxFQUFDLEtBQVk7SUFDdEQsT0FBTyxDQUFDLEVBQUUsQ0FBQyxRQUFRLENBQUMsT0FBTyxFQUFDLEtBQUssQ0FBQyxDQUFDO0lBQ25DLE1BQU0sQ0FBQyxJQUFJLENBQUM7Q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