Compare commits

...

18 Commits

Author SHA1 Message Date
15044149f2 7.0.0 2019-02-17 21:07:23 +01:00
c92b759432 BREAKING CHANGE(smartfile.fs.fileExists now returns a Promise<boolean>): update 2019-02-17 21:07:22 +01:00
9b8f055ec2 6.0.12 2019-01-27 03:11:11 +01:00
69433b242b fix(core): update 2019-01-27 03:11:10 +01:00
db1d2acb47 6.0.11 2018-11-22 23:38:06 +01:00
920552ea23 fix(fs.listFolders): fix 2018-11-22 23:38:05 +01:00
dd05708f28 6.0.10 2018-11-22 23:26:28 +01:00
d97abe443d fix(snyk): add .snyk file 2018-11-22 23:26:27 +01:00
818767b7cc 6.0.9 2018-11-22 23:23:26 +01:00
52367f5c1a fix(fs.listFolders()): fix retuen type 2018-11-22 23:23:26 +01:00
b6b2101054 6.0.8 2018-08-19 21:21:27 +02:00
e322a41c45 fix(CI): update testing framework 2018-08-19 21:21:26 +02:00
f5e2c0c7d7 6.0.7 2018-08-19 17:10:27 +02:00
6733a156b8 fix(dependencies): update 2018-08-19 17:10:27 +02:00
ebac45a152 6.0.6 2018-08-08 22:22:48 +02:00
92ac410b96 fix(dependencies): update dependencies to latest standards 2018-08-08 22:22:47 +02:00
078bdda803 6.0.5 2018-08-06 09:37:10 +02:00
7b87adf3d9 fix(core): switch from npmts to @gitzone/tsbuild for bulding the module 2018-08-06 09:37:09 +02:00
10 changed files with 1033 additions and 328 deletions

View File

@ -26,6 +26,7 @@ mirror:
snyk:
stage: security
script:
- npmci npm prepare
- npmci command npm install -g snyk
- npmci command npm install --ignore-scripts
- npmci command snyk test
@ -39,6 +40,7 @@ snyk:
testLEGACY:
stage: test
script:
- npmci npm prepare
- npmci node install legacy
- npmci npm install
- npmci npm test
@ -51,6 +53,7 @@ testLEGACY:
testLTS:
stage: test
script:
- npmci npm prepare
- npmci node install lts
- npmci npm install
- npmci npm test
@ -62,6 +65,7 @@ testLTS:
testSTABLE:
stage: test
script:
- npmci npm prepare
- npmci node install stable
- npmci npm install
- npmci npm test
@ -117,8 +121,10 @@ pages:
image: hosttoday/ht-docker-node:npmci
stage: metadata
script:
- npmci command npm install -g npmpage
- npmci command npmpage
- npmci command npm install -g typedoc typescript
- npmci npm prepare
- npmci npm install
- npmci command typedoc --module "commonjs" --target "ES2016" --out public/ ts/
tags:
- docker
- notpriv
@ -129,13 +135,3 @@ pages:
paths:
- public
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
View File

@ -0,0 +1,4 @@
# Snyk (https://snyk.io) policy file, patches or ignores known vulnerabilities.
version: v1.13.1
ignore: {}
patch: {}

View File

@ -7,9 +7,7 @@
},
"npmci": {
"npmGlobalTools": [
"npmts"
],
"npmGlobalTools": [],
"npmAccessLevel": "public"
}
}

1194
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +1,7 @@
{
"name": "@pushrocks/smartfile",
"private": false,
"version": "6.0.4",
"version": "7.0.0",
"description": "offers smart ways to work with files in nodejs",
"main": "dist/index.js",
"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)",
"update": "(git checkout master && git pull origin master && npm install)",
"upgrade": "(npm run update) && (ncu upgradeAll && npm install)",
"build": "(npmts)"
"build": "(tsbuild)"
},
"repository": {
"type": "git",
@ -28,21 +28,24 @@
},
"homepage": "https://gitlab.com/pushrocks/smartfile",
"dependencies": {
"@pushrocks/smartpath": "^4.0.1",
"@pushrocks/smartpromise": "^2.0.5",
"@pushrocks/smartrequest": "^1.0.15",
"@types/fs-extra": "^5.0.3",
"@pushrocks/smartrequest": "^1.1.14",
"@types/fs-extra": "^5.0.5",
"@types/vinyl": "^2.0.2",
"fs-extra": "^6.0.1",
"glob": "^7.1.2",
"js-yaml": "^3.10.0",
"smartpath": "^3.2.8",
"fs-extra": "^7.0.1",
"glob": "^7.1.3",
"js-yaml": "^3.12.1",
"vinyl-file": "^3.0.0"
},
"devDependencies": {
"@gitzone/tsrun": "^1.1.1",
"@gitzone/tstest": "^1.0.12",
"@types/node": "^10.5.1",
"@gitzone/tsbuild": "^2.1.8",
"@gitzone/tsrun": "^1.1.17",
"@gitzone/tstest": "^1.0.18",
"@pushrocks/tapbundle": "^3.0.7",
"@types/node": "^11.9.4",
"gulp-function": "^2.2.14",
"tapbundle": "^2.0.2"
"tslint": "^5.12.1",
"tslint-config-prettier": "^1.18.0"
}
}

View File

@ -1,7 +1,7 @@
import * as smartfile from '../ts/index';
import path = require('path');
import { expect, tap } from 'tapbundle';
import { expect, tap } from '@pushrocks/tapbundle';
// ---------------------------
// smartfile.fs

View File

@ -14,6 +14,28 @@ export interface ISmartfileConstructorOptions {
* -> is vinyl file compatible
*/
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
*/

View File

@ -29,10 +29,10 @@ export let fileExistsSync = function(filePath): boolean {
* @param filePath
* @returns {any}
*/
export let fileExists = function(filePath) {
let done = plugins.smartpromise.defer();
plugins.fs.access(filePath, 4, function(err) {
err ? done.reject(err) : done.resolve();
export let fileExists = (filePath): Promise<boolean> => {
const done = plugins.smartpromise.defer<boolean>();
plugins.fs.access(filePath, 4, err => {
err ? done.resolve(false) : done.resolve(true);
});
return done.promise;
};
@ -40,7 +40,7 @@ export let fileExists = function(filePath) {
/**
* Checks if given path points to an existing directory
*/
export let isDirectory = function(pathArg): boolean {
export let isDirectory = (pathArg): boolean => {
try {
return plugins.fsExtra.statSync(pathArg).isDirectory();
} catch (err) {
@ -194,7 +194,7 @@ export let removeManySync = function(filePathArrayArg: string[]): void {
* @returns {any}
*/
export let toObjectSync = function(filePathArg, fileTypeArg?) {
let fileString = plugins.fsExtra.readFileSync(filePathArg, 'utf8');
const fileString = plugins.fsExtra.readFileSync(filePathArg, 'utf8');
let fileType;
fileTypeArg ? (fileType = fileTypeArg) : (fileType = SmartfileInterpreter.filetype(filePathArg));
return SmartfileInterpreter.objectFile(fileString, fileType);
@ -206,7 +206,7 @@ export let toObjectSync = function(filePathArg, fileTypeArg?) {
* @returns {string|Buffer|any}
*/
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;
};
@ -255,28 +255,18 @@ export let toVinylSync = function(filePathArg, options = {}) {
/**
* 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) {
let done = plugins.smartpromise.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);
});
}
done.resolve(folderArray);
return done.promise;
export let listFolders = async (pathArg: string, regexFilter?: RegExp): Promise<string[]> => {
return listFoldersSync(pathArg, regexFilter);
};
/**
* 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) {
export let listFoldersSync = (pathArg: string, regexFilter?: RegExp): string[] => {
let folderArray = plugins.fsExtra.readdirSync(pathArg).filter((file) => {
return plugins.fsExtra.statSync(plugins.path.join(pathArg, file)).isDirectory();
});
if (regexFilter) {
@ -291,26 +281,16 @@ export let listFoldersSync = function(pathArg: string, regexFilter?: RegExp): st
* lists Files in a directory on local disk
* @returns Promise
*/
export let listFiles = function(pathArg: string, regexFilter?: RegExp) {
let done = plugins.smartpromise.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);
});
}
done.resolve(fileArray);
return done.promise;
export let listFiles = async (pathArg: string, regexFilter?: RegExp): Promise<string[]> => {
return listFilesSync(pathArg, regexFilter);
};
/**
* 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) {
export let listFilesSync = (pathArg: string, regexFilter?: RegExp): string[] => {
let fileArray = plugins.fsExtra.readdirSync(pathArg).filter(file => {
return plugins.fsExtra.statSync(plugins.path.join(pathArg, file)).isFile();
});
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
* @returns Promise<string[]>
*/
export let listAllItems = function(pathArg: string, regexFilter?: RegExp): Promise<string[]> {
let done = plugins.smartpromise.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 = async (pathArg: string, regexFilter?: RegExp): Promise<string[]> => {
return listAllItemsSync(pathArg, regexFilter);
};
/**
@ -342,7 +314,7 @@ 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[] {
export let listAllItemsSync = (pathArg: string, regexFilter?: RegExp): string[] => {
let allItmesArray = plugins.fsExtra.readdirSync(pathArg).filter(function(file) {
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
*/
export let listFileTree = (dirPathArg: string, miniMatchFilter: string): Promise<string[]> => {
let done = plugins.smartpromise.defer<string[]>();
const done = plugins.smartpromise.defer<string[]>();
// handle absolute miniMatchFilter
let dirPath: string;
@ -370,7 +342,7 @@ export let listFileTree = (dirPathArg: string, miniMatchFilter: string): Promise
dirPath = dirPathArg;
}
let options = {
const options = {
cwd: dirPath,
nodir: true,
dot: true

View File

@ -4,6 +4,6 @@ export let glob = require('glob');
export import path = require('path');
export import smartpromise = require('@pushrocks/smartpromise');
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 yaml = require('js-yaml');

View File

@ -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"
}