fix(core): update

This commit is contained in:
Philipp Kunz 2019-01-27 03:11:10 +01:00
parent db1d2acb47
commit 69433b242b
4 changed files with 680 additions and 144 deletions

735
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -35,17 +35,17 @@
"@types/vinyl": "^2.0.2", "@types/vinyl": "^2.0.2",
"fs-extra": "^7.0.1", "fs-extra": "^7.0.1",
"glob": "^7.1.3", "glob": "^7.1.3",
"js-yaml": "^3.10.0", "js-yaml": "^3.12.1",
"vinyl-file": "^3.0.0" "vinyl-file": "^3.0.0"
}, },
"devDependencies": { "devDependencies": {
"@gitzone/tsbuild": "^2.0.22", "@gitzone/tsbuild": "^2.1.5",
"@gitzone/tsrun": "^1.1.13", "@gitzone/tsrun": "^1.1.17",
"@gitzone/tstest": "^1.0.15", "@gitzone/tstest": "^1.0.18",
"@pushrocks/tapbundle": "^3.0.7", "@pushrocks/tapbundle": "^3.0.7",
"@types/node": "^10.12.10", "@types/node": "^10.12.18",
"gulp-function": "^2.2.14", "gulp-function": "^2.2.14",
"tslint": "^5.11.0", "tslint": "^5.12.1",
"tslint-config-prettier": "^1.16.0" "tslint-config-prettier": "^1.17.0"
} }
} }

View File

@ -14,6 +14,28 @@ export interface ISmartfileConstructorOptions {
* -> is vinyl file compatible * -> is vinyl file compatible
*/ */
export class Smartfile { export class Smartfile {
// ======
// STATIC
// ======
/**
* creates a Smartfile from a filePath
* @param filePath
*/
public static async fromFilePath (filePath: string) {
filePath = plugins.path.resolve(filePath);
const fileString = fs.toStringSync(filePath);
const smartfile = new Smartfile({
path: filePath,
contentString: fileString
});
return smartfile;
}
// ========
// INSTANCE
// ========
/** /**
* the full path of the file on disk * the full path of the file on disk
*/ */

View File

@ -29,9 +29,9 @@ export let fileExistsSync = function(filePath): boolean {
* @param filePath * @param filePath
* @returns {any} * @returns {any}
*/ */
export let fileExists = function(filePath) { export let fileExists = (filePath): Promise<void> => {
let done = plugins.smartpromise.defer(); let done = plugins.smartpromise.defer<void>();
plugins.fs.access(filePath, 4, function(err) { plugins.fs.access(filePath, 4, err => {
err ? done.reject(err) : done.resolve(); err ? done.reject(err) : done.resolve();
}); });
return done.promise; return done.promise;
@ -194,7 +194,7 @@ export let removeManySync = function(filePathArrayArg: string[]): void {
* @returns {any} * @returns {any}
*/ */
export let toObjectSync = function(filePathArg, fileTypeArg?) { export let toObjectSync = function(filePathArg, fileTypeArg?) {
let fileString = plugins.fsExtra.readFileSync(filePathArg, 'utf8'); const 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);
@ -206,7 +206,7 @@ export let toObjectSync = function(filePathArg, fileTypeArg?) {
* @returns {string|Buffer|any} * @returns {string|Buffer|any}
*/ */
export let toStringSync = function(filePath: string): string { export let toStringSync = function(filePath: string): string {
let fileString: any = plugins.fsExtra.readFileSync(filePath, 'utf8'); const fileString: string = plugins.fsExtra.readFileSync(filePath, 'utf8');
return fileString; return fileString;
}; };
@ -257,11 +257,8 @@ export let toVinylSync = function(filePathArg, options = {}) {
* lists Folders in a directory on local disk * lists Folders in a directory on local disk
* @returns Promise with an array that contains the folder names * @returns Promise with an array that contains the folder names
*/ */
export let listFolders = (pathArg: string, regexFilter?: RegExp): Promise<string[]> => { export let listFolders = async (pathArg: string, regexFilter?: RegExp): Promise<string[]> => {
const done = plugins.smartpromise.defer<string[]>(); return listFoldersSync(pathArg, regexFilter);
const folderArray = listFoldersSync(pathArg, regexFilter);
done.resolve(folderArray);
return done.promise;
}; };
/** /**
@ -284,26 +281,16 @@ export let listFoldersSync = (pathArg: string, regexFilter?: RegExp): string[] =
* 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 = async (pathArg: string, regexFilter?: RegExp): Promise<string[]> => {
let done = plugins.smartpromise.defer(); return listFilesSync(pathArg, regexFilter);
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);
});
}
done.resolve(fileArray);
return done.promise;
}; };
/** /**
* 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 = (pathArg: string, regexFilter?: RegExp): string[] => {
let fileArray = plugins.fsExtra.readdirSync(pathArg).filter(function(file) { let fileArray = plugins.fsExtra.readdirSync(pathArg).filter(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) {
@ -318,16 +305,8 @@ 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 = async (pathArg: string, regexFilter?: RegExp): Promise<string[]> => {
let done = plugins.smartpromise.defer<string[]>(); return listAllItemsSync(pathArg, regexFilter);
let allItmesArray = plugins.fsExtra.readdirSync(pathArg);
if (regexFilter) {
allItmesArray = allItmesArray.filter(fileItem => {
return regexFilter.test(fileItem);
});
}
done.resolve(allItmesArray);
return done.promise;
}; };
/** /**
@ -335,7 +314,7 @@ 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 = (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();
}); });
@ -353,7 +332,7 @@ export let listAllItemsSync = function(pathArg: string, regexFilter?: RegExp): s
* @returns Promise<string[]> string array with the absolute paths of all matching files * @returns Promise<string[]> string array with the absolute paths of all matching files
*/ */
export let listFileTree = (dirPathArg: string, miniMatchFilter: string): Promise<string[]> => { export let listFileTree = (dirPathArg: string, miniMatchFilter: string): Promise<string[]> => {
let done = plugins.smartpromise.defer<string[]>(); const done = plugins.smartpromise.defer<string[]>();
// handle absolute miniMatchFilter // handle absolute miniMatchFilter
let dirPath: string; let dirPath: string;
@ -363,7 +342,7 @@ export let listFileTree = (dirPathArg: string, miniMatchFilter: string): Promise
dirPath = dirPathArg; dirPath = dirPathArg;
} }
let options = { const options = {
cwd: dirPath, cwd: dirPath,
nodir: true, nodir: true,
dot: true dot: true