Compare commits

...

4 Commits

Author SHA1 Message Date
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
5 changed files with 40 additions and 12 deletions

2
package-lock.json generated
View File

@ -1,6 +1,6 @@
{ {
"name": "@pushrocks/smartfile", "name": "@pushrocks/smartfile",
"version": "8.0.5", "version": "8.0.7",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {

View File

@ -1,7 +1,7 @@
{ {
"name": "@pushrocks/smartfile", "name": "@pushrocks/smartfile",
"private": false, "private": false,
"version": "8.0.5", "version": "8.0.7",
"description": "offers smart ways to work with files in nodejs", "description": "offers smart ways to work with files in nodejs",
"main": "dist_ts/index.js", "main": "dist_ts/index.js",
"typings": "dist_ts/index.d.ts", "typings": "dist_ts/index.d.ts",

View File

@ -63,24 +63,28 @@ export class Smartfile extends plugins.smartjson.Smartjson {
public path: string; public path: string;
/** /**
* * a parsed path
*/ */
@plugins.smartjson.foldDec()
public parsedPath: plugins.path.ParsedPath; public parsedPath: plugins.path.ParsedPath;
/** /**
* the content of the file as Buffer * the content of the file as Buffer
*/ */
@plugins.smartjson.foldDec()
public contentBuffer: Buffer; public contentBuffer: Buffer;
/** /**
* The current working directory of the file * The current working directory of the file
* Note:this is similar to gulp and different from native node path base * Note:this is similar to gulp and different from native node path base
*/ */
@plugins.smartjson.foldDec()
public base: string; public base: string;
/** /**
* sync the file with disk * sync the file with disk
*/ */
@plugins.smartjson.foldDec()
public sync: boolean; public sync: boolean;
/** /**
@ -109,13 +113,32 @@ export class Smartfile extends plugins.smartjson.Smartjson {
} }
/** /**
* write file to disk * write file to disk at its original location
* Behaviours: * Behaviours:
* - no argument write to exactly where the file was picked up * - no argument write to exactly where the file was picked up
*/ */
public async write(pathArg?: string) { public async write() {
const stringToWrite = this.contentBuffer.toString(); await memory.toFs(this.contentBuffer, this.path);
await memory.toFs(stringToWrite, 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) {
if (!plugins.path.isAbsolute(dirPathArg)) {
dirPathArg = plugins.path.join(process.cwd(), dirPathArg);
}
const relativePath = this.relative;
const filePath = plugins.path.join(dirPathArg, relativePath);
await memory.toFs(this.contentBuffer, filePath);
} }
/** /**

View File

@ -46,6 +46,12 @@ export class VirtualDirectory {
}; };
} }
public async saveToDisk() {
for (const smartfileArg of this.fileArray) {
}
}
// TODO implement root shifting to get subdirectories as new virtual directories // TODO implement root shifting to get subdirectories as new virtual directories
// TODO implement root shifting to combine VirtualDirecotries in a parent virtual directory // TODO implement root shifting to combine VirtualDirecotries in a parent virtual directory
} }

View File

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