fix(core): update
This commit is contained in:
parent
afb7fa8e89
commit
292c2699ea
@ -1,5 +1,5 @@
|
|||||||
import * as smartfile from '../ts/index';
|
import * as smartfile from '../ts/index';
|
||||||
import path = require('path');
|
import * as path from 'path';
|
||||||
|
|
||||||
import { expect, tap } from '@pushrocks/tapbundle';
|
import { expect, tap } from '@pushrocks/tapbundle';
|
||||||
|
|
||||||
@ -8,7 +8,9 @@ import { expect, tap } from '@pushrocks/tapbundle';
|
|||||||
// ---------------------------
|
// ---------------------------
|
||||||
|
|
||||||
tap.test('.fs.fileExistsSync -> should return an accurate boolean', async () => {
|
tap.test('.fs.fileExistsSync -> should return an accurate boolean', async () => {
|
||||||
|
// tslint:disable-next-line: no-unused-expression
|
||||||
expect(smartfile.fs.fileExistsSync('./test/testassets/mytest.json')).to.be.true;
|
expect(smartfile.fs.fileExistsSync('./test/testassets/mytest.json')).to.be.true;
|
||||||
|
// tslint:disable-next-line: no-unused-expression
|
||||||
expect(smartfile.fs.fileExistsSync('./test/testassets/notthere.json')).be.false;
|
expect(smartfile.fs.fileExistsSync('./test/testassets/notthere.json')).be.false;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
15
test/test.virtualdirectory.ts
Normal file
15
test/test.virtualdirectory.ts
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
import { tap, expect } from '@pushrocks/tapbundle';
|
||||||
|
|
||||||
|
import * as smartfile from '../ts';
|
||||||
|
|
||||||
|
tap.test('should create a virtualdirectory', async () => {
|
||||||
|
const virtualDir = await smartfile.VirtualDirectory.fromFsDirPath('./test/testassets/testfolder');
|
||||||
|
expect(virtualDir.smartfileArray.length).to.equal(4);
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('should write to a directory', async () => {
|
||||||
|
const virtualDir = await smartfile.VirtualDirectory.fromFsDirPath('./test/testassets/testfolder');
|
||||||
|
virtualDir.saveToDisk('./test/testassets/test');
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.start();
|
@ -133,12 +133,10 @@ export class Smartfile extends plugins.smartjson.Smartjson {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async writeToDir(dirPathArg: string) {
|
public async writeToDir(dirPathArg: string) {
|
||||||
if (!plugins.path.isAbsolute(dirPathArg)) {
|
dirPathArg = plugins.smartpath.transform.toAbsolute(dirPathArg);
|
||||||
dirPathArg = plugins.path.join(process.cwd(), dirPathArg);
|
const filePath = plugins.path.join(dirPathArg, this.path);
|
||||||
}
|
|
||||||
const relativePath = this.relative;
|
|
||||||
const filePath = plugins.path.join(dirPathArg, relativePath);
|
|
||||||
await memory.toFs(this.contentBuffer, filePath);
|
await memory.toFs(this.contentBuffer, filePath);
|
||||||
|
return filePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -24,16 +24,16 @@ export class VirtualDirectory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// INSTANCE
|
// INSTANCE
|
||||||
private fileArray: Smartfile[] = [];
|
public smartfileArray: Smartfile[] = [];
|
||||||
|
|
||||||
constructor() {}
|
constructor() {}
|
||||||
|
|
||||||
public addSmartfiles(smartfileArrayArg: Smartfile[]) {
|
public addSmartfiles(smartfileArrayArg: Smartfile[]) {
|
||||||
this.fileArray = this.fileArray.concat(smartfileArrayArg);
|
this.smartfileArray = this.smartfileArray.concat(smartfileArrayArg);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getFileByPath(pathArg: string) {
|
public async getFileByPath(pathArg: string) {
|
||||||
for (const smartfile of this.fileArray) {
|
for (const smartfile of this.smartfileArray) {
|
||||||
if (smartfile.path === pathArg) {
|
if (smartfile.path === pathArg) {
|
||||||
return smartfile;
|
return smartfile;
|
||||||
}
|
}
|
||||||
@ -42,13 +42,17 @@ export class VirtualDirectory {
|
|||||||
|
|
||||||
public async toVirtualDirTransferableObject(): Promise<plugins.smartfileInterfaces.VirtualDirTransferableObject> {
|
public async toVirtualDirTransferableObject(): Promise<plugins.smartfileInterfaces.VirtualDirTransferableObject> {
|
||||||
return {
|
return {
|
||||||
files: this.fileArray.map(smartfileArg => smartfileArg.foldToJson())
|
files: this.smartfileArray.map(smartfileArg => smartfileArg.foldToJson())
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public async saveToDisk() {
|
public async saveToDisk(dirArg: string) {
|
||||||
for (const smartfileArg of this.fileArray) {
|
console.log(`writing VirtualDirectory with ${this.smartfileArray.length} to directory:
|
||||||
|
--> ${dirArg}`);
|
||||||
|
for (const smartfileArg of this.smartfileArray) {
|
||||||
|
const filePath = await smartfileArg.writeToDir(dirArg);
|
||||||
|
console.log(`wrote ${smartfileArg.relative} to
|
||||||
|
--> ${filePath}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -227,7 +227,7 @@ export const fileTreeToObject = async (dirPathArg: string, miniMatchFilter: stri
|
|||||||
if (plugins.path.isAbsolute(miniMatchFilter)) {
|
if (plugins.path.isAbsolute(miniMatchFilter)) {
|
||||||
dirPath = '/';
|
dirPath = '/';
|
||||||
} else {
|
} else {
|
||||||
dirPath = dirPathArg;
|
dirPath = plugins.smartpath.transform.toAbsolute(dirPathArg);
|
||||||
}
|
}
|
||||||
|
|
||||||
const fileTree = await listFileTree(dirPath, miniMatchFilter);
|
const fileTree = await listFileTree(dirPath, miniMatchFilter);
|
||||||
|
Loading…
Reference in New Issue
Block a user