@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.
- package/dist/UtilDevTool.js +8 -6
- package/package.json +1 -1
- package/src/UtilDevTool.ts +10 -6
package/dist/UtilDevTool.js
CHANGED
@@ -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
|
158
|
-
|
159
|
-
|
160
|
-
if (!
|
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
|
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
package/src/UtilDevTool.ts
CHANGED
@@ -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
|
156
|
-
|
157
|
-
|
158
|
-
|
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
|
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);
|