fix(core): update
This commit is contained in:
parent
c6280eb6fc
commit
f4129c04b2
11
test/test.ts
11
test/test.ts
@ -59,15 +59,15 @@ tap.test('.fs.fileTreeToObject -> should read a file tree into an Object', async
|
|||||||
});
|
});
|
||||||
|
|
||||||
tap.test('.fs.copy() -> should copy a directory', async () => {
|
tap.test('.fs.copy() -> should copy a directory', async () => {
|
||||||
smartfile.fs.copy('./test/testassets/testfolder/', './test/testassets/temp/');
|
await smartfile.fs.copy('./test/testassets/testfolder/', './test/testassets/temp/');
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('.fs.copy() -> should copy a file', async () => {
|
tap.test('.fs.copy() -> should copy a file', async () => {
|
||||||
smartfile.fs.copy('./test/testassets/mytest.yaml', './test/testassets/temp/');
|
await smartfile.fs.copy('./test/testassets/mytest.yaml', './test/testassets/temp/mytest.yaml');
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('.fs.copy() -> should copy a file and rename it', async () => {
|
tap.test('.fs.copy() -> should copy a file and rename it', async () => {
|
||||||
smartfile.fs.copy('./test/testassets/mytest.yaml', './test/testassets/temp/mytestRenamed.yaml');
|
await smartfile.fs.copy('./test/testassets/mytest.yaml', './test/testassets/temp/mytestRenamed.yaml');
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('.fs.remove() -> should remove an entire directory', async () => {});
|
tap.test('.fs.remove() -> should remove an entire directory', async () => {});
|
||||||
@ -145,14 +145,13 @@ tap.test(
|
|||||||
);
|
);
|
||||||
|
|
||||||
tap.test('.remote.toString() -> should load a remote file to a variable', async () => {
|
tap.test('.remote.toString() -> should load a remote file to a variable', async () => {
|
||||||
let responseString = await smartfile.remote.toString(
|
const responseString = await smartfile.remote.toString(
|
||||||
'https://raw.githubusercontent.com/pushrocks/smartfile/master/test/mytest.txt'
|
'https://raw.githubusercontent.com/pushrocks/smartfile/master/test/testassets/mytest.txt'
|
||||||
);
|
);
|
||||||
expect(responseString).to.equal('Some TestString &&%$');
|
expect(responseString).to.equal('Some TestString &&%$');
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('.remote.toString() -> should reject a Promise when the link is false', async tools => {
|
tap.test('.remote.toString() -> should reject a Promise when the link is false', async tools => {
|
||||||
tools.returnError;
|
|
||||||
await smartfile.remote.toString('https://push.rocks/doesnotexist.txt').catch(err => {
|
await smartfile.remote.toString('https://push.rocks/doesnotexist.txt').catch(err => {
|
||||||
return expect(err.message).to.equal(
|
return expect(err.message).to.equal(
|
||||||
'could not get remote file from https://push.rocks/doesnotexist.txt'
|
'could not get remote file from https://push.rocks/doesnotexist.txt'
|
||||||
|
4
test/testassets/temp/mytest.yaml
Normal file
4
test/testassets/temp/mytest.yaml
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
key1: this works
|
||||||
|
key2: this works too
|
||||||
|
key3:
|
||||||
|
nestedkey1: hello
|
@ -13,7 +13,7 @@ import * as memory from './smartfile.memory';
|
|||||||
* @param filePath
|
* @param filePath
|
||||||
* @returns {boolean}
|
* @returns {boolean}
|
||||||
*/
|
*/
|
||||||
export let fileExistsSync = function(filePath): boolean {
|
export const fileExistsSync = (filePath): boolean => {
|
||||||
let fileExistsBool: boolean = false;
|
let fileExistsBool: boolean = false;
|
||||||
try {
|
try {
|
||||||
plugins.fsExtra.readFileSync(filePath);
|
plugins.fsExtra.readFileSync(filePath);
|
||||||
@ -29,7 +29,7 @@ export let fileExistsSync = function(filePath): boolean {
|
|||||||
* @param filePath
|
* @param filePath
|
||||||
* @returns {any}
|
* @returns {any}
|
||||||
*/
|
*/
|
||||||
export let fileExists = (filePath): Promise<boolean> => {
|
export let fileExists = async (filePath): Promise<boolean> => {
|
||||||
const done = plugins.smartpromise.defer<boolean>();
|
const done = plugins.smartpromise.defer<boolean>();
|
||||||
plugins.fs.access(filePath, 4, err => {
|
plugins.fs.access(filePath, 4, err => {
|
||||||
err ? done.resolve(false) : done.resolve(true);
|
err ? done.resolve(false) : done.resolve(true);
|
||||||
@ -40,7 +40,7 @@ export let fileExists = (filePath): Promise<boolean> => {
|
|||||||
/**
|
/**
|
||||||
* Checks if given path points to an existing directory
|
* Checks if given path points to an existing directory
|
||||||
*/
|
*/
|
||||||
export let isDirectory = (pathArg): boolean => {
|
export const isDirectory = (pathArg): boolean => {
|
||||||
try {
|
try {
|
||||||
return plugins.fsExtra.statSync(pathArg).isDirectory();
|
return plugins.fsExtra.statSync(pathArg).isDirectory();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@ -51,7 +51,7 @@ export let isDirectory = (pathArg): boolean => {
|
|||||||
/**
|
/**
|
||||||
* Checks if a given path points to an existing file
|
* Checks if a given path points to an existing file
|
||||||
*/
|
*/
|
||||||
export let isFile = function(pathArg): boolean {
|
export const isFile = (pathArg): boolean => {
|
||||||
return plugins.fsExtra.statSync(pathArg).isFile();
|
return plugins.fsExtra.statSync(pathArg).isFile();
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -62,10 +62,13 @@ export let isFile = function(pathArg): boolean {
|
|||||||
/**
|
/**
|
||||||
* copies a file from A to B on the local disk
|
* copies a file from A to B on the local disk
|
||||||
*/
|
*/
|
||||||
export let copy = function(fromArg: string, toArg: string) {
|
export const copy = async (fromArg: string, toArg: string): Promise<boolean> => {
|
||||||
let done = plugins.smartpromise.defer();
|
const done = plugins.smartpromise.defer<boolean>();
|
||||||
plugins.fsExtra.copy(fromArg, toArg, {}, function() {
|
plugins.fsExtra.copy(fromArg, toArg, {}, (err) => {
|
||||||
done.resolve();
|
if (err) {
|
||||||
|
throw new Error(`Could not copy from ${fromArg} to ${toArg}: ${err}`);
|
||||||
|
}
|
||||||
|
done.resolve(true);
|
||||||
});
|
});
|
||||||
return done.promise;
|
return done.promise;
|
||||||
};
|
};
|
||||||
@ -73,7 +76,7 @@ export let copy = function(fromArg: string, toArg: string) {
|
|||||||
/**
|
/**
|
||||||
* copies a file SYNCHRONOUSLY from A to B on the local disk
|
* copies a file SYNCHRONOUSLY from A to B on the local disk
|
||||||
*/
|
*/
|
||||||
export let copySync = function(fromArg: string, toArg: string): boolean {
|
export const copySync = (fromArg: string, toArg: string): boolean => {
|
||||||
plugins.fsExtra.copySync(fromArg, toArg);
|
plugins.fsExtra.copySync(fromArg, toArg);
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
@ -205,7 +208,7 @@ export let toObjectSync = function(filePathArg, fileTypeArg?) {
|
|||||||
* @param filePath
|
* @param filePath
|
||||||
* @returns {string|Buffer|any}
|
* @returns {string|Buffer|any}
|
||||||
*/
|
*/
|
||||||
export let toStringSync = function(filePath: string): string {
|
export const toStringSync = (filePath: string): string => {
|
||||||
const fileString: string = plugins.fsExtra.readFileSync(filePath, 'utf8');
|
const fileString: string = plugins.fsExtra.readFileSync(filePath, 'utf8');
|
||||||
return fileString;
|
return fileString;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user