smartfile/dist/smartfile.fs.js

155 lines
15 KiB
JavaScript
Raw Normal View History

2016-06-23 16:31:55 +00:00
"use strict";
require("typings-global");
var plugins = require("./smartfile.plugins");
var SmartfileInterpreter = require("./smartfile.interpreter");
/*===============================================================
============================ FS ACTIONS =========================
===============================================================*/
2016-06-23 16:39:02 +00:00
/**
* copies a file from A to B on the local disk
*/
2016-06-23 16:31:55 +00:00
exports.copy = function (fromArg, toArg) {
var done = plugins.q.defer();
plugins.fs.copy(fromArg, toArg, {}, function () {
done.resolve();
});
return done.promise;
};
2016-06-23 16:39:02 +00:00
/**
* copies a file SYNCHRONOUSLY from A to B on the local disk
*/
2016-06-23 16:31:55 +00:00
exports.copySync = function (fromArg, toArg) {
plugins.fs.copySync(fromArg, toArg);
return true;
};
2016-06-23 16:39:02 +00:00
/**
* removes a file or folder from local disk
*/
2016-06-23 16:31:55 +00:00
exports.remove = function (pathArg) {
var done = plugins.q.defer();
plugins.fs.remove(pathArg, function () {
done.resolve();
});
return done.promise;
};
2016-06-23 16:39:02 +00:00
/**
* removes a file SYNCHRONOUSLY from local disk
*/
2016-06-23 16:31:55 +00:00
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);
};
2016-06-23 16:39:02 +00:00
/**
* lists Folders in a directory on local disk
*/
exports.listFolders = function (pathArg) {
2016-06-23 16:31:55 +00:00
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;
};
2016-06-23 16:39:02 +00:00
/**
* lists Folders SYNCHRONOUSLY in a directory on local disk
*/
exports.listFoldersSync = function (pathArg) {
return plugins.fs.readdirSync(pathArg).filter(function (file) {
return plugins.fs.statSync(plugins.path.join(pathArg, file)).isDirectory();
});
};
2016-06-23 16:31:55 +00:00
/**
*
* @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();
};
2016-06-23 16:39:02 +00:00
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNtYXJ0ZmlsZS5mcy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsUUFBTyxnQkFBZ0IsQ0F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