+15
-23
@@ -12,27 +12,19 @@ 'use strict'; | ||
| function isFile(path) { | ||
| function type(path) { | ||
| try { | ||
| const stat = node_fs.statSync(path); | ||
| return stat.isFile(); | ||
| } catch (error) { | ||
| return false; | ||
| return stat.isDirectory() ? "dir" : stat.isFile() ? "file" : void 0; | ||
| } catch { | ||
| return void 0; | ||
| } | ||
| } | ||
| function isDirectory(path) { | ||
| try { | ||
| const stat = node_fs.statSync(path); | ||
| return stat.isDirectory(); | ||
| } catch (error) { | ||
| return false; | ||
| } | ||
| } | ||
| function copyDir(source, dest, limit) { | ||
| const list = readdirSyncRecursive__default(source, "relativePath"); | ||
| const files = list.filter((l) => isFile(l)); | ||
| const dirs = list.filter((l) => isDirectory(l)); | ||
| const files = list.filter((l) => type(l) === "file"); | ||
| const dirs = list.filter((l) => type(l) === "dir"); | ||
| for (const dir of dirs) { | ||
| const destPath = dir.replace(source, dest); | ||
| if (!node_fs.existsSync(destPath)) { | ||
| node_fs.mkdirSync(destPath, { recursive: true }); | ||
| copyDir(dir, destPath, void 0); | ||
| const _dest = dir.replace(source, dest); | ||
| if (!node_fs.existsSync(_dest)) { | ||
| node_fs.mkdirSync(_dest, { recursive: true }); | ||
| copyDir(dir, _dest, void 0); | ||
| } | ||
@@ -44,7 +36,7 @@ } | ||
| async__default.eachLimit(files, limit, (file, next) => { | ||
| const destPath = file.replace(source, dest); | ||
| const readStream = node_fs.createReadStream(file); | ||
| const writeStream = node_fs.createWriteStream(destPath); | ||
| readStream.pipe(writeStream); | ||
| writeStream.on("finish", next); | ||
| const _dest = file.replace(source, dest); | ||
| const s = node_fs.createReadStream(file); | ||
| const d = node_fs.createWriteStream(_dest); | ||
| s.pipe(d); | ||
| d.on("finish", next); | ||
| }); | ||
@@ -51,0 +43,0 @@ } |
+15
-23
@@ -5,27 +5,19 @@ import async from 'async'; | ||
| function isFile(path) { | ||
| function type(path) { | ||
| try { | ||
| const stat = statSync(path); | ||
| return stat.isFile(); | ||
| } catch (error) { | ||
| return false; | ||
| return stat.isDirectory() ? "dir" : stat.isFile() ? "file" : void 0; | ||
| } catch { | ||
| return void 0; | ||
| } | ||
| } | ||
| function isDirectory(path) { | ||
| try { | ||
| const stat = statSync(path); | ||
| return stat.isDirectory(); | ||
| } catch (error) { | ||
| return false; | ||
| } | ||
| } | ||
| function copyDir(source, dest, limit) { | ||
| const list = readdirSyncRecursive(source, "relativePath"); | ||
| const files = list.filter((l) => isFile(l)); | ||
| const dirs = list.filter((l) => isDirectory(l)); | ||
| const files = list.filter((l) => type(l) === "file"); | ||
| const dirs = list.filter((l) => type(l) === "dir"); | ||
| for (const dir of dirs) { | ||
| const destPath = dir.replace(source, dest); | ||
| if (!existsSync(destPath)) { | ||
| mkdirSync(destPath, { recursive: true }); | ||
| copyDir(dir, destPath, void 0); | ||
| const _dest = dir.replace(source, dest); | ||
| if (!existsSync(_dest)) { | ||
| mkdirSync(_dest, { recursive: true }); | ||
| copyDir(dir, _dest, void 0); | ||
| } | ||
@@ -37,7 +29,7 @@ } | ||
| async.eachLimit(files, limit, (file, next) => { | ||
| const destPath = file.replace(source, dest); | ||
| const readStream = createReadStream(file); | ||
| const writeStream = createWriteStream(destPath); | ||
| readStream.pipe(writeStream); | ||
| writeStream.on("finish", next); | ||
| const _dest = file.replace(source, dest); | ||
| const s = createReadStream(file); | ||
| const d = createWriteStream(_dest); | ||
| s.pipe(d); | ||
| d.on("finish", next); | ||
| }); | ||
@@ -44,0 +36,0 @@ } |
+5
-5
| { | ||
| "name": "cpr-dir", | ||
| "version": "1.0.2", | ||
| "version": "1.0.3", | ||
| "description": "Copy directory recursively like `cp -r` command", | ||
@@ -28,3 +28,3 @@ "type": "module", | ||
| "build": "unbuild", | ||
| "release": "npm publish" | ||
| "release": "unbuild && npm publish" | ||
| }, | ||
@@ -50,4 +50,4 @@ "repository": { | ||
| "@types/async": "^3.2.24", | ||
| "@types/node": "^22.10.0", | ||
| "prettier": "^3.4.1", | ||
| "@types/node": "^22.10.2", | ||
| "prettier": "^3.4.2", | ||
| "typescript": "^5.7.2", | ||
@@ -57,3 +57,3 @@ "unbuild": "^2.0.0" | ||
| "dependencies": { | ||
| "@lxf2513/readdir-sync-recursive": "^1.1.0", | ||
| "@lxf2513/readdir-sync-recursive": "^1.2.2", | ||
| "async": "^3.2.6" | ||
@@ -60,0 +60,0 @@ }, |
6176
-4.91%80
-16.67%