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",
"version": "8.0.5",
"version": "8.0.7",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

View File

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

View File

@ -63,24 +63,28 @@ export class Smartfile extends plugins.smartjson.Smartjson {
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;
/**
@ -109,13 +113,32 @@ export class Smartfile extends plugins.smartjson.Smartjson {
}
/**
* 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) {
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 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 * 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 {