smartfile/dist/smartfile.fs.js
2016-06-23 18:39:02 +02:00

155 lines
15 KiB
JavaScript

"use strict";
require("typings-global");
var plugins = require("./smartfile.plugins");
var SmartfileInterpreter = require("./smartfile.interpreter");
/*===============================================================
============================ FS ACTIONS =========================
===============================================================*/
/**
* copies a file from A to B on the local disk
*/
exports.copy = function (fromArg, toArg) {
var done = plugins.q.defer();
plugins.fs.copy(fromArg, toArg, {}, function () {
done.resolve();
});
return done.promise;
};
/**
* copies a file SYNCHRONOUSLY from A to B on the local disk
*/
exports.copySync = function (fromArg, toArg) {
plugins.fs.copySync(fromArg, toArg);
return true;
};
/**
* removes a file or folder from local disk
*/
exports.remove = function (pathArg) {
var done = plugins.q.defer();
plugins.fs.remove(pathArg, function () {
done.resolve();
});
return done.promise;
};
/**
* removes a file SYNCHRONOUSLY from local disk
*/
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);
};
/**
* lists Folders in a directory on local disk
*/
exports.listFolders = 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;
};
/**
* 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();
});
};
/**
*
* @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,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNtYXJ0ZmlsZS5mcy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsUUFBTyxnQkFBZ0IsQ0FBQyxDQUFBO0FBRXhCLElBQU8sT0FBTyxXQUFXLHFCQUFxQixDQUFDLENBQUM7QUFDaEQsSUFBTyxvQkFBb0IsV0FBVyx5QkFBeUIsQ0FBQyxDQUFDO0FBRWpFOztpRUFFaUU7QUFFakU7O0dBRUc7QUFDUSxZQUFJLEdBQUcsVUFBUyxPQUFjLEVBQUUsS0FBWTtJQUNuRCxJQUFJLElBQUksR0FBRyxPQUFPLENBQUMsQ0FBQyxDQUFD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