diff --git a/src/node/build/build.ts b/src/node/build/build.ts index 46e4d5c0..7686365b 100644 --- a/src/node/build/build.ts +++ b/src/node/build/build.ts @@ -55,7 +55,7 @@ export async function build( const entryPath = path.join(siteConfig.tempDir, 'app.js') const { render } = await import(pathToFileURL(entryPath).toString()) - await task('rendering pages', async () => { + await task('rendering pages', async (updateProgress) => { const appChunk = clientResult && (clientResult.output.find( @@ -108,9 +108,11 @@ export async function build( ]) } } - + debugger + const pages = ['404.md', ...siteConfig.pages] + let count_done = 0 await pMap( - ['404.md', ...siteConfig.pages], + pages, async (page) => { await renderPage( render, @@ -124,6 +126,7 @@ export async function build( metadataScript, additionalHeadTags ) + updateProgress(++count_done, pages.length) }, { concurrency: siteConfig.buildConcurrency } ) diff --git a/src/node/utils/task.ts b/src/node/utils/task.ts index 4a65e6e6..691624a9 100644 --- a/src/node/utils/task.ts +++ b/src/node/utils/task.ts @@ -4,7 +4,12 @@ import humanizeDuration from 'humanize-duration' export const okMark = '\x1b[32m✓\x1b[0m' export const failMark = '\x1b[31m✖\x1b[0m' -export async function task(taskName: string, task: () => Promise) { +type UpdateHandle = (done: number, total?: number) => any + +export async function task( + taskName: string, + task: (update: UpdateHandle) => Promise +): Promise { const spinner = ora({ discardStdin: false }) spinner.start(taskName + '...') @@ -12,7 +17,17 @@ export async function task(taskName: string, task: () => Promise) { const timeStart = performance.now() try { - await task() + const updateHandle: UpdateHandle = (done, total) => { + if (total === undefined) { + spinner.text = `${taskName} [ ${done} ]` + } else { + // match length to display them in same width + const _total = `${total}` + const _done = `${done}`.padStart(_total.length, ' ') + spinner.text = `${taskName} [ ${_done} / ${_total} ]` + } + } + return await task(updateHandle) } catch (e) { symbol = failMark throw e