fix(core): update

This commit is contained in:
2020-10-05 16:20:57 +00:00
parent b9fefc7c95
commit de09f85c34
8 changed files with 76 additions and 13 deletions

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,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 {

View File

@ -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<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[]) {
@ -27,6 +40,12 @@ export class VirtualDirectory {
}
}
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
}

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

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

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