Skip to content

Commit ad4fac0

Browse files
committed
fix(cli): refactor file rendering to use async/await for better readability
Closes: #536
1 parent 3c06ad1 commit ad4fac0

File tree

2 files changed

+27
-25
lines changed

2 files changed

+27
-25
lines changed

packages/cli/src/commands/init/InitCmd.ts

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ export class InitCmd implements CommandProvider {
332332
const runtime = runtimes.get();
333333

334334
// files with higher priority
335-
const promises = [
335+
const files = [
336336
"tsconfig.base.json",
337337
"tsconfig.json",
338338
"tsconfig.spec.json",
@@ -354,11 +354,13 @@ export class InitCmd implements CommandProvider {
354354
`pm2.${pm2}`,
355355
"/views/home.ejs",
356356
...runtime.files()
357-
].map((id) => {
358-
return id && render(id, ctx);
359-
});
357+
];
360358

361-
await Promise.all(promises);
359+
for (const id of files) {
360+
if (id) {
361+
await render(id, ctx);
362+
}
363+
}
362364
}
363365

364366
async renderFiles(ctx: InitOptions) {
@@ -373,30 +375,30 @@ export class InitCmd implements CommandProvider {
373375

374376
startTime = Date.now();
375377

376-
const promises = files.map((option) => {
378+
for (const option of files) {
377379
if (!option) {
378-
return;
380+
continue;
379381
}
380382

381383
if (isString(option)) {
382384
const [id, name] = option.split(":");
383385

384-
return render(id, {
386+
await render(id, {
385387
...ctx,
386388
from: TEMPLATE_DIR,
387389
name: name || id
388390
});
389-
} else {
390-
if ("id" in option) {
391-
return render(option.id, {
392-
...ctx,
393-
...option
394-
});
395-
}
391+
continue;
396392
}
397-
});
398393

399-
await Promise.all(promises);
394+
if ("id" in option) {
395+
await render(option.id, {
396+
...ctx,
397+
...option
398+
});
399+
}
400+
}
401+
400402
taskOutput(`Plugins files rendered (${Date.now() - startTime}ms)`);
401403
}
402404

yarn.lock

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2798,7 +2798,7 @@ __metadata:
27982798
tslib: "npm:^2.7.0"
27992799
typescript: "npm:5.6.2"
28002800
vitest: "npm:4.1.0"
2801-
zod: "npm:4.3.6"
2801+
zod: "npm:^4.3.6"
28022802
peerDependencies:
28032803
"@tsed/core": ">=8.0.0"
28042804
"@tsed/di": ">=8.0.0"
@@ -17525,20 +17525,20 @@ __metadata:
1752517525
languageName: node
1752617526
linkType: hard
1752717527

17528-
"zod@npm:4.3.6":
17529-
version: 4.3.6
17530-
resolution: "zod@npm:4.3.6"
17531-
checksum: 10/25fc0f62e01b557b4644bf0b393bbaf47542ab30877c37837ea8caf314a8713d220c7d7fe51f68ffa72f0e1018ddfa34d96f1973d23033f5a2a5a9b6b9d9da01
17532-
languageName: node
17533-
linkType: hard
17534-
1753517528
"zod@npm:^3.25 || ^4.0":
1753617529
version: 4.2.1
1753717530
resolution: "zod@npm:4.2.1"
1753817531
checksum: 10/f21d106ce31e0f24040aa13b13fdd1300fcc8119622b28ca1b1b726ff70b75190dbcfeb927d34f19174683afa298e5df4d806f622abe9b037a0aadb9cdef6443
1753917532
languageName: node
1754017533
linkType: hard
1754117534

17535+
"zod@npm:^4.3.6":
17536+
version: 4.3.6
17537+
resolution: "zod@npm:4.3.6"
17538+
checksum: 10/25fc0f62e01b557b4644bf0b393bbaf47542ab30877c37837ea8caf314a8713d220c7d7fe51f68ffa72f0e1018ddfa34d96f1973d23033f5a2a5a9b6b9d9da01
17539+
languageName: node
17540+
linkType: hard
17541+
1754217542
"zwitch@npm:^1.0.0":
1754317543
version: 1.0.5
1754417544
resolution: "zwitch@npm:1.0.5"

0 commit comments

Comments
 (0)