Compare commits
12 Commits
Author | SHA1 | Date | |
---|---|---|---|
6170b37d29 | |||
4c23992681 | |||
77c88f09cd | |||
469a454fa6 | |||
15044149f2 | |||
c92b759432 | |||
9b8f055ec2 | |||
69433b242b | |||
db1d2acb47 | |||
920552ea23 | |||
dd05708f28 | |||
d97abe443d |
@ -37,18 +37,6 @@ snyk:
|
|||||||
# ====================
|
# ====================
|
||||||
# test stage
|
# test stage
|
||||||
# ====================
|
# ====================
|
||||||
testLEGACY:
|
|
||||||
stage: test
|
|
||||||
script:
|
|
||||||
- npmci npm prepare
|
|
||||||
- npmci node install legacy
|
|
||||||
- npmci npm install
|
|
||||||
- npmci npm test
|
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
- notpriv
|
|
||||||
allow_failure: true
|
|
||||||
|
|
||||||
testLTS:
|
testLTS:
|
||||||
stage: test
|
stage: test
|
||||||
|
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: {}
|
31
README.md
31
README.md
@ -1,24 +1,20 @@
|
|||||||
# @pushrocks/smartfile
|
# @pushrocks/smartfile
|
||||||
|
smart ways to work with files in nodejs
|
||||||
|
|
||||||
make files easily accessible for processing in javascript.
|
## Availabililty and Links
|
||||||
|
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartfile)
|
||||||
## Availabililty
|
* [gitlab.com (source)](https://gitlab.com/pushrocks/smartfile)
|
||||||
|
* [github.com (source mirror)](https://github.com/pushrocks/smartfile)
|
||||||
[](https://www.npmjs.com/package/smartfile)
|
* [docs (typedoc)](https://pushrocks.gitlab.io/smartfile/)
|
||||||
[](https://gitlab.com/pushrocks/smartfile)
|
|
||||||
[](https://github.com/pushrocks/smartfile)
|
|
||||||
[](https://pushrocks.gitlab.io/smartfile/)
|
|
||||||
|
|
||||||
## Status for master
|
## Status for master
|
||||||
|
|
||||||
[](https://gitlab.com/pushrocks/smartfile/commits/master)
|
[](https://gitlab.com/pushrocks/smartfile/commits/master)
|
||||||
[](https://gitlab.com/pushrocks/smartfile/commits/master)
|
[](https://gitlab.com/pushrocks/smartfile/commits/master)
|
||||||
[](https://david-dm.org/pushrocks/smartfile)
|
[](https://www.npmjs.com/package/@pushrocks/smartfile)
|
||||||
[](https://www.bithound.io/github/pushrocks/smartfile/master/dependencies/npm)
|
[](https://snyk.io/test/npm/@pushrocks/smartfile)
|
||||||
[](https://www.bithound.io/github/pushrocks/smartfile)
|
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||||
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||||
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
[](https://prettier.io/)
|
||||||
[](http://standardjs.com/)
|
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
@ -36,8 +32,9 @@ smartfile thinks in sections:
|
|||||||
| interpreter | (object) handles yaml and json |
|
| interpreter | (object) handles yaml and json |
|
||||||
| smartfile | (class) a virtual representation of a file, alternative to vinyl file format |
|
| smartfile | (class) a virtual representation of a file, alternative to vinyl file format |
|
||||||
|
|
||||||
For further information read the linked docs at the top of this README.
|
For further information read the linked docs at the top of this readme.
|
||||||
|
|
||||||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
||||||
|
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
|
||||||
|
|
||||||
[](https://push.rocks)
|
[](https://maintainedby.lossless.com)
|
||||||
|
@ -3,11 +3,19 @@
|
|||||||
"mode": "default",
|
"mode": "default",
|
||||||
"coverageTreshold": 70
|
"coverageTreshold": 70
|
||||||
},
|
},
|
||||||
"npmdocker":{
|
"npmdocker": {},
|
||||||
|
|
||||||
},
|
|
||||||
"npmci": {
|
"npmci": {
|
||||||
"npmGlobalTools": [],
|
"npmGlobalTools": [],
|
||||||
"npmAccessLevel": "public"
|
"npmAccessLevel": "public"
|
||||||
|
},
|
||||||
|
"gitzone": {
|
||||||
|
"module": {
|
||||||
|
"githost": "gitlab.com",
|
||||||
|
"gitscope": "pushrocks",
|
||||||
|
"gitrepo": "smartfile",
|
||||||
|
"shortDescription": "smart ways to work with files in nodejs",
|
||||||
|
"npmPackagename": "@pushrocks/smartfile",
|
||||||
|
"license": "MIT"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
933
package-lock.json
generated
933
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
20
package.json
20
package.json
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartfile",
|
"name": "@pushrocks/smartfile",
|
||||||
"private": false,
|
"private": false,
|
||||||
"version": "6.0.9",
|
"version": "7.0.2",
|
||||||
"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",
|
||||||
@ -29,23 +29,23 @@
|
|||||||
"homepage": "https://gitlab.com/pushrocks/smartfile",
|
"homepage": "https://gitlab.com/pushrocks/smartfile",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pushrocks/smartpath": "^4.0.1",
|
"@pushrocks/smartpath": "^4.0.1",
|
||||||
"@pushrocks/smartpromise": "^2.0.5",
|
"@pushrocks/smartpromise": "^3.0.2",
|
||||||
"@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.13.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.2.1",
|
||||||
"@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.13.0",
|
||||||
"gulp-function": "^2.2.14",
|
"gulp-function": "^2.2.14",
|
||||||
"tslint": "^5.11.0",
|
"tslint": "^5.15.0",
|
||||||
"tslint-config-prettier": "^1.16.0"
|
"tslint-config-prettier": "^1.18.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,27 @@ 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