const fs = require('fs'); const path = require('path'); function mkdir(targetDir, {isRelativeToScript = false} = {}) { const sep = path.sep; const initDir = path.isAbsolute(targetDir) ? sep : ''; const baseDir = isRelativeToScript ? __dirname : '.'; targetDir.split(sep).reduce((parentDir, childDir) => { const curDir = path.resolve(baseDir, parentDir, childDir); try { fs.mkdirSync(curDir); } catch (err) { if (err.code !== 'EEXIST') { throw err; } } return curDir; }, initDir); } function rmdir(p) { console.log("path = "+p); if (fs.existsSync(p)) { fs.readdirSync(p).forEach(function(file, index){ var curPath = p + "/" + file; if (fs.lstatSync(curPath).isDirectory()) { // recurse rmdir(curPath); } else { // delete file fs.unlinkSync(curPath); } }); fs.rmdirSync(p); } }; function mv(old, ne) { console.log("old: '"+old+"' new = '"+ne+"'") return fs.renameSync(old, ne); }; function rm(file) { fs.unlinkSync(file); } module.exports.mkdir = mkdir; module.exports.rmdir = rmdir; module.exports.mv = mv; module.exports.rm = rm;