@zwa73/dev-utils 1.0.39 → 1.0.41
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.d.ts +3 -1
- package/dist/UtilDevTool.js +9 -1
- package/dist/UtilMacro.js +3 -4
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -1
- package/package.json +1 -1
- package/src/UtilDevTool.ts +12 -2
- package/src/UtilMacro.ts +3 -4
- package/src/index.ts +1 -1
package/dist/UtilDevTool.d.ts
CHANGED
@@ -57,6 +57,8 @@ export declare namespace UtilDT {
|
|
57
57
|
type CodeTextOpt = {
|
58
58
|
/**匹配的region/comment id */
|
59
59
|
matchId: string;
|
60
|
+
/**region/comment id正则的执行结果*/
|
61
|
+
execArr: RegExpExecArray;
|
60
62
|
/**展开宏的目标文件 */
|
61
63
|
filePath: string;
|
62
64
|
/**展开宏区域的原文本 */
|
@@ -86,6 +88,6 @@ export declare namespace UtilDT {
|
|
86
88
|
* @param opt.filePath - 目标文件 默认为去除".macro"的同名文件
|
87
89
|
* @param opt.glob - 使用glob匹配而非文件路径
|
88
90
|
*/
|
89
|
-
export function fileMacro(codeText: string | ((opt: CodeTextOpt) => string | Promise<string>), opt?: MacroOpt): Promise<void>;
|
91
|
+
export function fileMacro(codeText: string | ((opt: Omit<CodeTextOpt, 'ident' | 'matchId' | 'execArr'>) => string | Promise<string>), opt?: MacroOpt): Promise<void>;
|
90
92
|
export {};
|
91
93
|
}
|
package/dist/UtilDevTool.js
CHANGED
@@ -192,6 +192,7 @@ var UtilDT;
|
|
192
192
|
const ol = fileText.length;
|
193
193
|
const parseCode = await parseCodeText(codeText, {
|
194
194
|
matchId: idmatch[0],
|
195
|
+
execArr: idmatch,
|
195
196
|
text: (0, utils_1.dedent)(content),
|
196
197
|
inent,
|
197
198
|
filePath
|
@@ -245,6 +246,7 @@ var UtilDT;
|
|
245
246
|
const ol = fileText.length;
|
246
247
|
const parseCode = await parseCodeText(codeText, {
|
247
248
|
matchId: idmatch[0],
|
249
|
+
execArr: idmatch,
|
248
250
|
text: (0, utils_1.dedent)(content),
|
249
251
|
inent,
|
250
252
|
filePath
|
@@ -279,7 +281,13 @@ var UtilDT;
|
|
279
281
|
const queuefunc = async () => {
|
280
282
|
await utils_1.UtilFT.ensurePathExists(filePath);
|
281
283
|
const text = await readFile(filePath);
|
282
|
-
const parseCode = await parseCodeText(codeText, {
|
284
|
+
const parseCode = await parseCodeText(codeText, {
|
285
|
+
matchId: '',
|
286
|
+
execArr: /''/.exec(''),
|
287
|
+
text,
|
288
|
+
inent: '',
|
289
|
+
filePath
|
290
|
+
});
|
283
291
|
await fs.promises.writeFile(filePath, parseCode, 'utf-8');
|
284
292
|
};
|
285
293
|
plist.push(utils_1.UtilFunc.queueProc(path.posix.normalize(filePath.replaceAll("\\", "/")), queuefunc));
|
package/dist/UtilMacro.js
CHANGED
@@ -14,16 +14,15 @@ var UtilMacro;
|
|
14
14
|
* @example
|
15
15
|
*/
|
16
16
|
function exportComment(glob) {
|
17
|
-
(0, QuickFunc_1.commentMacro)(/export (\S*)/, ({ filePath, matchId }) => {
|
18
|
-
const globp = /export (\S*)/.exec(matchId)[1];
|
17
|
+
(0, QuickFunc_1.commentMacro)(/export (\S*)/, ({ filePath, matchId, execArr }) => {
|
19
18
|
const basedir = path_1.default.dirname(filePath).replaceAll('\\', '/');
|
20
|
-
const result = utils_1.UtilFT.fileSearchGlob(basedir,
|
19
|
+
const result = utils_1.UtilFT.fileSearchGlob(basedir, execArr[1], { normalize: 'posix' })
|
21
20
|
.map((file) => path_1.default.posix.relative(basedir, file))
|
22
21
|
.map((file) => path_1.default.parse(file).name)
|
23
22
|
.filter((file) => file != path_1.default.parse(filePath).name)
|
24
23
|
.map((file) => `export * from './${file}'`)
|
25
24
|
.join(';');
|
26
|
-
return result;
|
25
|
+
return result.length > 0 ? `${result};` : result;
|
27
26
|
}, { glob: true, filePath: glob });
|
28
27
|
}
|
29
28
|
UtilMacro.exportComment = exportComment;
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
@@ -17,4 +17,4 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./UtilDevTool"), exports);
|
18
18
|
__exportStar(require("./Command"), exports);
|
19
19
|
__exportStar(require("./QuickFunc"), exports);
|
20
|
-
|
20
|
+
__exportStar(require("./UtilMacro"), exports);
|
package/package.json
CHANGED
package/src/UtilDevTool.ts
CHANGED
@@ -142,6 +142,8 @@ type MacroOpt = Partial<{
|
|
142
142
|
type CodeTextOpt = {
|
143
143
|
/**匹配的region/comment id */
|
144
144
|
matchId:string;
|
145
|
+
/**region/comment id正则的执行结果*/
|
146
|
+
execArr:RegExpExecArray;
|
145
147
|
/**展开宏的目标文件 */
|
146
148
|
filePath:string;
|
147
149
|
/**展开宏区域的原文本 */
|
@@ -212,6 +214,7 @@ export async function regionMacro(regionId:string|RegExp,codeText:string|((opt:C
|
|
212
214
|
const ol = fileText.length;
|
213
215
|
const parseCode = await parseCodeText(codeText,{
|
214
216
|
matchId :idmatch[0],
|
217
|
+
execArr :idmatch,
|
215
218
|
text :dedent(content),
|
216
219
|
inent ,
|
217
220
|
filePath
|
@@ -265,6 +268,7 @@ export async function commentMacro(commentId:string|RegExp,codeText:string|((opt
|
|
265
268
|
const ol = fileText.length;
|
266
269
|
const parseCode = await parseCodeText(codeText,{
|
267
270
|
matchId :idmatch[0],
|
271
|
+
execArr :idmatch,
|
268
272
|
text :dedent(content),
|
269
273
|
inent ,
|
270
274
|
filePath
|
@@ -290,14 +294,20 @@ export async function commentMacro(commentId:string|RegExp,codeText:string|((opt
|
|
290
294
|
* @param opt.filePath - 目标文件 默认为去除".macro"的同名文件
|
291
295
|
* @param opt.glob - 使用glob匹配而非文件路径
|
292
296
|
*/
|
293
|
-
export async function fileMacro(codeText:string|((opt:CodeTextOpt)=>string|Promise<string>),opt?:MacroOpt){
|
297
|
+
export async function fileMacro(codeText:string|((opt:Omit<CodeTextOpt,'ident'|'matchId'|'execArr'>)=>string|Promise<string>),opt?:MacroOpt){
|
294
298
|
const plist:Promise<void>[] = [];
|
295
299
|
const filePaths = parseMacroPaths(opt);
|
296
300
|
for(const filePath of filePaths){
|
297
301
|
const queuefunc = async ()=>{
|
298
302
|
await UtilFT.ensurePathExists(filePath);
|
299
303
|
const text = await readFile(filePath);
|
300
|
-
const parseCode = await parseCodeText(codeText,{
|
304
|
+
const parseCode = await parseCodeText(codeText,{
|
305
|
+
matchId:'',
|
306
|
+
execArr:/''/.exec('')!,
|
307
|
+
text,
|
308
|
+
inent:'',
|
309
|
+
filePath
|
310
|
+
});
|
301
311
|
await fs.promises.writeFile(filePath, parseCode, 'utf-8');
|
302
312
|
}
|
303
313
|
plist.push(UtilFunc.queueProc(path.posix.normalize(filePath.replaceAll("\\","/")),queuefunc))
|
package/src/UtilMacro.ts
CHANGED
@@ -9,16 +9,15 @@ export namespace UtilMacro{
|
|
9
9
|
* @example
|
10
10
|
*/
|
11
11
|
export function exportComment(glob:string){
|
12
|
-
commentMacro(/export (\S*)/,({filePath,matchId})=>{
|
13
|
-
const globp = /export (\S*)/.exec(matchId)![1];
|
12
|
+
commentMacro(/export (\S*)/,({filePath,matchId,execArr})=>{
|
14
13
|
const basedir = path.dirname(filePath).replaceAll('\\','/');
|
15
|
-
const result = UtilFT.fileSearchGlob(basedir,
|
14
|
+
const result = UtilFT.fileSearchGlob(basedir,execArr[1],{normalize:'posix'})
|
16
15
|
.map((file)=>path.posix.relative(basedir,file))
|
17
16
|
.map((file)=>path.parse(file).name)
|
18
17
|
.filter((file)=>file!=path.parse(filePath).name)
|
19
18
|
.map((file)=>`export * from './${file}'`)
|
20
19
|
.join(';');
|
21
|
-
return result;
|
20
|
+
return result.length>0? `${result};` : result;
|
22
21
|
},{glob:true,filePath:glob});
|
23
22
|
}
|
24
23
|
}
|
package/src/index.ts
CHANGED