Compare commits
10 Commits
Author | SHA1 | Date | |
---|---|---|---|
0a95ae6284 | |||
de09f85c34 | |||
b9fefc7c95 | |||
76eae15f7d | |||
2e457f6011 | |||
e83c63fd2a | |||
c01006e365 | |||
a7adec8275 | |||
2eddbf5751 | |||
eca3e141d2 |
@ -26,16 +26,28 @@ mirror:
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
audit:
|
||||
auditProductionDependencies:
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
stage: security
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci command npm install --production --ignore-scripts
|
||||
- npmci command npm config set registry https://registry.npmjs.org
|
||||
- npmci command npm audit --audit-level=high --only=prod --production
|
||||
tags:
|
||||
- docker
|
||||
|
||||
auditDevDependencies:
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
stage: security
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci command npm install --ignore-scripts
|
||||
- npmci command npm config set registry https://registry.npmjs.org
|
||||
- npmci command npm audit --audit-level=high
|
||||
- npmci command npm audit --audit-level=high --only=dev
|
||||
tags:
|
||||
- docker
|
||||
allow_failure: true
|
||||
|
||||
# ====================
|
||||
# test stage
|
||||
|
1550
package-lock.json
generated
1550
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
14
package.json
14
package.json
@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@pushrocks/smartfile",
|
||||
"private": false,
|
||||
"version": "8.0.0",
|
||||
"version": "8.0.5",
|
||||
"description": "offers smart ways to work with files in nodejs",
|
||||
"main": "dist_ts/index.js",
|
||||
"typings": "dist_ts/index.d.ts",
|
||||
@ -24,22 +24,26 @@
|
||||
},
|
||||
"homepage": "https://gitlab.com/pushrocks/smartfile",
|
||||
"dependencies": {
|
||||
"@pushrocks/smartfile-interfaces": "^1.0.7",
|
||||
"@pushrocks/smarthash": "^2.1.6",
|
||||
"@pushrocks/smartjson": "^4.0.3",
|
||||
"@pushrocks/smartmime": "^1.0.3",
|
||||
"@pushrocks/smartpath": "^4.0.3",
|
||||
"@pushrocks/smartpromise": "^3.0.6",
|
||||
"@pushrocks/smartrequest": "^1.1.47",
|
||||
"@pushrocks/smartrequest": "^1.1.51",
|
||||
"@types/fs-extra": "^9.0.1",
|
||||
"@types/glob": "^7.1.3",
|
||||
"@types/js-yaml": "^3.12.5",
|
||||
"fs-extra": "^9.0.1",
|
||||
"glob": "^7.1.6",
|
||||
"js-yaml": "^3.14.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@gitzone/tsbuild": "^2.1.24",
|
||||
"@gitzone/tsbuild": "^2.1.25",
|
||||
"@gitzone/tsrun": "^1.2.12",
|
||||
"@gitzone/tstest": "^1.0.43",
|
||||
"@gitzone/tstest": "^1.0.52",
|
||||
"@pushrocks/tapbundle": "^3.2.9",
|
||||
"@types/node": "^14.0.27",
|
||||
"@types/node": "^14.11.2",
|
||||
"gulp-function": "^2.2.14",
|
||||
"tslint": "^6.1.3",
|
||||
"tslint-config-prettier": "^1.18.0"
|
||||
|
@ -5,6 +5,7 @@ import * as SmartfileMemory from './smartfile.memory';
|
||||
import * as SmartfileRemote from './smartfile.remote';
|
||||
|
||||
export { Smartfile } from './smartfile.classes.smartfile';
|
||||
export { VirtualDirectory } from './smartfile.classes.virtualdirectory';
|
||||
|
||||
export let fs = SmartfileFs;
|
||||
export let interpreter = SmartfileInterpreter;
|
||||
|
@ -12,7 +12,7 @@ export interface ISmartfileConstructorOptions {
|
||||
* class Smartfile
|
||||
* -> is vinyl file compatible
|
||||
*/
|
||||
export class Smartfile {
|
||||
export class Smartfile extends plugins.smartjson.Smartjson {
|
||||
// ======
|
||||
// STATIC
|
||||
// ======
|
||||
@ -59,6 +59,7 @@ export class Smartfile {
|
||||
/**
|
||||
* the full path of the file on disk
|
||||
*/
|
||||
@plugins.smartjson.foldDec()
|
||||
public path: string;
|
||||
|
||||
/**
|
||||
@ -88,6 +89,7 @@ export class Smartfile {
|
||||
*/
|
||||
|
||||
constructor(optionsArg: ISmartfileConstructorOptions) {
|
||||
super();
|
||||
if (optionsArg.contentBuffer) {
|
||||
this.contentBuffer = optionsArg.contentBuffer;
|
||||
} else {
|
||||
|
51
ts/smartfile.classes.virtualdirectory.ts
Normal file
51
ts/smartfile.classes.virtualdirectory.ts
Normal file
@ -0,0 +1,51 @@
|
||||
import { Smartfile } from './smartfile.classes.smartfile';
|
||||
import * as plugins from './smartfile.plugins';
|
||||
import * as fs from './smartfile.fs';
|
||||
|
||||
/**
|
||||
* a virtual directory exposes a fs api
|
||||
*/
|
||||
export class VirtualDirectory {
|
||||
// STATIC
|
||||
public static async fromFsDirPath(pathArg: string): Promise<VirtualDirectory> {
|
||||
const newVirtualDir = new VirtualDirectory();
|
||||
newVirtualDir.addSmartfiles(await fs.fileTreeToObject(pathArg, '**/*'));
|
||||
return newVirtualDir;
|
||||
}
|
||||
|
||||
public static async fromVirtualDirTransferableObject(
|
||||
virtualDirTransferableObjectArg: plugins.smartfileInterfaces.VirtualDirTransferableObject
|
||||
): Promise<VirtualDirectory> {
|
||||
const newVirtualDir = new VirtualDirectory();
|
||||
for (const fileArg of virtualDirTransferableObjectArg.files) {
|
||||
newVirtualDir.addSmartfiles([Smartfile.enfoldFromJson(fileArg) as Smartfile]);
|
||||
}
|
||||
return newVirtualDir;
|
||||
}
|
||||
|
||||
// INSTANCE
|
||||
private fileArray: Smartfile[] = [];
|
||||
|
||||
constructor() {}
|
||||
|
||||
public addSmartfiles(smartfileArrayArg: Smartfile[]) {
|
||||
this.fileArray = this.fileArray.concat(smartfileArrayArg);
|
||||
}
|
||||
|
||||
public async getFileByPath(pathArg: string) {
|
||||
for (const smartfile of this.fileArray) {
|
||||
if (smartfile.path === pathArg) {
|
||||
return smartfile;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public async toVirtualDirTransferableObject(): Promise<plugins.smartfileInterfaces.VirtualDirTransferableObject> {
|
||||
return {
|
||||
files: this.fileArray.map(smartfileArg => smartfileArg.foldToJson())
|
||||
};
|
||||
}
|
||||
|
||||
// TODO implement root shifting to get subdirectories as new virtual directories
|
||||
// TODO implement root shifting to combine VirtualDirecotries in a parent virtual directory
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
import plugins = require('./smartfile.plugins');
|
||||
import SmartfileInterpreter = require('./smartfile.interpreter');
|
||||
import * as plugins from './smartfile.plugins';
|
||||
import * as interpreter from './smartfile.interpreter';
|
||||
|
||||
import { Smartfile } from './smartfile.classes.smartfile';
|
||||
|
||||
@ -186,8 +186,8 @@ export const removeManySync = (filePathArrayArg: string[]): void => {
|
||||
export const toObjectSync = (filePathArg, fileTypeArg?) => {
|
||||
const fileString = plugins.fsExtra.readFileSync(filePathArg, 'utf8');
|
||||
let fileType;
|
||||
fileTypeArg ? (fileType = fileTypeArg) : (fileType = SmartfileInterpreter.filetype(filePathArg));
|
||||
return SmartfileInterpreter.objectFile(fileString, fileType);
|
||||
fileTypeArg ? (fileType = fileTypeArg) : (fileType = interpreter.filetype(filePathArg));
|
||||
return interpreter.objectFile(fileString, fileType);
|
||||
};
|
||||
|
||||
/**
|
||||
@ -195,7 +195,10 @@ export const toObjectSync = (filePathArg, fileTypeArg?) => {
|
||||
*/
|
||||
export const toStringSync = (filePath: string): string => {
|
||||
const encoding = plugins.smartmime.getEncoding(filePath);
|
||||
const fileString: string = plugins.fsExtra.readFileSync(filePath, encoding);
|
||||
let fileString: string | Buffer = plugins.fsExtra.readFileSync(filePath, encoding);
|
||||
if (Buffer.isBuffer(fileString)) {
|
||||
fileString = fileString.toString('binary');
|
||||
}
|
||||
return fileString;
|
||||
};
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
import plugins = require('./smartfile.plugins');
|
||||
import * as plugins from './smartfile.plugins';
|
||||
|
||||
export let filetype = (pathArg: string): string => {
|
||||
const extName = plugins.path.extname(pathArg);
|
||||
|
@ -5,13 +5,15 @@ import * as path from 'path';
|
||||
export { fs, path };
|
||||
|
||||
// @pushrocks scope
|
||||
import * as smartfileInterfaces from '@pushrocks/smartfile-interfaces';
|
||||
import * as smarthash from '@pushrocks/smarthash';
|
||||
import * as smartjson from '@pushrocks/smartjson';
|
||||
import * as smartmime from '@pushrocks/smartmime';
|
||||
import * as smartpath from '@pushrocks/smartpath';
|
||||
import * as smartpromise from '@pushrocks/smartpromise';
|
||||
import * as smartrequest from '@pushrocks/smartrequest';
|
||||
|
||||
export { smarthash, smartmime, smartpath, smartpromise, smartrequest };
|
||||
export { smartfileInterfaces, smarthash, smartjson, smartmime, smartpath, smartpromise, smartrequest };
|
||||
|
||||
// third party scope
|
||||
import * as fsExtra from 'fs-extra';
|
||||
|
8
tsconfig.json
Normal file
8
tsconfig.json
Normal file
@ -0,0 +1,8 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"experimentalDecorators": true,
|
||||
"esModuleInterop": true,
|
||||
"target": "ES2017",
|
||||
"moduleResolution": "node"
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user