Skip to content

Commit 58bd33e

Browse files
committed
fix: change timing optional
1 parent 93764e1 commit 58bd33e

File tree

4 files changed

+21
-14
lines changed

4 files changed

+21
-14
lines changed

.changeset/poor-ties-visit.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@modern-js/codesmith-api-app': patch
3+
'@modern-js/codesmith': patch
4+
---
5+
6+
fix: change timing to optional
7+
fix: timing 改为可选

packages/api/app/src/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ export class AppAPI {
174174
type: 'handlebars' | 'ejs' = 'handlebars',
175175
) {
176176
try {
177-
this.generatorCore.logger.timing(`forgeTemplate`);
177+
this.generatorCore.logger?.timing?.(`forgeTemplate`);
178178
const { material } = this.generatorContext.current!;
179179
const resourceMap = await material.find(templatePattern, {
180180
nodir: true,
@@ -207,7 +207,7 @@ export class AppAPI {
207207
this.generatorCore.logger.warn(i18n.t(localeKeys.templated.failed));
208208
throw new Error('base forging failed');
209209
} finally {
210-
this.generatorCore.logger.timing(`forgeTemplate`, true);
210+
this.generatorCore.logger?.timing?.(`forgeTemplate`, true);
211211
}
212212
}
213213

@@ -218,7 +218,7 @@ export class AppAPI {
218218
parameters?: Record<string, any>,
219219
) {
220220
try {
221-
this.generatorCore.logger.timing(`renderTemplateByFileType`);
221+
this.generatorCore.logger?.timing?.(`renderTemplateByFileType`);
222222
const { material } = this.generatorContext.current!;
223223
const resourceMap = await material.find(templatePattern, {
224224
nodir: true,
@@ -272,7 +272,7 @@ export class AppAPI {
272272
this.generatorCore.logger.warn(i18n.t(localeKeys.templated.failed));
273273
throw new Error('base forging failed');
274274
} finally {
275-
this.generatorCore.logger.timing(`renderTemplateByFileType`, true);
275+
this.generatorCore.logger?.timing?.(`renderTemplateByFileType`, true);
276276
}
277277
}
278278

packages/core/src/codesmith/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export class CodeSmith {
3131
}
3232

3333
public async forge({ tasks, pwd }: ForgeOptions) {
34-
this.logger.timing('CodeSmith all tasks');
34+
this.logger?.timing?.('CodeSmith all tasks');
3535
this.core = new GeneratorCore({
3636
logger: this.logger,
3737
materialsManager: this.materialsManager,
@@ -49,7 +49,7 @@ export class CodeSmith {
4949
this.logger.error('run task error:', e);
5050
throw new Error('run task error');
5151
} finally {
52-
this.logger.timing('CodeSmith all tasks', true);
52+
this.logger?.timing?.('CodeSmith all tasks', true);
5353
}
5454
}
5555

@@ -58,8 +58,8 @@ export class CodeSmith {
5858
throw new Error("no core in 'runTask'");
5959
}
6060
const { generator, config } = task;
61-
this.logger.timing(`runTask ${generator}`);
61+
this.logger?.timing?.(`runTask ${generator}`);
6262
await this.core.runGenerator(generator, config);
63-
this.logger.timing(`runTask ${generator}`, true);
63+
this.logger?.timing?.(`runTask ${generator}`, true);
6464
}
6565
}

packages/core/src/generator/index.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ check path: ${chalk.blue.underline(
177177
}
178178

179179
async loadGenerator(generator: string) {
180-
this.logger.timing(`loadGenerator ${generator}`);
180+
this.logger?.timing?.(`loadGenerator ${generator}`);
181181
let generatorPath = generator;
182182
if (generator.startsWith('file:')) {
183183
generatorPath = path.join(this.basePath, generator.slice(5));
@@ -190,7 +190,7 @@ check path: ${chalk.blue.underline(
190190
return {};
191191
}
192192
this.logger.debug('[runGenerator] task.generator loaded');
193-
this.logger.timing(`loadGenerator ${generator}`, true);
193+
this.logger?.timing?.(`loadGenerator ${generator}`, true);
194194

195195
const generatorScript = nodeRequire(generatorPkg.basePath);
196196
if (typeof generatorScript !== 'function') {
@@ -210,7 +210,7 @@ check path: ${chalk.blue.underline(
210210
}
211211

212212
async runGenerator(generator: string, config: Record<string, unknown> = {}) {
213-
this.logger.timing(`runGenerator ${generator}`);
213+
this.logger?.timing?.(`runGenerator ${generator}`);
214214
const spinner = ora({
215215
text: 'Load Generator...',
216216
spinner: 'runner',
@@ -231,15 +231,15 @@ check path: ${chalk.blue.underline(
231231
this.setbasePath(this._context.current!.material.basePath!);
232232
await generatorScript(this._context, this);
233233
this.setCurrent(null);
234-
this.logger.timing(`runGenerator ${generator}`, true);
234+
this.logger?.timing?.(`runGenerator ${generator}`, true);
235235
}
236236

237237
async runSubGenerator(
238238
subGenerator: string,
239239
relativePwdPath = '',
240240
config?: Record<string, any>,
241241
) {
242-
this.logger.timing(`runSubGenerator ${subGenerator}`);
242+
this.logger?.timing?.(`runSubGenerator ${subGenerator}`);
243243
const spinner = ora({
244244
text: 'Load Generator...',
245245
spinner: 'runner',
@@ -273,6 +273,6 @@ check path: ${chalk.blue.underline(
273273
await generatorScript(subContext, this);
274274
this.setOutputPath(preOutputPath);
275275
this.setbasePath(preBasePath);
276-
this.logger.timing(`runSubGenerator ${subGenerator}`, true);
276+
this.logger?.timing?.(`runSubGenerator ${subGenerator}`, true);
277277
}
278278
}

0 commit comments

Comments
 (0)