| 'use strict'; | ||
| const fs = require('fs'); | ||
| const path = require('path'); | ||
| const mkdirSyncRecursive = require('mkdir-sync-recursive'); | ||
| function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; } | ||
| const fs__default = /*#__PURE__*/_interopDefaultCompat(fs); | ||
| const path__default = /*#__PURE__*/_interopDefaultCompat(path); | ||
| const mkdirSyncRecursive__default = /*#__PURE__*/_interopDefaultCompat(mkdirSyncRecursive); | ||
| const name$1 = "node-cpr"; | ||
| const version = "1.2.0"; | ||
| const author = "lxf <infiniment@163.com>"; | ||
| const license = "MIT"; | ||
| const description = "The cp -r command implementation for node."; | ||
| const type = "module"; | ||
| const bin = "./dist/bin.mjs"; | ||
| const main = "./dist/index.cjs"; | ||
| const module$1 = "./dist/index.mjs"; | ||
| const types = "./dist/index.d.cts"; | ||
| const repository = { | ||
| type: "git", | ||
| url: "git+git@github.com:luoxiangfan/cpr.git" | ||
| }; | ||
| const exports$1 = { | ||
| ".": { | ||
| "import": { | ||
| types: "./dist/index.d.mts", | ||
| "default": "./dist/index.mjs" | ||
| }, | ||
| require: { | ||
| types: "./dist/index.d.cts", | ||
| "default": "./dist/index.cjs" | ||
| } | ||
| } | ||
| }; | ||
| const files = [ | ||
| "dist" | ||
| ]; | ||
| const scripts = { | ||
| "type-check": "tsc --strict --noEmit", | ||
| format: "prettier --write src/", | ||
| build: "unbuild", | ||
| release: "npm publish" | ||
| }; | ||
| const keywords = [ | ||
| "cp", | ||
| "cp -r", | ||
| "recursive", | ||
| "copy" | ||
| ]; | ||
| const devDependencies = { | ||
| "@types/node": "^22.10.0", | ||
| prettier: "^3.4.1", | ||
| typescript: "^5.7.2", | ||
| unbuild: "^2.0.0" | ||
| }; | ||
| const dependencies = { | ||
| "mkdir-sync-recursive": "^1.0.2" | ||
| }; | ||
| const packageConfig = { | ||
| name: name$1, | ||
| version: version, | ||
| author: author, | ||
| license: license, | ||
| description: description, | ||
| type: type, | ||
| bin: bin, | ||
| main: main, | ||
| module: module$1, | ||
| types: types, | ||
| repository: repository, | ||
| exports: exports$1, | ||
| files: files, | ||
| scripts: scripts, | ||
| keywords: keywords, | ||
| devDependencies: devDependencies, | ||
| dependencies: dependencies | ||
| }; | ||
| const { name } = packageConfig; | ||
| function exit(name2) { | ||
| console.error(`Try \`${name2} --help\` for more information.`); | ||
| return 1; | ||
| } | ||
| function isFile(filePath) { | ||
| try { | ||
| const stat = fs__default.statSync(path__default.resolve(filePath)); | ||
| return stat.isFile(); | ||
| } catch (error) { | ||
| return false; | ||
| } | ||
| } | ||
| function isDirectory(filePath) { | ||
| try { | ||
| const stat = fs__default.statSync(path__default.resolve(filePath)); | ||
| return stat.isDirectory(); | ||
| } catch (error) { | ||
| return false; | ||
| } | ||
| } | ||
| function isPathExist(filePath) { | ||
| try { | ||
| return fs__default.existsSync(filePath); | ||
| } catch (error) { | ||
| return false; | ||
| } | ||
| } | ||
| const isArray = Array.isArray; | ||
| function errorMsg(source, dest, mkdirp) { | ||
| if (!dest) { | ||
| console.error( | ||
| `${name}: missing destination file operand after '${source}'` | ||
| ); | ||
| return exit(name); | ||
| } else if (typeof source === "string") { | ||
| const sourceExist = isPathExist(source); | ||
| if (sourceExist && isDirectory(source) && isFile(dest)) { | ||
| console.error( | ||
| `${name}: cannot overwrite non-directory '${dest}' with directory ${source}'` | ||
| ); | ||
| return exit(name); | ||
| } | ||
| if (!sourceExist) { | ||
| console.error( | ||
| `${name}: cannot stat '${source}': No such file or directory` | ||
| ); | ||
| return exit(name); | ||
| } | ||
| } else { | ||
| const invalidPaths = source.filter((f) => !isFile(f) && !isDirectory(f)); | ||
| const lastInvalidIndex = invalidPaths.length - 1; | ||
| if (!mkdirp && !isDirectory(dest)) { | ||
| console.error(`${name}: target '${dest}' is not a directory`); | ||
| return exit(name); | ||
| } else { | ||
| invalidPaths.forEach((f, idx) => { | ||
| if (!isFile(f) && !isDirectory(f)) { | ||
| console.error( | ||
| `${name}: cannot stat '${f}': No such file or directory` | ||
| ); | ||
| if (idx === lastInvalidIndex) { | ||
| return 1; | ||
| } | ||
| } | ||
| }); | ||
| } | ||
| } | ||
| } | ||
| function copyFile(src, dest) { | ||
| let destPath = dest; | ||
| if (isDirectory(dest)) { | ||
| if (isFile(src)) { | ||
| destPath = dest + "/" + path__default.basename(src); | ||
| } else { | ||
| destPath = dest + "/" + src; | ||
| } | ||
| } | ||
| fs__default.copyFileSync(src, destPath); | ||
| } | ||
| function copyDir(src, dest) { | ||
| mkdirSyncRecursive__default(dest); | ||
| try { | ||
| const files = fs__default.readdirSync(src, { encoding: "utf-8" }); | ||
| for (const file of files) { | ||
| let srcPath = path__default.join(src, file); | ||
| let destPath = path__default.join(dest, file); | ||
| if (isDirectory(srcPath)) { | ||
| copyDir(srcPath, destPath); | ||
| } | ||
| if (isFile(srcPath)) { | ||
| copyFile(srcPath, destPath); | ||
| } | ||
| } | ||
| } catch (err) { | ||
| console.error(err); | ||
| } | ||
| } | ||
| function cpr(source, dest, mkdirp) { | ||
| if (errorMsg(source, dest, mkdirp)) { | ||
| return; | ||
| } | ||
| if (mkdirp && !isPathExist(dest)) { | ||
| mkdirSyncRecursive__default(dest); | ||
| } | ||
| if (isArray(source)) { | ||
| source.forEach((s) => { | ||
| if (isFile(s)) { | ||
| copyFile(s, dest); | ||
| } | ||
| if (isDirectory(s)) { | ||
| if (isPathExist(dest)) { | ||
| copyDir(s, dest + "/" + s); | ||
| } else { | ||
| copyDir(s, dest); | ||
| } | ||
| } | ||
| }); | ||
| } else { | ||
| if (isDirectory(source)) { | ||
| if (isPathExist(dest)) { | ||
| copyDir(source, dest + "/" + source); | ||
| } else { | ||
| copyDir(source, dest); | ||
| } | ||
| } else { | ||
| copyFile(source, dest); | ||
| } | ||
| } | ||
| } | ||
| exports.cpr = cpr; | ||
| exports.exit = exit; | ||
| exports.packageConfig = packageConfig; |
| import fs from 'fs'; | ||
| import path from 'path'; | ||
| import mkdirSyncRecursive from 'mkdir-sync-recursive'; | ||
| const name$1 = "node-cpr"; | ||
| const version = "1.2.0"; | ||
| const author = "lxf <infiniment@163.com>"; | ||
| const license = "MIT"; | ||
| const description = "The cp -r command implementation for node."; | ||
| const type = "module"; | ||
| const bin = "./dist/bin.mjs"; | ||
| const main = "./dist/index.cjs"; | ||
| const module = "./dist/index.mjs"; | ||
| const types = "./dist/index.d.cts"; | ||
| const repository = { | ||
| type: "git", | ||
| url: "git+git@github.com:luoxiangfan/cpr.git" | ||
| }; | ||
| const exports = { | ||
| ".": { | ||
| "import": { | ||
| types: "./dist/index.d.mts", | ||
| "default": "./dist/index.mjs" | ||
| }, | ||
| require: { | ||
| types: "./dist/index.d.cts", | ||
| "default": "./dist/index.cjs" | ||
| } | ||
| } | ||
| }; | ||
| const files = [ | ||
| "dist" | ||
| ]; | ||
| const scripts = { | ||
| "type-check": "tsc --strict --noEmit", | ||
| format: "prettier --write src/", | ||
| build: "unbuild", | ||
| release: "npm publish" | ||
| }; | ||
| const keywords = [ | ||
| "cp", | ||
| "cp -r", | ||
| "recursive", | ||
| "copy" | ||
| ]; | ||
| const devDependencies = { | ||
| "@types/node": "^22.10.0", | ||
| prettier: "^3.4.1", | ||
| typescript: "^5.7.2", | ||
| unbuild: "^2.0.0" | ||
| }; | ||
| const dependencies = { | ||
| "mkdir-sync-recursive": "^1.0.2" | ||
| }; | ||
| const packageConfig = { | ||
| name: name$1, | ||
| version: version, | ||
| author: author, | ||
| license: license, | ||
| description: description, | ||
| type: type, | ||
| bin: bin, | ||
| main: main, | ||
| module: module, | ||
| types: types, | ||
| repository: repository, | ||
| exports: exports, | ||
| files: files, | ||
| scripts: scripts, | ||
| keywords: keywords, | ||
| devDependencies: devDependencies, | ||
| dependencies: dependencies | ||
| }; | ||
| const { name } = packageConfig; | ||
| function exit(name2) { | ||
| console.error(`Try \`${name2} --help\` for more information.`); | ||
| return 1; | ||
| } | ||
| function isFile(filePath) { | ||
| try { | ||
| const stat = fs.statSync(path.resolve(filePath)); | ||
| return stat.isFile(); | ||
| } catch (error) { | ||
| return false; | ||
| } | ||
| } | ||
| function isDirectory(filePath) { | ||
| try { | ||
| const stat = fs.statSync(path.resolve(filePath)); | ||
| return stat.isDirectory(); | ||
| } catch (error) { | ||
| return false; | ||
| } | ||
| } | ||
| function isPathExist(filePath) { | ||
| try { | ||
| return fs.existsSync(filePath); | ||
| } catch (error) { | ||
| return false; | ||
| } | ||
| } | ||
| const isArray = Array.isArray; | ||
| function errorMsg(source, dest, mkdirp) { | ||
| if (!dest) { | ||
| console.error( | ||
| `${name}: missing destination file operand after '${source}'` | ||
| ); | ||
| return exit(name); | ||
| } else if (typeof source === "string") { | ||
| const sourceExist = isPathExist(source); | ||
| if (sourceExist && isDirectory(source) && isFile(dest)) { | ||
| console.error( | ||
| `${name}: cannot overwrite non-directory '${dest}' with directory ${source}'` | ||
| ); | ||
| return exit(name); | ||
| } | ||
| if (!sourceExist) { | ||
| console.error( | ||
| `${name}: cannot stat '${source}': No such file or directory` | ||
| ); | ||
| return exit(name); | ||
| } | ||
| } else { | ||
| const invalidPaths = source.filter((f) => !isFile(f) && !isDirectory(f)); | ||
| const lastInvalidIndex = invalidPaths.length - 1; | ||
| if (!mkdirp && !isDirectory(dest)) { | ||
| console.error(`${name}: target '${dest}' is not a directory`); | ||
| return exit(name); | ||
| } else { | ||
| invalidPaths.forEach((f, idx) => { | ||
| if (!isFile(f) && !isDirectory(f)) { | ||
| console.error( | ||
| `${name}: cannot stat '${f}': No such file or directory` | ||
| ); | ||
| if (idx === lastInvalidIndex) { | ||
| return 1; | ||
| } | ||
| } | ||
| }); | ||
| } | ||
| } | ||
| } | ||
| function copyFile(src, dest) { | ||
| let destPath = dest; | ||
| if (isDirectory(dest)) { | ||
| if (isFile(src)) { | ||
| destPath = dest + "/" + path.basename(src); | ||
| } else { | ||
| destPath = dest + "/" + src; | ||
| } | ||
| } | ||
| fs.copyFileSync(src, destPath); | ||
| } | ||
| function copyDir(src, dest) { | ||
| mkdirSyncRecursive(dest); | ||
| try { | ||
| const files = fs.readdirSync(src, { encoding: "utf-8" }); | ||
| for (const file of files) { | ||
| let srcPath = path.join(src, file); | ||
| let destPath = path.join(dest, file); | ||
| if (isDirectory(srcPath)) { | ||
| copyDir(srcPath, destPath); | ||
| } | ||
| if (isFile(srcPath)) { | ||
| copyFile(srcPath, destPath); | ||
| } | ||
| } | ||
| } catch (err) { | ||
| console.error(err); | ||
| } | ||
| } | ||
| function cpr(source, dest, mkdirp) { | ||
| if (errorMsg(source, dest, mkdirp)) { | ||
| return; | ||
| } | ||
| if (mkdirp && !isPathExist(dest)) { | ||
| mkdirSyncRecursive(dest); | ||
| } | ||
| if (isArray(source)) { | ||
| source.forEach((s) => { | ||
| if (isFile(s)) { | ||
| copyFile(s, dest); | ||
| } | ||
| if (isDirectory(s)) { | ||
| if (isPathExist(dest)) { | ||
| copyDir(s, dest + "/" + s); | ||
| } else { | ||
| copyDir(s, dest); | ||
| } | ||
| } | ||
| }); | ||
| } else { | ||
| if (isDirectory(source)) { | ||
| if (isPathExist(dest)) { | ||
| copyDir(source, dest + "/" + source); | ||
| } else { | ||
| copyDir(source, dest); | ||
| } | ||
| } else { | ||
| copyFile(source, dest); | ||
| } | ||
| } | ||
| } | ||
| export { cpr as c, exit as e, packageConfig as p }; |
+16
-121
@@ -7,3 +7,3 @@ #!/usr/bin/env node | ||
| const readline = require('readline'); | ||
| const index = require('./shared/node-cpr.fc34dab9.cjs'); | ||
| const index = require('./shared/node-cpr.a266359a.cjs'); | ||
| require('fs'); | ||
@@ -13,75 +13,5 @@ require('path'); | ||
| const validArgs = ["-h", "-v", "--help", "--version"]; | ||
| const validArgs = ["-h", "-v", "--help", "--version", "--mkdirp"]; | ||
| const name$1 = "node-cpr"; | ||
| const version$1 = "1.1.1"; | ||
| const author = "lxf <infiniment@163.com>"; | ||
| const license = "MIT"; | ||
| const description = "The cp -r command implementation for node."; | ||
| const type = "module"; | ||
| const bin = "./dist/bin.mjs"; | ||
| const main$1 = "./dist/index.cjs"; | ||
| const module$1 = "./dist/index.mjs"; | ||
| const types = "./dist/index.d.cts"; | ||
| const repository = { | ||
| type: "git", | ||
| url: "git+git@github.com:luoxiangfan/cpr.git" | ||
| }; | ||
| const exports$1 = { | ||
| ".": { | ||
| "import": { | ||
| types: "./dist/index.d.mts", | ||
| "default": "./dist/index.mjs" | ||
| }, | ||
| require: { | ||
| types: "./dist/index.d.cts", | ||
| "default": "./dist/index.cjs" | ||
| } | ||
| } | ||
| }; | ||
| const files = [ | ||
| "dist" | ||
| ]; | ||
| const scripts = { | ||
| "type-check": "tsc --strict --noEmit", | ||
| format: "prettier --write src/", | ||
| build: "unbuild", | ||
| release: "npm publish" | ||
| }; | ||
| const keywords = [ | ||
| "cp", | ||
| "cp -r", | ||
| "recursive", | ||
| "copy" | ||
| ]; | ||
| const devDependencies = { | ||
| "@types/node": "^22.9.3", | ||
| prettier: "^3.3.3", | ||
| typescript: "^5.7.2", | ||
| unbuild: "^2.0.0" | ||
| }; | ||
| const dependencies = { | ||
| "mkdir-sync-recursive": "^1.0.2" | ||
| }; | ||
| const packageConfig = { | ||
| name: name$1, | ||
| version: version$1, | ||
| author: author, | ||
| license: license, | ||
| description: description, | ||
| type: type, | ||
| bin: bin, | ||
| main: main$1, | ||
| module: module$1, | ||
| types: types, | ||
| repository: repository, | ||
| exports: exports$1, | ||
| files: files, | ||
| scripts: scripts, | ||
| keywords: keywords, | ||
| devDependencies: devDependencies, | ||
| dependencies: dependencies | ||
| }; | ||
| const { name, version } = packageConfig; | ||
| const { name, version } = index.packageConfig; | ||
| const help = `${name} | ||
@@ -95,4 +25,4 @@ Usage: ${name} [OPTION]... SOURCE... DIRECTORY | ||
| -v --version output version information and exit | ||
| --mkdirp make dest directory recursively if it not exist | ||
| `; | ||
| let srcPaths = []; | ||
| let destPath = ""; | ||
@@ -105,2 +35,4 @@ const main = async (...args2) => { | ||
| let files = []; | ||
| let sources = []; | ||
| let mkdirp = false; | ||
| if (!_args.length || _args.length === 1 && idx > -1) { | ||
@@ -119,5 +51,7 @@ console.error(`${name}: missing file operand`); | ||
| destPath = files.slice(-1)[0]; | ||
| const sources = files.slice(0, -1); | ||
| const invalidPaths = sources.filter((f) => !index.isFile(f) && !index.isDirectory(f)); | ||
| const lastInvalidIndex = invalidPaths.length - 1; | ||
| sources = files.slice(0, -1); | ||
| if (files.length === 1) { | ||
| sources = files; | ||
| destPath = ""; | ||
| } | ||
| if (options.length) { | ||
@@ -132,2 +66,4 @@ const arg = options[0]; | ||
| return 0; | ||
| } else if (arg === "--mkdirp") { | ||
| mkdirp = true; | ||
| } | ||
@@ -138,44 +74,3 @@ } else { | ||
| } | ||
| } else if (files.length === 1) { | ||
| console.error( | ||
| `${name}: missing destination file operand after '${files[0]}'` | ||
| ); | ||
| index.exit(name); | ||
| } else if (files.length === 2) { | ||
| if (sources.length === 1) { | ||
| const source = sources[0]; | ||
| const sourceExist = index.isPathExist(source); | ||
| if (sourceExist && index.isDirectory(source) && index.isFile(destPath)) { | ||
| console.error( | ||
| `${name}: cannot overwrite non-directory '${destPath}' with directory ${source}'` | ||
| ); | ||
| return 1; | ||
| } | ||
| if (!sourceExist) { | ||
| console.error( | ||
| `${name}: cannot stat '${source}': No such file or directory` | ||
| ); | ||
| return 1; | ||
| } | ||
| } | ||
| } else if (files.length > 2) { | ||
| if (!index.isDirectory(destPath)) { | ||
| console.error(`${name}: target '${destPath}' is not a directory`); | ||
| return 1; | ||
| } else { | ||
| invalidPaths.forEach((f, idx2) => { | ||
| if (!index.isFile(f) && !index.isDirectory(f)) { | ||
| console.error( | ||
| `${name}: cannot stat '${f}': No such file or directory` | ||
| ); | ||
| if (idx2 === lastInvalidIndex) { | ||
| return 1; | ||
| } | ||
| } | ||
| }); | ||
| } | ||
| } | ||
| if (sources.every((s) => index.isFile(s) || index.isDirectory(s))) { | ||
| srcPaths = sources; | ||
| } | ||
| const rl = readline.createInterface({ | ||
@@ -185,6 +80,6 @@ input: process.stdin, | ||
| }); | ||
| if (srcPaths.length === 1) { | ||
| index.cpr(srcPaths[0], destPath); | ||
| if (sources.length === 1) { | ||
| index.cpr(sources[0], destPath); | ||
| } else { | ||
| index.cpr(srcPaths, destPath); | ||
| index.cpr(sources, destPath, mkdirp); | ||
| } | ||
@@ -191,0 +86,0 @@ rl.close(); |
+1
-1
| declare const help: string; | ||
| declare const main: { | ||
| (...args: string[]): Promise<0 | 1>; | ||
| (...args: string[]): Promise<number>; | ||
| help: string; | ||
@@ -5,0 +5,0 @@ version: string; |
+1
-1
| declare const help: string; | ||
| declare const main: { | ||
| (...args: string[]): Promise<0 | 1>; | ||
| (...args: string[]): Promise<number>; | ||
| help: string; | ||
@@ -5,0 +5,0 @@ version: string; |
+1
-1
| declare const help: string; | ||
| declare const main: { | ||
| (...args: string[]): Promise<0 | 1>; | ||
| (...args: string[]): Promise<number>; | ||
| help: string; | ||
@@ -5,0 +5,0 @@ version: string; |
+15
-120
| #!/usr/bin/env node | ||
| import { createInterface } from 'readline'; | ||
| import { e as exit, i as isFile, a as isDirectory, b as isPathExist, c as cpr } from './shared/node-cpr.d8ffe622.mjs'; | ||
| import { e as exit, c as cpr, p as packageConfig } from './shared/node-cpr.d7939413.mjs'; | ||
| import 'fs'; | ||
@@ -8,74 +8,4 @@ import 'path'; | ||
| const validArgs = ["-h", "-v", "--help", "--version"]; | ||
| const validArgs = ["-h", "-v", "--help", "--version", "--mkdirp"]; | ||
| const name$1 = "node-cpr"; | ||
| const version$1 = "1.1.1"; | ||
| const author = "lxf <infiniment@163.com>"; | ||
| const license = "MIT"; | ||
| const description = "The cp -r command implementation for node."; | ||
| const type = "module"; | ||
| const bin = "./dist/bin.mjs"; | ||
| const main$1 = "./dist/index.cjs"; | ||
| const module = "./dist/index.mjs"; | ||
| const types = "./dist/index.d.cts"; | ||
| const repository = { | ||
| type: "git", | ||
| url: "git+git@github.com:luoxiangfan/cpr.git" | ||
| }; | ||
| const exports = { | ||
| ".": { | ||
| "import": { | ||
| types: "./dist/index.d.mts", | ||
| "default": "./dist/index.mjs" | ||
| }, | ||
| require: { | ||
| types: "./dist/index.d.cts", | ||
| "default": "./dist/index.cjs" | ||
| } | ||
| } | ||
| }; | ||
| const files = [ | ||
| "dist" | ||
| ]; | ||
| const scripts = { | ||
| "type-check": "tsc --strict --noEmit", | ||
| format: "prettier --write src/", | ||
| build: "unbuild", | ||
| release: "npm publish" | ||
| }; | ||
| const keywords = [ | ||
| "cp", | ||
| "cp -r", | ||
| "recursive", | ||
| "copy" | ||
| ]; | ||
| const devDependencies = { | ||
| "@types/node": "^22.9.3", | ||
| prettier: "^3.3.3", | ||
| typescript: "^5.7.2", | ||
| unbuild: "^2.0.0" | ||
| }; | ||
| const dependencies = { | ||
| "mkdir-sync-recursive": "^1.0.2" | ||
| }; | ||
| const packageConfig = { | ||
| name: name$1, | ||
| version: version$1, | ||
| author: author, | ||
| license: license, | ||
| description: description, | ||
| type: type, | ||
| bin: bin, | ||
| main: main$1, | ||
| module: module, | ||
| types: types, | ||
| repository: repository, | ||
| exports: exports, | ||
| files: files, | ||
| scripts: scripts, | ||
| keywords: keywords, | ||
| devDependencies: devDependencies, | ||
| dependencies: dependencies | ||
| }; | ||
| const { name, version } = packageConfig; | ||
@@ -90,4 +20,4 @@ const help = `${name} | ||
| -v --version output version information and exit | ||
| --mkdirp make dest directory recursively if it not exist | ||
| `; | ||
| let srcPaths = []; | ||
| let destPath = ""; | ||
@@ -100,2 +30,4 @@ const main = async (...args2) => { | ||
| let files = []; | ||
| let sources = []; | ||
| let mkdirp = false; | ||
| if (!_args.length || _args.length === 1 && idx > -1) { | ||
@@ -114,5 +46,7 @@ console.error(`${name}: missing file operand`); | ||
| destPath = files.slice(-1)[0]; | ||
| const sources = files.slice(0, -1); | ||
| const invalidPaths = sources.filter((f) => !isFile(f) && !isDirectory(f)); | ||
| const lastInvalidIndex = invalidPaths.length - 1; | ||
| sources = files.slice(0, -1); | ||
| if (files.length === 1) { | ||
| sources = files; | ||
| destPath = ""; | ||
| } | ||
| if (options.length) { | ||
@@ -127,2 +61,4 @@ const arg = options[0]; | ||
| return 0; | ||
| } else if (arg === "--mkdirp") { | ||
| mkdirp = true; | ||
| } | ||
@@ -133,44 +69,3 @@ } else { | ||
| } | ||
| } else if (files.length === 1) { | ||
| console.error( | ||
| `${name}: missing destination file operand after '${files[0]}'` | ||
| ); | ||
| exit(name); | ||
| } else if (files.length === 2) { | ||
| if (sources.length === 1) { | ||
| const source = sources[0]; | ||
| const sourceExist = isPathExist(source); | ||
| if (sourceExist && isDirectory(source) && isFile(destPath)) { | ||
| console.error( | ||
| `${name}: cannot overwrite non-directory '${destPath}' with directory ${source}'` | ||
| ); | ||
| return 1; | ||
| } | ||
| if (!sourceExist) { | ||
| console.error( | ||
| `${name}: cannot stat '${source}': No such file or directory` | ||
| ); | ||
| return 1; | ||
| } | ||
| } | ||
| } else if (files.length > 2) { | ||
| if (!isDirectory(destPath)) { | ||
| console.error(`${name}: target '${destPath}' is not a directory`); | ||
| return 1; | ||
| } else { | ||
| invalidPaths.forEach((f, idx2) => { | ||
| if (!isFile(f) && !isDirectory(f)) { | ||
| console.error( | ||
| `${name}: cannot stat '${f}': No such file or directory` | ||
| ); | ||
| if (idx2 === lastInvalidIndex) { | ||
| return 1; | ||
| } | ||
| } | ||
| }); | ||
| } | ||
| } | ||
| if (sources.every((s) => isFile(s) || isDirectory(s))) { | ||
| srcPaths = sources; | ||
| } | ||
| const rl = createInterface({ | ||
@@ -180,6 +75,6 @@ input: process.stdin, | ||
| }); | ||
| if (srcPaths.length === 1) { | ||
| cpr(srcPaths[0], destPath); | ||
| if (sources.length === 1) { | ||
| cpr(sources[0], destPath); | ||
| } else { | ||
| cpr(srcPaths, destPath); | ||
| cpr(sources, destPath, mkdirp); | ||
| } | ||
@@ -186,0 +81,0 @@ rl.close(); |
+1
-1
@@ -5,3 +5,3 @@ 'use strict'; | ||
| require('path'); | ||
| const index = require('./shared/node-cpr.fc34dab9.cjs'); | ||
| const index = require('./shared/node-cpr.a266359a.cjs'); | ||
| require('mkdir-sync-recursive'); | ||
@@ -8,0 +8,0 @@ |
+1
-1
@@ -1,3 +0,3 @@ | ||
| declare function cpr(source: string | string[], dest: string): void; | ||
| declare function cpr(source: string | string[], dest: string, mkdirp?: boolean): void; | ||
| export { cpr }; |
+1
-1
@@ -1,3 +0,3 @@ | ||
| declare function cpr(source: string | string[], dest: string): void; | ||
| declare function cpr(source: string | string[], dest: string, mkdirp?: boolean): void; | ||
| export { cpr }; |
+1
-1
@@ -1,3 +0,3 @@ | ||
| declare function cpr(source: string | string[], dest: string): void; | ||
| declare function cpr(source: string | string[], dest: string, mkdirp?: boolean): void; | ||
| export { cpr }; |
+1
-1
| import 'fs'; | ||
| import 'path'; | ||
| export { c as cpr } from './shared/node-cpr.d8ffe622.mjs'; | ||
| export { c as cpr } from './shared/node-cpr.d7939413.mjs'; | ||
| import 'mkdir-sync-recursive'; |
+3
-3
| { | ||
| "name": "node-cpr", | ||
| "version": "1.1.1", | ||
| "version": "1.2.0", | ||
| "author": "lxf <infiniment@163.com>", | ||
@@ -44,4 +44,4 @@ "license": "MIT", | ||
| "devDependencies": { | ||
| "@types/node": "^22.9.3", | ||
| "prettier": "^3.3.3", | ||
| "@types/node": "^22.10.0", | ||
| "prettier": "^3.4.1", | ||
| "typescript": "^5.7.2", | ||
@@ -48,0 +48,0 @@ "unbuild": "^2.0.0" |
| import fs from 'fs'; | ||
| import path from 'path'; | ||
| import mkdirSyncRecursive from 'mkdir-sync-recursive'; | ||
| function exit(name) { | ||
| console.error(`Try \`${name} --help\` for more information`); | ||
| return 1; | ||
| } | ||
| function isFile(filePath) { | ||
| try { | ||
| const stat = fs.statSync(path.resolve(filePath)); | ||
| return stat.isFile(); | ||
| } catch (error) { | ||
| return false; | ||
| } | ||
| } | ||
| function isDirectory(filePath) { | ||
| try { | ||
| const stat = fs.statSync(path.resolve(filePath)); | ||
| return stat.isDirectory(); | ||
| } catch (error) { | ||
| return false; | ||
| } | ||
| } | ||
| function isPathExist(filePath) { | ||
| try { | ||
| return fs.existsSync(filePath); | ||
| } catch (error) { | ||
| return false; | ||
| } | ||
| } | ||
| const isArray = Array.isArray; | ||
| function copyFile(src, dest) { | ||
| let destPath = dest; | ||
| if (isDirectory(dest)) { | ||
| if (isFile(src)) { | ||
| destPath = dest + "/" + path.basename(src); | ||
| } else { | ||
| destPath = dest + "/" + src; | ||
| } | ||
| } | ||
| fs.copyFileSync(src, destPath); | ||
| } | ||
| function copyDir(src, dest) { | ||
| mkdirSyncRecursive(dest); | ||
| try { | ||
| const files = fs.readdirSync(src, { encoding: "utf-8" }); | ||
| for (const file of files) { | ||
| let srcPath = path.join(src, file); | ||
| let destPath = path.join(dest, file); | ||
| if (isDirectory(srcPath)) { | ||
| copyDir(srcPath, destPath); | ||
| } | ||
| if (isFile(srcPath)) { | ||
| copyFile(srcPath, destPath); | ||
| } | ||
| } | ||
| } catch (err) { | ||
| console.error(err); | ||
| } | ||
| } | ||
| function cpr(source, dest) { | ||
| if (isArray(source)) { | ||
| source.forEach((s) => { | ||
| if (isFile(s)) { | ||
| copyFile(s, dest); | ||
| } | ||
| if (isDirectory(s)) { | ||
| if (isPathExist(dest)) { | ||
| copyDir(s, dest + "/" + s); | ||
| } else { | ||
| copyDir(s, dest); | ||
| } | ||
| } | ||
| }); | ||
| } else { | ||
| if (isDirectory(source)) { | ||
| if (isPathExist(dest)) { | ||
| copyDir(source, dest + "/" + source); | ||
| } else { | ||
| copyDir(source, dest); | ||
| } | ||
| } else { | ||
| copyFile(source, dest); | ||
| } | ||
| } | ||
| } | ||
| export { isDirectory as a, isPathExist as b, cpr as c, exit as e, isFile as i }; |
| 'use strict'; | ||
| const fs = require('fs'); | ||
| const path = require('path'); | ||
| const mkdirSyncRecursive = require('mkdir-sync-recursive'); | ||
| function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; } | ||
| const fs__default = /*#__PURE__*/_interopDefaultCompat(fs); | ||
| const path__default = /*#__PURE__*/_interopDefaultCompat(path); | ||
| const mkdirSyncRecursive__default = /*#__PURE__*/_interopDefaultCompat(mkdirSyncRecursive); | ||
| function exit(name) { | ||
| console.error(`Try \`${name} --help\` for more information`); | ||
| return 1; | ||
| } | ||
| function isFile(filePath) { | ||
| try { | ||
| const stat = fs__default.statSync(path__default.resolve(filePath)); | ||
| return stat.isFile(); | ||
| } catch (error) { | ||
| return false; | ||
| } | ||
| } | ||
| function isDirectory(filePath) { | ||
| try { | ||
| const stat = fs__default.statSync(path__default.resolve(filePath)); | ||
| return stat.isDirectory(); | ||
| } catch (error) { | ||
| return false; | ||
| } | ||
| } | ||
| function isPathExist(filePath) { | ||
| try { | ||
| return fs__default.existsSync(filePath); | ||
| } catch (error) { | ||
| return false; | ||
| } | ||
| } | ||
| const isArray = Array.isArray; | ||
| function copyFile(src, dest) { | ||
| let destPath = dest; | ||
| if (isDirectory(dest)) { | ||
| if (isFile(src)) { | ||
| destPath = dest + "/" + path__default.basename(src); | ||
| } else { | ||
| destPath = dest + "/" + src; | ||
| } | ||
| } | ||
| fs__default.copyFileSync(src, destPath); | ||
| } | ||
| function copyDir(src, dest) { | ||
| mkdirSyncRecursive__default(dest); | ||
| try { | ||
| const files = fs__default.readdirSync(src, { encoding: "utf-8" }); | ||
| for (const file of files) { | ||
| let srcPath = path__default.join(src, file); | ||
| let destPath = path__default.join(dest, file); | ||
| if (isDirectory(srcPath)) { | ||
| copyDir(srcPath, destPath); | ||
| } | ||
| if (isFile(srcPath)) { | ||
| copyFile(srcPath, destPath); | ||
| } | ||
| } | ||
| } catch (err) { | ||
| console.error(err); | ||
| } | ||
| } | ||
| function cpr(source, dest) { | ||
| if (isArray(source)) { | ||
| source.forEach((s) => { | ||
| if (isFile(s)) { | ||
| copyFile(s, dest); | ||
| } | ||
| if (isDirectory(s)) { | ||
| if (isPathExist(dest)) { | ||
| copyDir(s, dest + "/" + s); | ||
| } else { | ||
| copyDir(s, dest); | ||
| } | ||
| } | ||
| }); | ||
| } else { | ||
| if (isDirectory(source)) { | ||
| if (isPathExist(dest)) { | ||
| copyDir(source, dest + "/" + source); | ||
| } else { | ||
| copyDir(source, dest); | ||
| } | ||
| } else { | ||
| copyFile(source, dest); | ||
| } | ||
| } | ||
| } | ||
| exports.cpr = cpr; | ||
| exports.exit = exit; | ||
| exports.isDirectory = isDirectory; | ||
| exports.isFile = isFile; | ||
| exports.isPathExist = isPathExist; |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
18995
2.23%603
3.79%