UNPKG

st-cp

Version:

CLI tool for platform independent, recursive copying of files and folders.

40 lines 1.61 kB
"use strict"; 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"); exports.copyPathOrFile = { resolve: path_1.resolve, relative: path_1.relative, copyPathOrFile: function (sourcePath, destination, option) { var destinationPath = destination.path; //create folder if not exist if (destination.isDirectory) { if (!fs_1.existsSync(destinationPath)) { fs_1.mkdirSync(destinationPath, { recursive: true, }); } } else { if (destinationPath.indexOf(path_1.sep) > 0) { fs_1.mkdirSync(destinationPath.substring(0, destinationPath.lastIndexOf(path_1.sep)), { recursive: true, }); } } var recursive = "p"; if (destination.isDirectory || (is_directory_1.isDirectory(sourcePath) && !fs_1.existsSync(destinationPath))) { recursive = "rp"; } else if (fs_1.existsSync(destinationPath)) { if (option.printWarning) { console.log(chalk.yellow("[!] Warning: Destination file already exists: " + path_1.relative(process.cwd(), destinationPath))); } } child_process_1.execSync("cp -" + recursive + " \"" + sourcePath + "\" \"" + destinationPath + "\"", { stdio: "inherit" }); } }; //# sourceMappingURL=st-cp-linux.js.map