start implementation of Smartfile class

This commit is contained in:
Philipp Kunz 2017-03-04 21:10:46 +01:00
parent 943a0c30c2
commit e9c9e95118
13 changed files with 493 additions and 379 deletions

3
dist/index.js vendored
View File

@ -1,4 +1,5 @@
"use strict"; "use strict";
Object.defineProperty(exports, "__esModule", { value: true });
require("typings-global"); require("typings-global");
const SmartfileFs = require("./smartfile.fs"); const SmartfileFs = require("./smartfile.fs");
const SmartfileInterpreter = require("./smartfile.interpreter"); const SmartfileInterpreter = require("./smartfile.interpreter");
@ -11,4 +12,4 @@ exports.interpreter = SmartfileInterpreter;
exports.memory = SmartfileMemory; exports.memory = SmartfileMemory;
exports.remote = SmartfileRemote; exports.remote = SmartfileRemote;
exports.requireReload = SmartfileFs.requireReload; exports.requireReload = SmartfileFs.requireReload;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsMEJBQXVCO0FBR3ZCLDhDQUE2QztBQUM3QyxnRUFBK0Q7QUFDL0Qsc0RBQXFEO0FBQ3JELHNEQUFxRDtBQUVyRCw2RUFBdUQ7QUFBL0Msa0RBQUEsU0FBUyxDQUFBO0FBRU4sUUFBQSxFQUFFLEdBQUcsV0FBVyxDQUFBO0FBQ2hCLFFBQUEsV0FBVyxHQUFHLG9CQUFvQixDQUFBO0FBQ2xDLFFBQUEsTUFBTSxHQUFHLGVBQWUsQ0FBQTtBQUN4QixRQUFBLE1BQU0sR0FBRyxlQUFlLENBQUE7QUFDeEIsUUFBQSxhQUFhLEdBQUcsV0FBVyxDQUFDLGFBQWEsQ0FBQSJ9 //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLDBCQUF1QjtBQUd2Qiw4Q0FBNkM7QUFDN0MsZ0VBQStEO0FBQy9ELHNEQUFxRDtBQUNyRCxzREFBcUQ7QUFFckQsNkVBQXVEO0FBQS9DLGtEQUFBLFNBQVMsQ0FBQTtBQUVOLFFBQUEsRUFBRSxHQUFHLFdBQVcsQ0FBQTtBQUNoQixRQUFBLFdBQVcsR0FBRyxvQkFBb0IsQ0FBQTtBQUNsQyxRQUFBLE1BQU0sR0FBRyxlQUFlLENBQUE7QUFDeEIsUUFBQSxNQUFNLEdBQUcsZUFBZSxDQUFBO0FBQ3hCLFFBQUEsYUFBYSxHQUFHLFdBQVcsQ0FBQyxhQUFhLENBQUEifQ==

View File

@ -1,3 +1,16 @@
export declare class Smartfile { /// <reference types="node" />
constructor(); export interface ISmartfileConstructorOptions {
path?: string;
contentsString?: string;
contentBuffer?: Buffer;
}
export declare class Smartfile {
path: string;
contents: Buffer;
constructor(optionsArg: ISmartfileConstructorOptions);
/**
* set contents from string
* @param contentString
*/
setContentFromString(contentString: string): void;
} }

View File

@ -1,7 +1,22 @@
"use strict"; "use strict";
Object.defineProperty(exports, "__esModule", { value: true });
class Smartfile { class Smartfile {
constructor() { constructor(optionsArg) {
if (optionsArg.contentBuffer) {
this.contents = optionsArg.contentBuffer;
}
else if (optionsArg.contentsString) {
this.contents = new Buffer(optionsArg.contentsString);
}
this.path = optionsArg.path;
}
/**
* set contents from string
* @param contentString
*/
setContentFromString(contentString) {
this.contents = new Buffer(contentString);
} }
} }
exports.Smartfile = Smartfile; exports.Smartfile = Smartfile;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRmaWxlLmNsYXNzZXMuc21hcnRmaWxlLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRmaWxlLmNsYXNzZXMuc21hcnRmaWxlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQTtJQUNJO0lBRUEsQ0FBQztDQUNKO0FBSkQsOEJBSUMifQ== //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRmaWxlLmNsYXNzZXMuc21hcnRmaWxlLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRmaWxlLmNsYXNzZXMuc21hcnRmaWxlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7O0FBUUE7SUFHRSxZQUFZLFVBQXdDO1FBQ2xELEVBQUUsQ0FBQyxDQUFDLFVBQVUsQ0FBQyxhQUFhLENBQUMsQ0FBQyxDQUFDO1lBQzdCLElBQUksQ0FBQyxRQUFRLEdBQUcsVUFBVSxDQUFDLGFBQWEsQ0FBQTtRQUMxQyxDQUFDO1FBQUMsSUFBSSxDQUFDLEVBQUUsQ0FBQSxDQUFDLFVBQVUsQ0FBQyxjQUFjLENBQUMsQ0FBQyxDQUFDO1lBQ3BDLElBQUksQ0FBQyxRQUFRLEdBQUcsSUFBSSxNQUFNLENBQUMsVUFBVSxDQUFDLGNBQWMsQ0FBQyxDQUFBO1FBQ3ZELENBQUM7UUFDRCxJQUFJLENBQUMsSUFBSSxHQUFHLFVBQVUsQ0FBQyxJQUFJLENBQUE7SUFDN0IsQ0FBQztJQUVEOzs7T0FHRztJQUNILG9CQUFvQixDQUFDLGFBQXFCO1FBQ3hDLElBQUksQ0FBQyxRQUFRLEdBQUcsSUFBSSxNQUFNLENBQUMsYUFBYSxDQUFDLENBQUE7SUFDM0MsQ0FBQztDQUNGO0FBbkJELDhCQW1CQyJ9

View File

@ -1,4 +1,5 @@
import 'typings-global'; import 'typings-global';
import { Smartfile } from './smartfile.classes.smartfile';
/** /**
* *
* @param filePath * @param filePath
@ -90,6 +91,7 @@ export declare let toObjectSync: (filePathArg: any, fileTypeArg?: any) => any;
* @returns {string|Buffer|any} * @returns {string|Buffer|any}
*/ */
export declare let toStringSync: (filePath: any) => any; export declare let toStringSync: (filePath: any) => any;
export declare let fileTreeToObject: (dirPathArg: string, miniMatchFilter: string) => Promise<Smartfile[]>;
/** /**
* *
* @param filePathArg * @param filePathArg

23
dist/smartfile.fs.js vendored

File diff suppressed because one or more lines are too long

View File

@ -1,4 +1,5 @@
"use strict"; "use strict";
Object.defineProperty(exports, "__esModule", { value: true });
require("typings-global"); require("typings-global");
const plugins = require("./smartfile.plugins"); const plugins = require("./smartfile.plugins");
exports.filetype = (pathArg) => { exports.filetype = (pathArg) => {
@ -18,4 +19,4 @@ exports.objectFile = (fileStringArg, fileTypeArg) => {
break; break;
} }
}; };
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRmaWxlLmludGVycHJldGVyLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRmaWxlLmludGVycHJldGVyLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSwwQkFBdUI7QUFFdkIsK0NBQStDO0FBRXBDLFFBQUEsUUFBUSxHQUFHLENBQUMsT0FBZTtJQUNsQyxJQUFJLE9BQU8sR0FBRyxPQUFPLENBQUMsSUFBSSxDQUFDLE9BQU8sQ0FBQyxPQUFPLENBQUMsQ0FBQTtJQUMzQyxJQUFJLFFBQVEsR0FBRyxPQUFPLENBQUMsT0FBTyxDQUFDLFlBQVksRUFBQyxJQUFJLENBQUMsQ0FBQSxDQUFDLHlCQUF5QjtJQUMzRSxNQUFNLENBQUMsUUFBUSxDQUFBO0FBQ25CLENBQUMsQ0FBQTtBQUVVLFFBQUEsVUFBVSxHQUFHLENBQUMsYUFBcUIsRUFBRSxXQUFXO0lBQ3ZELE1BQU0sQ0FBQyxDQUFDLFdBQVcsQ0FBQyxDQUFDLENBQUM7UUFDbEIsS0FBSyxLQUFLLENBQUU7UUFDWixLQUFLLE1BQU07WUFDUCxNQUFNLENBQUMsT0FBTyxDQ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QUFBO1FBQy9DLEtBQUssTUFBTTtZQUNQLE1BQU0sQ0FBQyxJQUFJLENBQUMsS0FBSyxDQUFDLGFBQWEsQ0FBQyxDQUFBO1FBQ3BDO1lBQ0ksT0FBTyxDQUFDLEtBQUssQ0FBQyxZQUFZLEdBQUcsV0FBVyxDQUFDLElBQUksR0FBRyxnQkFBZ0IsQ0FBQyxDQUFBO1lBQ2pFLEtBQUssQ0FBQTtJQUNiLENBQUM7QUFDTCxDQUFDLENBQUEifQ==

File diff suppressed because one or more lines are too long

View File

@ -1,4 +1,5 @@
"use strict"; "use strict";
Object.defineProperty(exports, "__esModule", { value: true });
require("typings-global"); require("typings-global");
exports.fs = require("fs"); exports.fs = require("fs");
exports.fsExtra = require("fs-extra"); exports.fsExtra = require("fs-extra");
@ -10,4 +11,4 @@ exports.requireReload = require('require-reload');
exports.smartpath = require("smartpath"); exports.smartpath = require("smartpath");
exports.vinylFile = require('vinyl-file'); exports.vinylFile = require('vinyl-file');
exports.yaml = require('js-yaml'); exports.yaml = require('js-yaml');
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRmaWxlLnBsdWdpbnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydGZpbGUucGx1Z2lucy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsMEJBQXVCO0FBQ3ZCLDJCQUFnQztBQUNoQyxzQ0FBMkM7QUFDaEMsUUFBQSxJQUFJLEdBQUcsT0FBTyxDQUFDLE1BQU0sQ0FBQyxDQUFBO0FBQ2pDLCtCQUFvQztBQUNwQyw4QkFBbUM7QUFDbkMsK0NBQW9EO0FBQ3pDLFFBQUEsYUFBYSxHQUFHLE9BQU8sQ0FBQyxnQkFBZ0IsQ0FBQyxDQUFBO0FBQ3BELHlDQUE4QztBQUNuQyxRQUFBLFNBQVMsR0FBRyxPQUFPLENBQUMsWUFBWSxDQUFDLENBQUE7QUFDakMsUUFBQSxJQUFJLEdBQUcsT0FBTyxDQUFDLFNBQVMsQ0FBQyxDQUFBIn0= //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRmaWxlLnBsdWdpbnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydGZpbGUucGx1Z2lucy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLDBCQUF1QjtBQUN2QiwyQkFBZ0M7QUFDaEMsc0NBQTJDO0FBQ2hDLFFBQUEsSUFBSSxHQUFHLE9BQU8sQ0FBQyxNQUFNLENBQUMsQ0FBQTtBQUNqQywrQkFBb0M7QUFDcEMsOEJBQW1DO0FBQ25DLCtDQUFvRDtBQUN6QyxRQUFBLGFBQWEsR0FBRyxPQUFPLENBQUMsZ0JBQWdCLENBQUMsQ0FBQTtBQUNwRCx5Q0FBOEM7QUFDbkMsUUFBQSxTQUFTLEdBQUcsT0FBTyxDQUFDLFlBQVksQ0FBQyxDQUFBO0FBQ2pDLFFBQUEsSUFBSSxHQUFHLE9BQU8sQ0FBQyxTQUFTLENBQUMsQ0FBQSJ9

View File

@ -1,4 +1,5 @@
"use strict"; "use strict";
Object.defineProperty(exports, "__esModule", { value: true });
require("typings-global"); require("typings-global");
const plugins = require("./smartfile.plugins"); const plugins = require("./smartfile.plugins");
/* export let toFs = function (from: string, toPath: string) { /* export let toFs = function (from: string, toPath: string) {
@ -47,4 +48,4 @@ exports.toString = (fromArg) => {
}); });
return done.promise; return done.promise;
}; };
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRmaWxlLnJlbW90ZS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0ZmlsZS5yZW1vdGUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLDBCQUF1QjtBQUN2QiwrQ0FBK0M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sQ0FBQSJ9

File diff suppressed because one or more lines are too long

View File

@ -65,6 +65,17 @@ describe('smartfile', function () {
}) })
}) })
}) })
describe('toObjectFromFileTree', function () {
it('should read a file tree into an Object', function () {
smartfile.fs.fileTreeToObject(path.resolve('./test/'), '**/*.txt')
.then((fileArrayArg) => {
// expect(fileArrayArg[1]).to.be.instanceof(smartfile.Smartfile)
})
})
})
describe('.copy()', function () { describe('.copy()', function () {
it('should copy a directory', function () { it('should copy a directory', function () {
smartfile.fs.copy('./test/testfolder/', './test/temp/') smartfile.fs.copy('./test/testfolder/', './test/temp/')
@ -84,19 +95,19 @@ describe('smartfile', function () {
smartfile.fs.remove('./test/temp/mytestRenamed.yaml') smartfile.fs.remove('./test/temp/mytestRenamed.yaml')
.then(() => { done() }) .then(() => { done() })
}) })
it('smartfile.fs.removeSync -> should remove single files synchronouly',function() { it('smartfile.fs.removeSync -> should remove single files synchronouly', function () {
smartfile.fs.removeSync('./test/temp/testfile1.txt') smartfile.fs.removeSync('./test/temp/testfile1.txt')
expect(smartfile.fs.fileExistsSync('./test/temp/testfile1.txt')).to.be.false expect(smartfile.fs.fileExistsSync('./test/temp/testfile1.txt')).to.be.false
}) })
it('smartfile.fs.removeMany -> should remove and array of files',function(done) { it('smartfile.fs.removeMany -> should remove and array of files', function (done) {
smartfile.fs.removeMany(['./test/temp/testfile1.txt','./test/temp/testfile2.txt']).then(() => { smartfile.fs.removeMany([ './test/temp/testfile1.txt', './test/temp/testfile2.txt' ]).then(() => {
expect(smartfile.fs.fileExistsSync('./test/temp/testfile1.txt')).to.be.false expect(smartfile.fs.fileExistsSync('./test/temp/testfile1.txt')).to.be.false
expect(smartfile.fs.fileExistsSync('./test/temp/testfile2.txt')).to.be.false expect(smartfile.fs.fileExistsSync('./test/temp/testfile2.txt')).to.be.false
done() done()
}) })
}) })
it('smartfile.fs.removeManySync -> should remove and array of single files synchronouly',function() { it('smartfile.fs.removeManySync -> should remove and array of single files synchronouly', function () {
smartfile.fs.removeManySync(['./test/temp/testfile1.txt','./test/temp/testfile2.txt']) smartfile.fs.removeManySync([ './test/temp/testfile1.txt', './test/temp/testfile2.txt' ])
expect(smartfile.fs.fileExistsSync('./test/temp/testfile1.txt')).to.be.false expect(smartfile.fs.fileExistsSync('./test/temp/testfile1.txt')).to.be.false
expect(smartfile.fs.fileExistsSync('./test/temp/testfile2.txt')).to.be.false expect(smartfile.fs.fileExistsSync('./test/temp/testfile2.txt')).to.be.false
}) })
@ -146,7 +157,7 @@ describe('smartfile', function () {
describe('.memory', function () { describe('.memory', function () {
describe('.toGulpStream()', function () { describe('.toGulpStream()', function () {
it('should produce a valid gulp stream', function () { it('should produce a valid gulp stream', function () {
let localArray = ['test1', 'test2', 'test3'] let localArray = [ 'test1', 'test2', 'test3' ]
smartfile.memory.toGulpStream(localArray) smartfile.memory.toGulpStream(localArray)
}) })
}) })
@ -159,13 +170,13 @@ describe('smartfile', function () {
}) })
describe('toVinylArraySync()', function () { describe('toVinylArraySync()', function () {
it('should produce a an array of vinylfiles', function () { it('should produce a an array of vinylfiles', function () {
let localStringArray = ['string1', 'string2', 'string3'] let localStringArray = [ 'string1', 'string2', 'string3' ]
let localOptions = { filename: 'vinylfile2', base: '/someDir' } let localOptions = { filename: 'vinylfile2', base: '/someDir' }
let testResult = smartfile.memory.toVinylArraySync(localStringArray, localOptions) let testResult = smartfile.memory.toVinylArraySync(localStringArray, localOptions)
expect(testResult).to.be.a('array') expect(testResult).to.be.a('array')
expect(testResult.length === 3).to.be.true expect(testResult.length === 3).to.be.true
for (let myKey in testResult) { for (let myKey in testResult) {
expect(testResult[myKey] instanceof vinyl).to.be.true expect(testResult[ myKey ] instanceof vinyl).to.be.true
} }
}) })
}) })

View File

@ -1,5 +1,28 @@
export class Smartfile { import * as plugins from './smartfile.plugins'
constructor() {
export interface ISmartfileConstructorOptions {
path?: string
contentsString?: string
contentBuffer?: Buffer
}
export class Smartfile {
path: string
contents: Buffer
constructor(optionsArg: ISmartfileConstructorOptions) {
if (optionsArg.contentBuffer) {
this.contents = optionsArg.contentBuffer
} else if(optionsArg.contentsString) {
this.contents = new Buffer(optionsArg.contentsString)
}
this.path = optionsArg.path
}
/**
* set contents from string
* @param contentString
*/
setContentFromString(contentString: string) {
this.contents = new Buffer(contentString)
} }
} }

View File

@ -2,6 +2,9 @@ import 'typings-global'
import plugins = require('./smartfile.plugins') import plugins = require('./smartfile.plugins')
import SmartfileInterpreter = require('./smartfile.interpreter') import SmartfileInterpreter = require('./smartfile.interpreter')
import { Smartfile } from './smartfile.classes.smartfile'
import * as memory from './smartfile.memory' import * as memory from './smartfile.memory'
/*=============================================================== /*===============================================================
============================ Checks ============================= ============================ Checks =============================
@ -12,7 +15,7 @@ import * as memory from './smartfile.memory'
* @param filePath * @param filePath
* @returns {boolean} * @returns {boolean}
*/ */
export let fileExistsSync = function(filePath): boolean { export let fileExistsSync = function (filePath): boolean {
let fileExistsBool: boolean = false let fileExistsBool: boolean = false
try { try {
plugins.fsExtra.readFileSync(filePath) plugins.fsExtra.readFileSync(filePath)
@ -28,7 +31,7 @@ export let fileExistsSync = function(filePath): boolean {
* @param filePath * @param filePath
* @returns {any} * @returns {any}
*/ */
export let fileExists = function(filePath){ export let fileExists = function (filePath) {
let done = plugins.q.defer() let done = plugins.q.defer()
plugins.fs.access(filePath, 4, function (err) { plugins.fs.access(filePath, 4, function (err) {
err ? done.reject(err) : done.resolve() err ? done.reject(err) : done.resolve()
@ -39,14 +42,14 @@ export let fileExists = function(filePath){
/** /**
* Checks if given path points to an existing directory * Checks if given path points to an existing directory
*/ */
export let isDirectory = function(pathArg): boolean{ export let isDirectory = function (pathArg): boolean {
return plugins.fsExtra.statSync(pathArg).isDirectory() return plugins.fsExtra.statSync(pathArg).isDirectory()
} }
/** /**
* Checks if a given path points to an existing file * Checks if a given path points to an existing file
*/ */
export let isFile = function(pathArg): boolean{ export let isFile = function (pathArg): boolean {
return plugins.fsExtra.statSync(pathArg).isFile() return plugins.fsExtra.statSync(pathArg).isFile()
} }
@ -57,9 +60,9 @@ export let isFile = function(pathArg): boolean{
/** /**
* copies a file from A to B on the local disk * copies a file from A to B on the local disk
*/ */
export let copy = function(fromArg: string, toArg: string){ export let copy = function (fromArg: string, toArg: string) {
let done = plugins.q.defer() let done = plugins.q.defer()
plugins.fsExtra.copy(fromArg,toArg,{},function(){ plugins.fsExtra.copy(fromArg, toArg, {}, function () {
done.resolve() done.resolve()
}) })
return done.promise return done.promise
@ -68,8 +71,8 @@ export let copy = function(fromArg: string, toArg: string){
/** /**
* copies a file SYNCHRONOUSLY from A to B on the local disk * copies a file SYNCHRONOUSLY from A to B on the local disk
*/ */
export let copySync = function(fromArg: string,toArg: string): boolean{ export let copySync = function (fromArg: string, toArg: string): boolean {
plugins.fsExtra.copySync(fromArg,toArg) plugins.fsExtra.copySync(fromArg, toArg)
return true return true
} }
@ -78,7 +81,7 @@ export let copySync = function(fromArg: string,toArg: string): boolean{
*/ */
export let ensureDir = (dirPathArg: string) => { export let ensureDir = (dirPathArg: string) => {
let done = plugins.q.defer() let done = plugins.q.defer()
plugins.fsExtra.ensureDir(dirPathArg,done.resolve) plugins.fsExtra.ensureDir(dirPathArg, done.resolve)
return done.promise return done.promise
} }
@ -95,7 +98,7 @@ export let ensureDirSync = (dirPathArg: string) => {
*/ */
export let ensureEmptyDir = (dirPathArg: string) => { export let ensureEmptyDir = (dirPathArg: string) => {
let done = plugins.q.defer() let done = plugins.q.defer()
plugins.fsExtra.ensureDir(dirPathArg,() => { plugins.fsExtra.ensureDir(dirPathArg, () => {
plugins.fsExtra.emptyDir(dirPathArg, done.resolve) plugins.fsExtra.emptyDir(dirPathArg, done.resolve)
}) })
return done.promise return done.promise
@ -142,9 +145,9 @@ export let ensureFileSync = (filePathArg: string, initFileStringArg: string): vo
/** /**
* removes a file or folder from local disk * removes a file or folder from local disk
*/ */
export let remove = function(pathArg: string): Promise<void> { export let remove = function (pathArg: string): Promise<void> {
let done = plugins.q.defer<void>() let done = plugins.q.defer<void>()
plugins.fsExtra.remove(pathArg,function(){ plugins.fsExtra.remove(pathArg, function () {
done.resolve() done.resolve()
}) })
return done.promise return done.promise
@ -153,7 +156,7 @@ export let remove = function(pathArg: string): Promise<void> {
/** /**
* removes a file SYNCHRONOUSLY from local disk * removes a file SYNCHRONOUSLY from local disk
*/ */
export let removeSync = function(pathArg: string): boolean{ export let removeSync = function (pathArg: string): boolean {
plugins.fsExtra.removeSync(pathArg) plugins.fsExtra.removeSync(pathArg)
return true return true
} }
@ -161,7 +164,7 @@ export let removeSync = function(pathArg: string): boolean{
/** /**
* removes an array of filePaths from disk * removes an array of filePaths from disk
*/ */
export let removeMany = function(filePathArrayArg: string[]){ export let removeMany = function (filePathArrayArg: string[]) {
let promiseArray: Promise<void>[] = [] let promiseArray: Promise<void>[] = []
for (let filePath of filePathArrayArg) { for (let filePath of filePathArrayArg) {
promiseArray.push(remove(filePath)) promiseArray.push(remove(filePath))
@ -172,7 +175,7 @@ export let removeMany = function(filePathArrayArg: string[]){
/** /**
* like removeFilePathArray but SYNCHRONOUSLY * like removeFilePathArray but SYNCHRONOUSLY
*/ */
export let removeManySync = function(filePathArrayArg: string[]): void { export let removeManySync = function (filePathArrayArg: string[]): void {
for (let filePath of filePathArrayArg) { for (let filePath of filePathArrayArg) {
removeSync(filePath) removeSync(filePath)
} }
@ -188,11 +191,11 @@ export let removeManySync = function(filePathArrayArg: string[]): void {
* @param fileTypeArg * @param fileTypeArg
* @returns {any} * @returns {any}
*/ */
export let toObjectSync = function(filePathArg,fileTypeArg?) { export let toObjectSync = function (filePathArg, fileTypeArg?) {
let fileString = plugins.fsExtra.readFileSync(filePathArg, 'utf8') let fileString = plugins.fsExtra.readFileSync(filePathArg, 'utf8')
let fileType let fileType
fileTypeArg ? fileType = fileTypeArg : fileType = SmartfileInterpreter.filetype(filePathArg) fileTypeArg ? fileType = fileTypeArg : fileType = SmartfileInterpreter.filetype(filePathArg)
return SmartfileInterpreter.objectFile(fileString,fileType) return SmartfileInterpreter.objectFile(fileString, fileType)
} }
/** /**
@ -200,20 +203,32 @@ export let toObjectSync = function(filePathArg,fileTypeArg?) {
* @param filePath * @param filePath
* @returns {string|Buffer|any} * @returns {string|Buffer|any}
*/ */
export let toStringSync = function(filePath) { export let toStringSync = function (filePath) {
let fileString let fileString
fileString = plugins.fsExtra.readFileSync(filePath, 'utf8') fileString = plugins.fsExtra.readFileSync(filePath, 'utf8')
return fileString return fileString
} }
export let fileTreeToObject = async (dirPathArg: string, miniMatchFilter: string) => {
let fileTree = await listFileTree(dirPathArg, miniMatchFilter)
let smartfileArray: Smartfile[] = []
for (let filePath of fileTree) {
smartfileArray.push(new Smartfile({
path: filePath,
contentBuffer: new Buffer(toStringSync(filePath))
}))
}
return smartfileArray
}
/** /**
* *
* @param filePathArg * @param filePathArg
* @param options * @param options
* @returns {number} * @returns {number}
*/ */
export let toVinylSync = function(filePathArg,options = {}) { export let toVinylSync = function (filePathArg, options = {}) {
return plugins.vinylFile.readSync(filePathArg,options) return plugins.vinylFile.readSync(filePathArg, options)
} }
/** /**
@ -221,7 +236,7 @@ export let toVinylSync = function(filePathArg,options = {}) {
* @param path * @param path
* @returns {any} * @returns {any}
*/ */
export let requireReload = function(path: string){ export let requireReload = function (path: string) {
return plugins.requireReload(path) return plugins.requireReload(path)
} }
@ -229,9 +244,9 @@ export let requireReload = function(path: string){
* lists Folders in a directory on local disk * lists Folders in a directory on local disk
* @returns Promise * @returns Promise
*/ */
export let listFolders = function(pathArg: string,regexFilter?: RegExp){ export let listFolders = function (pathArg: string, regexFilter?: RegExp) {
let done = plugins.q.defer() let done = plugins.q.defer()
let folderArray = plugins.fsExtra.readdirSync(pathArg).filter(function(file) { let folderArray = plugins.fsExtra.readdirSync(pathArg).filter(function (file) {
return plugins.fsExtra.statSync(plugins.path.join(pathArg, file)).isDirectory() return plugins.fsExtra.statSync(plugins.path.join(pathArg, file)).isDirectory()
}) })
if (regexFilter) { if (regexFilter) {
@ -247,8 +262,8 @@ export let listFolders = function(pathArg: string,regexFilter?: RegExp){
* lists Folders SYNCHRONOUSLY in a directory on local disk * lists Folders SYNCHRONOUSLY in a directory on local disk
* @returns an array with the folder names as strings * @returns an array with the folder names as strings
*/ */
export let listFoldersSync = function(pathArg: string,regexFilter?: RegExp): string[]{ export let listFoldersSync = function (pathArg: string, regexFilter?: RegExp): string[] {
let folderArray = plugins.fsExtra.readdirSync(pathArg).filter(function(file) { let folderArray = plugins.fsExtra.readdirSync(pathArg).filter(function (file) {
return plugins.fsExtra.statSync(plugins.path.join(pathArg, file)).isDirectory() return plugins.fsExtra.statSync(plugins.path.join(pathArg, file)).isDirectory()
}) })
if (regexFilter) { if (regexFilter) {
@ -263,9 +278,9 @@ export let listFoldersSync = function(pathArg: string,regexFilter?: RegExp): str
* lists Files in a directory on local disk * lists Files in a directory on local disk
* @returns Promise * @returns Promise
*/ */
export let listFiles = function(pathArg: string, regexFilter?: RegExp){ export let listFiles = function (pathArg: string, regexFilter?: RegExp) {
let done = plugins.q.defer() let done = plugins.q.defer()
let fileArray = plugins.fsExtra.readdirSync(pathArg).filter(function(file) { let fileArray = plugins.fsExtra.readdirSync(pathArg).filter(function (file) {
return plugins.fsExtra.statSync(plugins.path.join(pathArg, file)).isFile() return plugins.fsExtra.statSync(plugins.path.join(pathArg, file)).isFile()
}) })
if (regexFilter) { if (regexFilter) {
@ -281,8 +296,8 @@ export let listFiles = function(pathArg: string, regexFilter?: RegExp){
* lists Files SYNCHRONOUSLY in a directory on local disk * lists Files SYNCHRONOUSLY in a directory on local disk
* @returns an array with the folder names as strings * @returns an array with the folder names as strings
*/ */
export let listFilesSync = function(pathArg: string, regexFilter?: RegExp): string[]{ export let listFilesSync = function (pathArg: string, regexFilter?: RegExp): string[] {
let fileArray = plugins.fsExtra.readdirSync(pathArg).filter(function(file) { let fileArray = plugins.fsExtra.readdirSync(pathArg).filter(function (file) {
return plugins.fsExtra.statSync(plugins.path.join(pathArg, file)).isFile() return plugins.fsExtra.statSync(plugins.path.join(pathArg, file)).isFile()
}) })
if (regexFilter) { if (regexFilter) {
@ -297,7 +312,7 @@ export let listFilesSync = function(pathArg: string, regexFilter?: RegExp): stri
* lists all items (folders AND files) in a directory on local disk * lists all items (folders AND files) in a directory on local disk
* @returns Promise<string[]> * @returns Promise<string[]>
*/ */
export let listAllItems = function(pathArg: string, regexFilter?: RegExp): Promise<string[]> { export let listAllItems = function (pathArg: string, regexFilter?: RegExp): Promise<string[]> {
let done = plugins.q.defer<string[]>() let done = plugins.q.defer<string[]>()
let allItmesArray = plugins.fsExtra.readdirSync(pathArg) let allItmesArray = plugins.fsExtra.readdirSync(pathArg)
if (regexFilter) { if (regexFilter) {
@ -314,8 +329,8 @@ export let listAllItems = function(pathArg: string, regexFilter?: RegExp): Promi
* @returns an array with the folder names as strings * @returns an array with the folder names as strings
* @executes SYNC * @executes SYNC
*/ */
export let listAllItemsSync = function(pathArg: string, regexFilter?: RegExp): string[]{ export let listAllItemsSync = function (pathArg: string, regexFilter?: RegExp): string[] {
let allItmesArray = plugins.fsExtra.readdirSync(pathArg).filter(function(file) { let allItmesArray = plugins.fsExtra.readdirSync(pathArg).filter(function (file) {
return plugins.fsExtra.statSync(plugins.path.join(pathArg, file)).isFile() return plugins.fsExtra.statSync(plugins.path.join(pathArg, file)).isFile()
}) })
if (regexFilter) { if (regexFilter) {
@ -345,7 +360,7 @@ export let listFileTree = (dirPathArg: string, miniMatchFilter: string): Promise
let options = { let options = {
cwd: dirPath cwd: dirPath
} }
plugins.glob(miniMatchFilter,options,(err,files: string[]) => { plugins.glob(miniMatchFilter, options, (err, files: string[]) => {
if (err) { if (err) {
console.log(err) console.log(err)
done.reject(err) done.reject(err)