@zwa73/dev-utils 1.0.32 → 1.0.34

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.
@@ -51,6 +51,6 @@ export declare namespace UtilDT {
51
51
  * @param codeText - 文本
52
52
  * @param targetPath - 目标文件 默认为去除".macro"的同名文件
53
53
  */
54
- export function $macro(regionId: string, codeText: string, targetPath?: string): Promise<void>;
54
+ export function $macro(regionId: string, codeText: string | (() => string | Promise<string>), targetPath?: string): Promise<void>;
55
55
  export {};
56
56
  }
@@ -162,7 +162,8 @@ var UtilDT;
162
162
  return;
163
163
  }
164
164
  const match = getregex().exec(text);
165
- const mapText = codeText.split('\n').map((line) => `${match[1]}${line}`).join('\n');
165
+ const strText = typeof codeText === "function" ? await codeText() : codeText;
166
+ const mapText = strText.split('\n').map((line) => `${match[1]}${line}`).join('\n');
166
167
  const ntext = text.replace(getregex(), `$1$2${mapText}\n$4`);
167
168
  await fs.promises.writeFile(baseFilePath, ntext, 'utf-8');
168
169
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zwa73/dev-utils",
3
- "version": "1.0.32",
3
+ "version": "1.0.34",
4
4
  "description": "编译与调试工具",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -137,7 +137,7 @@ export async function batchNode(filepath:string|string[],opt?:BatchNodeOpt) {
137
137
  * @param codeText - 文本
138
138
  * @param targetPath - 目标文件 默认为去除".macro"的同名文件
139
139
  */
140
- export async function $macro(regionId:string,codeText:string,targetPath?:string){
140
+ export async function $macro(regionId:string,codeText:string|(()=>string|Promise<string>),targetPath?:string){
141
141
  const loc = UtilFunc.getFuncLoc(2);
142
142
  if(!loc){
143
143
  SLogger.error(`UtilDT.$macro 未能找到函数位置`);
@@ -162,7 +162,8 @@ export async function $macro(regionId:string,codeText:string,targetPath?:string)
162
162
  return;
163
163
  }
164
164
  const match = getregex().exec(text)!;
165
- const mapText = codeText.split('\n').map((line)=>`${match[1]}${line}`).join('\n');
165
+ const strText = typeof codeText === "function" ? await codeText() : codeText;
166
+ const mapText = strText.split('\n').map((line)=>`${match[1]}${line}`).join('\n');
166
167
  const ntext = text.replace(getregex(), `$1$2${mapText}\n$4`);
167
168
  await fs.promises.writeFile(baseFilePath, ntext, 'utf-8');
168
169
  }