@zwa73/dev-utils 1.0.44 → 1.0.46
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/Init.js +6 -3
- package/dist/Command/MapPath.js +5 -5
- package/dist/Command/Node.js +1 -1
- package/dist/Command/Release.js +2 -2
- package/dist/Command/RouteInterface.js +5 -25
- package/dist/Command/ScanDups.js +3 -3
- package/dist/UtilDevTool.js +15 -12
- package/dist/UtilMacro.js +6 -6
- package/package.json +3 -2
- package/src/Command/Init.ts +1 -1
- package/src/Command/MapPath.ts +5 -5
- package/src/Command/Node.ts +1 -1
- package/src/Command/Release.ts +1 -1
- package/src/Command/RouteInterface.ts +1 -1
- package/src/Command/ScanDups.ts +3 -3
- package/src/UtilDevTool.ts +9 -9
- package/src/UtilMacro.ts +5 -5
package/dist/Command/Init.js
CHANGED
@@ -22,10 +22,13 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
22
22
|
__setModuleDefault(result, mod);
|
23
23
|
return result;
|
24
24
|
};
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
27
|
+
};
|
25
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
26
29
|
exports.CmdInit = void 0;
|
27
30
|
const fs = __importStar(require("fs"));
|
28
|
-
const
|
31
|
+
const pathe_1 = __importDefault(require("pathe"));
|
29
32
|
const utils_1 = require("@zwa73/utils");
|
30
33
|
const RouteInterface_1 = require("./RouteInterface");
|
31
34
|
/**复制基础文件 */
|
@@ -33,8 +36,8 @@ async function copyData() {
|
|
33
36
|
const filelist = await fs.promises.readdir(RouteInterface_1.DATA_PATH);
|
34
37
|
const plist = filelist.map(async (fileName) => {
|
35
38
|
utils_1.SLogger.info(`正在复制 ${fileName}`);
|
36
|
-
const filePath =
|
37
|
-
const targetPath =
|
39
|
+
const filePath = pathe_1.default.join(RouteInterface_1.DATA_PATH, fileName);
|
40
|
+
const targetPath = pathe_1.default.join(RouteInterface_1.PROJECT_PATH, fileName);
|
38
41
|
if (!await utils_1.UtilFT.pathExists(targetPath))
|
39
42
|
await fs.promises.cp(filePath, targetPath, { recursive: true });
|
40
43
|
else
|
package/dist/Command/MapPath.js
CHANGED
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.CmdMapPath = void 0;
|
7
7
|
const utils_1 = require("@zwa73/utils");
|
8
8
|
const fs_1 = __importDefault(require("fs"));
|
9
|
-
const
|
9
|
+
const pathe_1 = __importDefault(require("pathe"));
|
10
10
|
const DupMethodList = ["no-rename", "overwrite", "move"];
|
11
11
|
/**重命名文件或路径 */
|
12
12
|
const CmdMapPath = (program) => program
|
@@ -27,14 +27,14 @@ const CmdMapPath = (program) => program
|
|
27
27
|
if (!DupMethodList.includes(options.duplicateHandling))
|
28
28
|
(0, utils_1.throwError)(`${options.duplicateHandling} 不是有效的 duplicate-handling`);
|
29
29
|
const duplicateHandling = options.duplicateHandling;
|
30
|
-
const basePath =
|
30
|
+
const basePath = process.cwd();
|
31
31
|
// 遍历当前目录下的所有文件
|
32
32
|
const filePaths = utils_1.UtilFT.fileSearchRegex(basePath, regex.source, { relative: options.recursive, style: "posix" })
|
33
|
-
.map((filePath) =>
|
33
|
+
.map((filePath) => pathe_1.default.relative(basePath, filePath))
|
34
34
|
.filter((filePath) => excludeRegex ? (!excludeRegex.test(filePath)) : true);
|
35
35
|
//对单个路径映射
|
36
36
|
const mapPath = async (source, target) => {
|
37
|
-
const dir =
|
37
|
+
const dir = pathe_1.default.parse(target).dir;
|
38
38
|
await utils_1.UtilFT.ensurePathExists(dir, { dir: true });
|
39
39
|
if (options.test)
|
40
40
|
return utils_1.SLogger.info(`${source} -> ${target}`);
|
@@ -52,7 +52,7 @@ const CmdMapPath = (program) => program
|
|
52
52
|
//如果文件已存在
|
53
53
|
if (await utils_1.UtilFT.pathExists(newFilePath)) {
|
54
54
|
await (0, utils_1.matchProc)(duplicateHandling, {
|
55
|
-
'move': () => mapPath(filePath,
|
55
|
+
'move': () => mapPath(filePath, pathe_1.default.join(options.duplicateOutput, newFilePath)),
|
56
56
|
'no-rename': () => utils_1.SLogger.info(`重名文件存在,跳过:${newFilePath}`),
|
57
57
|
'overwrite': () => mapPath(filePath, newFilePath),
|
58
58
|
});
|
package/dist/Command/Node.js
CHANGED
@@ -12,7 +12,7 @@ const CmdNode = (program) => program
|
|
12
12
|
utils_1.SLogger.info(`编译并运行: ${arg}`);
|
13
13
|
let cmd = `ts-node -r tsconfig-paths/register ${arg}`;
|
14
14
|
if (opt.project)
|
15
|
-
cmd +=
|
15
|
+
cmd += ` -P ${opt.project}`;
|
16
16
|
await utils_1.UtilFunc.exec(cmd, { outlvl: 'info', errlvl: 'error' });
|
17
17
|
});
|
18
18
|
exports.CmdNode = CmdNode;
|
package/dist/Command/Release.js
CHANGED
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
4
|
};
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
6
|
exports.CmdRelease = void 0;
|
7
|
-
const
|
7
|
+
const pathe_1 = __importDefault(require("pathe"));
|
8
8
|
const utils_1 = require("@zwa73/utils");
|
9
9
|
const RouteInterface_1 = require("./RouteInterface");
|
10
10
|
/**解析版本号为number数组 */
|
@@ -31,7 +31,7 @@ function checkVersion(oldVersion, newVersion) {
|
|
31
31
|
}
|
32
32
|
/**更新版本号 */
|
33
33
|
async function updateVersion(newVersion) {
|
34
|
-
const packagePath =
|
34
|
+
const packagePath = pathe_1.default.join(RouteInterface_1.PROJECT_PATH, "package.json");
|
35
35
|
const packageData = await utils_1.UtilFT.loadJSONFile(packagePath);
|
36
36
|
if (newVersion) {
|
37
37
|
checkVersion(packageData.version, newVersion);
|
@@ -1,37 +1,17 @@
|
|
1
1
|
"use strict";
|
2
|
-
var
|
3
|
-
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
7
|
-
}
|
8
|
-
Object.defineProperty(o, k2, desc);
|
9
|
-
}) : (function(o, m, k, k2) {
|
10
|
-
if (k2 === undefined) k2 = k;
|
11
|
-
o[k2] = m[k];
|
12
|
-
}));
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
15
|
-
}) : function(o, v) {
|
16
|
-
o["default"] = v;
|
17
|
-
});
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
19
|
-
if (mod && mod.__esModule) return mod;
|
20
|
-
var result = {};
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
22
|
-
__setModuleDefault(result, mod);
|
23
|
-
return result;
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
24
4
|
};
|
25
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
26
6
|
exports.checkProject = exports.withOfficialSource = exports.withMirrorSource = exports.parseBoolean = exports.parseNumber = exports.parseInteger = exports.PROJECT_PATH = exports.DATA_PATH = exports.OFFICIAL_SOURCE = exports.MIRROR_SOURCE = void 0;
|
27
|
-
const
|
7
|
+
const pathe_1 = __importDefault(require("pathe"));
|
28
8
|
const utils_1 = require("@zwa73/utils");
|
29
9
|
/**npm镜像源 */
|
30
10
|
exports.MIRROR_SOURCE = "https://registry.npmmirror.com/";
|
31
11
|
/**npm官方源 */
|
32
12
|
exports.OFFICIAL_SOURCE = "https://registry.npmjs.org/";
|
33
13
|
/**data文件夹路径 */
|
34
|
-
exports.DATA_PATH =
|
14
|
+
exports.DATA_PATH = pathe_1.default.join(__dirname, '..', '..', 'data');
|
35
15
|
/**项目路径 */
|
36
16
|
exports.PROJECT_PATH = process.cwd();
|
37
17
|
/** 检测非浮点的整数类型 */
|
@@ -79,7 +59,7 @@ async function withOfficialSource(func) {
|
|
79
59
|
exports.withOfficialSource = withOfficialSource;
|
80
60
|
/**检查目录是否为项目 */
|
81
61
|
async function checkProject() {
|
82
|
-
const filePath =
|
62
|
+
const filePath = pathe_1.default.join(exports.PROJECT_PATH, "package.json");
|
83
63
|
if (!(await utils_1.UtilFT.pathExists(filePath)))
|
84
64
|
(0, utils_1.throwError)(`当前目录: ${exports.PROJECT_PATH} 不是npm项目目录, 请先使用 npm init`);
|
85
65
|
}
|
package/dist/Command/ScanDups.js
CHANGED
@@ -7,7 +7,7 @@ exports.CmdScanDups = void 0;
|
|
7
7
|
const utils_1 = require("@zwa73/utils");
|
8
8
|
const fs_1 = __importDefault(require("fs"));
|
9
9
|
const crypto_1 = __importDefault(require("crypto"));
|
10
|
-
const
|
10
|
+
const pathe_1 = __importDefault(require("pathe"));
|
11
11
|
async function calculateHash(filePath) {
|
12
12
|
return new Promise((resolve, reject) => {
|
13
13
|
const hash = crypto_1.default.createHash('md5');
|
@@ -27,7 +27,7 @@ const CmdScanDups = (program) => program
|
|
27
27
|
.option("-r, --recursive", "是否处理子目录, 默认 true", true)
|
28
28
|
.action(async (options) => {
|
29
29
|
const regex = new RegExp(options.regex);
|
30
|
-
const basePath =
|
30
|
+
const basePath = process.cwd();
|
31
31
|
const pList = utils_1.UtilFT.fileSearchRegex(basePath, regex.source, {
|
32
32
|
relative: options.recursive,
|
33
33
|
style: "posix",
|
@@ -46,6 +46,6 @@ const CmdScanDups = (program) => program
|
|
46
46
|
if (options.out === "console")
|
47
47
|
utils_1.SLogger.info(out);
|
48
48
|
else
|
49
|
-
await utils_1.UtilFT.writeJSONFile(
|
49
|
+
await utils_1.UtilFT.writeJSONFile(pathe_1.default.join(basePath, options.out), out);
|
50
50
|
});
|
51
51
|
exports.CmdScanDups = CmdScanDups;
|
package/dist/UtilDevTool.js
CHANGED
@@ -22,9 +22,12 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
22
22
|
__setModuleDefault(result, mod);
|
23
23
|
return result;
|
24
24
|
};
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
27
|
+
};
|
25
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
26
29
|
exports.UtilDT = void 0;
|
27
|
-
const
|
30
|
+
const pathe_1 = __importDefault(require("pathe"));
|
28
31
|
const TJS = __importStar(require("typescript-json-schema"));
|
29
32
|
const fs = __importStar(require("fs"));
|
30
33
|
const utils_1 = require("@zwa73/utils");
|
@@ -55,8 +58,8 @@ var UtilDT;
|
|
55
58
|
const files = utils_1.UtilFT.fileSearchGlob(dir, opt?.include ?? "**/*.schema.ts", { ingore: opt?.exclude });
|
56
59
|
const program = TJS.getProgramFromFiles(files, compilerOptions);
|
57
60
|
const schema = TJS.generateSchema(program, "*", settings);
|
58
|
-
const outDir = opt?.outDir ??
|
59
|
-
const schemasPath =
|
61
|
+
const outDir = opt?.outDir ?? pathe_1.default.join(process.cwd(), 'schema');
|
62
|
+
const schemasPath = pathe_1.default.join(outDir, 'schemas.json');
|
60
63
|
//进行预处理并展开
|
61
64
|
await expandSchema(schemasPath, schema, opt?.coverDefine ?? {});
|
62
65
|
}
|
@@ -78,8 +81,8 @@ var UtilDT;
|
|
78
81
|
continue;
|
79
82
|
if ((/^.+_[0-9]/).test(typeName) || (/^{./).test(typeName))
|
80
83
|
continue;
|
81
|
-
const basename =
|
82
|
-
const tpath =
|
84
|
+
const basename = pathe_1.default.basename(schemasPath);
|
85
|
+
const tpath = pathe_1.default.join(pathe_1.default.dirname(schemasPath), `${typeName}.schema.json`);
|
83
86
|
if (!utils_1.UtilFT.isValidFilePath(tpath))
|
84
87
|
continue;
|
85
88
|
plist.push(utils_1.UtilFT.writeJSONFile(tpath, {
|
@@ -124,7 +127,7 @@ var UtilDT;
|
|
124
127
|
if (!Array.isArray(filepath))
|
125
128
|
filepath = [filepath];
|
126
129
|
// 将所有的相对路径转换为绝对路径
|
127
|
-
const absolutePaths = filepath.map(fp =>
|
130
|
+
const absolutePaths = filepath.map(fp => pathe_1.default.resolve(process.cwd(), fp));
|
128
131
|
// 创建一个字符串,其中包含所有文件的 require 语句
|
129
132
|
const requires = absolutePaths.map(fp => `require('${fp}')`).join(';');
|
130
133
|
// 创建并执行 ts-node 命令
|
@@ -142,9 +145,9 @@ var UtilDT;
|
|
142
145
|
? opt.glob
|
143
146
|
? utils_1.UtilFT.fileSearchGlob(process.cwd(), opt.filePath, { style: "posix" })
|
144
147
|
: typeof opt?.filePath === "string"
|
145
|
-
? [
|
146
|
-
: opt?.filePath.map((filepath) =>
|
147
|
-
: [
|
148
|
+
? [opt?.filePath]
|
149
|
+
: opt?.filePath.map((filepath) => filepath)
|
150
|
+
: [basePath.replace(/(.+)\.macro\.(js|ts|cjs|mjs)$/, "$1.$2")];
|
148
151
|
};
|
149
152
|
const readFile = async (basePath) => (await fs.promises.readFile(basePath, 'utf-8')).replaceAll("\r\n", "\n");
|
150
153
|
const parseCodeText = async (codeText, opt) => {
|
@@ -205,7 +208,7 @@ var UtilDT;
|
|
205
208
|
else if (!opt?.glob)
|
206
209
|
utils_1.SLogger.error(`UtilDT.regionMacro 无法找到区域 ${regionId}`);
|
207
210
|
};
|
208
|
-
plist.push(utils_1.UtilFunc.queueProc(
|
211
|
+
plist.push(utils_1.UtilFunc.queueProc(pathe_1.default.normalize(filePath), queuefunc));
|
209
212
|
}
|
210
213
|
await Promise.all(plist);
|
211
214
|
}
|
@@ -263,7 +266,7 @@ var UtilDT;
|
|
263
266
|
else if (!opt?.glob)
|
264
267
|
utils_1.SLogger.error(`UtilDT.commentMacro 无法找到注释 ${commentId}`);
|
265
268
|
};
|
266
|
-
plist.push(utils_1.UtilFunc.queueProc(
|
269
|
+
plist.push(utils_1.UtilFunc.queueProc(pathe_1.default.normalize(filePath), queuefunc));
|
267
270
|
}
|
268
271
|
await Promise.all(plist);
|
269
272
|
}
|
@@ -290,7 +293,7 @@ var UtilDT;
|
|
290
293
|
});
|
291
294
|
await fs.promises.writeFile(filePath, parseCode, 'utf-8');
|
292
295
|
};
|
293
|
-
plist.push(utils_1.UtilFunc.queueProc(
|
296
|
+
plist.push(utils_1.UtilFunc.queueProc(pathe_1.default.normalize(filePath), queuefunc));
|
294
297
|
}
|
295
298
|
await Promise.all(plist);
|
296
299
|
}
|
package/dist/UtilMacro.js
CHANGED
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.UtilMacro = void 0;
|
7
7
|
const utils_1 = require("@zwa73/utils");
|
8
8
|
const QuickFunc_1 = require("./QuickFunc");
|
9
|
-
const
|
9
|
+
const pathe_1 = __importDefault(require("pathe"));
|
10
10
|
var UtilMacro;
|
11
11
|
(function (UtilMacro) {
|
12
12
|
/**根据注释批量生成导出
|
@@ -15,11 +15,11 @@ var UtilMacro;
|
|
15
15
|
*/
|
16
16
|
function exportComment(glob) {
|
17
17
|
(0, QuickFunc_1.commentMacro)(/export (\S*)/, ({ filePath, matchId, execArr }) => {
|
18
|
-
const basedir =
|
19
|
-
const result = utils_1.UtilFT.fileSearchGlob(basedir, execArr[1]
|
20
|
-
.map((file) =>
|
21
|
-
.map((file) =>
|
22
|
-
.filter((file) => file !=
|
18
|
+
const basedir = pathe_1.default.dirname(filePath);
|
19
|
+
const result = utils_1.UtilFT.fileSearchGlob(basedir, execArr[1])
|
20
|
+
.map((file) => pathe_1.default.relative(basedir, file))
|
21
|
+
.map((file) => pathe_1.default.parse(file).name)
|
22
|
+
.filter((file) => file != pathe_1.default.parse(filePath).name)
|
23
23
|
.map((file) => `export * from './${file}'`)
|
24
24
|
.join(';');
|
25
25
|
return result.length > 0 ? `${result};` : result;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@zwa73/dev-utils",
|
3
|
-
"version": "1.0.
|
3
|
+
"version": "1.0.46",
|
4
4
|
"description": "编译与调试工具",
|
5
5
|
"main": "index.js",
|
6
6
|
"scripts": {
|
@@ -16,8 +16,9 @@
|
|
16
16
|
"author": "zwa73",
|
17
17
|
"license": "ISC",
|
18
18
|
"dependencies": {
|
19
|
-
"@zwa73/utils": "^1.0.
|
19
|
+
"@zwa73/utils": "^1.0.121",
|
20
20
|
"commander": "^11.1.0",
|
21
|
+
"pathe": "^1.1.2",
|
21
22
|
"ts-node": "^10.9.2",
|
22
23
|
"tsconfig-paths": "^4.2.0",
|
23
24
|
"typescript-json-schema": "^0.63.0"
|
package/src/Command/Init.ts
CHANGED
package/src/Command/MapPath.ts
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
import { SLogger, UtilFT, matchProc,
|
1
|
+
import { SLogger, UtilFT, matchProc, throwError } from "@zwa73/utils";
|
2
2
|
import { Command } from "commander";
|
3
3
|
import fs from "fs";
|
4
|
-
import path from "
|
4
|
+
import path from "pathe";
|
5
5
|
|
6
6
|
const DupMethodList = ["no-rename","overwrite","move"] as const;
|
7
7
|
type DupMethod = typeof DupMethodList[number];
|
@@ -25,10 +25,10 @@ export const CmdMapPath = (program: Command) => program
|
|
25
25
|
if(!DupMethodList.includes(options.duplicateHandling))
|
26
26
|
throwError(`${options.duplicateHandling} 不是有效的 duplicate-handling`);
|
27
27
|
const duplicateHandling = options.duplicateHandling as DupMethod;
|
28
|
-
const basePath =
|
28
|
+
const basePath = process.cwd();
|
29
29
|
// 遍历当前目录下的所有文件
|
30
30
|
const filePaths = UtilFT.fileSearchRegex(basePath, regex.source,{relative:options.recursive,style:"posix"})
|
31
|
-
.map((filePath)=>path.
|
31
|
+
.map((filePath)=>path.relative(basePath, filePath))
|
32
32
|
.filter((filePath)=>excludeRegex ? (!excludeRegex.test(filePath)) : true);
|
33
33
|
|
34
34
|
//对单个路径映射
|
@@ -50,7 +50,7 @@ export const CmdMapPath = (program: Command) => program
|
|
50
50
|
//如果文件已存在
|
51
51
|
if(await UtilFT.pathExists(newFilePath)){
|
52
52
|
await matchProc(duplicateHandling,{
|
53
|
-
'move': ()=> mapPath(filePath, path.
|
53
|
+
'move': ()=> mapPath(filePath, path.join(options.duplicateOutput, newFilePath)),
|
54
54
|
'no-rename': ()=> SLogger.info(`重名文件存在,跳过:${newFilePath}`),
|
55
55
|
'overwrite': ()=> mapPath(filePath,newFilePath),
|
56
56
|
})
|
package/src/Command/Node.ts
CHANGED
@@ -11,6 +11,6 @@ export const CmdNode = (program:Command)=>program
|
|
11
11
|
.action(async (arg, opt) => {
|
12
12
|
SLogger.info(`编译并运行: ${arg}`);
|
13
13
|
let cmd = `ts-node -r tsconfig-paths/register ${arg}`;
|
14
|
-
if(opt.project) cmd
|
14
|
+
if(opt.project) cmd+=` -P ${opt.project}`;
|
15
15
|
await UtilFunc.exec(cmd,{outlvl:'info',errlvl:'error'});
|
16
16
|
});
|
package/src/Command/Release.ts
CHANGED
package/src/Command/ScanDups.ts
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
import { SLogger, UtilFT
|
1
|
+
import { SLogger, UtilFT } from "@zwa73/utils";
|
2
2
|
import { Command } from "commander";
|
3
3
|
import fs from "fs";
|
4
4
|
import crypto from 'crypto';
|
5
|
-
import path from "
|
5
|
+
import path from "pathe";
|
6
6
|
|
7
7
|
async function calculateHash(filePath:string) {
|
8
8
|
return new Promise<string>((resolve, reject) => {
|
@@ -25,7 +25,7 @@ export const CmdScanDups = (program: Command) => program
|
|
25
25
|
.option("-r, --recursive", "是否处理子目录, 默认 true", true)
|
26
26
|
.action(async (options) => {
|
27
27
|
const regex = new RegExp(options.regex);
|
28
|
-
const basePath =
|
28
|
+
const basePath = process.cwd();
|
29
29
|
const pList = UtilFT.fileSearchRegex(basePath, regex.source, {
|
30
30
|
relative: options.recursive,
|
31
31
|
style: "posix",
|
package/src/UtilDevTool.ts
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
import
|
1
|
+
import path from 'pathe';
|
2
2
|
import * as TJS from 'typescript-json-schema';
|
3
3
|
import * as fs from 'fs';
|
4
|
-
import { JObject, SLogger, UtilFT, UtilFunc, dedent,
|
4
|
+
import { JObject, SLogger, UtilFT, UtilFunc, dedent, throwError } from '@zwa73/utils';
|
5
5
|
|
6
6
|
export namespace UtilDT{
|
7
7
|
|
@@ -123,7 +123,7 @@ export async function batchNode(filepath:string|string[],opt?:BatchNodeOpt) {
|
|
123
123
|
// 确保 filepath 总是一个数组
|
124
124
|
if (!Array.isArray(filepath)) filepath = [filepath];
|
125
125
|
// 将所有的相对路径转换为绝对路径
|
126
|
-
const absolutePaths = filepath.map(fp => path.
|
126
|
+
const absolutePaths = filepath.map(fp => path.resolve(process.cwd(), fp));
|
127
127
|
// 创建一个字符串,其中包含所有文件的 require 语句
|
128
128
|
const requires = absolutePaths.map(fp => `require('${fp}')`).join(';');
|
129
129
|
// 创建并执行 ts-node 命令
|
@@ -160,9 +160,9 @@ const parseMacroPaths = (opt?:MacroOpt)=>{
|
|
160
160
|
? opt.glob
|
161
161
|
? UtilFT.fileSearchGlob(process.cwd(),opt.filePath,{style:"posix"})
|
162
162
|
: typeof opt?.filePath==="string"
|
163
|
-
? [
|
164
|
-
: opt?.filePath.map((filepath)=>
|
165
|
-
: [
|
163
|
+
? [opt?.filePath]
|
164
|
+
: opt?.filePath.map((filepath)=>filepath)
|
165
|
+
: [basePath.replace(/(.+)\.macro\.(js|ts|cjs|mjs)$/,"$1.$2")];
|
166
166
|
}
|
167
167
|
const readFile = async (basePath:string)=>
|
168
168
|
(await fs.promises.readFile(basePath,'utf-8')).replaceAll("\r\n","\n");
|
@@ -226,7 +226,7 @@ export async function regionMacro(regionId:string|RegExp,codeText:string|((opt:C
|
|
226
226
|
await fs.promises.writeFile(filePath, fileText, 'utf-8');
|
227
227
|
else if(!opt?.glob) SLogger.error(`UtilDT.regionMacro 无法找到区域 ${regionId}`);
|
228
228
|
}
|
229
|
-
plist.push(UtilFunc.queueProc(path.
|
229
|
+
plist.push(UtilFunc.queueProc(path.normalize(filePath),queuefunc))
|
230
230
|
}
|
231
231
|
await Promise.all(plist);
|
232
232
|
}
|
@@ -284,7 +284,7 @@ export async function commentMacro(commentId:string|RegExp,codeText:string|((opt
|
|
284
284
|
await fs.promises.writeFile(filePath, fileText, 'utf-8');
|
285
285
|
else if(!opt?.glob) SLogger.error(`UtilDT.commentMacro 无法找到注释 ${commentId}`);
|
286
286
|
}
|
287
|
-
plist.push(UtilFunc.queueProc(path.
|
287
|
+
plist.push(UtilFunc.queueProc(path.normalize(filePath),queuefunc))
|
288
288
|
}
|
289
289
|
await Promise.all(plist);
|
290
290
|
}
|
@@ -310,7 +310,7 @@ export async function fileMacro(codeText:string|((opt:Omit<CodeTextOpt,'ident'|'
|
|
310
310
|
});
|
311
311
|
await fs.promises.writeFile(filePath, parseCode, 'utf-8');
|
312
312
|
}
|
313
|
-
plist.push(UtilFunc.queueProc(path.
|
313
|
+
plist.push(UtilFunc.queueProc(path.normalize(filePath),queuefunc))
|
314
314
|
}
|
315
315
|
await Promise.all(plist);
|
316
316
|
}
|
package/src/UtilMacro.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
import { UtilFT
|
1
|
+
import { UtilFT } from "@zwa73/utils";
|
2
2
|
import { commentMacro } from "./QuickFunc"
|
3
|
-
import path from "
|
3
|
+
import path from "pathe";
|
4
4
|
|
5
5
|
|
6
6
|
export namespace UtilMacro{
|
@@ -10,9 +10,9 @@ export namespace UtilMacro{
|
|
10
10
|
*/
|
11
11
|
export function exportComment(glob:string){
|
12
12
|
commentMacro(/export (\S*)/,({filePath,matchId,execArr})=>{
|
13
|
-
const basedir =
|
14
|
-
const result = UtilFT.fileSearchGlob(basedir,execArr[1]
|
15
|
-
.map((file)=>path.
|
13
|
+
const basedir = path.dirname(filePath);
|
14
|
+
const result = UtilFT.fileSearchGlob(basedir,execArr[1])
|
15
|
+
.map((file)=>path.relative(basedir,file))
|
16
16
|
.map((file)=>path.parse(file).name)
|
17
17
|
.filter((file)=>file!=path.parse(filePath).name)
|
18
18
|
.map((file)=>`export * from './${file}'`)
|