Compare commits
8 Commits
Author | SHA1 | Date | |
---|---|---|---|
15044149f2 | |||
c92b759432 | |||
9b8f055ec2 | |||
69433b242b | |||
db1d2acb47 | |||
920552ea23 | |||
dd05708f28 | |||
d97abe443d |
4
.snyk
Normal file
4
.snyk
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
# Snyk (https://snyk.io) policy file, patches or ignores known vulnerabilities.
|
||||||
|
version: v1.13.1
|
||||||
|
ignore: {}
|
||||||
|
patch: {}
|
743
package-lock.json
generated
743
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
18
package.json
18
package.json
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartfile",
|
"name": "@pushrocks/smartfile",
|
||||||
"private": false,
|
"private": false,
|
||||||
"version": "6.0.9",
|
"version": "7.0.0",
|
||||||
"description": "offers smart ways to work with files in nodejs",
|
"description": "offers smart ways to work with files in nodejs",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"typings": "dist/index.d.ts",
|
"typings": "dist/index.d.ts",
|
||||||
@ -31,21 +31,21 @@
|
|||||||
"@pushrocks/smartpath": "^4.0.1",
|
"@pushrocks/smartpath": "^4.0.1",
|
||||||
"@pushrocks/smartpromise": "^2.0.5",
|
"@pushrocks/smartpromise": "^2.0.5",
|
||||||
"@pushrocks/smartrequest": "^1.1.14",
|
"@pushrocks/smartrequest": "^1.1.14",
|
||||||
"@types/fs-extra": "^5.0.4",
|
"@types/fs-extra": "^5.0.5",
|
||||||
"@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.8",
|
||||||
"@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": "^11.9.4",
|
||||||
"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.18.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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
|
||||||
*/
|
*/
|
||||||
|
@ -29,10 +29,10 @@ export let fileExistsSync = function(filePath): boolean {
|
|||||||
* @param filePath
|
* @param filePath
|
||||||
* @returns {any}
|
* @returns {any}
|
||||||
*/
|
*/
|
||||||
export let fileExists = function(filePath) {
|
export let fileExists = (filePath): Promise<boolean> => {
|
||||||
let done = plugins.smartpromise.defer();
|
const done = plugins.smartpromise.defer<boolean>();
|
||||||
plugins.fs.access(filePath, 4, function(err) {
|
plugins.fs.access(filePath, 4, err => {
|
||||||
err ? done.reject(err) : done.resolve();
|
err ? done.resolve(false) : done.resolve(true);
|
||||||
});
|
});
|
||||||
return done.promise;
|
return done.promise;
|
||||||
};
|
};
|
||||||
@ -40,7 +40,7 @@ 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 = (pathArg): boolean => {
|
||||||
try {
|
try {
|
||||||
return plugins.fsExtra.statSync(pathArg).isDirectory();
|
return plugins.fsExtra.statSync(pathArg).isDirectory();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@ -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,26 +257,16 @@ 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 = function(pathArg: string, regexFilter?: RegExp): Promise<string[]> {
|
export let listFolders = async (pathArg: string, regexFilter?: RegExp): Promise<string[]> => {
|
||||||
let done = plugins.smartpromise.defer<string[]>();
|
return listFoldersSync(pathArg, regexFilter);
|
||||||
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);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
done.resolve(folderArray);
|
|
||||||
return done.promise;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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 = (pathArg: string, regexFilter?: RegExp): string[] => {
|
||||||
let folderArray = plugins.fsExtra.readdirSync(pathArg).filter(function(file) {
|
let folderArray = plugins.fsExtra.readdirSync(pathArg).filter((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) {
|
||||||
@ -291,26 +281,16 @@ export let listFoldersSync = function(pathArg: string, regexFilter?: RegExp): st
|
|||||||
* 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) {
|
||||||
@ -325,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;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -342,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();
|
||||||
});
|
});
|
||||||
@ -360,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;
|
||||||
@ -370,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
|
||||||
|
Reference in New Issue
Block a user