Skip to content

Commit

Permalink
Add spinner to bundle
Browse files Browse the repository at this point in the history
  • Loading branch information
codetheweb committed Jan 23, 2024
1 parent 5741e65 commit 06e8fd0
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/cli/commands/bundle.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Command, Option } from "clipanion"
import { bundle } from "src/bundle/bundle"
import fs from "node:fs/promises"
import { sizeFormatter } from "human-readable"
import { durationFormatter, sizeFormatter } from "human-readable"
import ora from "ora"

export class BundleCommand extends Command {
static paths = [[`bundle`]]
Expand Down Expand Up @@ -32,13 +33,22 @@ export class BundleCommand extends Command {
return 1
}

const spinner = ora("Bundling...").start()
const buildStartedAt = performance.now()

const output = await bundle({
directoryPath: this.appDirectory,
})

await fs.writeFile(this.outputPath, output)
this.context.stdout.write(
`Wrote bundle to ${this.outputPath} (${sizeFormatter()(output.length)})\n`
)

spinner.stopAndPersist({
symbol: "☃️",
text: ` brr... bundled in ${durationFormatter({
allowMultiples: ["m", "s", "ms"],
})(performance.now() - buildStartedAt)} (${sizeFormatter()(
output.length
)})`,
})
}
}

0 comments on commit 06e8fd0

Please sign in to comment.