Skip to content

Commit 1968330

Browse files
committed
feat: log only print total time per job
1 parent a867ee9 commit 1968330

7 files changed

Lines changed: 30 additions & 22 deletions

File tree

packages/openapi-python/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
"@hey-api/shared": "workspace:*",
6565
"@hey-api/spec-types": "workspace:*",
6666
"@hey-api/types": "workspace:*",
67+
"@lukeed/ms": "2.0.2",
6768
"ansi-colors": "4.1.3",
6869
"color-support": "1.1.3",
6970
"commander": "14.0.3"

packages/openapi-python/src/createClient.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
patchOpenApiSpec,
1616
postprocessOutput,
1717
} from '@hey-api/shared';
18+
import { format as ms } from '@lukeed/ms';
1819
import colors from 'ansi-colors';
1920

2021
import { postProcessors } from './config/output/postprocess';
@@ -44,6 +45,7 @@ export async function createClient({
4445
headers: new Headers(),
4546
}));
4647

48+
const jobStart = Date.now();
4749
const inputPaths = config.input.map((input) => compileInputPath(input));
4850

4951
// on first run, print the message as soon as possible
@@ -166,9 +168,11 @@ export async function createClient({
166168
eventParser.timeEnd();
167169

168170
const eventGenerator = logger.timeEvent('generator');
169-
const { codegenMs, fileCount, writeMs } = await generateOutput(context);
171+
const { fileCount } = await generateOutput(context);
170172
eventGenerator.timeEnd();
171173

174+
const totalMs = Date.now() - jobStart;
175+
172176
const eventPostprocess = logger.timeEvent('postprocess');
173177
if (!config.dryRun) {
174178
const jobPrefix = colors.gray(`[Job ${jobIndex + 1}] `);
@@ -179,7 +183,7 @@ export async function createClient({
179183
? `./${path.relative(process.env.INIT_CWD, config.output.path)}`
180184
: config.output.path;
181185
console.log(
182-
`${jobPrefix}${colors.green('✅ Done!')} Your output is in ${colors.cyanBright(outputPath)} ${colors.gray(`(${fileCount} files, codegen ${(codegenMs / 1000).toFixed(2)}s, write ${(writeMs / 1000).toFixed(2)}s)`)}`,
186+
`${jobPrefix}${colors.green('✅ Done!')} Your output is in ${colors.cyanBright(outputPath)} ${colors.gray(`(${fileCount} files in ${ms(totalMs)})`)}`,
183187
);
184188
}
185189
}

packages/openapi-python/src/generate/output.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ import { getTypedConfig } from '../config/utils';
88
import { getClientPlugin } from '../plugins/@hey-api/client-core/utils';
99
import { generateClientBundle } from './client';
1010

11-
export async function generateOutput(
12-
context: Context,
13-
): Promise<{ codegenMs: number; fileCount: number; writeMs: number }> {
11+
export async function generateOutput(context: Context): Promise<{ fileCount: number }> {
1412
const outputPath = path.resolve(context.config.output.path);
1513

1614
if (context.config.output.clean) {
@@ -39,7 +37,6 @@ export async function generateOutput(
3937
});
4038
}
4139

42-
const codegenStart = Date.now();
4340
for (const plugin of context.registerPlugins()) {
4441
await plugin.run();
4542
}
@@ -65,9 +62,6 @@ export async function generateOutput(
6562
}
6663
fileCount++;
6764
}
68-
const codegenMs = Date.now() - codegenStart;
69-
70-
const writeStart = Date.now();
7165
await Promise.all(writes);
7266

7367
const { source } = context.config.output;
@@ -91,6 +85,5 @@ export async function generateOutput(
9185
}
9286
}
9387

94-
const writeMs = Date.now() - writeStart;
95-
return { codegenMs, fileCount, writeMs };
88+
return { fileCount };
9689
}

packages/openapi-ts/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
"@hey-api/shared": "workspace:*",
7474
"@hey-api/spec-types": "workspace:*",
7575
"@hey-api/types": "workspace:*",
76+
"@lukeed/ms": "2.0.2",
7677
"ansi-colors": "4.1.3",
7778
"color-support": "1.1.3",
7879
"commander": "14.0.3",

packages/openapi-ts/src/createClient.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
patchOpenApiSpec,
1616
postprocessOutput,
1717
} from '@hey-api/shared';
18+
import { format as ms } from '@lukeed/ms';
1819
import colors from 'ansi-colors';
1920

2021
import { postProcessors } from './config/output/postprocess';
@@ -44,6 +45,7 @@ export async function createClient({
4445
headers: new Headers(),
4546
}));
4647

48+
const jobStart = Date.now();
4749
const inputPaths = config.input.map((input) => compileInputPath(input));
4850

4951
// on first run, print the message as soon as possible
@@ -166,9 +168,11 @@ export async function createClient({
166168
eventParser.timeEnd();
167169

168170
const eventGenerator = logger.timeEvent('generator');
169-
const { codegenMs, fileCount, writeMs } = await generateOutput(context);
171+
const { fileCount } = await generateOutput(context);
170172
eventGenerator.timeEnd();
171173

174+
const totalMs = Date.now() - jobStart;
175+
172176
const eventPostprocess = logger.timeEvent('postprocess');
173177
if (!config.dryRun) {
174178
const jobPrefix = colors.gray(`[Job ${jobIndex + 1}] `);
@@ -179,7 +183,7 @@ export async function createClient({
179183
? `./${path.relative(process.env.INIT_CWD, config.output.path)}`
180184
: config.output.path;
181185
console.log(
182-
`${jobPrefix}${colors.green('✅ Done!')} Your output is in ${colors.cyanBright(outputPath)} ${colors.gray(`(${fileCount} files, codegen ${(codegenMs / 1000).toFixed(2)}s, write ${(writeMs / 1000).toFixed(2)}s)`)}`,
186+
`${jobPrefix}${colors.green('✅ Done!')} Your output is in ${colors.cyanBright(outputPath)} ${colors.gray(`(${fileCount} files in ${ms(totalMs)})`)}`,
183187
);
184188
}
185189
}

packages/openapi-ts/src/generate/output.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ import { getTypedConfig } from '../config/utils';
99
import { getClientPlugin } from '../plugins/@hey-api/client-core/utils';
1010
import { generateClientBundle } from './client';
1111

12-
export async function generateOutput(
13-
context: Context,
14-
): Promise<{ codegenMs: number; fileCount: number; writeMs: number }> {
12+
export async function generateOutput(context: Context): Promise<{ fileCount: number }> {
1513
const outputPath = path.resolve(context.config.output.path);
1614

1715
if (context.config.output.clean) {
@@ -36,7 +34,6 @@ export async function generateOutput(
3634
});
3735
}
3836

39-
const codegenStart = Date.now();
4037
for (const plugin of context.registerPlugins()) {
4138
await plugin.run();
4239
}
@@ -62,9 +59,6 @@ export async function generateOutput(
6259
}
6360
fileCount++;
6461
}
65-
const codegenMs = Date.now() - codegenStart;
66-
67-
const writeStart = Date.now();
6862
await Promise.all(writes);
6963

7064
const { source } = context.config.output;
@@ -88,6 +82,5 @@ export async function generateOutput(
8882
}
8983
}
9084

91-
const writeMs = Date.now() - writeStart;
92-
return { codegenMs, fileCount, writeMs };
85+
return { fileCount };
9386
}

pnpm-lock.yaml

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)