st-cp
Version:
CLI tool for platform independent, recursive copying of files and folders.
43 lines • 1.85 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
var chalk = require("chalk");
var child_process_1 = require("child_process");
var fs_1 = require("fs");
var path_1 = require("path");
var is_directory_1 = require("./is-directory");
var path = path_1.win32;
var resolve = path_1.win32.resolve;
var relative = path_1.win32.relative;
var extractFileName = function (sourcePath) {
return path.basename(sourcePath);
};
var appendFileName = function (destinationPath, fileName) {
return destinationPath + path.sep + fileName;
};
exports.copyPathOrFile = {
resolve: resolve,
relative: relative,
copyPathOrFile: function (sourcePath, destination, option) {
var destinationPath = destination.path;
if (is_directory_1.isDirectory(sourcePath)) {
var destinationPathWithOptionalFileName = destination.isDirectory ? appendFileName(destinationPath, extractFileName(sourcePath)) : destinationPath;
child_process_1.execSync("(robocopy \"" + sourcePath + "\" \"" + destinationPathWithOptionalFileName + "\" /MIR /NFL /NDL /NJH /NJS /nc /ns /np) ^& IF %ERRORLEVEL% LEQ 1 exit 0", { stdio: "inherit" });
}
else {
if (fs_1.existsSync(destinationPath)) {
if (destination.isDirectory) {
fs_1.copyFileSync(sourcePath, appendFileName(destinationPath, extractFileName(sourcePath)));
}
else {
if (option.printWarning) {
console.log(chalk.yellow("[!] Warning: Destination file already exists: " + relative(process.cwd(), destinationPath)));
}
}
}
else {
fs_1.copyFileSync(sourcePath, destinationPath);
}
}
},
};
//# sourceMappingURL=st-cp-windows.js.map
;