Skip to content

Commit 9cd9334

Browse files
committed
chore: Add more logs to build process
1 parent 5c73ab1 commit 9cd9334

File tree

5 files changed

+65
-17
lines changed

5 files changed

+65
-17
lines changed

src/commands/build/index.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
import {getHooks as getTocHooks} from '~/core/toc';
1717
import {PAGE_PROCESS_CONCURRENCY, Stage, YFM_CONFIG_FILENAME} from '~/constants';
1818
import {Command} from '~/core/config';
19-
import {normalizePath, setExt} from '~/core/utils';
19+
import {console, normalizePath, setExt} from '~/core/utils';
2020
import {Extension as LocalSearchExtension} from '~/extensions/local-search';
2121
import {Extension as GenericIncluderExtension} from '~/extensions/generic-includer';
2222
import {Extension as OpenapiIncluderExtension} from '~/extensions/openapi';
@@ -170,9 +170,11 @@ export class Build extends BaseProgram<BuildConfig, BuildArgs> {
170170
await getHooks(this).BeforeRun.for(outputFormat).promise(this.run);
171171

172172
if (isMainThread) {
173+
console.log('Prepare build input');
173174
await this.prepareInput();
174175
}
175176

177+
console.log('Prepare build runtime');
176178
await this.prepareRun();
177179

178180
if (!isMainThread) {
@@ -181,6 +183,7 @@ export class Build extends BaseProgram<BuildConfig, BuildArgs> {
181183

182184
await threads.setup();
183185

186+
console.log('Collect project files info');
184187
const ignore = this.run.config.ignore.map((rule) => rule.replace(/\/*$/g, '/**'));
185188
const paths = await this.run.glob('**/toc.yaml', {
186189
cwd: this.run.input,
@@ -208,6 +211,7 @@ export class Build extends BaseProgram<BuildConfig, BuildArgs> {
208211
const {tocs, entries, copymap} = this.run.toc;
209212
const vcs = this.run.vcs.getData();
210213

214+
console.log('Sync project data');
211215
await this.sync(tocs, entries, copymap, vcs);
212216

213217
await this.concurrently(tocs, async (raw) => {
@@ -216,6 +220,7 @@ export class Build extends BaseProgram<BuildConfig, BuildArgs> {
216220
await this.run.write(join(this.run.output, toc.path), toc.toString(), true);
217221
});
218222

223+
console.log('Process project files');
219224
await this.concurrently(entries, async (entry) => {
220225
try {
221226
this.run.logger.proc(entry);
@@ -234,12 +239,14 @@ export class Build extends BaseProgram<BuildConfig, BuildArgs> {
234239

235240
await handler(this.run);
236241

242+
console.log('Aggregate build artifacts');
237243
await this.releaseRun();
238244

239245
await getHooks(this).AfterRun.for(outputFormat).promise(this.run);
240246
await getBaseHooks(this).AfterAnyRun.promise(this.run);
241247

242-
await this.releaseOutput();
248+
console.log('Cleanup build results');
249+
await this.cleanup();
243250
}
244251

245252
async concurrently<T>(items: T[], iterator: (item: T, index: number) => Promise<void>) {
@@ -281,10 +288,6 @@ export class Build extends BaseProgram<BuildConfig, BuildArgs> {
281288
await this.run.copy(originalInput, input, ['node_modules/**', '*/node_modules/**']);
282289
}
283290

284-
private async releaseOutput() {
285-
await this.cleanup();
286-
}
287-
288291
private async prepareRun() {
289292
await this.run.vars.init();
290293
await this.run.leading.init();

src/commands/threads.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {Observable, Subject} from 'threads/observable';
1010
// @ts-ignore
1111
import {expose} from 'threads/worker';
1212

13-
import {Defer, Graph, all} from '~/core/utils';
13+
import {Defer, Graph, all, console} from '~/core/utils';
1414
import {LogLevel} from '~/core/logger';
1515
import {Program, parse} from '~/commands';
1616

@@ -129,6 +129,8 @@ export async function init(_program: Program, runargv: string[]) {
129129
return;
130130
}
131131

132+
console.log(`Init ${jobs} processing threads`);
133+
132134
program = _program;
133135
argv = runargv;
134136
threads = Array(jobs)
@@ -152,6 +154,12 @@ export async function init(_program: Program, runargv: string[]) {
152154
}
153155

154156
export async function setup() {
157+
if (!threads.length) {
158+
return;
159+
}
160+
161+
console.log('Wait for threads setup');
162+
155163
await all(
156164
threads.map(async (defer) => {
157165
const thread = await defer.promise;

src/core/utils/console.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/* eslint-disable no-console */
2+
3+
class MutableConsole {
4+
log(...args: unknown[]) {
5+
this.write('log', args);
6+
}
7+
8+
warn(...args: unknown[]) {
9+
console.warn(...args);
10+
}
11+
12+
error(...args: unknown[]) {
13+
console.error(...args);
14+
}
15+
16+
time(label: string) {
17+
if (process.env.NODE_ENV !== 'test') {
18+
console.time(label);
19+
}
20+
}
21+
22+
timeEnd(label: string) {
23+
if (process.env.NODE_ENV !== 'test') {
24+
console.timeEnd(label);
25+
}
26+
}
27+
28+
private write(level: 'log' | 'error' | 'warn', args: unknown[]) {
29+
if (process.env.NODE_ENV !== 'test') {
30+
console[level](...args);
31+
}
32+
}
33+
}
34+
35+
const _console = new MutableConsole();
36+
37+
export {_console as console};

src/core/utils/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export * from './common';
2+
export * from './console';
23
export * from './decorators';
34
export * from './extension';
45
export * from './path';

src/index.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import './require';
77
import * as threads from '~/commands/threads';
88
import {Program, parse} from '~/commands';
99
import {stats} from '~/core/logger';
10+
import {console} from '~/core/utils';
1011

1112
export * from '~/commands';
1213

@@ -42,27 +43,25 @@ if (isMainThread && require.main === module) {
4243
// eslint-disable-next-line no-console
4344
console.time(MAIN_TIMER_ID);
4445

45-
if (global.VERSION && process.env.NODE_ENV !== 'test') {
46+
if (global.VERSION) {
4647
// eslint-disable-next-line no-console
4748
console.log(`Using v${global.VERSION} version`);
4849
}
4950

5051
const report = await run(process.argv);
5152

52-
if (process.env.NODE_ENV !== 'test') {
53-
// eslint-disable-next-line no-console
54-
console.timeEnd(MAIN_TIMER_ID);
53+
// eslint-disable-next-line no-console
54+
console.timeEnd(MAIN_TIMER_ID);
5555

56-
if (report.code) {
57-
// eslint-disable-next-line no-console
58-
console.log(
59-
red(dedent`
56+
if (report.code) {
57+
// eslint-disable-next-line no-console
58+
console.log(
59+
red(dedent`
6060
================================
6161
YFM build completed with ERRORS!
6262
================================
6363
`),
64-
);
65-
}
64+
);
6665
}
6766

6867
process.exit(report.code);

0 commit comments

Comments
 (0)