@zwa73/dev-utils 1.0.15 → 1.0.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/Command/MapPath.js
CHANGED
@@ -19,6 +19,7 @@ const CmdMapPath = (program) => program
|
|
19
19
|
.option("-do, --duplicate-output <dir>", "移动重命名的重名文件的目录", "Duplicates")
|
20
20
|
.option("-r, --recursive", "是否处理子目录", false)
|
21
21
|
.option("-c, --copy", "复制而不是重命名文件", false)
|
22
|
+
.option("-t, --test", "不对文件进行实际操作, 在控制台输出映射结果", false)
|
22
23
|
.action(async (regexStr, replacement, options) => {
|
23
24
|
const regex = new RegExp(regexStr);
|
24
25
|
const excludeRegex = options.exclude ? new RegExp(options.exclude) : null;
|
@@ -27,13 +28,15 @@ const CmdMapPath = (program) => program
|
|
27
28
|
const duplicateHandling = options.duplicateHandling;
|
28
29
|
const basePath = process.cwd();
|
29
30
|
// 遍历当前目录下的所有文件
|
30
|
-
const filePaths = utils_1.UtilFT.fileSearchRegex(basePath, regex.source, { relative: options.recursive })
|
31
|
+
const filePaths = utils_1.UtilFT.fileSearchRegex(basePath, regex.source, { relative: options.recursive, normalize: "posix" })
|
31
32
|
.map((filePath) => path_1.default.relative(basePath, filePath))
|
32
33
|
.filter((filePath) => excludeRegex ? (!excludeRegex.test(filePath)) : true);
|
33
34
|
//对单个路径映射
|
34
35
|
const mapPath = async (source, target) => {
|
35
36
|
const dir = path_1.default.parse(target).dir;
|
36
37
|
await utils_1.UtilFT.ensurePathExists(dir, { dir: true });
|
38
|
+
if (options.test)
|
39
|
+
return utils_1.SLogger.info(`${source} -> ${target}`);
|
37
40
|
if (options.copy)
|
38
41
|
await fs_1.default.promises.copyFile(source, target);
|
39
42
|
else
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@zwa73/dev-utils",
|
3
|
-
"version": "1.0.
|
3
|
+
"version": "1.0.17",
|
4
4
|
"description": "编译与调试工具",
|
5
5
|
"main": "index.js",
|
6
6
|
"scripts": {
|
@@ -15,7 +15,7 @@
|
|
15
15
|
"author": "zwa73",
|
16
16
|
"license": "ISC",
|
17
17
|
"dependencies": {
|
18
|
-
"@zwa73/utils": "^1.0.
|
18
|
+
"@zwa73/utils": "^1.0.109",
|
19
19
|
"commander": "^11.1.0",
|
20
20
|
"ts-node": "^10.9.2",
|
21
21
|
"tsconfig-paths": "^4.2.0",
|
package/src/Command/MapPath.ts
CHANGED
@@ -17,6 +17,7 @@ export const CmdMapPath = (program: Command) => program
|
|
17
17
|
.option("-do, --duplicate-output <dir>", "移动重命名的重名文件的目录", "Duplicates")
|
18
18
|
.option("-r, --recursive", "是否处理子目录", false)
|
19
19
|
.option("-c, --copy", "复制而不是重命名文件", false)
|
20
|
+
.option("-t, --test", "不对文件进行实际操作, 在控制台输出映射结果", false)
|
20
21
|
.action(async (regexStr, replacement, options) => {
|
21
22
|
const regex = new RegExp(regexStr);
|
22
23
|
const excludeRegex = options.exclude ? new RegExp(options.exclude) : null;
|
@@ -25,7 +26,7 @@ export const CmdMapPath = (program: Command) => program
|
|
25
26
|
const duplicateHandling = options.duplicateHandling as DupMethod;
|
26
27
|
const basePath = process.cwd();
|
27
28
|
// 遍历当前目录下的所有文件
|
28
|
-
const filePaths = UtilFT.fileSearchRegex(basePath, regex.source,{relative:options.recursive})
|
29
|
+
const filePaths = UtilFT.fileSearchRegex(basePath, regex.source,{relative:options.recursive,normalize:"posix"})
|
29
30
|
.map((filePath)=>path.relative(basePath, filePath))
|
30
31
|
.filter((filePath)=>excludeRegex ? (!excludeRegex.test(filePath)) : true);
|
31
32
|
|
@@ -33,6 +34,7 @@ export const CmdMapPath = (program: Command) => program
|
|
33
34
|
const mapPath = async (source:string,target:string)=>{
|
34
35
|
const dir = path.parse(target).dir;
|
35
36
|
await UtilFT.ensurePathExists(dir,{dir:true});
|
37
|
+
if(options.test) return SLogger.info(`${source} -> ${target}`);
|
36
38
|
if (options.copy)
|
37
39
|
await fs.promises.copyFile(source, target);
|
38
40
|
else
|