@zwa73/dev-utils 1.0.27 → 1.0.28
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 +18 -15
- package/package.json +1 -1
- package/src/UtilDevTool.ts +20 -16
package/dist/UtilDevTool.js
CHANGED
@@ -147,21 +147,24 @@ var UtilDT;
|
|
147
147
|
const baseFilePath = targetPath
|
148
148
|
? path.resolve(process.cwd(), targetPath)
|
149
149
|
: loc.filePath.replace(/(.+)\.macro\.(js|ts|cjs|mjs)$/, "$1.$2");
|
150
|
-
|
151
|
-
utils_1.
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
150
|
+
const queuefunc = async () => {
|
151
|
+
if (!(await utils_1.UtilFT.pathExists(baseFilePath))) {
|
152
|
+
utils_1.SLogger.error(`UtilDT.$macro ${baseFilePath} 不存在`);
|
153
|
+
return;
|
154
|
+
}
|
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)) {
|
161
|
+
utils_1.SLogger.error(`UtilDT.$macro 无法找到区域 ${regionId}`);
|
162
|
+
return;
|
163
|
+
}
|
164
|
+
const ntext = text.replace(regex, `$1${codeText}\n$3`);
|
165
|
+
await fs.promises.writeFile(baseFilePath, ntext, 'utf-8');
|
166
|
+
};
|
167
|
+
await utils_1.UtilFunc.queueProc(path.posix.normalize(baseFilePath.replaceAll("\\", "/")), queuefunc);
|
165
168
|
}
|
166
169
|
UtilDT.$macro = $macro;
|
167
170
|
})(UtilDT || (exports.UtilDT = UtilDT = {}));
|
package/package.json
CHANGED
package/src/UtilDevTool.ts
CHANGED
@@ -56,16 +56,16 @@ export async function buildSchema(dir:string,opt?:BuildSchemaOpt){
|
|
56
56
|
files,
|
57
57
|
compilerOptions,
|
58
58
|
);
|
59
|
-
const schema = TJS.generateSchema(program, "*", settings) as
|
59
|
+
const schema = TJS.generateSchema(program, "*", settings) as JObject;
|
60
60
|
const outDir = opt?.outDir ?? path.join(process.cwd(),'schema');
|
61
61
|
const schemasPath = path.join(outDir,'schemas.json');
|
62
62
|
//进行预处理并展开
|
63
63
|
await expandSchema(schemasPath,schema,opt?.coverDefine??{});
|
64
64
|
}
|
65
65
|
/**展开schema以供使用 */
|
66
|
-
async function expandSchema(schemasPath:string,schema:
|
66
|
+
async function expandSchema(schemasPath:string,schema:JObject,coverDefine:JObject){
|
67
67
|
//覆盖
|
68
|
-
coverObj(schema["definitions"],coverDefine);
|
68
|
+
coverObj(schema["definitions"] as JObject,coverDefine);
|
69
69
|
//替换SchemaString标识符
|
70
70
|
schema = JSON.parse(JSON.stringify(schema).replace(/\^\.\*SchemaString\$/g,'^.*$'));
|
71
71
|
const plist:Promise<void>[] = [];
|
@@ -131,6 +131,7 @@ export async function batchNode(filepath:string|string[],opt?:BatchNodeOpt) {
|
|
131
131
|
await UtilFunc.exec(cmd, { outlvl: 'info', errlvl: 'warn' });
|
132
132
|
}
|
133
133
|
|
134
|
+
|
134
135
|
/**将codeText写入对应region
|
135
136
|
* @param regionId - 区域id
|
136
137
|
* @param codeText - 文本
|
@@ -145,19 +146,22 @@ export async function $macro(regionId:string,codeText:string,targetPath?:string)
|
|
145
146
|
const baseFilePath = targetPath
|
146
147
|
? path.resolve(process.cwd(),targetPath)
|
147
148
|
: loc.filePath.replace(/(.+)\.macro\.(js|ts|cjs|mjs)$/,"$1.$2");
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
149
|
+
const queuefunc = async ()=>{
|
150
|
+
if(!(await UtilFT.pathExists(baseFilePath))) {
|
151
|
+
SLogger.error(`UtilDT.$macro ${baseFilePath} 不存在`);
|
152
|
+
return
|
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)) {
|
159
|
+
SLogger.error(`UtilDT.$macro 无法找到区域 ${regionId}`);
|
160
|
+
return;
|
161
|
+
}
|
162
|
+
const ntext = text.replace(regex, `$1${codeText}\n$3`);
|
163
|
+
await fs.promises.writeFile(baseFilePath, ntext, 'utf-8');
|
159
164
|
}
|
160
|
-
|
161
|
-
await fs.promises.writeFile(baseFilePath, ntext, 'utf-8');
|
165
|
+
await UtilFunc.queueProc(path.posix.normalize(baseFilePath.replaceAll("\\","/")),queuefunc);
|
162
166
|
}
|
163
167
|
}
|