diff --git a/ts/smartfile.classes.smartfile.ts b/ts/smartfile.classes.smartfile.ts index 42e64a1..73cc117 100644 --- a/ts/smartfile.classes.smartfile.ts +++ b/ts/smartfile.classes.smartfile.ts @@ -113,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); } /** diff --git a/ts/smartfile.classes.virtualdirectory.ts b/ts/smartfile.classes.virtualdirectory.ts index 03a29b9..5ad4815 100644 --- a/ts/smartfile.classes.virtualdirectory.ts +++ b/ts/smartfile.classes.virtualdirectory.ts @@ -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 } diff --git a/ts/smartfile.memory.ts b/ts/smartfile.memory.ts index 4637504..eb292cf 100644 --- a/ts/smartfile.memory.ts +++ b/ts/smartfile.memory.ts @@ -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 {