Skip to content

Commit

Permalink
chore(og-image|git-changelog): added elapsed time print after ora pri…
Browse files Browse the repository at this point in the history
…nt (#123)

Signed-off-by: Neko Ayaka <[email protected]>
  • Loading branch information
nekomeowww authored Mar 26, 2024
1 parent 737ab34 commit 4716e1e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
5 changes: 4 additions & 1 deletion packages/vitepress-plugin-git-changelog/src/vite/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ export function GitChangelog(options: {
},
}),
async buildStart() {
const startsAt = Date.now()

const moduleNamePrefix = cyan('@nolebase/vitepress-plugin-git-changelog')
const grayPrefix = gray(':')
const spinnerPrefix = `${moduleNamePrefix}${grayPrefix}`
Expand Down Expand Up @@ -186,7 +188,8 @@ export function GitChangelog(options: {

commits = await aggregateCommits(getRepoURL, getCommitURL, getReleaseTagURL, logs, includeDirs, rewritePaths)

spinner.succeed(`${spinnerPrefix} calculated git logs and supplied as ${VirtualModuleID}.`)
const elapsed = Date.now() - startsAt
spinner.succeed(`${spinnerPrefix} ${VirtualModuleID} calculated. ${gray(`(${elapsed}ms)`)}`)
},
resolveId(id) {
if (id === VirtualModuleID)
Expand Down
7 changes: 6 additions & 1 deletion packages/vitepress-plugin-og-image/src/utils/task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ export const okMark = green('✓')
export const failMark = red('✖')

export async function task(taskName: string, task: () => Promise<string | undefined>) {
const startsAt = Date.now()

const moduleNamePrefix = cyan('@nolebase/vitepress-plugin-og-image')
const grayPrefix = gray(':')
const spinnerPrefix = `${moduleNamePrefix}${grayPrefix}`
Expand All @@ -46,7 +48,10 @@ export async function task(taskName: string, task: () => Promise<string | undefi
throw e
}

spinner.stopAndPersist({ symbol: okMark, suffixText: result ?? '' })
const elapsed = Date.now() - startsAt
const suffixText = `${gray(`(${elapsed}ms)`)} ${result}` ?? ''

spinner.stopAndPersist({ symbol: okMark, suffixText })
}

export function renderTaskResultsSummary(results: TaskResult[], siteConfig: SiteConfig) {
Expand Down

0 comments on commit 4716e1e

Please sign in to comment.