@zwa73/dev-utils 1.0.28 → 1.0.29

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.
@@ -153,15 +153,17 @@ var UtilDT;
153
153
  return;
154
154
  }
155
155
  ;
156
- const text = await fs.promises.readFile(baseFilePath, 'utf-8');
157
- const regex = new RegExp(`(//#region ${regionId}\\s*?\\n)([\\s\\S]+?)(//#endregion)`);
158
- //console.log(text)
159
- //console.log(regex)
160
- if (!regex.test(text)) {
156
+ const text = (await fs.promises.readFile(baseFilePath, 'utf-8')).replaceAll("\r\n", "\n");
157
+ const getregex = () => new RegExp(`([^\\S\\n]*)(//#region ${regionId}(?!\\S).*\\n)` +
158
+ /([\s\S]*?)/.source +
159
+ /([^\S\n]*\/\/#endregion(?!\S).*)/.source, "g");
160
+ if (!(getregex().test(text))) {
161
161
  utils_1.SLogger.error(`UtilDT.$macro 无法找到区域 ${regionId}`);
162
162
  return;
163
163
  }
164
- const ntext = text.replace(regex, `$1${codeText}\n$3`);
164
+ const match = getregex().exec(text);
165
+ const mapText = codeText.split('\n').map((line) => `${match[1]}${line}`).join('\n');
166
+ const ntext = text.replace(getregex(), `$1$2${mapText}\n$4`);
165
167
  await fs.promises.writeFile(baseFilePath, ntext, 'utf-8');
166
168
  };
167
169
  await utils_1.UtilFunc.queueProc(path.posix.normalize(baseFilePath.replaceAll("\\", "/")), queuefunc);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zwa73/dev-utils",
3
- "version": "1.0.28",
3
+ "version": "1.0.29",
4
4
  "description": "编译与调试工具",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -151,15 +151,19 @@ export async function $macro(regionId:string,codeText:string,targetPath?:string)
151
151
  SLogger.error(`UtilDT.$macro ${baseFilePath} 不存在`);
152
152
  return
153
153
  };
154
- const text = await fs.promises.readFile(baseFilePath,'utf-8');
155
- const regex = new RegExp(`(//#region ${regionId}\\s*?\\n)([\\s\\S]+?)(//#endregion)`);
156
- //console.log(text)
157
- //console.log(regex)
158
- if (!regex.test(text)) {
154
+ const text = (await fs.promises.readFile(baseFilePath,'utf-8')).replaceAll("\r\n","\n");
155
+ const getregex = ()=>new RegExp(
156
+ `([^\\S\\n]*)(//#region ${regionId}(?!\\S).*\\n)`+
157
+ /([\s\S]*?)/.source+
158
+ /([^\S\n]*\/\/#endregion(?!\S).*)/.source
159
+ ,"g");
160
+ if (!(getregex().test(text))) {
159
161
  SLogger.error(`UtilDT.$macro 无法找到区域 ${regionId}`);
160
162
  return;
161
163
  }
162
- const ntext = text.replace(regex, `$1${codeText}\n$3`);
164
+ const match = getregex().exec(text)!;
165
+ const mapText = codeText.split('\n').map((line)=>`${match[1]}${line}`).join('\n');
166
+ const ntext = text.replace(getregex(), `$1$2${mapText}\n$4`);
163
167
  await fs.promises.writeFile(baseFilePath, ntext, 'utf-8');
164
168
  }
165
169
  await UtilFunc.queueProc(path.posix.normalize(baseFilePath.replaceAll("\\","/")),queuefunc);