feat(build): report total build time · nuxt/cli@3d16e4c · GitHub
Skip to content

Commit 3d16e4c

Browse files
committed
feat(build): report total build time
1 parent 79a829d commit 3d16e4c

3 files changed

Lines changed: 49 additions & 2 deletions

File tree

‎packages/nuxt-cli/src/commands/build.ts‎

Lines changed: 5 additions & 2 deletions

‎packages/nuxt-cli/src/utils/formatting.ts‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,22 @@ export function formatInfoBox(infoObj: Record<string, string | undefined>): stri
9797

9898
return boxStr
9999
}
100+
101+
/**
102+
* Format an elapsed duration in milliseconds for display, using `ms` below a
103+
* second and seconds (or minutes and seconds) above it.
104+
*/
105+
export function formatDuration(ms: number): string {
106+
if (ms < 1000) {
107+
return `${Math.round(ms)}ms`
108+
}
109+
110+
const totalSeconds = ms / 1000
111+
if (totalSeconds < 60) {
112+
return `${Number(totalSeconds.toFixed(totalSeconds < 10 ? 2 : 1))}s`
113+
}
114+
115+
const minutes = Math.floor(totalSeconds / 60)
116+
const seconds = Math.round(totalSeconds - minutes * 60)
117+
return seconds ? `${minutes}m ${seconds}s` : `${minutes}m`
118+
}
Lines changed: 25 additions & 0 deletions

0 commit comments

Comments
 (0)