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";
Object.defineProperty(exports, "__esModule", { value: true });
require("typings-global");
const SmartfileFs = require("./smartfile.fs");
const SmartfileInterpreter = require("./smartfile.interpreter");
@ -11,4 +12,4 @@ exports.interpreter = SmartfileInterpreter;
exports.memory = SmartfileMemory;
exports.remote = SmartfileRemote;
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 {
constructor();
/// <reference types="node" />
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";
Object.defineProperty(exports, "__esModule", { value: true });
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;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRmaWxlLmNsYXNzZXMuc21hcnRmaWxlLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRmaWxlLmNsYXNzZXMuc21hcnRmaWxlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQTtJQUNJO0lBRUEsQ0FBQztDQUNKO0FBSkQsOEJBSUMifQ==
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRmaWxlLmNsYXNzZXMuc21hcnRmaWxlLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRmaWxlLmNsYXNzZXMuc21hcnRmaWxlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7O0FBUUE7SUFHRSxZQUFZLFVBQXdDO1FBQ2xELEVBQUUsQ0FBQyxDQUFDLFVBQVUsQ0FBQyxhQUFhLENBQUMsQ0FBQyxDQUFDO1lBQzdCLElBQUksQ0FBQyxRQUFRLEdBQUcsVUFBVSxDQUFDLGFBQWEsQ0FBQTtRQUMxQyxDQUFDO1FBQUMsSUFBSSxDQUFDLEVBQUUsQ0FBQSxDQUFDLFVBQVUsQ0FBQyxjQUFjLENBQUMsQ0FBQyxDQUFDO1lBQ3BDLElBQUksQ0FBQyxRQUFRLEdBQUcsSUFBSSxNQUFNLENBQUMsVUFBVSxDQUFDLGNBQWMsQ0FBQyxDQUFBO1FBQ3ZELENBQUM7UUFDRCxJQUFJLENBQUMsSUFBSSxHQUFHLFVBQVUsQ0FBQyxJQUFJLENBQUE7SUFDN0IsQ0FBQztJQUVEOzs7T0FHRztJQUNILG9CQUFvQixDQUFDLGFBQXFCO1FBQ3hDLElBQUksQ0FBQyxRQUFRLEdBQUcsSUFBSSxNQUFNLENBQUMsYUFBYSxDQUFDLENBQUE7SUFDM0MsQ0FBQztDQUNGO0FBbkJELDhCQW1CQyJ9

View File

@ -1,4 +1,5 @@
import 'typings-global';
import { Smartfile } from './smartfile.classes.smartfile';
/**
*
* @param filePath
@ -90,6 +91,7 @@ export declare let toObjectSync: (filePathArg: any, fileTypeArg?: any) => any;
* @returns {string|Buffer|any}
*/
export declare let toStringSync: (filePath: any) => any;
export declare let fileTreeToObject: (dirPathArg: string, miniMatchFilter: string) => Promise<Smartfile[]>;
/**
*
* @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";
Object.defineProperty(exports, "__esModule", { value: true });
require("typings-global");
const plugins = require("./smartfile.plugins");
exports.filetype = (pathArg) => {
@ -18,4 +19,4 @@ exports.objectFile = (fileStringArg, fileTypeArg) => {
break;
}
};
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRmaWxlLmludGVycHJldGVyLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRmaWxlLmludGVycHJldGVyLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSwwQkFBdUI7QUFFdkIsK0NBQStDO0FBRXBDLFFBQUEsUUFBUSxHQUFHLENBQUMsT0FBZTtJQUNsQyxJQUFJLE9BQU8sR0FBRyxPQUFPLENBQUMsSUFBSSxDQUFDLE9BQU8sQ0FBQyxPQUFPLENBQUMsQ0FBQTtJQUMzQyxJQUFJLFFBQVEsR0FBRyxPQUFPLENBQUMsT0FBTyxDQUFDLFlBQVksRUFBQyxJQUFJLENBQUMsQ0FBQSxDQUFDLHlCQUF5QjtJQUMzRSxNQUFNLENBQUMsUUFBUSxDQUFBO0FBQ25CLENBQUMsQ0FBQTtBQUVVLFFBQUEsVUFBVSxHQUFHLENBQUMsYUFBcUIsRUFBRSxXQUFXO0lBQ3ZELE1BQU0sQ0FBQyxDQUFDLFdBQVcsQ0FBQyxDQUFDLENBQUM7UUFDbEIsS0FBSyxLQUFLLENBQUU7UUFDWixLQUFLLE1BQU07WUFDUCxNQUFNLENBQUMsT0FBTyxDQUFDLElBQUksQ0FBQyxRQUFRLENBQUMsYUFBYSxDQUFDLENBQUE7UUFDL0MsS0FBSyxNQUFNO1lBQ1AsTUFBTSxDQUFDLElBQUksQ0FBQyxLQUFLLENBQUMsYUFBYSxDQUFDLENBQUE7UUFDcEM7WUFDSSxPQUFPLENBQUMsS0FBSyxDQUFDLFlBQVksR0FBRyxXQUFXLENBQUMsSUFBSSxHQUFHLGdCQUFnQixDQUFDLENBQUE7WUFDakUsS0FBSyxDQUFBO0lBQ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File diff suppressed because one or more lines are too long

View File

@ -1,4 +1,5 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
require("typings-global");
exports.fs = require("fs");
exports.fsExtra = require("fs-extra");
@ -10,4 +11,4 @@ exports.requireReload = require('require-reload');
exports.smartpath = require("smartpath");
exports.vinylFile = require('vinyl-file');
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";
Object.defineProperty(exports, "__esModule", { value: true });
require("typings-global");
const plugins = require("./smartfile.plugins");
/* export let toFs = function (from: string, toPath: string) {
@ -47,4 +48,4 @@ exports.toString = (fromArg) => {
});
return done.promise;
};
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRmaWxlLnJlbW90ZS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0ZmlsZS5yZW1vdGUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLDBCQUF1QjtBQUN2QiwrQ0FBK0M7QUFHL0M7Ozs7Ozs7SUFPSTtBQUVKOzs7O0dBSUc7QUFDUSxRQUFBLFFBQVEsR0FBRyxVQUFVLE9BQWU7SUFDN0MsSUFBSSxJQUFJLEdBQUcsT0FBTyxDQUFDLENBQUMsQ0FBQyxLQUFLLEVBQUUsQ0FBQTtJQUM1QixPQUFPLENBQUMsWUFBWSxDQUFDLE9BQU8sQ0FBQyxPQUFPLEVBQUU7UUFDcEMsTUFBTSxFQUFFLEtBQUs7S0FDZCxDQUFDLENBQUMsSUFBSSxDQUFDLENBQUMsR0FBUTtRQUNmLEVBQUUsQ0FBQyxDQUFDLEdBQUcsQ0FBQyxVQUFVLEtBQUssR0FBRyxDQUFDLENBQUMsQ0FBQztZQUMzQixJQUFJLENBQUMsT0FBTyxDQUFDLEdBQUcsQ0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UFJLElBQUksR0FBRyxPQUFPLENBQUMsQ0FBQyxDQUFDLEtBQUssRUFBRSxDQUFBO0lBQzVCLE9BQU8sQ0FBQyxZQUFZLENBQUMsR0FBRyxDQUFDLE9BQU8sQ0FBQyxDQUFDLElBQUksQ0FBQyxDQUFDLEdBQVE7UUFDOUMsRUFBRSxDQUFDLENBQUMsR0FBRyxDQUFDLFVBQVUsS0FBSyxHQUFHLENBQUMsQ0FBQyxDQUFDO1lBQzNCLElBQUksQ0FBQyxPQUFPLENBQUMsR0FBRyxDQUFDLElBQUksQ0FBQyxDQUFBO1FBQ3hCLENBQUM7UUFBQyxJQUFJLENBQUMsQ0FBQztZQUNOLE9BQU8sQ0FBQyxLQUFLLENBQUMsaUNBQWlDLEdBQUcsT0FBTyxDQUFDLENBQUE7WUFDMUQsSUFBSSxDQUFDLE1BQU0sQ0FBQyxJQUFJLEtBQUssQ0FBQyxpQ0FBaUMsR0FBRyxPQUFPLENBQUMsQ0FBQyxDQUFBO1FBQ3JFLENBQUM7SUFDSCxDQUFDLENBQUMsQ0FBQTtJQUNGLE1BQU0sQ0FBQyxJQUFJLENBQUMsT0FBTyxDQUFBO0FBQ3JCLENBQUMsQ0FBQSJ9

File diff suppressed because one or more lines are too long

View File

@ -7,221 +7,232 @@ import { expect } from 'smartchai'
import * as vinyl from 'vinyl'
describe('smartfile', function () {
describe('.fs', function () {
describe('.fileExistsSync', function () {
it('should return an accurate boolean', function () {
expect(smartfile.fs.fileExistsSync('./test/mytest.json')).to.be.true
expect(smartfile.fs.fileExistsSync('./test/notthere.json')).be.false
})
})
describe('.fileExists', function () {
it('should return a working promise', function () {
expect(smartfile.fs.fileExists('./test/mytest.json')).to.be.a('promise')
expect(smartfile.fs.fileExists('./test/mytest.json')).to.be.fulfilled
expect(smartfile.fs.fileExists('./test/notthere.json')).to.not.be.fulfilled
})
})
describe('.listFoldersSync()', function () {
it('should get the file type from a string', function () {
expect(smartfile.fs.listFoldersSync('./test/')).to.deep.include('testfolder')
expect(smartfile.fs.listFoldersSync('./test/')).to.not.deep.include('notExistentFolder')
})
})
describe('.listFolders()', function () {
it('should get the file type from a string', function (done) {
smartfile.fs.listFolders('./test/')
.then(function (folderArrayArg) {
expect(folderArrayArg).to.deep.include('testfolder')
expect(folderArrayArg).to.not.deep.include('notExistentFolder')
done()
})
})
})
describe('.listFilesSync()', function () {
it('should get the file type from a string', function () {
expect(smartfile.fs.listFilesSync('./test/')).to.deep.include('mytest.json')
expect(smartfile.fs.listFilesSync('./test/')).to.not.deep.include('notExistentFile')
expect(smartfile.fs.listFilesSync('./test/', /mytest\.json/)).to.deep.include('mytest.json')
expect(smartfile.fs.listFilesSync('./test/', /mytests.json/)).to.not.deep.include('mytest.json')
})
})
describe('.listFiles()', function () {
it('should get the file type from a string', function (done) {
smartfile.fs.listFiles('./test/')
.then(function (folderArrayArg) {
expect(folderArrayArg).to.deep.include('mytest.json')
expect(folderArrayArg).to.not.deep.include('notExistentFile')
done()
})
})
})
describe('.listFileTree()', function () {
it('should get a file tree', function (done) {
smartfile.fs.listFileTree(path.resolve('./test/'), '**/*.txt')
.then(function (folderArrayArg) {
expect(folderArrayArg).to.deep.include('testfolder/testfile1.txt')
expect(folderArrayArg).to.not.deep.include('mytest.json')
done()
})
})
})
describe('.copy()', function () {
it('should copy a directory', function () {
smartfile.fs.copy('./test/testfolder/', './test/temp/')
})
it('should copy a file', function () {
smartfile.fs.copy('./test/mytest.yaml', './test/temp/')
})
it('should copy a file and rename it', function () {
smartfile.fs.copy('./test/mytest.yaml', './test/temp/mytestRenamed.yaml')
})
})
describe('.remove()', function () {
it('should remove an entire directory', function () {
})
it('smartfile.fs.remove -> should remove single files', function (done) {
smartfile.fs.remove('./test/temp/mytestRenamed.yaml')
.then(() => { done() })
})
it('smartfile.fs.removeSync -> should remove single files synchronouly',function() {
smartfile.fs.removeSync('./test/temp/testfile1.txt')
expect(smartfile.fs.fileExistsSync('./test/temp/testfile1.txt')).to.be.false
})
it('smartfile.fs.removeMany -> should remove and array of files',function(done) {
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/testfile2.txt')).to.be.false
done()
})
})
it('smartfile.fs.removeManySync -> should remove and array of single files synchronouly',function() {
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/testfile2.txt')).to.be.false
})
})
describe('.fs', function () {
describe('.fileExistsSync', function () {
it('should return an accurate boolean', function () {
expect(smartfile.fs.fileExistsSync('./test/mytest.json')).to.be.true
expect(smartfile.fs.fileExistsSync('./test/notthere.json')).be.false
})
})
describe('.fileExists', function () {
it('should return a working promise', function () {
expect(smartfile.fs.fileExists('./test/mytest.json')).to.be.a('promise')
expect(smartfile.fs.fileExists('./test/mytest.json')).to.be.fulfilled
expect(smartfile.fs.fileExists('./test/notthere.json')).to.not.be.fulfilled
})
})
describe('.listFoldersSync()', function () {
it('should get the file type from a string', function () {
expect(smartfile.fs.listFoldersSync('./test/')).to.deep.include('testfolder')
expect(smartfile.fs.listFoldersSync('./test/')).to.not.deep.include('notExistentFolder')
})
})
describe('.listFolders()', function () {
it('should get the file type from a string', function (done) {
smartfile.fs.listFolders('./test/')
.then(function (folderArrayArg) {
expect(folderArrayArg).to.deep.include('testfolder')
expect(folderArrayArg).to.not.deep.include('notExistentFolder')
done()
})
})
})
describe('.listFilesSync()', function () {
it('should get the file type from a string', function () {
expect(smartfile.fs.listFilesSync('./test/')).to.deep.include('mytest.json')
expect(smartfile.fs.listFilesSync('./test/')).to.not.deep.include('notExistentFile')
expect(smartfile.fs.listFilesSync('./test/', /mytest\.json/)).to.deep.include('mytest.json')
expect(smartfile.fs.listFilesSync('./test/', /mytests.json/)).to.not.deep.include('mytest.json')
})
})
describe('.listFiles()', function () {
it('should get the file type from a string', function (done) {
smartfile.fs.listFiles('./test/')
.then(function (folderArrayArg) {
expect(folderArrayArg).to.deep.include('mytest.json')
expect(folderArrayArg).to.not.deep.include('notExistentFile')
done()
})
})
})
describe('.listFileTree()', function () {
it('should get a file tree', function (done) {
smartfile.fs.listFileTree(path.resolve('./test/'), '**/*.txt')
.then(function (folderArrayArg) {
expect(folderArrayArg).to.deep.include('testfolder/testfile1.txt')
expect(folderArrayArg).to.not.deep.include('mytest.json')
done()
})
})
})
describe('.interpreter', function () {
describe('.filetype()', function () {
it('should get the file type from a string', function () {
expect(smartfile.interpreter.filetype('./somefolder/data.json')).equal('json')
})
})
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('.fs', function () {
describe('.toObjectSync()', function () {
it('should read an ' + '.yaml' + ' file to an object', function () {
let testData = smartfile.fs.toObjectSync('./test/mytest.yaml')
expect(testData).have.property('key1', 'this works')
expect(testData).have.property('key2', 'this works too')
})
it('should state unknown file type for unknown file types', function () {
let testData = smartfile.fs.toObjectSync('./test/mytest.txt')
})
it('should read an ' + '.json' + ' file to an object', function () {
let testData = smartfile.fs.toObjectSync('./test/mytest.json')
expect(testData).have.property('key1', 'this works')
expect(testData).have.property('key2', 'this works too')
})
})
describe('.toStringSync()', function () {
it('should read a file to a string', function () {
expect(smartfile.fs.toStringSync('./test/mytest.txt'))
.to.equal('Some TestString &&%$')
})
})
describe('.toVinylSync', function () {
it('should read an ' + '.json OR .yaml' + ' file to an ' + 'vinyl file object', function () {
let testData = smartfile.fs.toVinylSync('./test/mytest.json')
expect(vinyl.isVinyl(testData)).to.be.true
})
})
describe('.copy()', function () {
it('should copy a directory', function () {
smartfile.fs.copy('./test/testfolder/', './test/temp/')
})
it('should copy a file', function () {
smartfile.fs.copy('./test/mytest.yaml', './test/temp/')
})
it('should copy a file and rename it', function () {
smartfile.fs.copy('./test/mytest.yaml', './test/temp/mytestRenamed.yaml')
})
})
describe('.remove()', function () {
it('should remove an entire directory', function () {
describe('.memory', function () {
describe('.toGulpStream()', function () {
it('should produce a valid gulp stream', function () {
let localArray = ['test1', 'test2', 'test3']
smartfile.memory.toGulpStream(localArray)
})
})
describe('toVinylFileSync()', function () {
it('should produce a vinylFile', function () {
let localString = 'myString'
let localOptions = { filename: 'vinylfile2', base: '/someDir' }
expect(smartfile.memory.toVinylFileSync(localString, localOptions) instanceof vinyl).to.be.true
})
})
describe('toVinylArraySync()', function () {
it('should produce a an array of vinylfiles', function () {
let localStringArray = ['string1', 'string2', 'string3']
let localOptions = { filename: 'vinylfile2', base: '/someDir' }
let testResult = smartfile.memory.toVinylArraySync(localStringArray, localOptions)
expect(testResult).to.be.a('array')
expect(testResult.length === 3).to.be.true
for (let myKey in testResult) {
expect(testResult[myKey] instanceof vinyl).to.be.true
}
})
})
describe('vinylToStringSync()', function () {
it('should produce a String from vinyl file', function () {
let localString = smartfile.memory.vinylToStringSync(new vinyl({
base: '/',
path: '/test.txt',
contents: new Buffer('myString')
}))
expect(localString).equal('myString')
})
})
describe('toFs()', function () {
it('should write a file to disk and return a promise', function (done) {
let localString = 'myString'
smartfile.memory.toFs(
localString,
path.join(process.cwd(), './test/temp/testMemToFs.txt')
).then(done)
})
})
describe('toFsSync()', function () {
it('should write a file to disk and return true if successfull', function () {
let localString = 'myString'
smartfile.memory.toFsSync(
localString,
path.join(process.cwd(), './test/temp/testMemToFsSync.txt')
)
})
})
it('smartfile.fs.remove -> should remove single files', function (done) {
smartfile.fs.remove('./test/temp/mytestRenamed.yaml')
.then(() => { done() })
})
it('smartfile.fs.removeSync -> should remove single files synchronouly', function () {
smartfile.fs.removeSync('./test/temp/testfile1.txt')
expect(smartfile.fs.fileExistsSync('./test/temp/testfile1.txt')).to.be.false
})
it('smartfile.fs.removeMany -> should remove and array of files', function (done) {
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/testfile2.txt')).to.be.false
done()
})
})
it('smartfile.fs.removeManySync -> should remove and array of single files synchronouly', function () {
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/testfile2.txt')).to.be.false
})
})
})
describe('.remote', function () {
describe('.toString()', function () {
it('should load a remote file to a variable', function (done) {
this.timeout(5000)
smartfile.remote.toString(
'https://raw.githubusercontent.com/pushrocks/smartfile/master/test/mytest.txt'
).then(function (responseString) {
expect(responseString).to.equal('Some TestString &&%$')
done()
})
})
it('should reject a Promise when the link is false', function (done) {
this.timeout(10000)
smartfile.remote.toString('https://push.rocks/doesnotexist.txt')
.then(
function () {
throw new Error('this test should not be resolved')
},
function () {
done()
}
)
})
})
describe('.interpreter', function () {
describe('.filetype()', function () {
it('should get the file type from a string', function () {
expect(smartfile.interpreter.filetype('./somefolder/data.json')).equal('json')
})
})
})
describe('.fs', function () {
describe('.toObjectSync()', function () {
it('should read an ' + '.yaml' + ' file to an object', function () {
let testData = smartfile.fs.toObjectSync('./test/mytest.yaml')
expect(testData).have.property('key1', 'this works')
expect(testData).have.property('key2', 'this works too')
})
it('should state unknown file type for unknown file types', function () {
let testData = smartfile.fs.toObjectSync('./test/mytest.txt')
})
it('should read an ' + '.json' + ' file to an object', function () {
let testData = smartfile.fs.toObjectSync('./test/mytest.json')
expect(testData).have.property('key1', 'this works')
expect(testData).have.property('key2', 'this works too')
})
})
describe('.toStringSync()', function () {
it('should read a file to a string', function () {
expect(smartfile.fs.toStringSync('./test/mytest.txt'))
.to.equal('Some TestString &&%$')
})
})
describe('.toVinylSync', function () {
it('should read an ' + '.json OR .yaml' + ' file to an ' + 'vinyl file object', function () {
let testData = smartfile.fs.toVinylSync('./test/mytest.json')
expect(vinyl.isVinyl(testData)).to.be.true
})
})
})
describe('.memory', function () {
describe('.toGulpStream()', function () {
it('should produce a valid gulp stream', function () {
let localArray = [ 'test1', 'test2', 'test3' ]
smartfile.memory.toGulpStream(localArray)
})
})
describe('toVinylFileSync()', function () {
it('should produce a vinylFile', function () {
let localString = 'myString'
let localOptions = { filename: 'vinylfile2', base: '/someDir' }
expect(smartfile.memory.toVinylFileSync(localString, localOptions) instanceof vinyl).to.be.true
})
})
describe('toVinylArraySync()', function () {
it('should produce a an array of vinylfiles', function () {
let localStringArray = [ 'string1', 'string2', 'string3' ]
let localOptions = { filename: 'vinylfile2', base: '/someDir' }
let testResult = smartfile.memory.toVinylArraySync(localStringArray, localOptions)
expect(testResult).to.be.a('array')
expect(testResult.length === 3).to.be.true
for (let myKey in testResult) {
expect(testResult[ myKey ] instanceof vinyl).to.be.true
}
})
})
describe('vinylToStringSync()', function () {
it('should produce a String from vinyl file', function () {
let localString = smartfile.memory.vinylToStringSync(new vinyl({
base: '/',
path: '/test.txt',
contents: new Buffer('myString')
}))
expect(localString).equal('myString')
})
})
describe('toFs()', function () {
it('should write a file to disk and return a promise', function (done) {
let localString = 'myString'
smartfile.memory.toFs(
localString,
path.join(process.cwd(), './test/temp/testMemToFs.txt')
).then(done)
})
})
describe('toFsSync()', function () {
it('should write a file to disk and return true if successfull', function () {
let localString = 'myString'
smartfile.memory.toFsSync(
localString,
path.join(process.cwd(), './test/temp/testMemToFsSync.txt')
)
})
})
})
describe('.remote', function () {
describe('.toString()', function () {
it('should load a remote file to a variable', function (done) {
this.timeout(5000)
smartfile.remote.toString(
'https://raw.githubusercontent.com/pushrocks/smartfile/master/test/mytest.txt'
).then(function (responseString) {
expect(responseString).to.equal('Some TestString &&%$')
done()
})
})
it('should reject a Promise when the link is false', function (done) {
this.timeout(10000)
smartfile.remote.toString('https://push.rocks/doesnotexist.txt')
.then(
function () {
throw new Error('this test should not be resolved')
},
function () {
done()
}
)
})
})
})
})

View File

@ -1,5 +1,28 @@
export class Smartfile {
constructor() {
import * as plugins from './smartfile.plugins'
}
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 SmartfileInterpreter = require('./smartfile.interpreter')
import { Smartfile } from './smartfile.classes.smartfile'
import * as memory from './smartfile.memory'
/*===============================================================
============================ Checks =============================
@ -12,15 +15,15 @@ import * as memory from './smartfile.memory'
* @param filePath
* @returns {boolean}
*/
export let fileExistsSync = function(filePath): boolean {
let fileExistsBool: boolean = false
try {
plugins.fsExtra.readFileSync(filePath)
fileExistsBool = true
} catch (err) {
fileExistsBool = false
}
return fileExistsBool
export let fileExistsSync = function (filePath): boolean {
let fileExistsBool: boolean = false
try {
plugins.fsExtra.readFileSync(filePath)
fileExistsBool = true
} catch (err) {
fileExistsBool = false
}
return fileExistsBool
}
/**
@ -28,26 +31,26 @@ export let fileExistsSync = function(filePath): boolean {
* @param filePath
* @returns {any}
*/
export let fileExists = function(filePath){
let done = plugins.q.defer()
plugins.fs.access(filePath, 4, function (err) {
err ? done.reject(err) : done.resolve()
})
return done.promise
export let fileExists = function (filePath) {
let done = plugins.q.defer()
plugins.fs.access(filePath, 4, function (err) {
err ? done.reject(err) : done.resolve()
})
return done.promise
}
/**
* Checks if given path points to an existing directory
*/
export let isDirectory = function(pathArg): boolean{
return plugins.fsExtra.statSync(pathArg).isDirectory()
export let isDirectory = function (pathArg): boolean {
return plugins.fsExtra.statSync(pathArg).isDirectory()
}
/**
* Checks if a given path points to an existing file
*/
export let isFile = function(pathArg): boolean{
return plugins.fsExtra.statSync(pathArg).isFile()
export let isFile = function (pathArg): boolean {
return plugins.fsExtra.statSync(pathArg).isFile()
}
/*===============================================================
@ -57,36 +60,36 @@ export let isFile = function(pathArg): boolean{
/**
* copies a file from A to B on the local disk
*/
export let copy = function(fromArg: string, toArg: string){
let done = plugins.q.defer()
plugins.fsExtra.copy(fromArg,toArg,{},function(){
done.resolve()
})
return done.promise
export let copy = function (fromArg: string, toArg: string) {
let done = plugins.q.defer()
plugins.fsExtra.copy(fromArg, toArg, {}, function () {
done.resolve()
})
return done.promise
}
/**
* copies a file SYNCHRONOUSLY from A to B on the local disk
*/
export let copySync = function(fromArg: string,toArg: string): boolean{
plugins.fsExtra.copySync(fromArg,toArg)
return true
export let copySync = function (fromArg: string, toArg: string): boolean {
plugins.fsExtra.copySync(fromArg, toArg)
return true
}
/**
* ensures that a directory is in place
*/
export let ensureDir = (dirPathArg: string) => {
let done = plugins.q.defer()
plugins.fsExtra.ensureDir(dirPathArg,done.resolve)
return done.promise
let done = plugins.q.defer()
plugins.fsExtra.ensureDir(dirPathArg, done.resolve)
return done.promise
}
/**
* ensures that a directory is in place
*/
export let ensureDirSync = (dirPathArg: string) => {
plugins.fsExtra.ensureDirSync(dirPathArg)
plugins.fsExtra.ensureDirSync(dirPathArg)
}
/**
@ -94,11 +97,11 @@ export let ensureDirSync = (dirPathArg: string) => {
* @executes ASYNC
*/
export let ensureEmptyDir = (dirPathArg: string) => {
let done = plugins.q.defer()
plugins.fsExtra.ensureDir(dirPathArg,() => {
plugins.fsExtra.emptyDir(dirPathArg, done.resolve)
})
return done.promise
let done = plugins.q.defer()
plugins.fsExtra.ensureDir(dirPathArg, () => {
plugins.fsExtra.emptyDir(dirPathArg, done.resolve)
})
return done.promise
}
/**
@ -106,8 +109,8 @@ export let ensureEmptyDir = (dirPathArg: string) => {
* @executes SYNC
*/
export let ensureEmptyDirSync = (dirPathArg: string) => {
plugins.fsExtra.ensureDirSync(dirPathArg)
plugins.fsExtra.emptyDirSync(dirPathArg)
plugins.fsExtra.ensureDirSync(dirPathArg)
plugins.fsExtra.emptyDirSync(dirPathArg)
}
/**
@ -118,10 +121,10 @@ export let ensureEmptyDirSync = (dirPathArg: string) => {
* @exec ASYNC
*/
export let ensureFile = (filePathArg, initFileStringArg): Promise<void> => {
let done = plugins.q.defer<void>()
ensureFileSync(filePathArg, initFileStringArg)
done.resolve()
return done.promise
let done = plugins.q.defer<void>()
ensureFileSync(filePathArg, initFileStringArg)
done.resolve()
return done.promise
}
/**
@ -132,50 +135,50 @@ export let ensureFile = (filePathArg, initFileStringArg): Promise<void> => {
* @exec SYNC
*/
export let ensureFileSync = (filePathArg: string, initFileStringArg: string): void => {
if (fileExistsSync(filePathArg)) {
return null
} else {
memory.toFsSync(initFileStringArg, filePathArg)
}
if (fileExistsSync(filePathArg)) {
return null
} else {
memory.toFsSync(initFileStringArg, filePathArg)
}
}
/**
* removes a file or folder from local disk
*/
export let remove = function(pathArg: string): Promise<void> {
let done = plugins.q.defer<void>()
plugins.fsExtra.remove(pathArg,function(){
done.resolve()
})
return done.promise
export let remove = function (pathArg: string): Promise<void> {
let done = plugins.q.defer<void>()
plugins.fsExtra.remove(pathArg, function () {
done.resolve()
})
return done.promise
}
/**
* removes a file SYNCHRONOUSLY from local disk
*/
export let removeSync = function(pathArg: string): boolean{
plugins.fsExtra.removeSync(pathArg)
return true
export let removeSync = function (pathArg: string): boolean {
plugins.fsExtra.removeSync(pathArg)
return true
}
/**
* removes an array of filePaths from disk
*/
export let removeMany = function(filePathArrayArg: string[]){
let promiseArray: Promise<void>[] = []
for (let filePath of filePathArrayArg) {
promiseArray.push(remove(filePath))
}
return Promise.all(promiseArray)
export let removeMany = function (filePathArrayArg: string[]) {
let promiseArray: Promise<void>[] = []
for (let filePath of filePathArrayArg) {
promiseArray.push(remove(filePath))
}
return Promise.all(promiseArray)
}
/**
* like removeFilePathArray but SYNCHRONOUSLY
*/
export let removeManySync = function(filePathArrayArg: string[]): void {
for (let filePath of filePathArrayArg) {
removeSync(filePath)
}
export let removeManySync = function (filePathArrayArg: string[]): void {
for (let filePath of filePathArrayArg) {
removeSync(filePath)
}
}
/*===============================================================
@ -188,11 +191,11 @@ export let removeManySync = function(filePathArrayArg: string[]): void {
* @param fileTypeArg
* @returns {any}
*/
export let toObjectSync = function(filePathArg,fileTypeArg?) {
let fileString = plugins.fsExtra.readFileSync(filePathArg, 'utf8')
let fileType
fileTypeArg ? fileType = fileTypeArg : fileType = SmartfileInterpreter.filetype(filePathArg)
return SmartfileInterpreter.objectFile(fileString,fileType)
export let toObjectSync = function (filePathArg, fileTypeArg?) {
let fileString = plugins.fsExtra.readFileSync(filePathArg, 'utf8')
let fileType
fileTypeArg ? fileType = fileTypeArg : fileType = SmartfileInterpreter.filetype(filePathArg)
return SmartfileInterpreter.objectFile(fileString, fileType)
}
/**
@ -200,10 +203,22 @@ export let toObjectSync = function(filePathArg,fileTypeArg?) {
* @param filePath
* @returns {string|Buffer|any}
*/
export let toStringSync = function(filePath) {
let fileString
fileString = plugins.fsExtra.readFileSync(filePath, 'utf8')
return fileString
export let toStringSync = function (filePath) {
let fileString
fileString = plugins.fsExtra.readFileSync(filePath, 'utf8')
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
}
/**
@ -212,8 +227,8 @@ export let toStringSync = function(filePath) {
* @param options
* @returns {number}
*/
export let toVinylSync = function(filePathArg,options = {}) {
return plugins.vinylFile.readSync(filePathArg,options)
export let toVinylSync = function (filePathArg, options = {}) {
return plugins.vinylFile.readSync(filePathArg, options)
}
/**
@ -221,92 +236,92 @@ export let toVinylSync = function(filePathArg,options = {}) {
* @param path
* @returns {any}
*/
export let requireReload = function(path: string){
return plugins.requireReload(path)
export let requireReload = function (path: string) {
return plugins.requireReload(path)
}
/**
* lists Folders in a directory on local disk
* @returns Promise
*/
export let listFolders = function(pathArg: string,regexFilter?: RegExp){
let done = plugins.q.defer()
let folderArray = plugins.fsExtra.readdirSync(pathArg).filter(function(file) {
return plugins.fsExtra.statSync(plugins.path.join(pathArg, file)).isDirectory()
export let listFolders = function (pathArg: string, regexFilter?: RegExp) {
let done = plugins.q.defer()
let folderArray = plugins.fsExtra.readdirSync(pathArg).filter(function (file) {
return plugins.fsExtra.statSync(plugins.path.join(pathArg, file)).isDirectory()
})
if (regexFilter) {
folderArray = folderArray.filter((fileItem) => {
return regexFilter.test(fileItem)
})
if (regexFilter) {
folderArray = folderArray.filter((fileItem) => {
return regexFilter.test(fileItem)
})
}
done.resolve(folderArray)
return done.promise
}
done.resolve(folderArray)
return done.promise
}
/**
* lists Folders SYNCHRONOUSLY in a directory on local disk
* @returns an array with the folder names as strings
*/
export let listFoldersSync = function(pathArg: string,regexFilter?: RegExp): string[]{
let folderArray = plugins.fsExtra.readdirSync(pathArg).filter(function(file) {
return plugins.fsExtra.statSync(plugins.path.join(pathArg, file)).isDirectory()
export let listFoldersSync = function (pathArg: string, regexFilter?: RegExp): string[] {
let folderArray = plugins.fsExtra.readdirSync(pathArg).filter(function (file) {
return plugins.fsExtra.statSync(plugins.path.join(pathArg, file)).isDirectory()
})
if (regexFilter) {
folderArray = folderArray.filter((fileItem) => {
return regexFilter.test(fileItem)
})
if (regexFilter) {
folderArray = folderArray.filter((fileItem) => {
return regexFilter.test(fileItem)
})
}
return folderArray
}
return folderArray
}
/**
* lists Files in a directory on local disk
* @returns Promise
*/
export let listFiles = function(pathArg: string, regexFilter?: RegExp){
let done = plugins.q.defer()
let fileArray = plugins.fsExtra.readdirSync(pathArg).filter(function(file) {
return plugins.fsExtra.statSync(plugins.path.join(pathArg, file)).isFile()
export let listFiles = function (pathArg: string, regexFilter?: RegExp) {
let done = plugins.q.defer()
let fileArray = plugins.fsExtra.readdirSync(pathArg).filter(function (file) {
return plugins.fsExtra.statSync(plugins.path.join(pathArg, file)).isFile()
})
if (regexFilter) {
fileArray = fileArray.filter((fileItem) => {
return regexFilter.test(fileItem)
})
if (regexFilter) {
fileArray = fileArray.filter((fileItem) => {
return regexFilter.test(fileItem)
})
}
done.resolve(fileArray)
return done.promise
}
done.resolve(fileArray)
return done.promise
}
/**
* lists Files SYNCHRONOUSLY in a directory on local disk
* @returns an array with the folder names as strings
*/
export let listFilesSync = function(pathArg: string, regexFilter?: RegExp): string[]{
let fileArray = plugins.fsExtra.readdirSync(pathArg).filter(function(file) {
return plugins.fsExtra.statSync(plugins.path.join(pathArg, file)).isFile()
export let listFilesSync = function (pathArg: string, regexFilter?: RegExp): string[] {
let fileArray = plugins.fsExtra.readdirSync(pathArg).filter(function (file) {
return plugins.fsExtra.statSync(plugins.path.join(pathArg, file)).isFile()
})
if (regexFilter) {
fileArray = fileArray.filter((fileItem) => {
return regexFilter.test(fileItem)
})
if (regexFilter) {
fileArray = fileArray.filter((fileItem) => {
return regexFilter.test(fileItem)
})
}
return fileArray
}
return fileArray
}
/**
* lists all items (folders AND files) in a directory on local disk
* @returns Promise<string[]>
*/
export let listAllItems = function(pathArg: string, regexFilter?: RegExp): Promise<string[]> {
let done = plugins.q.defer<string[]>()
let allItmesArray = plugins.fsExtra.readdirSync(pathArg)
if (regexFilter) {
allItmesArray = allItmesArray.filter((fileItem) => {
return regexFilter.test(fileItem)
})
};
done.resolve(allItmesArray)
return done.promise
export let listAllItems = function (pathArg: string, regexFilter?: RegExp): Promise<string[]> {
let done = plugins.q.defer<string[]>()
let allItmesArray = plugins.fsExtra.readdirSync(pathArg)
if (regexFilter) {
allItmesArray = allItmesArray.filter((fileItem) => {
return regexFilter.test(fileItem)
})
};
done.resolve(allItmesArray)
return done.promise
}
/**
@ -314,16 +329,16 @@ export let listAllItems = function(pathArg: string, regexFilter?: RegExp): Promi
* @returns an array with the folder names as strings
* @executes SYNC
*/
export let listAllItemsSync = function(pathArg: string, regexFilter?: RegExp): string[]{
let allItmesArray = plugins.fsExtra.readdirSync(pathArg).filter(function(file) {
return plugins.fsExtra.statSync(plugins.path.join(pathArg, file)).isFile()
export let listAllItemsSync = function (pathArg: string, regexFilter?: RegExp): string[] {
let allItmesArray = plugins.fsExtra.readdirSync(pathArg).filter(function (file) {
return plugins.fsExtra.statSync(plugins.path.join(pathArg, file)).isFile()
})
if (regexFilter) {
allItmesArray = allItmesArray.filter((fileItem) => {
return regexFilter.test(fileItem)
})
if (regexFilter) {
allItmesArray = allItmesArray.filter((fileItem) => {
return regexFilter.test(fileItem)
})
}
return allItmesArray
}
return allItmesArray
}
/**
@ -332,25 +347,25 @@ export let listAllItemsSync = function(pathArg: string, regexFilter?: RegExp): s
* @returns Promise<string[]> string array with the absolute paths of all matching files
*/
export let listFileTree = (dirPathArg: string, miniMatchFilter: string): Promise<string[]> => {
let done = plugins.q.defer<string[]>()
let done = plugins.q.defer<string[]>()
// handle absolute miniMatchFilter
let dirPath: string
if (plugins.path.isAbsolute(miniMatchFilter)) {
dirPath = '/'
} else {
dirPath = dirPathArg
}
// handle absolute miniMatchFilter
let dirPath: string
if (plugins.path.isAbsolute(miniMatchFilter)) {
dirPath = '/'
} else {
dirPath = dirPathArg
}
let options = {
cwd: dirPath
let options = {
cwd: dirPath
}
plugins.glob(miniMatchFilter, options, (err, files: string[]) => {
if (err) {
console.log(err)
done.reject(err)
}
plugins.glob(miniMatchFilter,options,(err,files: string[]) => {
if (err) {
console.log(err)
done.reject(err)
}
done.resolve(files)
})
return done.promise
done.resolve(files)
})
return done.promise
}