@zwa73/dev-utils 1.0.28 → 1.0.30
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 +9 -7
- package/package.json +1 -1
- package/src/UtilDevTool.ts +11 -7
package/dist/UtilDevTool.js
CHANGED
@@ -138,7 +138,7 @@ var UtilDT;
|
|
138
138
|
* @param targetPath - 目标文件 默认为去除".macro"的同名文件
|
139
139
|
*/
|
140
140
|
async function $macro(regionId, codeText, targetPath) {
|
141
|
-
const loc =
|
141
|
+
const loc = utils_1.UtilFunc.getFuncLoc(2);
|
142
142
|
if (!loc) {
|
143
143
|
utils_1.SLogger.error(`UtilDT.$macro 未能找到函数位置`);
|
144
144
|
return;
|
@@ -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
@@ -138,7 +138,7 @@ export async function batchNode(filepath:string|string[],opt?:BatchNodeOpt) {
|
|
138
138
|
* @param targetPath - 目标文件 默认为去除".macro"的同名文件
|
139
139
|
*/
|
140
140
|
export async function $macro(regionId:string,codeText:string,targetPath?:string){
|
141
|
-
const loc = getFuncLoc(2);
|
141
|
+
const loc = UtilFunc.getFuncLoc(2);
|
142
142
|
if(!loc){
|
143
143
|
SLogger.error(`UtilDT.$macro 未能找到函数位置`);
|
144
144
|
return
|
@@ -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);
|