Skip to content

Commit

Permalink
fix: change timing optional
Browse files Browse the repository at this point in the history
  • Loading branch information
KyrieLii committed Dec 8, 2023
1 parent 93764e1 commit 58bd33e
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 14 deletions.
7 changes: 7 additions & 0 deletions .changeset/poor-ties-visit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@modern-js/codesmith-api-app': patch
'@modern-js/codesmith': patch
---

fix: change timing to optional
fix: timing 改为可选
8 changes: 4 additions & 4 deletions packages/api/app/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ export class AppAPI {
type: 'handlebars' | 'ejs' = 'handlebars',
) {
try {
this.generatorCore.logger.timing(`forgeTemplate`);
this.generatorCore.logger?.timing?.(`forgeTemplate`);
const { material } = this.generatorContext.current!;
const resourceMap = await material.find(templatePattern, {
nodir: true,
Expand Down Expand Up @@ -207,7 +207,7 @@ export class AppAPI {
this.generatorCore.logger.warn(i18n.t(localeKeys.templated.failed));
throw new Error('base forging failed');
} finally {
this.generatorCore.logger.timing(`forgeTemplate`, true);
this.generatorCore.logger?.timing?.(`forgeTemplate`, true);
}
}

Expand All @@ -218,7 +218,7 @@ export class AppAPI {
parameters?: Record<string, any>,
) {
try {
this.generatorCore.logger.timing(`renderTemplateByFileType`);
this.generatorCore.logger?.timing?.(`renderTemplateByFileType`);
const { material } = this.generatorContext.current!;
const resourceMap = await material.find(templatePattern, {
nodir: true,
Expand Down Expand Up @@ -272,7 +272,7 @@ export class AppAPI {
this.generatorCore.logger.warn(i18n.t(localeKeys.templated.failed));
throw new Error('base forging failed');
} finally {
this.generatorCore.logger.timing(`renderTemplateByFileType`, true);
this.generatorCore.logger?.timing?.(`renderTemplateByFileType`, true);
}
}

Expand Down
8 changes: 4 additions & 4 deletions packages/core/src/codesmith/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class CodeSmith {
}

public async forge({ tasks, pwd }: ForgeOptions) {
this.logger.timing('CodeSmith all tasks');
this.logger?.timing?.('CodeSmith all tasks');
this.core = new GeneratorCore({
logger: this.logger,
materialsManager: this.materialsManager,
Expand All @@ -49,7 +49,7 @@ export class CodeSmith {
this.logger.error('run task error:', e);
throw new Error('run task error');
} finally {
this.logger.timing('CodeSmith all tasks', true);
this.logger?.timing?.('CodeSmith all tasks', true);
}
}

Expand All @@ -58,8 +58,8 @@ export class CodeSmith {
throw new Error("no core in 'runTask'");
}
const { generator, config } = task;
this.logger.timing(`runTask ${generator}`);
this.logger?.timing?.(`runTask ${generator}`);
await this.core.runGenerator(generator, config);
this.logger.timing(`runTask ${generator}`, true);
this.logger?.timing?.(`runTask ${generator}`, true);
}
}
12 changes: 6 additions & 6 deletions packages/core/src/generator/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ check path: ${chalk.blue.underline(
}

async loadGenerator(generator: string) {
this.logger.timing(`loadGenerator ${generator}`);
this.logger?.timing?.(`loadGenerator ${generator}`);
let generatorPath = generator;
if (generator.startsWith('file:')) {
generatorPath = path.join(this.basePath, generator.slice(5));
Expand All @@ -190,7 +190,7 @@ check path: ${chalk.blue.underline(
return {};
}
this.logger.debug('[runGenerator] task.generator loaded');
this.logger.timing(`loadGenerator ${generator}`, true);
this.logger?.timing?.(`loadGenerator ${generator}`, true);

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

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

async runSubGenerator(
subGenerator: string,
relativePwdPath = '',
config?: Record<string, any>,
) {
this.logger.timing(`runSubGenerator ${subGenerator}`);
this.logger?.timing?.(`runSubGenerator ${subGenerator}`);
const spinner = ora({
text: 'Load Generator...',
spinner: 'runner',
Expand Down Expand Up @@ -273,6 +273,6 @@ check path: ${chalk.blue.underline(
await generatorScript(subContext, this);
this.setOutputPath(preOutputPath);
this.setbasePath(preBasePath);
this.logger.timing(`runSubGenerator ${subGenerator}`, true);
this.logger?.timing?.(`runSubGenerator ${subGenerator}`, true);
}
}

0 comments on commit 58bd33e

Please sign in to comment.