add mkdirParentsPath and mkdirParentsPathSync mkdirp helper
This commit is contained in:
parent
b78969d045
commit
3fa4e575f8
1 changed files with 37 additions and 0 deletions
37
helpers/mkdirp.js
Normal file
37
helpers/mkdirp.js
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
import mkdirp from 'mkdirp';
|
||||||
|
import _ from 'lodash';
|
||||||
|
import deasync from 'deasync';
|
||||||
|
|
||||||
|
const mkdirParentsPath = (filePath) => new Promise(async (resolve, reject) =>{
|
||||||
|
const folderFileIn = "/" + _.initial(filePath.split("/")).join("/");
|
||||||
|
await mkdirp(folderFileIn).catch(reject);
|
||||||
|
resolve(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
const mkdirParentsPathSync = (filePath) => {
|
||||||
|
let done = false;
|
||||||
|
let err;
|
||||||
|
let result;
|
||||||
|
|
||||||
|
mkdirParentsPath(filePath).then(res => {
|
||||||
|
result = res;
|
||||||
|
done = true;
|
||||||
|
})
|
||||||
|
.catch(e => { // eslint-disable-line no-unused-vars
|
||||||
|
err = e;
|
||||||
|
done = true; // eslint-disable-line no-unused-vars });
|
||||||
|
});
|
||||||
|
deasync.loopWhile(function(){return !done;});
|
||||||
|
|
||||||
|
if (err) {
|
||||||
|
throw err;
|
||||||
|
} else {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export {
|
||||||
|
mkdirParentsPath as default,
|
||||||
|
mkdirParentsPath,
|
||||||
|
mkdirParentsPathSync
|
||||||
|
}
|
Loading…
Reference in a new issue