@zwa73/dev-utils 1.0.33 → 1.0.35
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/QuickFunc.d.ts +1 -1
- package/dist/QuickFunc.js +2 -2
- package/dist/UtilDevTool.d.ts +8 -2
- package/dist/UtilDevTool.js +11 -9
- package/package.json +1 -1
- package/src/QuickFunc.ts +1 -1
- package/src/UtilDevTool.ts +15 -8
package/dist/QuickFunc.d.ts
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
import { UtilDT } from "./UtilDevTool";
|
2
|
-
export declare const
|
2
|
+
export declare const regionMacro: typeof UtilDT.regionMacro;
|
package/dist/QuickFunc.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports
|
3
|
+
exports.regionMacro = void 0;
|
4
4
|
const UtilDevTool_1 = require("./UtilDevTool");
|
5
|
-
exports
|
5
|
+
exports.regionMacro = UtilDevTool_1.UtilDT.regionMacro;
|
package/dist/UtilDevTool.d.ts
CHANGED
@@ -46,11 +46,17 @@ export declare namespace UtilDT {
|
|
46
46
|
* @param opt.project - tsconfig路径
|
47
47
|
*/
|
48
48
|
export function batchNode(filepath: string | string[], opt?: BatchNodeOpt): Promise<void>;
|
49
|
+
/**宏的可选参数 */
|
50
|
+
type MacroOpt = {
|
51
|
+
/**宏展开的目标文件 */
|
52
|
+
targetPath: string;
|
53
|
+
};
|
49
54
|
/**将codeText写入对应region
|
50
55
|
* @param regionId - 区域id
|
51
56
|
* @param codeText - 文本
|
52
|
-
* @param
|
57
|
+
* @param opt - 可选参数
|
58
|
+
* @param opt.targetPath - 目标文件 默认为去除".macro"的同名文件
|
53
59
|
*/
|
54
|
-
export function
|
60
|
+
export function regionMacro(regionId: string, codeText: string | (() => string | Promise<string>), opt?: MacroOpt): Promise<void>;
|
55
61
|
export {};
|
56
62
|
}
|
package/dist/UtilDevTool.js
CHANGED
@@ -135,21 +135,22 @@ var UtilDT;
|
|
135
135
|
/**将codeText写入对应region
|
136
136
|
* @param regionId - 区域id
|
137
137
|
* @param codeText - 文本
|
138
|
-
* @param
|
138
|
+
* @param opt - 可选参数
|
139
|
+
* @param opt.targetPath - 目标文件 默认为去除".macro"的同名文件
|
139
140
|
*/
|
140
|
-
async function
|
141
|
+
async function regionMacro(regionId, codeText, opt) {
|
141
142
|
const loc = utils_1.UtilFunc.getFuncLoc(2);
|
142
143
|
if (!loc) {
|
143
|
-
utils_1.SLogger.error(`UtilDT
|
144
|
+
utils_1.SLogger.error(`UtilDT.macro 未能找到函数位置`);
|
144
145
|
return;
|
145
146
|
}
|
146
147
|
;
|
147
|
-
const baseFilePath = targetPath
|
148
|
-
? path.resolve(process.cwd(), targetPath)
|
148
|
+
const baseFilePath = opt?.targetPath
|
149
|
+
? path.resolve(process.cwd(), opt.targetPath)
|
149
150
|
: loc.filePath.replace(/(.+)\.macro\.(js|ts|cjs|mjs)$/, "$1.$2");
|
150
151
|
const queuefunc = async () => {
|
151
152
|
if (!(await utils_1.UtilFT.pathExists(baseFilePath))) {
|
152
|
-
utils_1.SLogger.error(`UtilDT
|
153
|
+
utils_1.SLogger.error(`UtilDT.macro ${baseFilePath} 不存在`);
|
153
154
|
return;
|
154
155
|
}
|
155
156
|
;
|
@@ -158,15 +159,16 @@ var UtilDT;
|
|
158
159
|
/([\s\S]*?)/.source +
|
159
160
|
/([^\S\n]*\/\/#endregion(?!\S).*)/.source, "g");
|
160
161
|
if (!(getregex().test(text))) {
|
161
|
-
utils_1.SLogger.error(`UtilDT
|
162
|
+
utils_1.SLogger.error(`UtilDT.macro 无法找到区域 ${regionId}`);
|
162
163
|
return;
|
163
164
|
}
|
164
165
|
const match = getregex().exec(text);
|
165
|
-
const
|
166
|
+
const strText = typeof codeText === "function" ? await codeText() : codeText;
|
167
|
+
const mapText = strText.split('\n').map((line) => `${match[1]}${line}`).join('\n');
|
166
168
|
const ntext = text.replace(getregex(), `$1$2${mapText}\n$4`);
|
167
169
|
await fs.promises.writeFile(baseFilePath, ntext, 'utf-8');
|
168
170
|
};
|
169
171
|
await utils_1.UtilFunc.queueProc(path.posix.normalize(baseFilePath.replaceAll("\\", "/")), queuefunc);
|
170
172
|
}
|
171
|
-
UtilDT
|
173
|
+
UtilDT.regionMacro = regionMacro;
|
172
174
|
})(UtilDT || (exports.UtilDT = UtilDT = {}));
|
package/package.json
CHANGED
package/src/QuickFunc.ts
CHANGED
package/src/UtilDevTool.ts
CHANGED
@@ -131,24 +131,30 @@ export async function batchNode(filepath:string|string[],opt?:BatchNodeOpt) {
|
|
131
131
|
await UtilFunc.exec(cmd, { outlvl: 'info', errlvl: 'warn' });
|
132
132
|
}
|
133
133
|
|
134
|
+
/**宏的可选参数 */
|
135
|
+
type MacroOpt = {
|
136
|
+
/**宏展开的目标文件 */
|
137
|
+
targetPath:string;
|
138
|
+
}
|
134
139
|
|
135
140
|
/**将codeText写入对应region
|
136
141
|
* @param regionId - 区域id
|
137
142
|
* @param codeText - 文本
|
138
|
-
* @param
|
143
|
+
* @param opt - 可选参数
|
144
|
+
* @param opt.targetPath - 目标文件 默认为去除".macro"的同名文件
|
139
145
|
*/
|
140
|
-
export async function
|
146
|
+
export async function regionMacro(regionId:string,codeText:string|(()=>string|Promise<string>),opt?:MacroOpt){
|
141
147
|
const loc = UtilFunc.getFuncLoc(2);
|
142
148
|
if(!loc){
|
143
|
-
SLogger.error(`UtilDT
|
149
|
+
SLogger.error(`UtilDT.macro 未能找到函数位置`);
|
144
150
|
return
|
145
151
|
};
|
146
|
-
const baseFilePath = targetPath
|
147
|
-
? path.resolve(process.cwd(),targetPath)
|
152
|
+
const baseFilePath = opt?.targetPath
|
153
|
+
? path.resolve(process.cwd(),opt.targetPath)
|
148
154
|
: loc.filePath.replace(/(.+)\.macro\.(js|ts|cjs|mjs)$/,"$1.$2");
|
149
155
|
const queuefunc = async ()=>{
|
150
156
|
if(!(await UtilFT.pathExists(baseFilePath))) {
|
151
|
-
SLogger.error(`UtilDT
|
157
|
+
SLogger.error(`UtilDT.macro ${baseFilePath} 不存在`);
|
152
158
|
return
|
153
159
|
};
|
154
160
|
const text = (await fs.promises.readFile(baseFilePath,'utf-8')).replaceAll("\r\n","\n");
|
@@ -158,11 +164,12 @@ export async function $macro(regionId:string,codeText:string,targetPath?:string)
|
|
158
164
|
/([^\S\n]*\/\/#endregion(?!\S).*)/.source
|
159
165
|
,"g");
|
160
166
|
if (!(getregex().test(text))) {
|
161
|
-
SLogger.error(`UtilDT
|
167
|
+
SLogger.error(`UtilDT.macro 无法找到区域 ${regionId}`);
|
162
168
|
return;
|
163
169
|
}
|
164
170
|
const match = getregex().exec(text)!;
|
165
|
-
const
|
171
|
+
const strText = typeof codeText === "function" ? await codeText() : codeText;
|
172
|
+
const mapText = strText.split('\n').map((line)=>`${match[1]}${line}`).join('\n');
|
166
173
|
const ntext = text.replace(getregex(), `$1$2${mapText}\n$4`);
|
167
174
|
await fs.promises.writeFile(baseFilePath, ntext, 'utf-8');
|
168
175
|
}
|