From de09f85c34ac0dc5bb4c8228b9eb34170ab6e6f3 Mon Sep 17 00:00:00 2001 From: Phil Kunz Date: Mon, 5 Oct 2020 16:20:57 +0000 Subject: [PATCH] fix(core): update --- package-lock.json | 33 +++++++++++++++++++++--- package.json | 2 ++ ts/smartfile.classes.smartfile.ts | 4 ++- ts/smartfile.classes.virtualdirectory.ts | 23 +++++++++++++++-- ts/smartfile.fs.ts | 13 ++++++---- ts/smartfile.interpreter.ts | 2 +- ts/smartfile.plugins.ts | 4 ++- tsconfig.json | 8 ++++++ 8 files changed, 76 insertions(+), 13 deletions(-) create mode 100644 tsconfig.json diff --git a/package-lock.json b/package-lock.json index da8b9d4..503d115 100644 --- a/package-lock.json +++ b/package-lock.json @@ -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", diff --git a/package.json b/package.json index 157f021..c0f9432 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/ts/smartfile.classes.smartfile.ts b/ts/smartfile.classes.smartfile.ts index 6969860..48f046d 100644 --- a/ts/smartfile.classes.smartfile.ts +++ b/ts/smartfile.classes.smartfile.ts @@ -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 { diff --git a/ts/smartfile.classes.virtualdirectory.ts b/ts/smartfile.classes.virtualdirectory.ts index 56d5a45..03a29b9 100644 --- a/ts/smartfile.classes.virtualdirectory.ts +++ b/ts/smartfile.classes.virtualdirectory.ts @@ -6,13 +6,26 @@ 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 { const newVirtualDir = new VirtualDirectory(); newVirtualDir.addSmartfiles(await fs.fileTreeToObject(pathArg, '**/*')); return newVirtualDir; } + public static async fromVirtualDirTransferableObject( + virtualDirTransferableObjectArg: plugins.smartfileInterfaces.VirtualDirTransferableObject + ): Promise { + 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[]) { @@ -27,6 +40,12 @@ export class VirtualDirectory { } } + public async toVirtualDirTransferableObject(): Promise { + 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 } diff --git a/ts/smartfile.fs.ts b/ts/smartfile.fs.ts index d73d744..829a43b 100644 --- a/ts/smartfile.fs.ts +++ b/ts/smartfile.fs.ts @@ -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; }; diff --git a/ts/smartfile.interpreter.ts b/ts/smartfile.interpreter.ts index 798baa4..d993dc6 100644 --- a/ts/smartfile.interpreter.ts +++ b/ts/smartfile.interpreter.ts @@ -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); diff --git a/ts/smartfile.plugins.ts b/ts/smartfile.plugins.ts index d8f5417..c5614d1 100644 --- a/ts/smartfile.plugins.ts +++ b/ts/smartfile.plugins.ts @@ -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'; diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..06b9f8b --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,8 @@ +{ + "compilerOptions": { + "experimentalDecorators": true, + "esModuleInterop": true, + "target": "ES2017", + "moduleResolution": "node" + } +} \ No newline at end of file