zoro-cli
Version:
39 lines (36 loc) • 1.14 kB
JavaScript
import _typeof from 'babel-runtime/helpers/typeof';
var path = require('path');
var fs = require('fs-extra');
var cwd = process.cwd();
module.exports = function handlePath(_ref) {
var file = _ref.file,
override = _ref.override;
var fromName = void 0;
var toName = void 0;
if ((typeof file === 'undefined' ? 'undefined' : _typeof(file)) === 'object') {
fromName = file.from;
toName = file.to;
} else {
fromName = file;
toName = file;
}
var to = path.join(cwd, toName);
var pathExist = false;
return fs.pathExists(to).then(function (exists) {
pathExist = exists;
// backup file if exist and override
if (exists && override) {
var backup = path.join(cwd, 'backup/' + toName + '.' + +new Date() + '.backup');
console.warn('backup ' + toName + ' to ' + backup);
return fs.copy(to, backup);
}
}).then(function () {
if (!pathExist || override) {
// copy file
var from = path.join(__dirname, '../res/configs/' + fromName);
console.log('copy ' + from + ' to ' + to);
return fs.copy(from, to);
}
console.log('skip ' + toName);
});
};