add removeMany and removeManySync
This commit is contained in:
parent
1fdd492eff
commit
2c52dec8ea
10
dist/smartfile.fs.d.ts
vendored
10
dist/smartfile.fs.d.ts
vendored
@ -56,11 +56,19 @@ export declare let ensureFileSync: (filePathArg: string, initFileStringArg: stri
|
||||
/**
|
||||
* removes a file or folder from local disk
|
||||
*/
|
||||
export declare let remove: (pathArg: string) => plugins.q.Promise<{}>;
|
||||
export declare let remove: (pathArg: string) => plugins.q.Promise<void>;
|
||||
/**
|
||||
* removes a file SYNCHRONOUSLY from local disk
|
||||
*/
|
||||
export declare let removeSync: (pathArg: string) => boolean;
|
||||
/**
|
||||
* removes an array of filePaths from disk
|
||||
*/
|
||||
export declare let removeMany: (filePathArrayArg: string[]) => plugins.q.Promise<void[]>;
|
||||
/**
|
||||
* like removeFilePathArray but SYNCHRONOUSLY
|
||||
*/
|
||||
export declare let removeManySync: (filePathArrayArg: string[]) => boolean;
|
||||
/**
|
||||
*
|
||||
* @param filePathArg
|
||||
|
21
dist/smartfile.fs.js
vendored
21
dist/smartfile.fs.js
vendored
File diff suppressed because one or more lines are too long
22
test/test.js
22
test/test.js
File diff suppressed because one or more lines are too long
21
test/test.ts
21
test/test.ts
@ -81,8 +81,25 @@ describe('smartfile'.yellow, function () {
|
||||
it('should remove an entire directory', function () {
|
||||
|
||||
})
|
||||
it('should remove single files', function () {
|
||||
|
||||
it('smartfile.fs.remove -> should remove single files', function (done) {
|
||||
smartfile.fs.remove('./test/temp/mytestRenamed.yaml')
|
||||
.then(() => { done() })
|
||||
})
|
||||
it('smartfile.fs.removeSync -> should remove single files synchronouly',function() {
|
||||
smartfile.fs.removeSync('./test/temp/testfile1.txt')
|
||||
should(smartfile.fs.fileExistsSync('./test/temp/testfile1.txt')).be.false()
|
||||
})
|
||||
it('smartfile.fs.removeMany -> should remove and array of files',function(done) {
|
||||
smartfile.fs.removeMany(['./test/temp/testfile1.txt','./test/temp/testfile2.txt']).then(() => {
|
||||
should(smartfile.fs.fileExistsSync('./test/temp/testfile1.txt')).be.false()
|
||||
should(smartfile.fs.fileExistsSync('./test/temp/testfile2.txt')).be.false()
|
||||
done()
|
||||
})
|
||||
})
|
||||
it('smartfile.fs.removeManySync -> should remove and array of single files synchronouly',function() {
|
||||
smartfile.fs.removeManySync(['./test/temp/testfile1.txt','./test/temp/testfile2.txt'])
|
||||
should(smartfile.fs.fileExistsSync('./test/temp/testfile1.txt')).be.false()
|
||||
should(smartfile.fs.fileExistsSync('./test/temp/testfile2.txt')).be.false()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@ -121,8 +121,8 @@ export let ensureFileSync = (filePathArg: string, initFileStringArg: string): vo
|
||||
/**
|
||||
* removes a file or folder from local disk
|
||||
*/
|
||||
export let remove = function(pathArg: string){
|
||||
let done = plugins.q.defer()
|
||||
export let remove = function(pathArg: string): plugins.q.Promise<void> {
|
||||
let done = plugins.q.defer<void>()
|
||||
plugins.fsExtra.remove(pathArg,function(){
|
||||
done.resolve()
|
||||
})
|
||||
@ -137,6 +137,27 @@ export let removeSync = function(pathArg: string): boolean{
|
||||
return true
|
||||
}
|
||||
|
||||
/**
|
||||
* removes an array of filePaths from disk
|
||||
*/
|
||||
export let removeMany = function(filePathArrayArg: string[]){
|
||||
let promiseArray: plugins.q.Promise<void>[] = []
|
||||
for (let filePath of filePathArrayArg) {
|
||||
promiseArray.push(remove(filePath))
|
||||
}
|
||||
return plugins.q.all(promiseArray)
|
||||
}
|
||||
|
||||
/**
|
||||
* like removeFilePathArray but SYNCHRONOUSLY
|
||||
*/
|
||||
export let removeManySync = function(filePathArrayArg: string[]){
|
||||
for (let filePath of filePathArrayArg) {
|
||||
removeSync(filePath)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
/*===============================================================
|
||||
============================ Write/Read =========================
|
||||
===============================================================*/
|
||||
|
Loading…
Reference in New Issue
Block a user