Compare commits
30 Commits
Author | SHA1 | Date | |
---|---|---|---|
f889664e4d | |||
f4129c04b2 | |||
c6280eb6fc | |||
4095738c6a | |||
6170b37d29 | |||
4c23992681 | |||
77c88f09cd | |||
469a454fa6 | |||
15044149f2 | |||
c92b759432 | |||
9b8f055ec2 | |||
69433b242b | |||
db1d2acb47 | |||
920552ea23 | |||
dd05708f28 | |||
d97abe443d | |||
818767b7cc | |||
52367f5c1a | |||
b6b2101054 | |||
e322a41c45 | |||
f5e2c0c7d7 | |||
6733a156b8 | |||
ebac45a152 | |||
92ac410b96 | |||
078bdda803 | |||
7b87adf3d9 | |||
908db4d847 | |||
87d047af42 | |||
610a70079d | |||
2c24cdc9f4 |
21
.gitignore
vendored
21
.gitignore
vendored
@ -1,7 +1,22 @@
|
|||||||
node_modules/
|
.nogit/
|
||||||
|
|
||||||
|
# artifacts
|
||||||
coverage/
|
coverage/
|
||||||
pages/
|
|
||||||
public/
|
public/
|
||||||
|
pages/
|
||||||
|
|
||||||
test/temp/
|
# installs
|
||||||
|
node_modules/
|
||||||
|
|
||||||
|
# caches
|
||||||
|
.yarn/
|
||||||
|
.cache/
|
||||||
|
.rpt2_cache
|
||||||
|
|
||||||
|
# builds
|
||||||
|
dist/
|
||||||
|
dist_web/
|
||||||
|
dist_serve/
|
||||||
|
dist_ts_web/
|
||||||
|
|
||||||
|
# custom
|
@ -1,5 +1,5 @@
|
|||||||
# gitzone standard
|
# gitzone ci_default
|
||||||
image: hosttoday/ht-docker-node:npmci
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
|
|
||||||
cache:
|
cache:
|
||||||
paths:
|
paths:
|
||||||
@ -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
|
||||||
@ -36,21 +37,11 @@ snyk:
|
|||||||
# ====================
|
# ====================
|
||||||
# test stage
|
# test stage
|
||||||
# ====================
|
# ====================
|
||||||
testLEGACY:
|
|
||||||
stage: test
|
|
||||||
script:
|
|
||||||
- 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
|
||||||
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
|
||||||
@ -58,22 +49,11 @@ testLTS:
|
|||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
- notpriv
|
||||||
|
|
||||||
testSTABLE:
|
|
||||||
stage: test
|
|
||||||
script:
|
|
||||||
- npmci node install stable
|
|
||||||
- npmci npm install
|
|
||||||
- npmci npm test
|
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
- notpriv
|
|
||||||
|
|
||||||
release:
|
release:
|
||||||
stage: release
|
stage: release
|
||||||
script:
|
script:
|
||||||
- npmci node install stable
|
- npmci node install lts
|
||||||
- npmci npm publish
|
- npmci npm publish
|
||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
@ -86,19 +66,11 @@ release:
|
|||||||
# ====================
|
# ====================
|
||||||
codequality:
|
codequality:
|
||||||
stage: metadata
|
stage: metadata
|
||||||
image: docker:stable
|
|
||||||
allow_failure: true
|
allow_failure: true
|
||||||
services:
|
|
||||||
- docker:stable-dind
|
|
||||||
script:
|
script:
|
||||||
- export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/')
|
- npmci command npm install -g tslint typescript
|
||||||
- docker run
|
- npmci npm install
|
||||||
--env SOURCE_CODE="$PWD"
|
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
|
||||||
--volume "$PWD":/code
|
|
||||||
--volume /var/run/docker.sock:/var/run/docker.sock
|
|
||||||
"registry.gitlab.com/gitlab-org/security-products/codequality:$SP_VERSION" /code
|
|
||||||
artifacts:
|
|
||||||
paths: [codeclimate.json]
|
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
- priv
|
- priv
|
||||||
@ -117,8 +89,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 @gitzone/tsdoc
|
||||||
- npmci command npmpage
|
- npmci npm prepare
|
||||||
|
- npmci npm install
|
||||||
|
- npmci command tsdoc
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
- notpriv
|
||||||
@ -129,13 +103,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: {}
|
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)
|
||||||
|
10
dist/index.d.ts
vendored
10
dist/index.d.ts
vendored
@ -1,10 +0,0 @@
|
|||||||
import * as SmartfileFs from './smartfile.fs';
|
|
||||||
import * as SmartfileInterpreter from './smartfile.interpreter';
|
|
||||||
import * as SmartfileMemory from './smartfile.memory';
|
|
||||||
import * as SmartfileRemote from './smartfile.remote';
|
|
||||||
export { Smartfile } from './smartfile.classes.smartfile';
|
|
||||||
export declare let fs: typeof SmartfileFs;
|
|
||||||
export declare let interpreter: typeof SmartfileInterpreter;
|
|
||||||
export declare let memory: typeof SmartfileMemory;
|
|
||||||
export declare let remote: typeof SmartfileRemote;
|
|
||||||
export declare let requireReload: (path: string) => any;
|
|
14
dist/index.js
vendored
14
dist/index.js
vendored
@ -1,14 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
|
||||||
const SmartfileFs = require("./smartfile.fs");
|
|
||||||
const SmartfileInterpreter = require("./smartfile.interpreter");
|
|
||||||
const SmartfileMemory = require("./smartfile.memory");
|
|
||||||
const SmartfileRemote = require("./smartfile.remote");
|
|
||||||
var smartfile_classes_smartfile_1 = require("./smartfile.classes.smartfile");
|
|
||||||
exports.Smartfile = smartfile_classes_smartfile_1.Smartfile;
|
|
||||||
exports.fs = SmartfileFs;
|
|
||||||
exports.interpreter = SmartfileInterpreter;
|
|
||||||
exports.memory = SmartfileMemory;
|
|
||||||
exports.remote = SmartfileRemote;
|
|
||||||
exports.requireReload = SmartfileFs.requireReload;
|
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUNBLDhDQUE2QztBQUM3QyxnRUFBK0Q7QUFDL0Qsc0RBQXFEO0FBQ3JELHNEQUFxRDtBQUVyRCw2RUFBdUQ7QUFBL0Msa0RBQUEsU0FBUyxDQUFBO0FBRU4sUUFBQSxFQUFFLEdBQUcsV0FBVyxDQUFBO0FBQ2hCLFFBQUEsV0FBVyxHQUFHLG9CQUFvQixDQUFBO0FBQ2xDLFFBQUEsTUFBTSxHQUFHLGVBQWUsQ0FBQTtBQUN4QixRQUFBLE1BQU0sR0FBRyxlQUFlLENBQUE7QUFDeEIsUUFBQSxhQUFhLEdBQUcsV0FBVyxDQUFDLGFBQWEsQ0FBQSJ9
|
|
79
dist/smartfile.classes.smartfile.d.ts
vendored
79
dist/smartfile.classes.smartfile.d.ts
vendored
@ -1,79 +0,0 @@
|
|||||||
/// <reference types="node" />
|
|
||||||
import * as plugins from './smartfile.plugins';
|
|
||||||
export interface ISmartfileConstructorOptions {
|
|
||||||
path?: string;
|
|
||||||
contentString?: string;
|
|
||||||
contentBuffer?: Buffer;
|
|
||||||
base?: string;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* class Smartfile
|
|
||||||
* -> is vinyl file compatible
|
|
||||||
*/
|
|
||||||
export declare class Smartfile {
|
|
||||||
/**
|
|
||||||
* the full path of the file on disk
|
|
||||||
*/
|
|
||||||
path: string;
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
parsedPath: plugins.path.ParsedPath;
|
|
||||||
/**
|
|
||||||
* the content of the file as Buffer
|
|
||||||
*/
|
|
||||||
contentBuffer: Buffer;
|
|
||||||
/**
|
|
||||||
* The current working directory of the file
|
|
||||||
* Note:this is similar to gulp and different from native node path base
|
|
||||||
*/
|
|
||||||
base: string;
|
|
||||||
/**
|
|
||||||
* sync the file with disk
|
|
||||||
*/
|
|
||||||
sync: boolean;
|
|
||||||
/**
|
|
||||||
* the constructor of Smartfile
|
|
||||||
* @param optionsArg
|
|
||||||
*/
|
|
||||||
constructor(optionsArg: ISmartfileConstructorOptions);
|
|
||||||
/**
|
|
||||||
* set contents from string
|
|
||||||
* @param contentString
|
|
||||||
*/
|
|
||||||
setContentsFromString(contentString: string): void;
|
|
||||||
/**
|
|
||||||
* write file to disk
|
|
||||||
* Behaviours:
|
|
||||||
* - no argument write to exactly where the file was picked up
|
|
||||||
*/
|
|
||||||
write(pathArg?: string): Promise<void>;
|
|
||||||
/**
|
|
||||||
* read file from disk
|
|
||||||
*/
|
|
||||||
read(): Promise<void>;
|
|
||||||
/**
|
|
||||||
* vinyl-compatibility: alias of this.contentBuffer
|
|
||||||
*/
|
|
||||||
contents: Buffer;
|
|
||||||
/**
|
|
||||||
* vinyl-compatibility
|
|
||||||
*/
|
|
||||||
readonly cwd: string;
|
|
||||||
/**
|
|
||||||
* return relative path of file
|
|
||||||
*/
|
|
||||||
readonly relative: string;
|
|
||||||
/**
|
|
||||||
* return truw when the file has content
|
|
||||||
*/
|
|
||||||
isNull(): boolean;
|
|
||||||
/**
|
|
||||||
* return true if contents are Buffer
|
|
||||||
*/
|
|
||||||
isBuffer(): boolean;
|
|
||||||
isDirectory(): boolean;
|
|
||||||
isStream(): boolean;
|
|
||||||
isSymbolic(): boolean;
|
|
||||||
updateFileName(fileNameArg: string): void;
|
|
||||||
}
|
|
119
dist/smartfile.classes.smartfile.js
vendored
119
dist/smartfile.classes.smartfile.js
vendored
@ -1,119 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
||||||
return new (P || (P = Promise))(function (resolve, reject) {
|
|
||||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
||||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
||||||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
|
||||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
||||||
});
|
|
||||||
};
|
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
|
||||||
const plugins = require("./smartfile.plugins");
|
|
||||||
const memory = require("./smartfile.memory");
|
|
||||||
/**
|
|
||||||
* class Smartfile
|
|
||||||
* -> is vinyl file compatible
|
|
||||||
*/
|
|
||||||
class Smartfile {
|
|
||||||
/**
|
|
||||||
* the constructor of Smartfile
|
|
||||||
* @param optionsArg
|
|
||||||
*/
|
|
||||||
constructor(optionsArg) {
|
|
||||||
if (optionsArg.contentBuffer) {
|
|
||||||
this.contentBuffer = optionsArg.contentBuffer;
|
|
||||||
}
|
|
||||||
else if (optionsArg.contentString) {
|
|
||||||
this.setContentsFromString(optionsArg.contentString);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
console.log('created empty Smartfile?');
|
|
||||||
}
|
|
||||||
this.path = optionsArg.path;
|
|
||||||
this.parsedPath = plugins.path.parse(this.path);
|
|
||||||
this.base = optionsArg.base;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* set contents from string
|
|
||||||
* @param contentString
|
|
||||||
*/
|
|
||||||
setContentsFromString(contentString) {
|
|
||||||
this.contents = new Buffer(contentString);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* write file to disk
|
|
||||||
* Behaviours:
|
|
||||||
* - no argument write to exactly where the file was picked up
|
|
||||||
*/
|
|
||||||
write(pathArg) {
|
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
|
||||||
const stringToWrite = this.contentBuffer.toString();
|
|
||||||
yield memory.toFs(stringToWrite, this.path);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* read file from disk
|
|
||||||
*/
|
|
||||||
read() {
|
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
|
||||||
});
|
|
||||||
}
|
|
||||||
// -----------------------------------------------
|
|
||||||
// vinyl compatibility
|
|
||||||
// -----------------------------------------------
|
|
||||||
/**
|
|
||||||
* vinyl-compatibility: alias of this.contentBuffer
|
|
||||||
*/
|
|
||||||
get contents() {
|
|
||||||
return this.contentBuffer;
|
|
||||||
}
|
|
||||||
set contents(contentsArg) {
|
|
||||||
this.contentBuffer = contentsArg;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* vinyl-compatibility
|
|
||||||
*/
|
|
||||||
get cwd() {
|
|
||||||
return process.cwd();
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* return relative path of file
|
|
||||||
*/
|
|
||||||
get relative() {
|
|
||||||
return plugins.path.relative(this.base, this.path);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* return truw when the file has content
|
|
||||||
*/
|
|
||||||
isNull() {
|
|
||||||
if (!this.contentBuffer) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* return true if contents are Buffer
|
|
||||||
*/
|
|
||||||
isBuffer() {
|
|
||||||
if (this.contents instanceof Buffer) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
isDirectory() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
isStream() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
isSymbolic() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
// update things
|
|
||||||
updateFileName(fileNameArg) {
|
|
||||||
let oldFileName = this.parsedPath.base;
|
|
||||||
this.path = this.path.replace(new RegExp(oldFileName + '$'), fileNameArg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
exports.Smartfile = Smartfile;
|
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRmaWxlLmNsYXNzZXMuc21hcnRmaWxlLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRmaWxlLmNsYXNzZXMuc21hcnRmaWxlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7QUFBQSwrQ0FBOEM7QUFFOUMsNkNBQTRDO0FBUzVDOzs7R0FHRztBQUNIO0lBMkJFOzs7T0FHRztJQUdILFlBQWEsVUFBd0M7UUFDbkQsSUFBSSxVQUFVLENBQUMsYUFBYSxFQUFFO1lBQzVCLElBQUksQ0FBQyxhQUFhLEdBQUcsVUFBVSxDQUFDLGFBQWEsQ0FBQTtTQUM5QzthQUFNLElBQUksVUFBVSxDQUFDLGFBQWEsRUFBRTtZQUNuQyxJQUFJLENBQUMscUJBQXFCLENBQUMsVUFBVSxDQUFDLGFBQWEsQ0FBQyxDQUFBO1NBQ3JEO2FBQU07WUFDTCxPQUFPLENBQUMsR0FBRyxDQUFDLDBCQUEwQixDQUFDLENBQUE7U0FDeEM7UUFDRCxJQUFJLENBQUMsSUFBSSxHQUFHLFVBQVUsQ0FBQyxJQUFJLENBQUE7UUFDM0IsSUFBSSxDQUFDLFVBQVUsR0FBRyxPQUFPLENBQUMsSUFBSSxDQUFDLEtBQUssQ0FBQyxJQUFJLENBQUMsSUFBSSxDQUFDLENBQUE7UUFDL0MsSUFBSSxDQUFDLElBQUksR0FBRyxVQUFVLENBQUMsSUFBSSxDQUFBO0lBQzdCLENBQUM7SUFHRDs7O09BR0c7SUFDSCxxQkFBcUIsQ0FBQyxhQUFxQjtRQUN6QyxJQUFJLENBQUMsUUFBUSxHQUFHLElBQUksTUFBTSxDQUFDLGFBQWEsQ0FBQyxDQUFBO0lBQzNDLENBQUM7SUFFRDs7OztPQUlHO0lBQ0csS0FBSyxDQUFFLE9BQWdCOztZQUMzQixNQUFNLGFBQWEsR0FBRyxJQUFJLENBQUMsYUFBYSxDQUFDLFFBQVEsRUFBRSxDQUFBO1lBQ25ELE1BQU0sTUFBTSxDQUFDLElBQUksQ0FBQyxhQUFhLEVBQUUsSUFBSSxDQUFDLElBQUksQ0FBQyxDQUFBO1FBQzdDLENBQUM7S0FBQTtJQUVEOztPQUVHO0lBQ0csSUFBSTs7UUFDVixDQUFDO0tBQUE7SUFFRCxrREFBa0Q7SUFDbEQsc0JBQXNCO0lBQ3RCLGtEQUFrRDtJQUNsRDs7T0FFRztJQUNILElBQUksUUFBUTtRQUNWLE9BQU8sSUFBSSxDQUFDLGFBQWEsQ0FBQTtJQUMzQixDQUFDO0lBQ0QsSUFBSSxRQUFRLENBQUUsV0FBVztRQUN2QixJQUFJLENBQUMsYUFBYSxHQUFHLFdBQVcsQ0FBQTtJQUNsQyxDQUFDO0lBRUQ7O09BRUc7SUFDSCxJQUFJLEdBQUc7UUFDTCxPQUFPLE9BQU8sQ0FBQyxHQUFHLEVBQUUsQ0FBQTtJQUN0QixDQUFDO0lBRUQ7O09BRUc7SUFDSCxJQUFJLFFBQVE7UUFDVixPQUFPLE9BQU8sQ0FBQyxJQUFJLENBQUMsUUFBUSxDQUFDLElBQUksQ0FBQyxJQUFJLEVBQUUsSUFBSSxDQUFDLElBQUksQ0FBQyxDQUFBO0lBQ3BELENBQUM7SUFFRDs7T0FFRztJQUNILE1BQU07UUFDSixJQUFJLENBQUMsSUFBSSxDQUFDLGFBQWEsRUFBRTtZQUN2QixPQUFPLElBQUksQ0FBQTtTQUNaO1FBQ0QsT0FBTyxLQUFLLENBQUE7SUFDZCxDQUFDO0lBRUQ7O09BRUc7SUFDSCxRQUFRO1FBQ04sSUFBSSxJQUFJLENBQUMsUUFBUSxZQUFZLE1BQU0sRUFBRTtZQUNuQyxPQUFPLElBQUksQ0FBQTtTQUNaO1FBQ0QsT0FBTyxLQUFLLENBQUE7SUFDZCxDQUFDO0lBRUQsV0FBVztRQUNULE9BQU8sS0FBSyxDQUFBO0lBQ2QsQ0FBQztJQUVELFFBQVE7UUFDTixPQUFPLEtBQUssQ0FBQTtJQUNkLENBQUM7SUFFRCxVQUFVO1FBQ1IsT0FBTyxLQUFLLENBQUE7SUFDZCxDQUFDO0lBRUQsZ0JBQWdCO0lBQ2hCLGNBQWMsQ0FBRSxXQUFtQjtRQUNqQyxJQUFJLFdBQVcsR0FBRyxJQUFJLENBQUMsVUFBVSxDQUFDLElBQUksQ0FBQTtRQUN0QyxJQUFJLENBQUMsSUFBSSxHQUFHLElBQUksQ0FBQyxJQUFJLENBQUMsT0FBTyxDQUFDLElBQUksTUFBTSxDQUFDLFdBQVcsR0FBRyxHQUFHLENBQUMsRUFBQyxXQUFXLENBQUMsQ0FBQTtJQUMxRSxDQUFDO0NBQ0Y7QUF2SUQsOEJBdUlDIn0=
|
|
143
dist/smartfile.fs.d.ts
vendored
143
dist/smartfile.fs.d.ts
vendored
@ -1,143 +0,0 @@
|
|||||||
import { Smartfile } from './smartfile.classes.smartfile';
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param filePath
|
|
||||||
* @returns {boolean}
|
|
||||||
*/
|
|
||||||
export declare let fileExistsSync: (filePath: any) => boolean;
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param filePath
|
|
||||||
* @returns {any}
|
|
||||||
*/
|
|
||||||
export declare let fileExists: (filePath: any) => Promise<{}>;
|
|
||||||
/**
|
|
||||||
* Checks if given path points to an existing directory
|
|
||||||
*/
|
|
||||||
export declare let isDirectory: (pathArg: any) => boolean;
|
|
||||||
/**
|
|
||||||
* Checks if a given path points to an existing file
|
|
||||||
*/
|
|
||||||
export declare let isFile: (pathArg: any) => boolean;
|
|
||||||
/**
|
|
||||||
* copies a file from A to B on the local disk
|
|
||||||
*/
|
|
||||||
export declare let copy: (fromArg: string, toArg: string) => Promise<{}>;
|
|
||||||
/**
|
|
||||||
* copies a file SYNCHRONOUSLY from A to B on the local disk
|
|
||||||
*/
|
|
||||||
export declare let copySync: (fromArg: string, toArg: string) => boolean;
|
|
||||||
/**
|
|
||||||
* ensures that a directory is in place
|
|
||||||
*/
|
|
||||||
export declare let ensureDir: (dirPathArg: string) => Promise<{}>;
|
|
||||||
/**
|
|
||||||
* ensures that a directory is in place
|
|
||||||
*/
|
|
||||||
export declare let ensureDirSync: (dirPathArg: string) => void;
|
|
||||||
/**
|
|
||||||
* ensure an empty directory
|
|
||||||
* @executes ASYNC
|
|
||||||
*/
|
|
||||||
export declare let ensureEmptyDir: (dirPathArg: string) => Promise<{}>;
|
|
||||||
/**
|
|
||||||
* ensure an empty directory
|
|
||||||
* @executes SYNC
|
|
||||||
*/
|
|
||||||
export declare let ensureEmptyDirSync: (dirPathArg: string) => void;
|
|
||||||
/**
|
|
||||||
* ensures that a file is on disk
|
|
||||||
* @param filePath the filePath to ensureDir
|
|
||||||
* @param the fileContent to place into a new file in case it doesn't exist yet
|
|
||||||
* @returns Promise<void>
|
|
||||||
* @exec ASYNC
|
|
||||||
*/
|
|
||||||
export declare let ensureFile: (filePathArg: any, initFileStringArg: any) => Promise<void>;
|
|
||||||
/**
|
|
||||||
* ensures that a file is on disk
|
|
||||||
* @param filePath the filePath to ensureDir
|
|
||||||
* @param the fileContent to place into a new file in case it doesn't exist yet
|
|
||||||
* @returns Promise<void>
|
|
||||||
* @exec SYNC
|
|
||||||
*/
|
|
||||||
export declare let ensureFileSync: (filePathArg: string, initFileStringArg: string) => void;
|
|
||||||
/**
|
|
||||||
* removes a file or folder from local disk
|
|
||||||
*/
|
|
||||||
export declare let remove: (pathArg: string) => Promise<void>;
|
|
||||||
/**
|
|
||||||
* removes a file SYNCHRONOUSLY from local disk
|
|
||||||
*/
|
|
||||||
export declare let removeSync: (pathArg: string) => boolean;
|
|
||||||
/**
|
|
||||||
* removes an array of filePaths from disk
|
|
||||||
*/
|
|
||||||
export declare let removeMany: (filePathArrayArg: string[]) => Promise<void[]>;
|
|
||||||
/**
|
|
||||||
* like removeFilePathArray but SYNCHRONOUSLY
|
|
||||||
*/
|
|
||||||
export declare let removeManySync: (filePathArrayArg: string[]) => void;
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param filePathArg
|
|
||||||
* @param fileTypeArg
|
|
||||||
* @returns {any}
|
|
||||||
*/
|
|
||||||
export declare let toObjectSync: (filePathArg: any, fileTypeArg?: any) => any;
|
|
||||||
/**
|
|
||||||
* reads a file content to a String
|
|
||||||
* @param filePath
|
|
||||||
* @returns {string|Buffer|any}
|
|
||||||
*/
|
|
||||||
export declare let toStringSync: (filePath: string) => string;
|
|
||||||
export declare let fileTreeToObject: (dirPathArg: string, miniMatchFilter: string) => Promise<Smartfile[]>;
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param filePathArg
|
|
||||||
* @param options
|
|
||||||
* @returns {number}
|
|
||||||
*/
|
|
||||||
export declare let toVinylSync: (filePathArg: any, options?: {}) => any;
|
|
||||||
/**
|
|
||||||
* lets you reload files hot.
|
|
||||||
* @param path
|
|
||||||
* @returns {any}
|
|
||||||
*/
|
|
||||||
export declare let requireReload: (path: string) => any;
|
|
||||||
/**
|
|
||||||
* lists Folders in a directory on local disk
|
|
||||||
* @returns Promise
|
|
||||||
*/
|
|
||||||
export declare let listFolders: (pathArg: string, regexFilter?: RegExp) => Promise<{}>;
|
|
||||||
/**
|
|
||||||
* lists Folders SYNCHRONOUSLY in a directory on local disk
|
|
||||||
* @returns an array with the folder names as strings
|
|
||||||
*/
|
|
||||||
export declare let listFoldersSync: (pathArg: string, regexFilter?: RegExp) => string[];
|
|
||||||
/**
|
|
||||||
* lists Files in a directory on local disk
|
|
||||||
* @returns Promise
|
|
||||||
*/
|
|
||||||
export declare let listFiles: (pathArg: string, regexFilter?: RegExp) => Promise<{}>;
|
|
||||||
/**
|
|
||||||
* lists Files SYNCHRONOUSLY in a directory on local disk
|
|
||||||
* @returns an array with the folder names as strings
|
|
||||||
*/
|
|
||||||
export declare let listFilesSync: (pathArg: string, regexFilter?: RegExp) => string[];
|
|
||||||
/**
|
|
||||||
* lists all items (folders AND files) in a directory on local disk
|
|
||||||
* @returns Promise<string[]>
|
|
||||||
*/
|
|
||||||
export declare let listAllItems: (pathArg: string, regexFilter?: RegExp) => Promise<string[]>;
|
|
||||||
/**
|
|
||||||
* lists all items (folders AND files) in a directory on local disk
|
|
||||||
* @returns an array with the folder names as strings
|
|
||||||
* @executes SYNC
|
|
||||||
*/
|
|
||||||
export declare let listAllItemsSync: (pathArg: string, regexFilter?: RegExp) => string[];
|
|
||||||
/**
|
|
||||||
* lists a file tree using a miniMatch filter
|
|
||||||
* note: if the miniMatch Filter is an absolute path, the cwdArg will be omitted
|
|
||||||
* @returns Promise<string[]> string array with the absolute paths of all matching files
|
|
||||||
*/
|
|
||||||
export declare let listFileTree: (dirPathArg: string, miniMatchFilter: string) => Promise<string[]>;
|
|
374
dist/smartfile.fs.js
vendored
374
dist/smartfile.fs.js
vendored
File diff suppressed because one or more lines are too long
2
dist/smartfile.interpreter.d.ts
vendored
2
dist/smartfile.interpreter.d.ts
vendored
@ -1,2 +0,0 @@
|
|||||||
export declare let filetype: (pathArg: string) => string;
|
|
||||||
export declare let objectFile: (fileStringArg: string, fileTypeArg: any) => any;
|
|
21
dist/smartfile.interpreter.js
vendored
21
dist/smartfile.interpreter.js
vendored
@ -1,21 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
|
||||||
const plugins = require("./smartfile.plugins");
|
|
||||||
exports.filetype = (pathArg) => {
|
|
||||||
let extName = plugins.path.extname(pathArg);
|
|
||||||
let fileType = extName.replace(/\.([a-z]*)/, '$1'); // remove . form fileType
|
|
||||||
return fileType;
|
|
||||||
};
|
|
||||||
exports.objectFile = (fileStringArg, fileTypeArg) => {
|
|
||||||
switch (fileTypeArg) {
|
|
||||||
case 'yml':
|
|
||||||
case 'yaml':
|
|
||||||
return plugins.yaml.safeLoad(fileStringArg);
|
|
||||||
case 'json':
|
|
||||||
return JSON.parse(fileStringArg);
|
|
||||||
default:
|
|
||||||
console.error('file type ' + fileTypeArg.blue + ' not supported');
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRmaWxlLmludGVycHJldGVyLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRmaWxlLmludGVycHJldGVyLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7O0FBQUEsK0NBQStDO0FBRXBDLFFBQUEsUUFBUSxHQUFHLENBQUMsT0FBZSxFQUFVLEVBQUU7SUFDOUMsSUFBSSxPQUFPLEdBQUcsT0FBTyxDQUFDLElBQUksQ0FBQyxPQUFPLENBQUMsT0FBTyxDQUFDLENBQUE7SUFDM0MsSUFBSSxRQUFRLEdBQUcsT0FBTyxDQUFDLE9BQU8sQ0FBQyxZQUFZLEVBQUMsSUFBSSxDQUFDLENBQUEsQ0FBQyx5QkFBeUI7SUFDM0UsT0FBTyxRQUFRLENBQUE7QUFDbkIsQ0FBQyxDQUFBO0FBRVUsUUFBQSxVQUFVLEdBQUcsQ0FBQyxhQUFxQixFQUFFLFdBQVcsRUFBRSxFQUFFO0lBQzNELFFBQVEsV0FBVyxFQUFFO1FBQ2pCLEtBQUssS0FBSyxDQUFFO1FBQ1osS0FBSyxNQUFNO1lBQ1AsT0FBTyxPQUFPLENBQUMsSUFBSSxDQUFDLFFBQVEsQ0FBQyxhQUFhLENBQUMsQ0FBQTtRQUMvQyxLQUFLLE1BQU07WUFDUCxPQUFPLElBQUksQ0FBQyxLQUFLLENBQUMsYUFBYSxDQUFDLENBQUE7UUFDcEM7WUFDSSxPQUFPLENBQUMsS0FBSyxDQUFDLFlBQVksR0FBRyxXQUFXLENBQUMsSUFBSSxHQUFHLGdCQUFnQixDQUFDLENBQUE7WUFDakUsTUFBSztLQUNaO0FBQ0wsQ0FBQyxDQUFBIn0=
|
|
25
dist/smartfile.memory.d.ts
vendored
25
dist/smartfile.memory.d.ts
vendored
@ -1,25 +0,0 @@
|
|||||||
import { Smartfile } from './smartfile.classes.smartfile';
|
|
||||||
/**
|
|
||||||
* converts file to Object
|
|
||||||
* @param fileStringArg
|
|
||||||
* @param fileTypeArg
|
|
||||||
* @returns {any|any}
|
|
||||||
*/
|
|
||||||
export declare let toObject: (fileStringArg: string, fileTypeArg: string) => any;
|
|
||||||
export interface IToFsOptions {
|
|
||||||
respectRelative?: boolean;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* writes string or Smartfile to disk.
|
|
||||||
* @param fileArg
|
|
||||||
* @param fileNameArg
|
|
||||||
* @param fileBaseArg
|
|
||||||
*/
|
|
||||||
export declare let toFs: (fileContentArg: string | Smartfile, filePathArg: any, optionsArg?: IToFsOptions) => Promise<{}>;
|
|
||||||
/**
|
|
||||||
* writes a string or a Smartfile to disk synchronously, only supports string
|
|
||||||
* @param fileArg
|
|
||||||
* @param filePathArg
|
|
||||||
*/
|
|
||||||
export declare let toFsSync: (fileArg: string, filePathArg: string) => void;
|
|
||||||
export declare let smartfileArrayToFs: (smartfileArrayArg: Smartfile[], dirArg: string) => Promise<void>;
|
|
87
dist/smartfile.memory.js
vendored
87
dist/smartfile.memory.js
vendored
@ -1,87 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
||||||
return new (P || (P = Promise))(function (resolve, reject) {
|
|
||||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
||||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
||||||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
|
||||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
||||||
});
|
|
||||||
};
|
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
|
||||||
const plugins = require("./smartfile.plugins");
|
|
||||||
const smartfile_classes_smartfile_1 = require("./smartfile.classes.smartfile");
|
|
||||||
const smartfileFs = require("./smartfile.fs");
|
|
||||||
const SmartfileInterpreter = require("./smartfile.interpreter");
|
|
||||||
/**
|
|
||||||
* converts file to Object
|
|
||||||
* @param fileStringArg
|
|
||||||
* @param fileTypeArg
|
|
||||||
* @returns {any|any}
|
|
||||||
*/
|
|
||||||
exports.toObject = function (fileStringArg, fileTypeArg) {
|
|
||||||
return SmartfileInterpreter.objectFile(fileStringArg, fileTypeArg);
|
|
||||||
};
|
|
||||||
/**
|
|
||||||
* writes string or Smartfile to disk.
|
|
||||||
* @param fileArg
|
|
||||||
* @param fileNameArg
|
|
||||||
* @param fileBaseArg
|
|
||||||
*/
|
|
||||||
exports.toFs = (fileContentArg, filePathArg, optionsArg = {}) => __awaiter(this, void 0, void 0, function* () {
|
|
||||||
let done = plugins.smartpromise.defer();
|
|
||||||
// check args
|
|
||||||
if (!fileContentArg || !filePathArg) {
|
|
||||||
throw new Error('expected valid arguments');
|
|
||||||
}
|
|
||||||
// prepare actual write action
|
|
||||||
let fileString;
|
|
||||||
let filePath = filePathArg;
|
|
||||||
// handle Smartfile
|
|
||||||
if (fileContentArg instanceof smartfile_classes_smartfile_1.Smartfile) {
|
|
||||||
let fileContentArg2 = fileContentArg;
|
|
||||||
fileString = fileContentArg.contentBuffer.toString();
|
|
||||||
// handle options
|
|
||||||
if (optionsArg.respectRelative) {
|
|
||||||
filePath = plugins.path.join(filePath, fileContentArg.path);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (typeof fileContentArg === 'string') {
|
|
||||||
fileString = fileContentArg;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
throw new Error('fileContent is neither string nor Smartfile');
|
|
||||||
}
|
|
||||||
yield smartfileFs.ensureDir(plugins.path.parse(filePath).dir);
|
|
||||||
plugins.fsExtra.writeFile(filePath, fileString, { encoding: 'utf8' }, done.resolve);
|
|
||||||
return yield done.promise;
|
|
||||||
});
|
|
||||||
/**
|
|
||||||
* writes a string or a Smartfile to disk synchronously, only supports string
|
|
||||||
* @param fileArg
|
|
||||||
* @param filePathArg
|
|
||||||
*/
|
|
||||||
exports.toFsSync = function (fileArg, filePathArg) {
|
|
||||||
// function checks to abort if needed
|
|
||||||
if (!fileArg || !filePathArg) {
|
|
||||||
throw new Error('expected a valid arguments');
|
|
||||||
}
|
|
||||||
// prepare actual write action
|
|
||||||
let fileString;
|
|
||||||
let filePath = filePathArg;
|
|
||||||
if (typeof fileArg !== 'string') {
|
|
||||||
throw new Error('fileArg is not of type String.');
|
|
||||||
}
|
|
||||||
else if (typeof fileArg === 'string') {
|
|
||||||
fileString = fileArg;
|
|
||||||
}
|
|
||||||
plugins.fsExtra.writeFileSync(filePath, fileString, { encoding: 'utf8' });
|
|
||||||
};
|
|
||||||
exports.smartfileArrayToFs = (smartfileArrayArg, dirArg) => __awaiter(this, void 0, void 0, function* () {
|
|
||||||
yield smartfileFs.ensureDir(dirArg);
|
|
||||||
for (let smartfile of smartfileArrayArg) {
|
|
||||||
yield exports.toFs(smartfile, dirArg, {
|
|
||||||
respectRelative: true
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRmaWxlLm1lbW9yeS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0ZmlsZS5tZW1vcnkudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7OztBQUFBLCtDQUErQztBQUMvQywrRUFBeUQ7QUFDekQsOENBQTZDO0FBRzdDLGdFQUFnRTtBQUVoRTs7Ozs7R0FLRztBQUNRLFFBQUEsUUFBUSxHQUFHLFVBQVUsYUFBcUIsRUFBRSxXQUFtQjtJQUN4RSxPQUFPLG9CQUFvQixDQUFDLFVBQVUsQ0FBQyxhQUFhLEVBQUUsV0FBVyxDQUFDLENBQUE7QUFDcEUsQ0FBQyxDQUFBO0FBTUQ7Ozs7O0dBS0c7QUFDUSxRQUFBLElBQUksR0FBRyxDQUFPLGNBQWtDLEVBQUUsV0FBVyxFQUFFLGFBQTJCLEVBQUUsRUFBRyxFQUFFO0lBQzFHLElBQUksSUFBSSxHQUFHLE9BQU8sQ0FBQyxZQUFZLENBQUMsS0FBSyxFQUFFLENBQUE7SUFFdkMsYUFBYTtJQUNiLElBQUksQ0FBQyxjQUFjLElBQUksQ0FBQyxXQUFXLEVBQUU7UUFDbkMsTUFBTSxJQUFJLEtBQUssQ0FBQywwQkFBMEIsQ0FBQyxDQUFBO0tBQzVDO0lBRUQsOEJBQThCO0lBQzlCLElBQUksVUFBa0IsQ0FBQTtJQUN0QixJQUFJLFFBQVEsR0FBVyxXQUFXLENBQUE7SUFFbEMsbUJBQW1CO0lBQ25CLElBQUksY0FBYyxZQUFZLHVDQUFTLEVBQUU7UUFDdkMsSUFBSSxlQUFlLEdBQVEsY0FBYyxDQUFBO1FBQ3pDLFVBQVUsR0FBRyxjQUFjLENBQUMsYUFBYSxDQUFDLFFBQVEsRUFBRSxDQUFBO1FBQ3BELGlCQUFpQjtRQUNqQixJQUFJLFVBQVUsQ0FBQyxlQUFlLEVBQUU7WUFDOUIsUUFBUSxHQUFHLE9BQU8sQ0FBQyxJQUFJLENBQUMsSUFBSSxDQUFDLFFBQVEsRUFBRSxjQUFjLENBQUMsSUFBSSxDQUFDLENBQUE7U0FDNUQ7S0FDRjtTQUFNLElBQUksT0FBTyxjQUFjLEtBQUssUUFBUSxFQUFFO1FBQzdDLFVBQVUsR0FBRyxjQUFjLENBQUE7S0FDNUI7U0FBTTtRQUNMLE1BQU0sSUFBSSxLQUFLLENBQUMsNkNBQTZDLENBQUMsQ0FBQTtLQUMvRDtJQUNELE1BQU0sV0FBVyxDQUFDLFNBQVMsQ0FBQyxPQUFPLENBQUMsSUFBSSxDQUFDLEtBQUssQ0FBQyxRQUFRLENBQUMsQ0FBQyxHQUFHLENBQUMsQ0FBQTtJQUM3RCxPQUFPLENBQUMsT0FBTyxDQUFDLFNBQVMsQ0FBQyxRQUFRLEVBQUUsVUFBVSxFQUFFLEVBQUMsUUFBUSxFQUFFLE1BQU0sRUFBQyxFQUFFLElBQUksQ0FBQyxPQUFPLENBQUMsQ0FBQTtJQUNqRixPQUFPLE1BQU0sSUFBSSxDQUFDLE9BQU8sQ0FBQTtBQUMzQixDQUFDLENBQUEsQ0FBQTtBQUVEOzs7O0dBSUc7QUFDUSxRQUFBLFFBQVEsR0FBRyxVQUFVLE9BQWUsRUFBRSxXQUFtQjtJQUNsRSxxQ0FBcUM7SUFDckMsSUFBSSxDQUFDLE9BQU8sSUFBSSxDQUFDLFdBQVcsRUFBRTtRQUM1QixNQUFNLElBQUksS0FBSyxDQUFDLDRCQUE0QixDQUFDLENBQUE7S0FDOUM7SUFFRCw4QkFBOEI7SUFDOUIsSUFBSSxVQUFrQixDQUFBO0lBQ3RCLElBQUksUUFBUSxHQUFXLFdBQVcsQ0FBQTtJQUVsQyxJQUFJLE9BQU8sT0FBTyxLQUFLLFFBQVEsRUFBRTtRQUMvQixNQUFNLElBQUksS0FBSyxDQUFDLGdDQUFnQyxDQUFDLENBQUE7S0FDbEQ7U0FBTSxJQUFJLE9BQU8sT0FBTyxLQUFLLFFBQVEsRUFBRTtRQUN0QyxVQUFVLEdBQUcsT0FBTyxDQUFBO0tBQ3JCO0lBQ0QsT0FBTyxDQUFDLE9BQU8sQ0FBQyxhQUFhLENBQUMsUUFBUSxFQUFFLFVBQVUsRUFBRSxFQUFDLFFBQVEsRUFBRSxNQUFNLEVBQUMsQ0FBQyxDQUFBO0FBQ3pFLENBQUMsQ0FBQTtBQUVVLFFBQUEsa0JBQWtCLEdBQUcsQ0FBTyxpQkFBOEIsRUFBRSxNQUFjLEVBQUUsRUFBRTtJQUN2RixNQUFNLFdBQVcsQ0FBQyxTQUFTLENBQUMsTUFBTSxDQUFDLENBQUE7SUFDbkMsS0FBSyxJQUFJLFNBQVMsSUFBSSxpQkFBaUIsRUFBRTtRQUN2QyxNQUFNLFlBQUksQ0FBQyxTQUFTLEVBQUUsTUFBTSxFQUFFO1lBQzVCLGVBQWUsRUFBRSxJQUFJO1NBQ3RCLENBQUMsQ0FBQTtLQUNIO0FBQ0gsQ0FBQyxDQUFBLENBQUEifQ==
|
|
10
dist/smartfile.plugins.d.ts
vendored
10
dist/smartfile.plugins.d.ts
vendored
@ -1,10 +0,0 @@
|
|||||||
export import fs = require('fs');
|
|
||||||
export import fsExtra = require('fs-extra');
|
|
||||||
export declare let glob: any;
|
|
||||||
export import path = require('path');
|
|
||||||
export import smartpromise = require('@pushrocks/smartpromise');
|
|
||||||
export import smartrequest = require('smartrequest');
|
|
||||||
export declare let requireReload: any;
|
|
||||||
export import smartpath = require('smartpath');
|
|
||||||
export declare let vinylFile: any;
|
|
||||||
export declare let yaml: any;
|
|
13
dist/smartfile.plugins.js
vendored
13
dist/smartfile.plugins.js
vendored
@ -1,13 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
|
||||||
exports.fs = require("fs");
|
|
||||||
exports.fsExtra = require("fs-extra");
|
|
||||||
exports.glob = require('glob');
|
|
||||||
exports.path = require("path");
|
|
||||||
exports.smartpromise = require("@pushrocks/smartpromise");
|
|
||||||
exports.smartrequest = require("smartrequest");
|
|
||||||
exports.requireReload = require('require-reload');
|
|
||||||
exports.smartpath = require("smartpath");
|
|
||||||
exports.vinylFile = require('vinyl-file');
|
|
||||||
exports.yaml = require('js-yaml');
|
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRmaWxlLnBsdWdpbnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydGZpbGUucGx1Z2lucy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLDJCQUFnQztBQUNoQyxzQ0FBMkM7QUFDaEMsUUFBQSxJQUFJLEdBQUcsT0FBTyxDQUFDLE1BQU0sQ0FBQyxDQUFBO0FBQ2pDLCtCQUFvQztBQUNwQywwREFBK0Q7QUFDL0QsK0NBQW9EO0FBQ3pDLFFBQUEsYUFBYSxHQUFHLE9BQU8sQ0FBQyxnQkFBZ0IsQ0FBQyxDQUFBO0FBQ3BELHlDQUE4QztBQUNuQyxRQUFBLFNBQVMsR0FBRyxPQUFPLENBQUMsWUFBWSxDQUFDLENBQUE7QUFDakMsUUFBQSxJQUFJLEdBQUcsT0FBTyxDQUFDLFNBQVMsQ0FBQyxDQUFBIn0=
|
|
12
dist/smartfile.remote.d.ts
vendored
12
dist/smartfile.remote.d.ts
vendored
@ -1,12 +0,0 @@
|
|||||||
/**
|
|
||||||
*
|
|
||||||
* @param fromArg
|
|
||||||
* @returns {any}
|
|
||||||
*/
|
|
||||||
export declare let toObject: (fromArg: string) => Promise<{}>;
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param fromArg
|
|
||||||
* @returns {any}
|
|
||||||
*/
|
|
||||||
export declare let toString: (fromArg: string) => Promise<{}>;
|
|
49
dist/smartfile.remote.js
vendored
49
dist/smartfile.remote.js
vendored
@ -1,49 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
|
||||||
const plugins = require("./smartfile.plugins");
|
|
||||||
/* export let toFs = function (from: string, toPath: string) {
|
|
||||||
let done = plugins.q.defer()
|
|
||||||
let stream = plugins.smartrequest(from).pipe(plugins.fsExtra.createWriteStream(toPath))
|
|
||||||
stream.on('finish', function () {
|
|
||||||
done.resolve(toPath)
|
|
||||||
})
|
|
||||||
return done.promise
|
|
||||||
} */
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param fromArg
|
|
||||||
* @returns {any}
|
|
||||||
*/
|
|
||||||
exports.toObject = function (fromArg) {
|
|
||||||
let done = plugins.smartpromise.defer();
|
|
||||||
plugins.smartrequest.request(fromArg, {
|
|
||||||
method: 'get'
|
|
||||||
}).then((res) => {
|
|
||||||
if (res.statusCode === 200) {
|
|
||||||
done.resolve(res.body);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
console.log('could not get remote file from ' + fromArg);
|
|
||||||
done.reject(new Error('could not get remote file from ' + fromArg));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return done.promise;
|
|
||||||
};
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param fromArg
|
|
||||||
* @returns {any}
|
|
||||||
*/
|
|
||||||
exports.toString = (fromArg) => {
|
|
||||||
let done = plugins.smartpromise.defer();
|
|
||||||
plugins.smartrequest.get(fromArg).then((res) => {
|
|
||||||
if (res.statusCode === 200) {
|
|
||||||
done.resolve(res.body);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
done.reject(new Error('could not get remote file from ' + fromArg));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return done.promise;
|
|
||||||
};
|
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRmaWxlLnJlbW90ZS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0ZmlsZS5yZW1vdGUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFBQSwrQ0FBK0M7QUFHL0M7Ozs7Ozs7SUFPSTtBQUVKOzs7O0dBSUc7QUFDUSxRQUFBLFFBQVEsR0FBRyxVQUFVLE9BQWU7SUFDN0MsSUFBSSxJQUFJLEdBQUcsT0FBTyxDQUFDLFlBQVksQ0FBQyxLQUFLLEVBQUUsQ0FBQTtJQUN2QyxPQUFPLENBQUMsWUFBWSxDQUFDLE9BQU8sQ0FBQyxPQUFPLEVBQUU7UUFDcEMsTUFBTSxFQUFFLEtBQUs7S0FDZCxDQUFDLENBQUMsSUFBSSxDQUFDLENBQUMsR0FBUSxFQUFFLEVBQUU7UUFDbkIsSUFBSSxHQUFHLENBQUMsVUFBVSxLQUFLLEdBQUcsRUFBRTtZQUMxQixJQUFJLENBQUMsT0FBTyxDQUFDLEdBQUcsQ0FBQyxJQUFJLENBQUMsQ0FBQTtTQUN2QjthQUFNO1lBQ0wsT0FBTyxDQUFDLEdBQUcsQ0FBQyxpQ0FBaUMsR0FBRyxPQUFPLENBQUMsQ0FBQTtZQUN4RCxJQUFJLENBQUMsTUFBTSxDQUFDLElBQUksS0FBSyxDQUFDLGlDQUFpQyxHQUFHLE9BQU8sQ0FBQyxDQUFDLENBQUE7U0FDcEU7SUFDSCxDQUFDLENBQUMsQ0FBQTtJQUNGLE9BQU8sSUFBSSxDQUFDLE9BQU8sQ0FBQTtBQUNyQixDQUFDLENBQUE7QUFFRDs7OztHQUlHO0FBQ1EsUUFBQSxRQUFRLEdBQUcsQ0FBQyxPQUFlLEVBQUUsRUFBRTtJQUN4QyxJQUFJLElBQUksR0FBRyxPQUFPLENBQUMsWUFBWSxDQUFDLEtBQUssRUFBRSxDQUFBO0lBQ3ZDLE9BQU8sQ0FBQyxZQUFZLENBQUMsR0FBRyxDQUFDLE9BQU8sQ0FBQyxDQUFDLElBQUksQ0FBQyxDQUFDLEdBQVEsRUFBRSxFQUFFO1FBQ2xELElBQUksR0FBRyxDQUFDLFVBQVUsS0FBSyxHQUFHLEVBQUU7WUFDMUIsSUFBSSxDQUFDLE9BQU8sQ0FBQyxHQUFHLENBQUMsSUFBSSxDQUFDLENBQUE7U0FDdkI7YUFBTTtZQUNMLElBQUksQ0FBQyxNQUFNLENBQUMsSUFBSSxLQUFLLENBQUMsaUNBQWlDLEdBQUcsT0FBTyxDQUFDLENBQUMsQ0FBQTtTQUNwRTtJQUNILENBQUMsQ0FBQyxDQUFBO0lBQ0YsT0FBTyxJQUFJLENBQUMsT0FBTyxDQUFBO0FBQ3JCLENBQUMsQ0FBQSJ9
|
|
@ -1,43 +0,0 @@
|
|||||||
# smartfile
|
|
||||||
|
|
||||||
make files easily accessible for processing in javascript.
|
|
||||||
|
|
||||||
## Availabililty
|
|
||||||
|
|
||||||
[](https://www.npmjs.com/package/smartfile)
|
|
||||||
[](https://gitlab.com/pushrocks/smartfile)
|
|
||||||
[](https://github.com/pushrocks/smartfile)
|
|
||||||
[](https://pushrocks.gitlab.io/smartfile/)
|
|
||||||
|
|
||||||
## Status for master
|
|
||||||
|
|
||||||
[](https://gitlab.com/pushrocks/smartfile/commits/master)
|
|
||||||
[](https://gitlab.com/pushrocks/smartfile/commits/master)
|
|
||||||
[](https://david-dm.org/pushrocks/smartfile)
|
|
||||||
[](https://www.bithound.io/github/pushrocks/smartfile/master/dependencies/npm)
|
|
||||||
[](https://www.bithound.io/github/pushrocks/smartfile)
|
|
||||||
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
|
||||||
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
|
||||||
[](http://standardjs.com/)
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
|
|
||||||
smartfile is an approach of being one tool to handle files in diverse environments.
|
|
||||||
|
|
||||||
### Smartfile Sections
|
|
||||||
|
|
||||||
smartfile thinks in sections:
|
|
||||||
|
|
||||||
| section | description |
|
|
||||||
| ----------- | ---------------------------------------------------------------------------- |
|
|
||||||
| fs | (object) gets data from fs to somewhere |
|
|
||||||
| memory | gets data from memory to somewhere |
|
|
||||||
| remote | gets data from remote locations to somewhere |
|
|
||||||
| interpreter | (object) handles yaml and json |
|
|
||||||
| 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.
|
|
||||||
|
|
||||||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
|
||||||
|
|
||||||
[](https://push.rocks)
|
|
@ -1,15 +1,21 @@
|
|||||||
{
|
{
|
||||||
"npmts":{
|
"npmts": {
|
||||||
"mode":"default",
|
"mode": "default",
|
||||||
"coverageTreshold":70
|
"coverageTreshold": 70
|
||||||
},
|
|
||||||
"npmdocker":{
|
|
||||||
|
|
||||||
},
|
},
|
||||||
|
"npmdocker": {},
|
||||||
"npmci": {
|
"npmci": {
|
||||||
"npmGlobalTools": [
|
"npmGlobalTools": [],
|
||||||
"npmts"
|
|
||||||
],
|
|
||||||
"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"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
1400
package-lock.json
generated
1400
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
42
package.json
42
package.json
@ -1,17 +1,17 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartfile",
|
"name": "@pushrocks/smartfile",
|
||||||
"private": false,
|
"private": false,
|
||||||
"version": "6.0.2",
|
"version": "7.0.4",
|
||||||
"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",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "(npmts)",
|
"test": "(tstest test/)",
|
||||||
"reinstall": "(rm -r node_modules && npm install)",
|
"reinstall": "(rm -r node_modules && npm install)",
|
||||||
"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": "echo \"Not needed for now\""
|
"build": "(tsbuild)"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@ -28,20 +28,34 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://gitlab.com/pushrocks/smartfile",
|
"homepage": "https://gitlab.com/pushrocks/smartfile",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pushrocks/smartpromise": "^2.0.5",
|
"@pushrocks/smartpath": "^4.0.1",
|
||||||
"@types/fs-extra": "^5.0.3",
|
"@pushrocks/smartpromise": "^3.0.2",
|
||||||
|
"@pushrocks/smartrequest": "^1.1.14",
|
||||||
|
"@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.13.1",
|
||||||
"require-reload": "0.2.2",
|
|
||||||
"smartpath": "^3.2.8",
|
|
||||||
"smartrequest": "^1.0.13",
|
|
||||||
"vinyl-file": "^3.0.0"
|
"vinyl-file": "^3.0.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "^10.5.1",
|
"@gitzone/tsbuild": "^2.1.8",
|
||||||
|
"@gitzone/tsrun": "^1.2.1",
|
||||||
|
"@gitzone/tstest": "^1.0.18",
|
||||||
|
"@pushrocks/tapbundle": "^3.0.7",
|
||||||
|
"@types/node": "^11.13.0",
|
||||||
"gulp-function": "^2.2.14",
|
"gulp-function": "^2.2.14",
|
||||||
"tapbundle": "^2.0.2"
|
"tslint": "^5.15.0",
|
||||||
}
|
"tslint-config-prettier": "^1.18.0"
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"ts/*",
|
||||||
|
"ts_web/*",
|
||||||
|
"dist/*",
|
||||||
|
"dist_web/*",
|
||||||
|
"assets/*",
|
||||||
|
"cli.js",
|
||||||
|
"npmextra.json",
|
||||||
|
"readme.md"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
81
test/test.ts
81
test/test.ts
@ -1,119 +1,119 @@
|
|||||||
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
|
||||||
// ---------------------------
|
// ---------------------------
|
||||||
|
|
||||||
tap.test('.fs.fileExistsSync -> should return an accurate boolean', async () => {
|
tap.test('.fs.fileExistsSync -> should return an accurate boolean', async () => {
|
||||||
expect(smartfile.fs.fileExistsSync('./test/mytest.json')).to.be.true;
|
expect(smartfile.fs.fileExistsSync('./test/testassets/mytest.json')).to.be.true;
|
||||||
expect(smartfile.fs.fileExistsSync('./test/notthere.json')).be.false;
|
expect(smartfile.fs.fileExistsSync('./test/testassets/notthere.json')).be.false;
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('.fs.fileExists -> should resolve or reject a promise', async () => {
|
tap.test('.fs.fileExists -> should resolve or reject a promise', async () => {
|
||||||
expect(smartfile.fs.fileExists('./test/mytest.json')).to.be.instanceof(Promise);
|
expect(smartfile.fs.fileExists('./test/testassets/mytest.json')).to.be.instanceof(Promise);
|
||||||
await smartfile.fs.fileExists('./test/mytest.json');
|
await smartfile.fs.fileExists('./test/testassets/mytest.json');
|
||||||
await smartfile.fs.fileExists('./test/notthere.json').catch(err => {
|
await smartfile.fs.fileExists('./test/testassets/notthere.json').catch(err => {
|
||||||
return expect(err.message).to.equal(
|
return expect(err.message).to.equal(
|
||||||
"ENOENT: no such file or directory, access './test/notthere.json'"
|
"ENOENT: no such file or directory, access './test/testassets/notthere.json'"
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('.fs.listFoldersSync() -> should get the file type from a string', async () => {
|
tap.test('.fs.listFoldersSync() -> should get the file type from a string', async () => {
|
||||||
expect(smartfile.fs.listFoldersSync('./test/')).to.include('testfolder');
|
expect(smartfile.fs.listFoldersSync('./test/testassets/')).to.include('testfolder');
|
||||||
expect(smartfile.fs.listFoldersSync('./test/')).to.not.include('notExistentFolder');
|
expect(smartfile.fs.listFoldersSync('./test/testassets/')).to.not.include('notExistentFolder');
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('.fs.listFolders() -> should get the file type from a string', async () => {
|
tap.test('.fs.listFolders() -> should get the file type from a string', async () => {
|
||||||
let folderArrayArg = await smartfile.fs.listFolders('./test/');
|
let folderArrayArg = await smartfile.fs.listFolders('./test/testassets/');
|
||||||
expect(folderArrayArg).to.include('testfolder');
|
expect(folderArrayArg).to.include('testfolder');
|
||||||
expect(folderArrayArg).to.not.include('notExistentFolder');
|
expect(folderArrayArg).to.not.include('notExistentFolder');
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('.fs.listFilesSync() -> should get the file type from a string', async () => {
|
tap.test('.fs.listFilesSync() -> should get the file type from a string', async () => {
|
||||||
expect(smartfile.fs.listFilesSync('./test/')).to.include('mytest.json');
|
expect(smartfile.fs.listFilesSync('./test/testassets/')).to.include('mytest.json');
|
||||||
expect(smartfile.fs.listFilesSync('./test/')).to.not.include('notExistentFile');
|
expect(smartfile.fs.listFilesSync('./test/testassets/')).to.not.include('notExistentFile');
|
||||||
expect(smartfile.fs.listFilesSync('./test/', /mytest\.json/)).to.include('mytest.json');
|
expect(smartfile.fs.listFilesSync('./test/testassets/', /mytest\.json/)).to.include('mytest.json');
|
||||||
expect(smartfile.fs.listFilesSync('./test/', /mytests.json/)).to.not.include('mytest.json');
|
expect(smartfile.fs.listFilesSync('./test/testassets/', /mytests.json/)).to.not.include('mytest.json');
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('.fs.listFiles() -> should get the file type from a string', async () => {
|
tap.test('.fs.listFiles() -> should get the file type from a string', async () => {
|
||||||
let folderArrayArg = await smartfile.fs.listFiles('./test/');
|
let folderArrayArg = await smartfile.fs.listFiles('./test/testassets/');
|
||||||
expect(folderArrayArg).to.include('mytest.json');
|
expect(folderArrayArg).to.include('mytest.json');
|
||||||
expect(folderArrayArg).to.not.include('notExistentFile');
|
expect(folderArrayArg).to.not.include('notExistentFile');
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('.fs.listFileTree() -> should get a file tree', async () => {
|
tap.test('.fs.listFileTree() -> should get a file tree', async () => {
|
||||||
let folderArrayArg = await smartfile.fs.listFileTree(path.resolve('./test/'), '**/*.txt');
|
let folderArrayArg = await smartfile.fs.listFileTree(path.resolve('./test/testassets/'), '**/*.txt');
|
||||||
expect(folderArrayArg).to.include('testfolder/testfile1.txt');
|
expect(folderArrayArg).to.include('testfolder/testfile1.txt');
|
||||||
expect(folderArrayArg).to.not.include('mytest.json');
|
expect(folderArrayArg).to.not.include('mytest.json');
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('.fs.fileTreeToObject -> should read a file tree into an Object', async () => {
|
tap.test('.fs.fileTreeToObject -> should read a file tree into an Object', async () => {
|
||||||
let fileArrayArg = await smartfile.fs.fileTreeToObject(path.resolve('./test/'), '**/*.txt');
|
let fileArrayArg = await smartfile.fs.fileTreeToObject(path.resolve('./test/testassets/'), '**/*.txt');
|
||||||
expect(fileArrayArg[0]).to.be.instanceof(smartfile.Smartfile);
|
expect(fileArrayArg[0]).to.be.instanceof(smartfile.Smartfile);
|
||||||
expect(fileArrayArg[0].contents.toString()).to.equal(fileArrayArg[0].contentBuffer.toString());
|
expect(fileArrayArg[0].contents.toString()).to.equal(fileArrayArg[0].contentBuffer.toString());
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('.fs.copy() -> should copy a directory', async () => {
|
tap.test('.fs.copy() -> should copy a directory', async () => {
|
||||||
smartfile.fs.copy('./test/testfolder/', './test/temp/');
|
await smartfile.fs.copy('./test/testassets/testfolder/', './test/testassets/temp/');
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('.fs.copy() -> should copy a file', async () => {
|
tap.test('.fs.copy() -> should copy a file', async () => {
|
||||||
smartfile.fs.copy('./test/mytest.yaml', './test/temp/');
|
await smartfile.fs.copy('./test/testassets/mytest.yaml', './test/testassets/temp/mytest.yaml');
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('.fs.copy() -> should copy a file and rename it', async () => {
|
tap.test('.fs.copy() -> should copy a file and rename it', async () => {
|
||||||
smartfile.fs.copy('./test/mytest.yaml', './test/temp/mytestRenamed.yaml');
|
await smartfile.fs.copy('./test/testassets/mytest.yaml', './test/testassets/temp/mytestRenamed.yaml');
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('.fs.remove() -> should remove an entire directory', async () => {});
|
tap.test('.fs.remove() -> should remove an entire directory', async () => {});
|
||||||
|
|
||||||
tap.test('.fs.remove -> should remove single files', async () => {
|
tap.test('.fs.remove -> should remove single files', async () => {
|
||||||
await smartfile.fs.remove('./test/temp/mytestRenamed.yaml');
|
await smartfile.fs.remove('./test/testassets/temp/mytestRenamed.yaml');
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('.fs.removeSync -> should remove single files synchronouly', async () => {
|
tap.test('.fs.removeSync -> should remove single files synchronouly', async () => {
|
||||||
smartfile.fs.removeSync('./test/temp/testfile1.txt');
|
smartfile.fs.removeSync('./test/testassets/temp/testfile1.txt');
|
||||||
expect(smartfile.fs.fileExistsSync('./test/temp/testfile1.txt')).to.be.false;
|
expect(smartfile.fs.fileExistsSync('./test/testassets/temp/testfile1.txt')).to.be.false;
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('.fs.removeMany -> should remove and array of files', async () => {
|
tap.test('.fs.removeMany -> should remove and array of files', async () => {
|
||||||
smartfile.fs.removeMany(['./test/temp/testfile1.txt', './test/temp/testfile2.txt']).then(() => {
|
smartfile.fs.removeMany(['./test/testassets/temp/testfile1.txt', './test/testassets/temp/testfile2.txt']).then(() => {
|
||||||
expect(smartfile.fs.fileExistsSync('./test/temp/testfile1.txt')).to.be.false;
|
expect(smartfile.fs.fileExistsSync('./test/testassets/temp/testfile1.txt')).to.be.false;
|
||||||
expect(smartfile.fs.fileExistsSync('./test/temp/testfile2.txt')).to.be.false;
|
expect(smartfile.fs.fileExistsSync('./test/testassets/temp/testfile2.txt')).to.be.false;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('.fs.removeManySync -> should remove and array of single files synchronouly', async () => {
|
tap.test('.fs.removeManySync -> should remove and array of single files synchronouly', async () => {
|
||||||
smartfile.fs.removeManySync(['./test/temp/testfile1.txt', './test/temp/testfile2.txt']);
|
smartfile.fs.removeManySync(['./test/testassets/temp/testfile1.txt', './test/testassets/temp/testfile2.txt']);
|
||||||
expect(smartfile.fs.fileExistsSync('./test/temp/testfile1.txt')).to.be.false;
|
expect(smartfile.fs.fileExistsSync('./test/testassets/temp/testfile1.txt')).to.be.false;
|
||||||
expect(smartfile.fs.fileExistsSync('./test/temp/testfile2.txt')).to.be.false;
|
expect(smartfile.fs.fileExistsSync('./test/testassets/temp/testfile2.txt')).to.be.false;
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('.fs.toObjectSync() -> should read an ' + '.yaml' + ' file to an object', async () => {
|
tap.test('.fs.toObjectSync() -> should read an ' + '.yaml' + ' file to an object', async () => {
|
||||||
let testData = smartfile.fs.toObjectSync('./test/mytest.yaml');
|
let testData = smartfile.fs.toObjectSync('./test/testassets/mytest.yaml');
|
||||||
expect(testData).to.include({ key1: 'this works' });
|
expect(testData).to.include({ key1: 'this works' });
|
||||||
expect(testData).to.include({ key2: 'this works too' });
|
expect(testData).to.include({ key2: 'this works too' });
|
||||||
});
|
});
|
||||||
tap.test(
|
tap.test(
|
||||||
'.fs.toObjectSync() -> should state unknown file type for unknown file types',
|
'.fs.toObjectSync() -> should state unknown file type for unknown file types',
|
||||||
async () => {
|
async () => {
|
||||||
let testData = smartfile.fs.toObjectSync('./test/mytest.txt');
|
let testData = smartfile.fs.toObjectSync('./test/testassets/mytest.txt');
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
tap.test('.fs.toObjectSync() -> should read an ' + '.json' + ' file to an object', async () => {
|
tap.test('.fs.toObjectSync() -> should read an ' + '.json' + ' file to an object', async () => {
|
||||||
let testData = smartfile.fs.toObjectSync('./test/mytest.json');
|
let testData = smartfile.fs.toObjectSync('./test/testassets/mytest.json');
|
||||||
expect(testData).to.include({ key1: 'this works' });
|
expect(testData).to.include({ key1: 'this works' });
|
||||||
expect(testData).to.include({ key2: 'this works too' });
|
expect(testData).to.include({ key2: 'this works too' });
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('.fs.toStringSync() -> should read a file to a string', async () => {
|
tap.test('.fs.toStringSync() -> should read a file to a string', async () => {
|
||||||
expect(smartfile.fs.toStringSync('./test/mytest.txt')).to.equal('Some TestString &&%$');
|
expect(smartfile.fs.toStringSync('./test/testassets/mytest.txt')).to.equal('Some TestString &&%$');
|
||||||
});
|
});
|
||||||
|
|
||||||
// ---------------------------
|
// ---------------------------
|
||||||
@ -130,7 +130,7 @@ tap.test('.interpreter.filetype() -> should get the file type from a string', as
|
|||||||
|
|
||||||
tap.test('.memory.toFs() -> should write a file to disk and return a promise', async () => {
|
tap.test('.memory.toFs() -> should write a file to disk and return a promise', async () => {
|
||||||
let localString = 'myString';
|
let localString = 'myString';
|
||||||
await smartfile.memory.toFs(localString, path.join(process.cwd(), './test/temp/testMemToFs.txt'));
|
await smartfile.memory.toFs(localString, path.join(process.cwd(), './test/testassets/temp/testMemToFs.txt'));
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test(
|
tap.test(
|
||||||
@ -139,20 +139,19 @@ tap.test(
|
|||||||
let localString = 'myString';
|
let localString = 'myString';
|
||||||
smartfile.memory.toFsSync(
|
smartfile.memory.toFsSync(
|
||||||
localString,
|
localString,
|
||||||
path.join(process.cwd(), './test/temp/testMemToFsSync.txt')
|
path.join(process.cwd(), './test/testassets/temp/testMemToFsSync.txt')
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
tap.test('.remote.toString() -> should load a remote file to a variable', async () => {
|
tap.test('.remote.toString() -> should load a remote file to a variable', async () => {
|
||||||
let responseString = await smartfile.remote.toString(
|
const responseString = await smartfile.remote.toString(
|
||||||
'https://raw.githubusercontent.com/pushrocks/smartfile/master/test/mytest.txt'
|
'https://raw.githubusercontent.com/pushrocks/smartfile/master/test/testassets/mytest.txt'
|
||||||
);
|
);
|
||||||
expect(responseString).to.equal('Some TestString &&%$');
|
expect(responseString).to.equal('Some TestString &&%$');
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('.remote.toString() -> should reject a Promise when the link is false', async tools => {
|
tap.test('.remote.toString() -> should reject a Promise when the link is false', async tools => {
|
||||||
tools.returnError;
|
|
||||||
await smartfile.remote.toString('https://push.rocks/doesnotexist.txt').catch(err => {
|
await smartfile.remote.toString('https://push.rocks/doesnotexist.txt').catch(err => {
|
||||||
return expect(err.message).to.equal(
|
return expect(err.message).to.equal(
|
||||||
'could not get remote file from https://push.rocks/doesnotexist.txt'
|
'could not get remote file from https://push.rocks/doesnotexist.txt'
|
||||||
@ -165,7 +164,7 @@ tap.test('.remote.toString() -> should reject a Promise when the link is false',
|
|||||||
// ---------------------------
|
// ---------------------------
|
||||||
|
|
||||||
tap.test('.Smartfile -> should produce vinyl compatible files', async () => {
|
tap.test('.Smartfile -> should produce vinyl compatible files', async () => {
|
||||||
let smartfileArray = await smartfile.fs.fileTreeToObject(process.cwd(), './test/testfolder/**/*');
|
let smartfileArray = await smartfile.fs.fileTreeToObject(process.cwd(), './test/testassets/testfolder/**/*');
|
||||||
let localSmartfile = smartfileArray[0];
|
let localSmartfile = smartfileArray[0];
|
||||||
expect(localSmartfile).to.be.instanceof(smartfile.Smartfile);
|
expect(localSmartfile).to.be.instanceof(smartfile.Smartfile);
|
||||||
expect(localSmartfile.contents).to.be.instanceof(Buffer);
|
expect(localSmartfile.contents).to.be.instanceof(Buffer);
|
||||||
@ -178,7 +177,7 @@ tap.test('.Smartfile -> should produce vinyl compatible files', async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should output a smartfile array to disk', async () => {
|
tap.test('should output a smartfile array to disk', async () => {
|
||||||
let smartfileArray = await smartfile.fs.fileTreeToObject('./test/testfolder/', '*');
|
let smartfileArray = await smartfile.fs.fileTreeToObject('./test/testassets/testfolder/', '*');
|
||||||
for (let smartfile of smartfileArray) {
|
for (let smartfile of smartfileArray) {
|
||||||
console.log(smartfile.relative);
|
console.log(smartfile.relative);
|
||||||
console.log(smartfile.path);
|
console.log(smartfile.path);
|
||||||
@ -187,7 +186,7 @@ tap.test('should output a smartfile array to disk', async () => {
|
|||||||
}
|
}
|
||||||
await smartfile.memory.smartfileArrayToFs(
|
await smartfile.memory.smartfileArrayToFs(
|
||||||
smartfileArray,
|
smartfileArray,
|
||||||
path.resolve('./test/temp/testoutput/')
|
path.resolve('./test/testassets/temp/testoutput/')
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
4
test/testassets/temp/mytest.yaml
Normal file
4
test/testassets/temp/mytest.yaml
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
key1: this works
|
||||||
|
key2: this works too
|
||||||
|
key3:
|
||||||
|
nestedkey1: hello
|
1
test/testassets/temp/testMemToFs.txt
Normal file
1
test/testassets/temp/testMemToFs.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
myString
|
1
test/testassets/temp/testMemToFsSync.txt
Normal file
1
test/testassets/temp/testMemToFsSync.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
myString
|
@ -0,0 +1 @@
|
|||||||
|
okidoks
|
1
test/testassets/testfolder/subfolder/subtestfile.txt
Normal file
1
test/testassets/testfolder/subfolder/subtestfile.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
hi
|
0
test/testassets/testfolder/testfile1.txt
Normal file
0
test/testassets/testfolder/testfile1.txt
Normal file
0
test/testassets/testfolder/testfile2.txt
Normal file
0
test/testassets/testfolder/testfile2.txt
Normal file
@ -10,4 +10,3 @@ export let fs = SmartfileFs;
|
|||||||
export let interpreter = SmartfileInterpreter;
|
export let interpreter = SmartfileInterpreter;
|
||||||
export let memory = SmartfileMemory;
|
export let memory = SmartfileMemory;
|
||||||
export let remote = SmartfileRemote;
|
export let remote = SmartfileRemote;
|
||||||
export let requireReload = SmartfileFs.requireReload;
|
|
||||||
|
@ -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
|
||||||
*/
|
*/
|
||||||
|
@ -13,7 +13,7 @@ import * as memory from './smartfile.memory';
|
|||||||
* @param filePath
|
* @param filePath
|
||||||
* @returns {boolean}
|
* @returns {boolean}
|
||||||
*/
|
*/
|
||||||
export let fileExistsSync = function(filePath): boolean {
|
export const fileExistsSync = (filePath): boolean => {
|
||||||
let fileExistsBool: boolean = false;
|
let fileExistsBool: boolean = false;
|
||||||
try {
|
try {
|
||||||
plugins.fsExtra.readFileSync(filePath);
|
plugins.fsExtra.readFileSync(filePath);
|
||||||
@ -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 = async (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 const isDirectory = (pathArg): boolean => {
|
||||||
try {
|
try {
|
||||||
return plugins.fsExtra.statSync(pathArg).isDirectory();
|
return plugins.fsExtra.statSync(pathArg).isDirectory();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@ -51,7 +51,7 @@ export let isDirectory = function(pathArg): boolean {
|
|||||||
/**
|
/**
|
||||||
* Checks if a given path points to an existing file
|
* Checks if a given path points to an existing file
|
||||||
*/
|
*/
|
||||||
export let isFile = function(pathArg): boolean {
|
export const isFile = (pathArg): boolean => {
|
||||||
return plugins.fsExtra.statSync(pathArg).isFile();
|
return plugins.fsExtra.statSync(pathArg).isFile();
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -62,10 +62,13 @@ export let isFile = function(pathArg): boolean {
|
|||||||
/**
|
/**
|
||||||
* copies a file from A to B on the local disk
|
* copies a file from A to B on the local disk
|
||||||
*/
|
*/
|
||||||
export let copy = function(fromArg: string, toArg: string) {
|
export const copy = async (fromArg: string, toArg: string): Promise<boolean> => {
|
||||||
let done = plugins.smartpromise.defer();
|
const done = plugins.smartpromise.defer<boolean>();
|
||||||
plugins.fsExtra.copy(fromArg, toArg, {}, function() {
|
plugins.fsExtra.copy(fromArg, toArg, {}, (err) => {
|
||||||
done.resolve();
|
if (err) {
|
||||||
|
throw new Error(`Could not copy from ${fromArg} to ${toArg}: ${err}`);
|
||||||
|
}
|
||||||
|
done.resolve(true);
|
||||||
});
|
});
|
||||||
return done.promise;
|
return done.promise;
|
||||||
};
|
};
|
||||||
@ -73,7 +76,7 @@ export let copy = function(fromArg: string, toArg: string) {
|
|||||||
/**
|
/**
|
||||||
* copies a file SYNCHRONOUSLY from A to B on the local disk
|
* copies a file SYNCHRONOUSLY from A to B on the local disk
|
||||||
*/
|
*/
|
||||||
export let copySync = function(fromArg: string, toArg: string): boolean {
|
export const copySync = (fromArg: string, toArg: string): boolean => {
|
||||||
plugins.fsExtra.copySync(fromArg, toArg);
|
plugins.fsExtra.copySync(fromArg, toArg);
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
@ -194,7 +197,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);
|
||||||
@ -205,12 +208,12 @@ export let toObjectSync = function(filePathArg, fileTypeArg?) {
|
|||||||
* @param filePath
|
* @param filePath
|
||||||
* @returns {string|Buffer|any}
|
* @returns {string|Buffer|any}
|
||||||
*/
|
*/
|
||||||
export let toStringSync = function(filePath: string): string {
|
export const toStringSync = (filePath: string): string => {
|
||||||
let fileString: any = plugins.fsExtra.readFileSync(filePath, 'utf8');
|
const fileString: string = plugins.fsExtra.readFileSync(filePath, 'utf8');
|
||||||
return fileString;
|
return fileString;
|
||||||
};
|
};
|
||||||
|
|
||||||
export let fileTreeToObject = async (dirPathArg: string, miniMatchFilter: string) => {
|
export const fileTreeToObject = async (dirPathArg: string, miniMatchFilter: string) => {
|
||||||
// handle absolute miniMatchFilter
|
// handle absolute miniMatchFilter
|
||||||
let dirPath: string;
|
let dirPath: string;
|
||||||
if (plugins.path.isAbsolute(miniMatchFilter)) {
|
if (plugins.path.isAbsolute(miniMatchFilter)) {
|
||||||
@ -219,8 +222,8 @@ export let fileTreeToObject = async (dirPathArg: string, miniMatchFilter: string
|
|||||||
dirPath = dirPathArg;
|
dirPath = dirPathArg;
|
||||||
}
|
}
|
||||||
|
|
||||||
let fileTree = await listFileTree(dirPath, miniMatchFilter);
|
const fileTree = await listFileTree(dirPath, miniMatchFilter);
|
||||||
let smartfileArray: Smartfile[] = [];
|
const smartfileArray: Smartfile[] = [];
|
||||||
for (let filePath of fileTree) {
|
for (let filePath of fileTree) {
|
||||||
let readPath = ((): string => {
|
let readPath = ((): string => {
|
||||||
if (!plugins.path.isAbsolute(filePath)) {
|
if (!plugins.path.isAbsolute(filePath)) {
|
||||||
@ -234,7 +237,7 @@ export let fileTreeToObject = async (dirPathArg: string, miniMatchFilter: string
|
|||||||
// push a read file as Smartfile
|
// push a read file as Smartfile
|
||||||
smartfileArray.push(
|
smartfileArray.push(
|
||||||
new Smartfile({
|
new Smartfile({
|
||||||
contentBuffer: new Buffer(fileContentString),
|
contentBuffer: Buffer.from(fileContentString),
|
||||||
base: dirPath,
|
base: dirPath,
|
||||||
path: filePath
|
path: filePath
|
||||||
})
|
})
|
||||||
@ -253,39 +256,20 @@ export let toVinylSync = function(filePathArg, options = {}) {
|
|||||||
return plugins.vinylFile.readSync(filePathArg, options);
|
return plugins.vinylFile.readSync(filePathArg, options);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* lets you reload files hot.
|
|
||||||
* @param path
|
|
||||||
* @returns {any}
|
|
||||||
*/
|
|
||||||
export let requireReload = function(path: string) {
|
|
||||||
return plugins.requireReload(path);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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) {
|
||||||
@ -300,26 +284,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) {
|
||||||
@ -334,16 +308,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;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -351,7 +317,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();
|
||||||
});
|
});
|
||||||
@ -368,8 +334,8 @@ export let listAllItemsSync = function(pathArg: string, regexFilter?: RegExp): s
|
|||||||
* note: if the miniMatch Filter is an absolute path, the cwdArg will be omitted
|
* note: if the miniMatch Filter is an absolute path, the cwdArg will be omitted
|
||||||
* @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 const listFileTree = async (dirPathArg: string, miniMatchFilter: string, absolutePathsBool: boolean = false): 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;
|
||||||
@ -379,7 +345,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
|
||||||
@ -391,5 +357,13 @@ export let listFileTree = (dirPathArg: string, miniMatchFilter: string): Promise
|
|||||||
}
|
}
|
||||||
done.resolve(files);
|
done.resolve(files);
|
||||||
});
|
});
|
||||||
return done.promise;
|
|
||||||
|
let fileList = await done.promise;
|
||||||
|
if (absolutePathsBool) {
|
||||||
|
fileList = fileList.map(filePath => {
|
||||||
|
return plugins.path.resolve(plugins.path.join(dirPath, filePath));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return fileList;
|
||||||
};
|
};
|
||||||
|
@ -3,8 +3,7 @@ export import fsExtra = require('fs-extra');
|
|||||||
export let glob = require('glob');
|
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('smartrequest');
|
export import smartrequest = require('@pushrocks/smartrequest');
|
||||||
export let requireReload = require('require-reload');
|
export import smartpath = require('@pushrocks/smartpath');
|
||||||
export import smartpath = require('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');
|
||||||
|
@ -39,7 +39,7 @@ export let toObject = function(fromArg: string) {
|
|||||||
*/
|
*/
|
||||||
export let toString = (fromArg: string) => {
|
export let toString = (fromArg: string) => {
|
||||||
let done = plugins.smartpromise.defer();
|
let done = plugins.smartpromise.defer();
|
||||||
plugins.smartrequest.get(fromArg).then((res: any) => {
|
plugins.smartrequest.getBinary(fromArg).then((res: any) => {
|
||||||
if (res.statusCode === 200) {
|
if (res.statusCode === 200) {
|
||||||
done.resolve(res.body);
|
done.resolve(res.body);
|
||||||
} else {
|
} else {
|
||||||
|
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