Compare commits
18 Commits
Author | SHA1 | Date | |
---|---|---|---|
15044149f2 | |||
c92b759432 | |||
9b8f055ec2 | |||
69433b242b | |||
db1d2acb47 | |||
920552ea23 | |||
dd05708f28 | |||
d97abe443d | |||
818767b7cc | |||
52367f5c1a | |||
b6b2101054 | |||
e322a41c45 | |||
f5e2c0c7d7 | |||
6733a156b8 | |||
ebac45a152 | |||
92ac410b96 | |||
078bdda803 | |||
7b87adf3d9 |
@ -26,6 +26,7 @@ mirror:
|
|||||||
snyk:
|
snyk:
|
||||||
stage: security
|
stage: security
|
||||||
script:
|
script:
|
||||||
|
- npmci npm prepare
|
||||||
- npmci command npm install -g snyk
|
- npmci command npm install -g snyk
|
||||||
- npmci command npm install --ignore-scripts
|
- npmci command npm install --ignore-scripts
|
||||||
- npmci command snyk test
|
- npmci command snyk test
|
||||||
@ -39,6 +40,7 @@ snyk:
|
|||||||
testLEGACY:
|
testLEGACY:
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
|
- npmci npm prepare
|
||||||
- npmci node install legacy
|
- npmci node install legacy
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci npm test
|
- npmci npm test
|
||||||
@ -51,6 +53,7 @@ testLEGACY:
|
|||||||
testLTS:
|
testLTS:
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
|
- npmci npm prepare
|
||||||
- npmci node install lts
|
- npmci node install lts
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci npm test
|
- npmci npm test
|
||||||
@ -62,6 +65,7 @@ testLTS:
|
|||||||
testSTABLE:
|
testSTABLE:
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
|
- npmci npm prepare
|
||||||
- npmci node install stable
|
- npmci node install stable
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci npm test
|
- npmci npm test
|
||||||
@ -117,8 +121,10 @@ pages:
|
|||||||
image: hosttoday/ht-docker-node:npmci
|
image: hosttoday/ht-docker-node:npmci
|
||||||
stage: metadata
|
stage: metadata
|
||||||
script:
|
script:
|
||||||
- npmci command npm install -g npmpage
|
- npmci command npm install -g typedoc typescript
|
||||||
- npmci command npmpage
|
- npmci npm prepare
|
||||||
|
- npmci npm install
|
||||||
|
- npmci command typedoc --module "commonjs" --target "ES2016" --out public/ ts/
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
- notpriv
|
||||||
@ -129,13 +135,3 @@ pages:
|
|||||||
paths:
|
paths:
|
||||||
- public
|
- public
|
||||||
allow_failure: true
|
allow_failure: true
|
||||||
|
|
||||||
windowsCompatibility:
|
|
||||||
image: stefanscherer/node-windows:10-build-tools
|
|
||||||
stage: metadata
|
|
||||||
script:
|
|
||||||
- npm install & npm test
|
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
|
||||||
tags:
|
|
||||||
- windows
|
|
||||||
allow_failure: true
|
|
||||||
|
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: {}
|
@ -7,9 +7,7 @@
|
|||||||
|
|
||||||
},
|
},
|
||||||
"npmci": {
|
"npmci": {
|
||||||
"npmGlobalTools": [
|
"npmGlobalTools": [],
|
||||||
"npmts"
|
|
||||||
],
|
|
||||||
"npmAccessLevel": "public"
|
"npmAccessLevel": "public"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
1194
package-lock.json
generated
1194
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
27
package.json
27
package.json
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartfile",
|
"name": "@pushrocks/smartfile",
|
||||||
"private": false,
|
"private": false,
|
||||||
"version": "6.0.4",
|
"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",
|
||||||
@ -11,7 +11,7 @@
|
|||||||
"release": "(git pull origin master && npm version patch && git push origin master && git checkout release && git merge master && git push origin release && git checkout master)",
|
"release": "(git pull origin master && npm version patch && git push origin master && git checkout release && git merge master && git push origin release && git checkout master)",
|
||||||
"update": "(git checkout master && git pull origin master && npm install)",
|
"update": "(git checkout master && git pull origin master && npm install)",
|
||||||
"upgrade": "(npm run update) && (ncu upgradeAll && npm install)",
|
"upgrade": "(npm run update) && (ncu upgradeAll && npm install)",
|
||||||
"build": "(npmts)"
|
"build": "(tsbuild)"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@ -28,21 +28,24 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://gitlab.com/pushrocks/smartfile",
|
"homepage": "https://gitlab.com/pushrocks/smartfile",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@pushrocks/smartpath": "^4.0.1",
|
||||||
"@pushrocks/smartpromise": "^2.0.5",
|
"@pushrocks/smartpromise": "^2.0.5",
|
||||||
"@pushrocks/smartrequest": "^1.0.15",
|
"@pushrocks/smartrequest": "^1.1.14",
|
||||||
"@types/fs-extra": "^5.0.3",
|
"@types/fs-extra": "^5.0.5",
|
||||||
"@types/vinyl": "^2.0.2",
|
"@types/vinyl": "^2.0.2",
|
||||||
"fs-extra": "^6.0.1",
|
"fs-extra": "^7.0.1",
|
||||||
"glob": "^7.1.2",
|
"glob": "^7.1.3",
|
||||||
"js-yaml": "^3.10.0",
|
"js-yaml": "^3.12.1",
|
||||||
"smartpath": "^3.2.8",
|
|
||||||
"vinyl-file": "^3.0.0"
|
"vinyl-file": "^3.0.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsrun": "^1.1.1",
|
"@gitzone/tsbuild": "^2.1.8",
|
||||||
"@gitzone/tstest": "^1.0.12",
|
"@gitzone/tsrun": "^1.1.17",
|
||||||
"@types/node": "^10.5.1",
|
"@gitzone/tstest": "^1.0.18",
|
||||||
|
"@pushrocks/tapbundle": "^3.0.7",
|
||||||
|
"@types/node": "^11.9.4",
|
||||||
"gulp-function": "^2.2.14",
|
"gulp-function": "^2.2.14",
|
||||||
"tapbundle": "^2.0.2"
|
"tslint": "^5.12.1",
|
||||||
|
"tslint-config-prettier": "^1.18.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import * as smartfile from '../ts/index';
|
import * as smartfile from '../ts/index';
|
||||||
import path = require('path');
|
import path = require('path');
|
||||||
|
|
||||||
import { expect, tap } from 'tapbundle';
|
import { expect, tap } from '@pushrocks/tapbundle';
|
||||||
|
|
||||||
// ---------------------------
|
// ---------------------------
|
||||||
// smartfile.fs
|
// smartfile.fs
|
||||||
|
@ -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;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -255,28 +255,18 @@ export let toVinylSync = function(filePathArg, options = {}) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* lists Folders in a directory on local disk
|
* lists Folders in a directory on local disk
|
||||||
* @returns Promise
|
* @returns Promise with an array that contains the folder names
|
||||||
*/
|
*/
|
||||||
export let listFolders = function(pathArg: string, regexFilter?: RegExp) {
|
export let listFolders = async (pathArg: string, regexFilter?: RegExp): Promise<string[]> => {
|
||||||
let done = plugins.smartpromise.defer();
|
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
|
||||||
|
@ -4,6 +4,6 @@ export let glob = require('glob');
|
|||||||
export import path = require('path');
|
export import path = require('path');
|
||||||
export import smartpromise = require('@pushrocks/smartpromise');
|
export import smartpromise = require('@pushrocks/smartpromise');
|
||||||
export import smartrequest = require('@pushrocks/smartrequest');
|
export import smartrequest = require('@pushrocks/smartrequest');
|
||||||
export import smartpath = require('smartpath');
|
export import smartpath = require('@pushrocks/smartpath');
|
||||||
export let vinylFile = require('vinyl-file');
|
export let vinylFile = require('vinyl-file');
|
||||||
export let yaml = require('js-yaml');
|
export let yaml = require('js-yaml');
|
||||||
|
16
tslint.json
16
tslint.json
@ -1,3 +1,17 @@
|
|||||||
{
|
{
|
||||||
"extends": "tslint-config-standard"
|
"extends": ["tslint:latest", "tslint-config-prettier"],
|
||||||
|
"rules": {
|
||||||
|
"semicolon": [true, "always"],
|
||||||
|
"no-console": false,
|
||||||
|
"ordered-imports": false,
|
||||||
|
"object-literal-sort-keys": false,
|
||||||
|
"member-ordering": {
|
||||||
|
"options":{
|
||||||
|
"order": [
|
||||||
|
"static-method"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"defaultSeverity": "warning"
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user