Merge branch 'feat/log-duration-for-each-task' into feat/multithread-render

pull/3386/head
Yuxuan Zhang 2 years ago
commit 50093fd358
No known key found for this signature in database
GPG Key ID: 6910B04F3351EF7D

@ -167,19 +167,18 @@ export async function bundle(
configFile: config.vite?.configFile
})
let clientResult!: Rollup.RollupOutput | null
let serverResult!: Rollup.RollupOutput
await task('building client + server bundles', async () => {
clientResult = config.mpa
? null
: ((await build(await resolveViteConfig(false))) as Rollup.RollupOutput)
serverResult = (await build(
await resolveViteConfig(true)
)) as Rollup.RollupOutput
})
const serverResult = await task(
'building server bundle',
() => resolveViteConfig(true).then(build) as Promise<Rollup.RollupOutput>
)
if (config.mpa) {
const clientResult = !config.mpa
? await task(
'building client bundle',
() =>
resolveViteConfig(false).then(build) as Promise<Rollup.RollupOutput>
)
: await task('building client bundle (MPA)', async () => {
// in MPA mode, we need to copy over the non-js asset files from the
// server build since there is no client-side build.
await Promise.all(
@ -198,9 +197,11 @@ export async function bundle(
}
// build <script client> bundle
if (Object.keys(clientJSMap).length) {
clientResult = await buildMPAClient(clientJSMap, config)
}
return buildMPAClient(clientJSMap, config)
} else {
return null
}
})
return { clientResult, serverResult, pageToHashMap }
}

@ -1,10 +1,32 @@
import ora from 'ora'
import humanizeDuration from 'humanize-duration'
import c from 'picocolors'
export const okMark = '\x1b[32m✓\x1b[0m'
export const failMark = '\x1b[31m✖\x1b[0m'
export const okMark = c.green('✓')
export const failMark = c.red('✖')
export const clearLine = '\x1b[2K\r'
export type UpdateHandle = (done: number, total?: number) => any
export type UpdateHandle = (
done?: number,
total?: number,
subtask?: string
) => any
let updateHandle: UpdateHandle | null = null
export const updateCurrentTask: UpdateHandle = (...args) => {
if (updateHandle) updateHandle(...args)
else if (!process.stderr.isTTY) {
return
} else if (args.length === 0) {
process.stderr.write(clearLine)
} else {
const name = args[2] || 'unknown task'
process.stderr.write(
`${clearLine}${name} [${args.slice(0, 2).join(' / ')}]`
)
}
}
export async function task<T>(
taskName: string,
@ -13,14 +35,17 @@ export async function task<T>(
const spinner = ora({ discardStdin: false })
spinner.start(taskName + '...')
const updateHandle: UpdateHandle = (done, total) => {
if (total === undefined) {
spinner.text = `${taskName} [ ${done} ]`
updateHandle = (done, total, subtask) => {
const taskFullName = subtask ? `${taskName} - ${subtask}` : taskName
if (done === undefined) {
spinner.text = taskFullName + '...'
} else if (total === undefined) {
spinner.text = `${taskFullName} [ ${done} ]`
} else {
// match length to display them in same width
const _total = `${total}`
const _done = `${done}`.padStart(_total.length, ' ')
spinner.text = `${taskName} [ ${_done} / ${_total} ]`
spinner.text = `${taskFullName} [ ${_done} / ${_total} ]`
}
}
@ -33,6 +58,7 @@ export async function task<T>(
success = false
throw e
} finally {
updateHandle = null
const timeEnd = performance.now()
const duration = humanizeDuration(timeEnd - timeStart, {
maxDecimalPoints: 2

Loading…
Cancel
Save