UNPKG

zoro-cli

Version:

39 lines (36 loc) 1 kB
const path = require('path'); const fs = require('fs-extra'); const cwd = process.cwd(); module.exports = function handlePath({ file, override }) { let fromName; let toName; if (typeof file === 'object') { fromName = file.from; toName = file.to; } else { fromName = file; toName = file; } const to = path.join(cwd, toName); let pathExist = false; return fs .pathExists(to) .then(exists => { pathExist = exists; // backup file if exist and override if (exists && override) { const backup = path.join(cwd, `backup/${toName}.${+new Date()}.backup`); console.warn(`backup ${toName} to ${backup}`); return fs.copy(to, backup); } }) .then(() => { if (!pathExist || override) { // copy file const from = path.join(__dirname, `../res/configs/${fromName}`); console.log(`copy ${from} to ${to}`); return fs.copy(from, to); } console.log(`skip ${toName}`); }); };