Compare commits
8 Commits
Author | SHA1 | Date | |
---|---|---|---|
b42595fccc | |||
2d9a65d11c | |||
b3ce66167e | |||
c7f800fc88 | |||
d8f4b011b7 | |||
b4add67f37 | |||
f86f053bd5 | |||
a78ca67b43 |
4
.gitignore
vendored
4
.gitignore
vendored
@ -15,8 +15,6 @@ node_modules/
|
|||||||
|
|
||||||
# builds
|
# builds
|
||||||
dist/
|
dist/
|
||||||
dist_web/
|
dist_*/
|
||||||
dist_serve/
|
|
||||||
dist_ts_web/
|
|
||||||
|
|
||||||
# custom
|
# custom
|
@ -24,13 +24,14 @@ mirror:
|
|||||||
- docker
|
- docker
|
||||||
- notpriv
|
- notpriv
|
||||||
|
|
||||||
snyk:
|
audit:
|
||||||
image: registry.gitlab.com/hosttoday/ht-docker-node:snyk
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
stage: security
|
stage: security
|
||||||
script:
|
script:
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
- npmci command npm install --ignore-scripts
|
- npmci command npm install --ignore-scripts
|
||||||
- npmci command snyk test
|
- npmci command npm config set registry https://registry.npmjs.org
|
||||||
|
- npmci command npm audit --audit-level=moderate
|
||||||
tags:
|
tags:
|
||||||
- lossless
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
|
774
package-lock.json
generated
774
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
30
package.json
30
package.json
@ -1,10 +1,10 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartfile",
|
"name": "@pushrocks/smartfile",
|
||||||
"private": false,
|
"private": false,
|
||||||
"version": "7.0.7",
|
"version": "7.0.11",
|
||||||
"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_ts/index.js",
|
||||||
"typings": "dist/index.d.ts",
|
"typings": "dist_ts/index.d.ts",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "(tstest test/)",
|
"test": "(tstest test/)",
|
||||||
"reinstall": "(rm -r node_modules && npm install)",
|
"reinstall": "(rm -r node_modules && npm install)",
|
||||||
@ -28,30 +28,32 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://gitlab.com/pushrocks/smartfile",
|
"homepage": "https://gitlab.com/pushrocks/smartfile",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pushrocks/smarthash": "^2.0.6",
|
"@pushrocks/smarthash": "^2.1.6",
|
||||||
|
"@pushrocks/smartmime": "^1.0.3",
|
||||||
"@pushrocks/smartpath": "^4.0.1",
|
"@pushrocks/smartpath": "^4.0.1",
|
||||||
"@pushrocks/smartpromise": "^3.0.5",
|
"@pushrocks/smartpromise": "^3.0.6",
|
||||||
"@pushrocks/smartrequest": "^1.1.27",
|
"@pushrocks/smartrequest": "^1.1.47",
|
||||||
"@types/fs-extra": "^8.0.0",
|
"@types/fs-extra": "^8.1.0",
|
||||||
"fs-extra": "^8.1.0",
|
"fs-extra": "^8.1.0",
|
||||||
"glob": "^7.1.4",
|
"glob": "^7.1.6",
|
||||||
"js-yaml": "^3.13.1"
|
"js-yaml": "^3.13.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.1.17",
|
"@gitzone/tsbuild": "^2.1.22",
|
||||||
"@gitzone/tsrun": "^1.2.8",
|
"@gitzone/tsrun": "^1.2.8",
|
||||||
"@gitzone/tstest": "^1.0.24",
|
"@gitzone/tstest": "^1.0.28",
|
||||||
"@pushrocks/tapbundle": "^3.0.13",
|
"@pushrocks/tapbundle": "^3.2.1",
|
||||||
"@types/node": "^12.7.8",
|
"@types/node": "^13.9.1",
|
||||||
"gulp-function": "^2.2.14",
|
"gulp-function": "^2.2.14",
|
||||||
"tslint": "^5.20.0",
|
"tslint": "^6.1.0",
|
||||||
"tslint-config-prettier": "^1.18.0"
|
"tslint-config-prettier": "^1.18.0"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"ts/**/*",
|
"ts/**/*",
|
||||||
"ts_web/**/*",
|
"ts_web/**/*",
|
||||||
"dist/**/*",
|
"dist/**/*",
|
||||||
"dist_web/**/*",
|
"dist_*/**/*",
|
||||||
|
"dist_ts/**/*",
|
||||||
"dist_ts_web/**/*",
|
"dist_ts_web/**/*",
|
||||||
"assets/**/*",
|
"assets/**/*",
|
||||||
"cli.js",
|
"cli.js",
|
||||||
|
44
readme.md
Normal file
44
readme.md
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
# @pushrocks/smartfile
|
||||||
|
smart ways to work with files in nodejs
|
||||||
|
|
||||||
|
## Availabililty and Links
|
||||||
|
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartfile)
|
||||||
|
* [gitlab.com (source)](https://gitlab.com/pushrocks/smartfile)
|
||||||
|
* [github.com (source mirror)](https://github.com/pushrocks/smartfile)
|
||||||
|
* [docs (typedoc)](https://pushrocks.gitlab.io/smartfile/)
|
||||||
|
|
||||||
|
## Status for master
|
||||||
|
[](https://gitlab.com/pushrocks/smartfile/commits/master)
|
||||||
|
[](https://gitlab.com/pushrocks/smartfile/commits/master)
|
||||||
|
[](https://www.npmjs.com/package/@pushrocks/smartfile)
|
||||||
|
[](https://snyk.io/test/npm/@pushrocks/smartfile)
|
||||||
|
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||||
|
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||||
|
[](https://prettier.io/)
|
||||||
|
|
||||||
|
## 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 |
|
||||||
|
|
||||||
|
## Contribution
|
||||||
|
|
||||||
|
We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :)
|
||||||
|
|
||||||
|
For further information read the linked docs at the top of this readme.
|
||||||
|
|
||||||
|
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
||||||
|
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
|
||||||
|
|
||||||
|
[](https://maintainedby.lossless.com)
|
@ -192,14 +192,17 @@ export const toObjectSync = (filePathArg, fileTypeArg?) => {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* reads a file content to a String
|
* reads a file content to a String
|
||||||
* @param filePath
|
|
||||||
* @returns {string|Buffer|any}
|
|
||||||
*/
|
*/
|
||||||
export const toStringSync = (filePath: string): string => {
|
export const toStringSync = (filePath: string): string => {
|
||||||
const fileString: string = plugins.fsExtra.readFileSync(filePath, 'utf8');
|
const encoding = plugins.smartmime.getEncoding(filePath);
|
||||||
|
const fileString: string = plugins.fsExtra.readFileSync(filePath, encoding);
|
||||||
return fileString;
|
return fileString;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const toBufferSync = (filePath: string): Buffer => {
|
||||||
|
return plugins.fsExtra.readFileSync(filePath);
|
||||||
|
};
|
||||||
|
|
||||||
export const fileTreeToHash = async (dirPathArg: string, miniMatchFilter: string) => {
|
export const fileTreeToHash = async (dirPathArg: string, miniMatchFilter: string) => {
|
||||||
const fileTreeObject = await fileTreeToObject(dirPathArg, miniMatchFilter);
|
const fileTreeObject = await fileTreeToObject(dirPathArg, miniMatchFilter);
|
||||||
let combinedString = '';
|
let combinedString = '';
|
||||||
|
@ -25,11 +25,11 @@ export interface IToFsOptions {
|
|||||||
* @param fileBaseArg
|
* @param fileBaseArg
|
||||||
*/
|
*/
|
||||||
export let toFs = async (
|
export let toFs = async (
|
||||||
fileContentArg: string | Smartfile,
|
fileContentArg: string | Buffer | Smartfile,
|
||||||
filePathArg,
|
filePathArg: string,
|
||||||
optionsArg: IToFsOptions = {}
|
optionsArg: IToFsOptions = {}
|
||||||
) => {
|
) => {
|
||||||
let done = plugins.smartpromise.defer();
|
const done = plugins.smartpromise.defer();
|
||||||
|
|
||||||
// check args
|
// check args
|
||||||
if (!fileContentArg || !filePathArg) {
|
if (!fileContentArg || !filePathArg) {
|
||||||
@ -38,23 +38,26 @@ export let toFs = async (
|
|||||||
|
|
||||||
// prepare actual write action
|
// prepare actual write action
|
||||||
let fileString: string;
|
let fileString: string;
|
||||||
|
let fileEncoding: string = 'utf8';
|
||||||
let filePath: string = filePathArg;
|
let filePath: string = filePathArg;
|
||||||
|
|
||||||
// handle Smartfile
|
// handle Smartfile
|
||||||
if (fileContentArg instanceof Smartfile) {
|
if (fileContentArg instanceof Smartfile) {
|
||||||
let fileContentArg2: any = fileContentArg;
|
|
||||||
fileString = fileContentArg.contentBuffer.toString();
|
fileString = fileContentArg.contentBuffer.toString();
|
||||||
// handle options
|
// handle options
|
||||||
if (optionsArg.respectRelative) {
|
if (optionsArg.respectRelative) {
|
||||||
filePath = plugins.path.join(filePath, fileContentArg.path);
|
filePath = plugins.path.join(filePath, fileContentArg.path);
|
||||||
}
|
}
|
||||||
|
} else if (Buffer.isBuffer(fileContentArg)) {
|
||||||
|
fileString = fileContentArg.toString('binary');
|
||||||
|
fileEncoding = 'binary';
|
||||||
} else if (typeof fileContentArg === 'string') {
|
} else if (typeof fileContentArg === 'string') {
|
||||||
fileString = fileContentArg;
|
fileString = fileContentArg;
|
||||||
} else {
|
} else {
|
||||||
throw new Error('fileContent is neither string nor Smartfile');
|
throw new Error('fileContent is neither string nor Smartfile');
|
||||||
}
|
}
|
||||||
await smartfileFs.ensureDir(plugins.path.parse(filePath).dir);
|
await smartfileFs.ensureDir(plugins.path.parse(filePath).dir);
|
||||||
plugins.fsExtra.writeFile(filePath, fileString, { encoding: 'utf8' }, done.resolve);
|
plugins.fsExtra.writeFile(filePath, fileString, { encoding: fileEncoding }, done.resolve);
|
||||||
return await done.promise;
|
return await done.promise;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -6,11 +6,12 @@ export { fs, path };
|
|||||||
|
|
||||||
// @pushrocks scope
|
// @pushrocks scope
|
||||||
import * as smarthash from '@pushrocks/smarthash';
|
import * as smarthash from '@pushrocks/smarthash';
|
||||||
|
import * as smartmime from '@pushrocks/smartmime';
|
||||||
import * as smartpath from '@pushrocks/smartpath';
|
import * as smartpath from '@pushrocks/smartpath';
|
||||||
import * as smartpromise from '@pushrocks/smartpromise';
|
import * as smartpromise from '@pushrocks/smartpromise';
|
||||||
import * as smartrequest from '@pushrocks/smartrequest';
|
import * as smartrequest from '@pushrocks/smartrequest';
|
||||||
|
|
||||||
export { smarthash, smartpath, smartpromise, smartrequest };
|
export { smarthash, smartmime, smartpath, smartpromise, smartrequest };
|
||||||
|
|
||||||
// third party scope
|
// third party scope
|
||||||
import * as fsExtra from 'fs-extra';
|
import * as fsExtra from 'fs-extra';
|
||||||
|
@ -15,8 +15,8 @@ import SmartfileInterpreter = require('./smartfile.interpreter');
|
|||||||
* @param fromArg
|
* @param fromArg
|
||||||
* @returns {any}
|
* @returns {any}
|
||||||
*/
|
*/
|
||||||
export let toObject = function(fromArg: string) {
|
export let toObject = (fromArg: string) => {
|
||||||
let done = plugins.smartpromise.defer();
|
const done = plugins.smartpromise.defer();
|
||||||
plugins.smartrequest
|
plugins.smartrequest
|
||||||
.request(fromArg, {
|
.request(fromArg, {
|
||||||
method: 'get'
|
method: 'get'
|
||||||
@ -37,11 +37,12 @@ export let toObject = function(fromArg: string) {
|
|||||||
* @param fromArg
|
* @param fromArg
|
||||||
* @returns {any}
|
* @returns {any}
|
||||||
*/
|
*/
|
||||||
export let toString = (fromArg: string) => {
|
export let toString = (fromArg: string): Promise<string> => {
|
||||||
let done = plugins.smartpromise.defer();
|
const done = plugins.smartpromise.defer<string>();
|
||||||
plugins.smartrequest.getBinary(fromArg).then((res: any) => {
|
plugins.smartrequest.getBinary(fromArg).then((res: any) => {
|
||||||
if (res.statusCode === 200) {
|
if (res.statusCode === 200) {
|
||||||
done.resolve(res.body);
|
const encoding = plugins.smartmime.getEncoding(fromArg);
|
||||||
|
done.resolve(res.body.toString(encoding));
|
||||||
} else {
|
} else {
|
||||||
done.reject(new Error('could not get remote file from ' + fromArg));
|
done.reject(new Error('could not get remote file from ' + fromArg));
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user