Compare commits

...

14 Commits

Author SHA1 Message Date
ce57478e39 8.0.8 2020-10-11 15:34:24 +00:00
292c2699ea fix(core): update 2020-10-11 15:34:24 +00:00
afb7fa8e89 8.0.7 2020-10-09 15:15:48 +00:00
e2c3005a08 fix(core): update 2020-10-09 15:15:47 +00:00
53e595a023 8.0.6 2020-10-06 00:57:48 +00:00
93702dca78 fix(core): update 2020-10-06 00:57:47 +00:00
0a95ae6284 8.0.5 2020-10-05 16:20:58 +00:00
de09f85c34 fix(core): update 2020-10-05 16:20:57 +00:00
b9fefc7c95 8.0.4 2020-10-02 14:34:10 +00:00
76eae15f7d fix(core): update 2020-10-02 14:34:09 +00:00
2e457f6011 8.0.3 2020-10-02 14:13:34 +00:00
e83c63fd2a fix(core): update 2020-10-02 14:13:34 +00:00
c01006e365 8.0.2 2020-10-02 13:29:40 +00:00
a7adec8275 fix(core): update 2020-10-02 13:29:40 +00:00
13 changed files with 157 additions and 33 deletions

View File

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

35
package-lock.json generated
View File

@ -1,6 +1,6 @@
{
"name": "@pushrocks/smartfile",
"version": "8.0.1",
"version": "8.0.8",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
@ -1548,6 +1548,11 @@
}
}
},
"@pushrocks/smartfile-interfaces": {
"version": "1.0.7",
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartfile-interfaces/-/smartfile-interfaces-1.0.7.tgz",
"integrity": "sha512-C/v9Scbx1J+ByMk3YBZrlLRYXdObty/Uz/h6kSZqsO8ghYuT9l7OVpEcyduiSVPakaMi6YnzfME3Nfs3oLj//Q=="
},
"@pushrocks/smarthash": {
"version": "2.1.6",
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmarthash/-/smarthash-2.1.6.tgz",
@ -1559,6 +1564,16 @@
"through2": "^3.0.1"
},
"dependencies": {
"@pushrocks/smartjson": {
"version": "3.0.10",
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartjson/-/smartjson-3.0.10.tgz",
"integrity": "sha512-0tBkET2yjmSSIf4DlgeyU8U/J2EshTmQGuMY28EjPq9VvuCFXLh72WmETpA4QqKRMqhWp1+P+RZgnQupW3GQxQ==",
"requires": {
"@types/fast-json-stable-stringify": "^2.0.0",
"fast-json-stable-stringify": "^2.1.0",
"lodash.clonedeep": "^4.5.0"
}
},
"@types/through2": {
"version": "2.0.34",
"resolved": "https://verdaccio.lossless.one/@types%2fthrough2/-/through2-2.0.34.tgz",
@ -1578,11 +1593,13 @@
}
},
"@pushrocks/smartjson": {
"version": "3.0.10",
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartjson/-/smartjson-3.0.10.tgz",
"integrity": "sha512-0tBkET2yjmSSIf4DlgeyU8U/J2EshTmQGuMY28EjPq9VvuCFXLh72WmETpA4QqKRMqhWp1+P+RZgnQupW3GQxQ==",
"version": "4.0.3",
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartjson/-/smartjson-4.0.3.tgz",
"integrity": "sha512-/VRRoQhSQa4XUO4uH3tmjKHczFyPp6z91Onwv702FSKDOj+Q2xOjtaL94hNa1NJdkRWzPtOMww6A5QMkQMpG4Q==",
"requires": {
"@types/buffer-json": "^2.0.0",
"@types/fast-json-stable-stringify": "^2.0.0",
"buffer-json": "^2.0.0",
"fast-json-stable-stringify": "^2.1.0",
"lodash.clonedeep": "^4.5.0"
}
@ -2078,6 +2095,11 @@
"@types/node": "*"
}
},
"@types/buffer-json": {
"version": "2.0.0",
"resolved": "https://verdaccio.lossless.one/@types%2fbuffer-json/-/buffer-json-2.0.0.tgz",
"integrity": "sha512-nFKOrY93Tvv5Tobws+YbkGlPOJsn1nVpZah3BlSyQ4EniFm97KLvSr54tZ5xQp8mlf/XxbYwskNCYQB9EdrPlQ=="
},
"@types/chai": {
"version": "4.2.12",
"resolved": "https://verdaccio.lossless.one/@types%2fchai/-/chai-4.2.12.tgz",
@ -3113,6 +3135,11 @@
"integrity": "sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A==",
"dev": true
},
"buffer-json": {
"version": "2.0.0",
"resolved": "https://verdaccio.lossless.one/buffer-json/-/buffer-json-2.0.0.tgz",
"integrity": "sha512-+jjPFVqyfF1esi9fvfUs3NqM0pH1ziZ36VP4hmA/y/Ssfo/5w5xHKfTw9BwQjoJ1w/oVtpLomqwUHKdefGyuHw=="
},
"buffer-xor": {
"version": "1.0.3",
"resolved": "https://verdaccio.lossless.one/buffer-xor/-/buffer-xor-1.0.3.tgz",

View File

@ -1,7 +1,7 @@
{
"name": "@pushrocks/smartfile",
"private": false,
"version": "8.0.1",
"version": "8.0.8",
"description": "offers smart ways to work with files in nodejs",
"main": "dist_ts/index.js",
"typings": "dist_ts/index.d.ts",
@ -24,7 +24,9 @@
},
"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",

View File

@ -1,5 +1,5 @@
import * as smartfile from '../ts/index';
import path = require('path');
import * as path from 'path';
import { expect, tap } from '@pushrocks/tapbundle';
@ -8,7 +8,9 @@ import { expect, tap } from '@pushrocks/tapbundle';
// ---------------------------
tap.test('.fs.fileExistsSync -> should return an accurate boolean', async () => {
// tslint:disable-next-line: no-unused-expression
expect(smartfile.fs.fileExistsSync('./test/testassets/mytest.json')).to.be.true;
// tslint:disable-next-line: no-unused-expression
expect(smartfile.fs.fileExistsSync('./test/testassets/notthere.json')).be.false;
});

View File

@ -0,0 +1,15 @@
import { tap, expect } from '@pushrocks/tapbundle';
import * as smartfile from '../ts';
tap.test('should create a virtualdirectory', async () => {
const virtualDir = await smartfile.VirtualDirectory.fromFsDirPath('./test/testassets/testfolder');
expect(virtualDir.smartfileArray.length).to.equal(4);
});
tap.test('should write to a directory', async () => {
const virtualDir = await smartfile.VirtualDirectory.fromFsDirPath('./test/testassets/testfolder');
virtualDir.saveToDisk('./test/testassets/test');
});
tap.start();

View File

@ -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;

View File

@ -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,27 +59,32 @@ export class Smartfile {
/**
* the full path of the file on disk
*/
@plugins.smartjson.foldDec()
public path: string;
/**
*
* a parsed path
*/
@plugins.smartjson.foldDec()
public parsedPath: plugins.path.ParsedPath;
/**
* the content of the file as Buffer
*/
@plugins.smartjson.foldDec()
public contentBuffer: Buffer;
/**
* The current working directory of the file
* Note:this is similar to gulp and different from native node path base
*/
@plugins.smartjson.foldDec()
public base: string;
/**
* sync the file with disk
*/
@plugins.smartjson.foldDec()
public sync: boolean;
/**
@ -88,6 +93,7 @@ export class Smartfile {
*/
constructor(optionsArg: ISmartfileConstructorOptions) {
super();
if (optionsArg.contentBuffer) {
this.contentBuffer = optionsArg.contentBuffer;
} else {
@ -107,13 +113,30 @@ export class Smartfile {
}
/**
* write file to disk
* write file to disk at its original location
* Behaviours:
* - no argument write to exactly where the file was picked up
*/
public async write(pathArg?: string) {
const stringToWrite = this.contentBuffer.toString();
await memory.toFs(stringToWrite, this.path);
public async write() {
await memory.toFs(this.contentBuffer, this.path);
}
/**
* writes the file to path given as argument
* @param filePathArg
*/
public async writeToDiskAtPath(filePathArg: string) {
if (!plugins.path.isAbsolute(filePathArg)) {
filePathArg = plugins.path.join(process.cwd(), filePathArg);
}
await memory.toFs(this.contentBuffer, filePathArg);
}
public async writeToDir(dirPathArg: string) {
dirPathArg = plugins.smartpath.transform.toAbsolute(dirPathArg);
const filePath = plugins.path.join(dirPathArg, this.path);
await memory.toFs(this.contentBuffer, filePath);
return filePath;
}
/**

View File

@ -6,26 +6,56 @@ import * as fs from './smartfile.fs';
* a virtual directory exposes a fs api
*/
export class VirtualDirectory {
private fileArray: Smartfile[] = [];
public static async fromFsDirPath(pathArg: string) {
// 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
public smartfileArray: Smartfile[] = [];
constructor() {}
public addSmartfiles(smartfileArrayArg: Smartfile[]) {
this.fileArray = this.fileArray.concat(smartfileArrayArg);
this.smartfileArray = this.smartfileArray.concat(smartfileArrayArg);
}
public async getFileByPath(pathArg: string) {
for (const smartfile of this.fileArray) {
for (const smartfile of this.smartfileArray) {
if (smartfile.path === pathArg) {
return smartfile;
}
}
}
public async toVirtualDirTransferableObject(): Promise<plugins.smartfileInterfaces.VirtualDirTransferableObject> {
return {
files: this.smartfileArray.map(smartfileArg => smartfileArg.foldToJson())
};
}
public async saveToDisk(dirArg: string) {
console.log(`writing VirtualDirectory with ${this.smartfileArray.length} to directory:
--> ${dirArg}`);
for (const smartfileArg of this.smartfileArray) {
const filePath = await smartfileArg.writeToDir(dirArg);
console.log(`wrote ${smartfileArg.relative} to
--> ${filePath}`);
}
}
// TODO implement root shifting to get subdirectories as new virtual directories
// TODO implement root shifting to combine VirtualDirecotries in a parent virtual directory
}

View File

@ -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;
};
@ -224,7 +227,7 @@ export const fileTreeToObject = async (dirPathArg: string, miniMatchFilter: stri
if (plugins.path.isAbsolute(miniMatchFilter)) {
dirPath = '/';
} else {
dirPath = dirPathArg;
dirPath = plugins.smartpath.transform.toAbsolute(dirPathArg);
}
const fileTree = await listFileTree(dirPath, miniMatchFilter);

View File

@ -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);

View File

@ -1,8 +1,7 @@
import plugins = require('./smartfile.plugins');
import * as plugins from './smartfile.plugins';
import { Smartfile } from './smartfile.classes.smartfile';
import * as smartfileFs from './smartfile.fs';
import SmartfileInterpreter = require('./smartfile.interpreter');
import * as interpreter from './smartfile.interpreter';
/**
* converts file to Object
@ -10,8 +9,8 @@ import SmartfileInterpreter = require('./smartfile.interpreter');
* @param fileTypeArg
* @returns {any|any}
*/
export let toObject = function (fileStringArg: string, fileTypeArg: string) {
return SmartfileInterpreter.objectFile(fileStringArg, fileTypeArg);
export let toObject = (fileStringArg: string, fileTypeArg: string) => {
return interpreter.objectFile(fileStringArg, fileTypeArg);
};
export interface IToFsOptions {

View File

@ -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
View File

@ -0,0 +1,8 @@
{
"compilerOptions": {
"experimentalDecorators": true,
"esModuleInterop": true,
"target": "ES2017",
"moduleResolution": "node"
}
}