@@ -64,23 +64,15 @@ export async function build(
64
64
process . on ( sig , ( ) => process . exit ( ) ) ;
65
65
} ) ;
66
66
67
- async function tryToBuildLocale ( {
68
- locale,
69
- isLastLocale,
70
- } : {
71
- locale : string ;
72
- isLastLocale : boolean ;
73
- } ) {
67
+ async function tryToBuildLocale ( { locale} : { locale : string } ) {
74
68
try {
75
- PerfLogger . start ( `Building site for locale ${ locale } ` ) ;
76
- await buildLocale ( {
77
- siteDir,
78
- locale,
79
- cliOptions,
80
- forceTerminate,
81
- isLastLocale,
82
- } ) ;
83
- PerfLogger . end ( `Building site for locale ${ locale } ` ) ;
69
+ await PerfLogger . async ( `${ logger . name ( locale ) } ` , ( ) =>
70
+ buildLocale ( {
71
+ siteDir,
72
+ locale,
73
+ cliOptions,
74
+ } ) ,
75
+ ) ;
84
76
} catch ( err ) {
85
77
throw new Error (
86
78
logger . interpolate `Unable to build website for locale name=${ locale } .` ,
@@ -91,20 +83,28 @@ export async function build(
91
83
}
92
84
}
93
85
94
- PerfLogger . start ( ` Get locales to build` ) ;
95
- const locales = await getLocalesToBuild ( { siteDir, cliOptions} ) ;
96
- PerfLogger . end ( `Get locales to build` ) ;
86
+ const locales = await PerfLogger . async ( ' Get locales to build' , ( ) =>
87
+ getLocalesToBuild ( { siteDir, cliOptions} ) ,
88
+ ) ;
97
89
98
90
if ( locales . length > 1 ) {
99
91
logger . info `Website will be built for all these locales: ${ locales } ` ;
100
92
}
101
93
102
- PerfLogger . start ( `Building ${ locales . length } locales` ) ;
103
- await mapAsyncSequential ( locales , ( locale ) => {
104
- const isLastLocale = locales . indexOf ( locale ) === locales . length - 1 ;
105
- return tryToBuildLocale ( { locale, isLastLocale} ) ;
106
- } ) ;
107
- PerfLogger . end ( `Building ${ locales . length } locales` ) ;
94
+ await PerfLogger . async ( `Build` , ( ) =>
95
+ mapAsyncSequential ( locales , async ( locale ) => {
96
+ const isLastLocale = locales . indexOf ( locale ) === locales . length - 1 ;
97
+ await tryToBuildLocale ( { locale} ) ;
98
+ if ( isLastLocale ) {
99
+ logger . info `Use code=${ 'npm run serve' } command to test your build locally.` ;
100
+ }
101
+
102
+ // TODO do we really need this historical forceTerminate exit???
103
+ if ( forceTerminate && isLastLocale && ! cliOptions . bundleAnalyzer ) {
104
+ process . exit ( 0 ) ;
105
+ }
106
+ } ) ,
107
+ ) ;
108
108
}
109
109
110
110
async function getLocalesToBuild ( {
@@ -144,14 +144,10 @@ async function buildLocale({
144
144
siteDir,
145
145
locale,
146
146
cliOptions,
147
- forceTerminate,
148
- isLastLocale,
149
147
} : {
150
148
siteDir : string ;
151
149
locale : string ;
152
150
cliOptions : Partial < BuildCLIOptions > ;
153
- forceTerminate : boolean ;
154
- isLastLocale : boolean ;
155
151
} ) : Promise < string > {
156
152
// Temporary workaround to unlock the ability to translate the site config
157
153
// We'll remove it if a better official API can be designed
@@ -160,81 +156,66 @@ async function buildLocale({
160
156
161
157
logger . info `name=${ `[${ locale } ]` } Creating an optimized production build...` ;
162
158
163
- PerfLogger . start ( 'Loading site') ;
164
- const site = await loadSite ( {
165
- siteDir,
166
- outDir : cliOptions . outDir ,
167
- config : cliOptions . config ,
168
- locale,
169
- localizePath : cliOptions . locale ? false : undefined ,
170
- } ) ;
171
- PerfLogger . end ( 'Loading site' ) ;
159
+ const site = await PerfLogger . async ( 'Load site', ( ) =>
160
+ loadSite ( {
161
+ siteDir,
162
+ outDir : cliOptions . outDir ,
163
+ config : cliOptions . config ,
164
+ locale,
165
+ localizePath : cliOptions . locale ? false : undefined ,
166
+ } ) ,
167
+ ) ;
172
168
173
169
const { props} = site ;
174
170
const { outDir, plugins} = props ;
175
171
176
172
// We can build the 2 configs in parallel
177
- PerfLogger . start ( 'Creating webpack configs' ) ;
178
173
const [ { clientConfig, clientManifestPath} , { serverConfig, serverBundlePath} ] =
179
- await Promise . all ( [
180
- getBuildClientConfig ( {
181
- props,
182
- cliOptions,
183
- } ) ,
184
- getBuildServerConfig ( {
185
- props,
186
- } ) ,
187
- ] ) ;
188
- PerfLogger . end ( 'Creating webpack configs' ) ;
189
-
190
- // Make sure generated client-manifest is cleaned first, so we don't reuse
191
- // the one from previous builds.
192
- // TODO do we really need this? .docusaurus folder is cleaned between builds
193
- PerfLogger . start ( 'Deleting previous client manifest' ) ;
194
- await ensureUnlink ( clientManifestPath ) ;
195
- PerfLogger . end ( 'Deleting previous client manifest' ) ;
174
+ await PerfLogger . async ( 'Creating webpack configs' , ( ) =>
175
+ Promise . all ( [
176
+ getBuildClientConfig ( {
177
+ props,
178
+ cliOptions,
179
+ } ) ,
180
+ getBuildServerConfig ( {
181
+ props,
182
+ } ) ,
183
+ ] ) ,
184
+ ) ;
196
185
197
186
// Run webpack to build JS bundle (client) and static html files (server).
198
- PerfLogger . start ( 'Bundling' ) ;
199
- await compile ( [ clientConfig , serverConfig ] ) ;
200
- PerfLogger . end ( 'Bundling' ) ;
187
+ await PerfLogger . async ( 'Bundling with Webpack' , ( ) =>
188
+ compile ( [ clientConfig , serverConfig ] ) ,
189
+ ) ;
201
190
202
- PerfLogger . start ( 'Executing static site generation' ) ;
203
- const { collectedData } = await executeSSG ( {
204
- props,
205
- serverBundlePath,
206
- clientManifestPath,
207
- } ) ;
208
- PerfLogger . end ( 'Executing static site generation' ) ;
191
+ const { collectedData } = await PerfLogger . async ( 'SSG' , ( ) =>
192
+ executeSSG ( {
193
+ props,
194
+ serverBundlePath,
195
+ clientManifestPath,
196
+ } ) ,
197
+ ) ;
209
198
210
199
// Remove server.bundle.js because it is not needed.
211
- PerfLogger . start ( 'Deleting server bundle' ) ;
212
- await ensureUnlink ( serverBundlePath ) ;
213
- PerfLogger . end ( 'Deleting server bundle' ) ;
200
+ await PerfLogger . async ( 'Deleting server bundle' , ( ) =>
201
+ ensureUnlink ( serverBundlePath ) ,
202
+ ) ;
214
203
215
204
// Plugin Lifecycle - postBuild.
216
- PerfLogger . start ( 'Executing postBuild()') ;
217
- await executePluginsPostBuild ( { plugins, props, collectedData} ) ;
218
- PerfLogger . end ( 'Executing postBuild()' ) ;
205
+ await PerfLogger . async ( ' postBuild()', ( ) =>
206
+ executePluginsPostBuild ( { plugins, props, collectedData} ) ,
207
+ ) ;
219
208
220
209
// TODO execute this in parallel to postBuild?
221
- PerfLogger . start ( 'Executing broken links checker') ;
222
- await executeBrokenLinksCheck ( { props, collectedData} ) ;
223
- PerfLogger . end ( 'Executing broken links checker' ) ;
210
+ await PerfLogger . async ( 'Broken links checker', ( ) =>
211
+ executeBrokenLinksCheck ( { props, collectedData} ) ,
212
+ ) ;
224
213
225
214
logger . success `Generated static files in path=${ path . relative (
226
215
process . cwd ( ) ,
227
216
outDir ,
228
217
) } .`;
229
218
230
- if ( isLastLocale ) {
231
- logger . info `Use code=${ 'npm run serve' } command to test your build locally.` ;
232
- }
233
-
234
- if ( forceTerminate && isLastLocale && ! cliOptions . bundleAnalyzer ) {
235
- process . exit ( 0 ) ;
236
- }
237
-
238
219
return outDir ;
239
220
}
240
221
@@ -247,40 +228,39 @@ async function executeSSG({
247
228
serverBundlePath : string ;
248
229
clientManifestPath : string ;
249
230
} ) {
250
- PerfLogger . start ( 'Reading client manifest' ) ;
251
- const manifest : Manifest = await fs . readJSON ( clientManifestPath , 'utf-8' ) ;
252
- PerfLogger . end ( 'Reading client manifest' ) ;
231
+ const manifest : Manifest = await PerfLogger . async (
232
+ 'Read client manifest' ,
233
+ ( ) => fs . readJSON ( clientManifestPath , 'utf-8' ) ,
234
+ ) ;
253
235
254
- PerfLogger . start ( 'Compiling SSR template' ) ;
255
- const ssrTemplate = await compileSSRTemplate (
256
- props . siteConfig . ssrTemplate ?? defaultSSRTemplate ,
236
+ const ssrTemplate = await PerfLogger . async ( 'Compile SSR template' , ( ) =>
237
+ compileSSRTemplate ( props . siteConfig . ssrTemplate ?? defaultSSRTemplate ) ,
257
238
) ;
258
- PerfLogger . end ( 'Compiling SSR template' ) ;
259
239
260
- PerfLogger . start ( 'Loading App renderer') ;
261
- const renderer = await loadAppRenderer ( {
262
- serverBundlePath,
263
- } ) ;
264
- PerfLogger . end ( 'Loading App renderer' ) ;
265
-
266
- PerfLogger . start ( 'Generate static files' ) ;
267
- const ssgResult = await generateStaticFiles ( {
268
- pathnames : props . routesPaths ,
269
- renderer,
270
- params : {
271
- trailingSlash : props . siteConfig . trailingSlash ,
272
- outDir : props . outDir ,
273
- baseUrl : props . baseUrl ,
274
- manifest,
275
- headTags : props . headTags ,
276
- preBodyTags : props . preBodyTags ,
277
- postBodyTags : props . postBodyTags ,
278
- ssrTemplate,
279
- noIndex : props . siteConfig . noIndex ,
280
- DOCUSAURUS_VERSION ,
281
- } ,
282
- } ) ;
283
- PerfLogger . end ( 'Generate static files' ) ;
240
+ const renderer = await PerfLogger . async ( 'Load App renderer', ( ) =>
241
+ loadAppRenderer ( {
242
+ serverBundlePath,
243
+ } ) ,
244
+ ) ;
245
+
246
+ const ssgResult = await PerfLogger . async ( 'Generate static files' , ( ) =>
247
+ generateStaticFiles ( {
248
+ pathnames : props . routesPaths ,
249
+ renderer,
250
+ params : {
251
+ trailingSlash : props . siteConfig . trailingSlash ,
252
+ outDir : props . outDir ,
253
+ baseUrl : props . baseUrl ,
254
+ manifest,
255
+ headTags : props . headTags ,
256
+ preBodyTags : props . preBodyTags ,
257
+ postBodyTags : props . postBodyTags ,
258
+ ssrTemplate,
259
+ noIndex : props . siteConfig . noIndex ,
260
+ DOCUSAURUS_VERSION ,
261
+ } ,
262
+ } ) ,
263
+ ) ;
284
264
285
265
return ssgResult ;
286
266
}
0 commit comments