Skip to content

Commit

Permalink
fix(cli): remove yarn install output and show spinner (#236)
Browse files Browse the repository at this point in the history
* fix(cli): remove yarn install output and show spinner

* update yarn.lock
  • Loading branch information
eunjae-lee authored Aug 1, 2023
1 parent 0bfbb3b commit c1dbd85
Show file tree
Hide file tree
Showing 5 changed files with 175 additions and 28 deletions.
1 change: 1 addition & 0 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"fs-extra": "^11.1.0",
"kleur": "^4.1.5",
"node-fetch": "^3.3.0",
"ora": "6.3.1",
"prompts": "^2.4.2",
"vite": "^4.2.2",
"walkdir": "^0.4.1"
Expand Down
12 changes: 4 additions & 8 deletions packages/cli/src/commands/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,10 @@ export const add: AddFunc = async (args) => {
}

const installCommand = getInstallCommand(packageManager)
console.log(`\nRunning \`${installCommand}\`..\n`)
console.log(
(
await runCommand(installCommand, {
cwd: destPath,
})
).stdout,
)
await runCommand(installCommand, {
cwd: destPath,
spinnerMessage: `Running \`${installCommand}\`..`,
})

const relativePath = getRelativePath(repoRootPath)

Expand Down
26 changes: 23 additions & 3 deletions packages/cli/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,32 @@ import type { PackageManager, Structure } from './commands/types'

type RunCommandFunc = (
command: string,
options?: import('execa').SyncOptions,
options?: { spinnerMessage?: string } & import('execa').SyncOptions,
) => Promise<import('execa').ExecaSyncReturnValue>

export const runCommand: RunCommandFunc = async (command, options) => {
export const runCommand: RunCommandFunc = async (
command,
{ spinnerMessage, ...options } = {},
) => {
const ora = (await import('ora')).default
const spinner = spinnerMessage !== undefined ? ora(spinnerMessage) : undefined
if (spinner) {
spinner.start()
}
const execa = await import('execa')
return execa.execaCommandSync(command, options)
try {
const result = await execa.execaCommand(command, options)
if (spinner) {
spinner.succeed()
}
return result
} catch (err) {
if (spinner) {
spinner.fail()
}
// eslint-disable-next-line
throw err
}
}

export const betterPrompts = async <Model>(
Expand Down
17 changes: 5 additions & 12 deletions packages/cli/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { resolve } from 'path'
import { configDefaults, defineConfig } from 'vitest/config'
import pkg from './package.json'
const externalDependencies = ['fs', 'path', ...Object.keys(pkg.dependencies)]

// https://vitejs.dev/config/
export default defineConfig({
Expand All @@ -14,18 +16,9 @@ export default defineConfig({
formats: ['cjs'],
},
rollupOptions: {
external: [
'prompts',
'kleur',
'fs',
'os',
'path',
'walkdir',
'execa',
'node-fetch',
'commander',
'fs-extra',
],
external: (id) => {
return externalDependencies.includes(id.split('/')[0])
},
},
},
})
147 changes: 142 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1587,6 +1587,7 @@ __metadata:
fs-extra: ^11.1.0
kleur: ^4.1.5
node-fetch: ^3.3.0
ora: 6.3.1
prompts: ^2.4.2
temp-dir: 3.0.0
vite: ^4.2.2
Expand Down Expand Up @@ -3107,13 +3108,31 @@ __metadata:
languageName: node
linkType: hard

"base64-js@npm:^1.3.1":
version: 1.5.1
resolution: "base64-js@npm:1.5.1"
checksum: 669632eb3745404c2f822a18fc3a0122d2f9a7a13f7fb8b5823ee19d1d2ff9ee5b52c53367176ea4ad093c332fd5ab4bd0ebae5a8e27917a4105a4cfc86b1005
languageName: node
linkType: hard

"binary-extensions@npm:^2.0.0":
version: 2.2.0
resolution: "binary-extensions@npm:2.2.0"
checksum: ccd267956c58d2315f5d3ea6757cf09863c5fc703e50fbeb13a7dc849b812ef76e3cf9ca8f35a0c48498776a7478d7b4a0418e1e2b8cb9cb9731f2922aaad7f8
languageName: node
linkType: hard

"bl@npm:^5.0.0":
version: 5.1.0
resolution: "bl@npm:5.1.0"
dependencies:
buffer: ^6.0.3
inherits: ^2.0.4
readable-stream: ^3.4.0
checksum: a7a438ee0bc540e80b8eb68cc1ad759a9c87df06874a99411d701d01cc0b36f30cd20050512ac3e77090138890960e07bfee724f3ee6619bb39a569f5cc3b1bc
languageName: node
linkType: hard

"boolbase@npm:^1.0.0":
version: 1.0.0
resolution: "boolbase@npm:1.0.0"
Expand Down Expand Up @@ -3188,6 +3207,16 @@ __metadata:
languageName: node
linkType: hard

"buffer@npm:^6.0.3":
version: 6.0.3
resolution: "buffer@npm:6.0.3"
dependencies:
base64-js: ^1.3.1
ieee754: ^1.2.1
checksum: 5ad23293d9a731e4318e420025800b42bf0d264004c0286c8cc010af7a270c7a0f6522e84f54b9ad65cbd6db20b8badbfd8d2ebf4f80fa03dab093b89e68c3f9
languageName: node
linkType: hard

"builtin-modules@npm:^3.3.0":
version: 3.3.0
resolution: "builtin-modules@npm:3.3.0"
Expand Down Expand Up @@ -3289,7 +3318,7 @@ __metadata:
languageName: node
linkType: hard

"chalk@npm:^5.2.0":
"chalk@npm:^5.0.0, chalk@npm:^5.2.0":
version: 5.3.0
resolution: "chalk@npm:5.3.0"
checksum: 623922e077b7d1e9dedaea6f8b9e9352921f8ae3afe739132e0e00c275971bdd331268183b2628cf4ab1727c45ea1f28d7e24ac23ce1db1eb653c414ca8a5a80
Expand Down Expand Up @@ -3357,6 +3386,22 @@ __metadata:
languageName: node
linkType: hard

"cli-cursor@npm:^4.0.0":
version: 4.0.0
resolution: "cli-cursor@npm:4.0.0"
dependencies:
restore-cursor: ^4.0.0
checksum: ab3f3ea2076e2176a1da29f9d64f72ec3efad51c0960898b56c8a17671365c26e67b735920530eaf7328d61f8bd41c27f46b9cf6e4e10fe2fa44b5e8c0e392cc
languageName: node
linkType: hard

"cli-spinners@npm:^2.6.1":
version: 2.9.0
resolution: "cli-spinners@npm:2.9.0"
checksum: a9c56e1f44457d4a9f4f535364e729cb8726198efa9e98990cfd9eda9e220dfa4ba12f92808d1be5e29029cdfead781db82dc8549b97b31c907d55f96aa9b0e2
languageName: node
linkType: hard

"cliui@npm:^8.0.1":
version: 8.0.1
resolution: "cliui@npm:8.0.1"
Expand All @@ -3368,6 +3413,13 @@ __metadata:
languageName: node
linkType: hard

"clone@npm:^1.0.2":
version: 1.0.4
resolution: "clone@npm:1.0.4"
checksum: d06418b7335897209e77bdd430d04f882189582e67bd1f75a04565f3f07f5b3f119a9d670c943b6697d0afb100f03b866b3b8a1f91d4d02d72c4ecf2bb64b5dd
languageName: node
linkType: hard

"clsx@npm:^1.2.1":
version: 1.2.1
resolution: "clsx@npm:1.2.1"
Expand Down Expand Up @@ -3659,6 +3711,15 @@ __metadata:
languageName: node
linkType: hard

"defaults@npm:^1.0.3":
version: 1.0.4
resolution: "defaults@npm:1.0.4"
dependencies:
clone: ^1.0.2
checksum: 3a88b7a587fc076b84e60affad8b85245c01f60f38fc1d259e7ac1d89eb9ce6abb19e27215de46b98568dd5bc48471730b327637e6f20b0f1bc85cf00440c80a
languageName: node
linkType: hard

"define-properties@npm:^1.1.3, define-properties@npm:^1.1.4, define-properties@npm:^1.2.0":
version: 1.2.0
resolution: "define-properties@npm:1.2.0"
Expand Down Expand Up @@ -5574,6 +5635,13 @@ __metadata:
languageName: node
linkType: hard

"ieee754@npm:^1.2.1":
version: 1.2.1
resolution: "ieee754@npm:1.2.1"
checksum: 5144c0c9815e54ada181d80a0b810221a253562422e7c6c3a60b1901154184f49326ec239d618c416c1c5945a2e197107aee8d986a3dd836b53dffefd99b5e7e
languageName: node
linkType: hard

"ignore@npm:^5.2.0, ignore@npm:^5.2.4":
version: 5.2.4
resolution: "ignore@npm:5.2.4"
Expand Down Expand Up @@ -5641,7 +5709,7 @@ __metadata:
languageName: node
linkType: hard

"inherits@npm:2, inherits@npm:^2.0.3":
"inherits@npm:2, inherits@npm:^2.0.3, inherits@npm:^2.0.4":
version: 2.0.4
resolution: "inherits@npm:2.0.4"
checksum: 4a48a733847879d6cf6691860a6b1e3f0f4754176e4d71494c41f3475553768b10f84b5ce1d40fbd0e34e6bfbb864ee35858ad4dd2cf31e02fc4a154b724d7f1
Expand Down Expand Up @@ -5776,6 +5844,13 @@ __metadata:
languageName: node
linkType: hard

"is-interactive@npm:^2.0.0":
version: 2.0.0
resolution: "is-interactive@npm:2.0.0"
checksum: e8d52ad490bed7ae665032c7675ec07732bbfe25808b0efbc4d5a76b1a1f01c165f332775c63e25e9a03d319ebb6b24f571a9e902669fc1e40b0a60b5be6e26c
languageName: node
linkType: hard

"is-lambda@npm:^1.0.1":
version: 1.0.1
resolution: "is-lambda@npm:1.0.1"
Expand Down Expand Up @@ -5891,6 +5966,13 @@ __metadata:
languageName: node
linkType: hard

"is-unicode-supported@npm:^1.1.0":
version: 1.3.0
resolution: "is-unicode-supported@npm:1.3.0"
checksum: 20a1fc161afafaf49243551a5ac33b6c4cf0bbcce369fcd8f2951fbdd000c30698ce320de3ee6830497310a8f41880f8066d440aa3eb0a853e2aa4836dd89abc
languageName: node
linkType: hard

"is-weakref@npm:^1.0.2":
version: 1.0.2
resolution: "is-weakref@npm:1.0.2"
Expand Down Expand Up @@ -6697,6 +6779,16 @@ __metadata:
languageName: node
linkType: hard

"log-symbols@npm:^5.1.0":
version: 5.1.0
resolution: "log-symbols@npm:5.1.0"
dependencies:
chalk: ^5.0.0
is-unicode-supported: ^1.1.0
checksum: 7291b6e7f1b3df6865bdaeb9b59605c832668ac2fa0965c63b1e7dd3700349aec09c1d7d40c368d5041ff58b7f89461a56e4009471921301af7b3609cbff9a29
languageName: node
linkType: hard

"loose-envify@npm:^1.1.0, loose-envify@npm:^1.4.0":
version: 1.4.0
resolution: "loose-envify@npm:1.4.0"
Expand Down Expand Up @@ -7267,7 +7359,7 @@ __metadata:
languageName: node
linkType: hard

"onetime@npm:^5.1.2":
"onetime@npm:^5.1.0, onetime@npm:^5.1.2":
version: 5.1.2
resolution: "onetime@npm:5.1.2"
dependencies:
Expand Down Expand Up @@ -7299,6 +7391,23 @@ __metadata:
languageName: node
linkType: hard

"ora@npm:6.3.1":
version: 6.3.1
resolution: "ora@npm:6.3.1"
dependencies:
chalk: ^5.0.0
cli-cursor: ^4.0.0
cli-spinners: ^2.6.1
is-interactive: ^2.0.0
is-unicode-supported: ^1.1.0
log-symbols: ^5.1.0
stdin-discarder: ^0.1.0
strip-ansi: ^7.0.1
wcwidth: ^1.0.1
checksum: 474c0596a35c1be1e836bb836bea8a2d9e37458fc63b020e1435c8fe2030ab224454bfb263618e3ec09fcab2008dd525e9047f4c61548c4ace7b6490a766fc1c
languageName: node
linkType: hard

"p-limit@npm:^2.2.0":
version: 2.3.0
resolution: "p-limit@npm:2.3.0"
Expand Down Expand Up @@ -7719,7 +7828,7 @@ __metadata:
languageName: node
linkType: hard

"readable-stream@npm:^3.6.0":
"readable-stream@npm:^3.4.0, readable-stream@npm:^3.6.0":
version: 3.6.2
resolution: "readable-stream@npm:3.6.2"
dependencies:
Expand Down Expand Up @@ -7880,6 +7989,16 @@ __metadata:
languageName: node
linkType: hard

"restore-cursor@npm:^4.0.0":
version: 4.0.0
resolution: "restore-cursor@npm:4.0.0"
dependencies:
onetime: ^5.1.0
signal-exit: ^3.0.2
checksum: 5b675c5a59763bf26e604289eab35711525f11388d77f409453904e1e69c0d37ae5889295706b2c81d23bd780165084d040f9b68fffc32cc921519031c4fa4af
languageName: node
linkType: hard

"retry@npm:^0.12.0":
version: 0.12.0
resolution: "retry@npm:0.12.0"
Expand Down Expand Up @@ -8084,7 +8203,7 @@ __metadata:
languageName: node
linkType: hard

"signal-exit@npm:^3.0.3, signal-exit@npm:^3.0.7":
"signal-exit@npm:^3.0.2, signal-exit@npm:^3.0.3, signal-exit@npm:^3.0.7":
version: 3.0.7
resolution: "signal-exit@npm:3.0.7"
checksum: a2f098f247adc367dffc27845853e9959b9e88b01cb301658cfe4194352d8d2bb32e18467c786a7fe15f1d44b233ea35633d076d5e737870b7139949d1ab6318
Expand Down Expand Up @@ -8212,6 +8331,15 @@ __metadata:
languageName: node
linkType: hard

"stdin-discarder@npm:^0.1.0":
version: 0.1.0
resolution: "stdin-discarder@npm:0.1.0"
dependencies:
bl: ^5.0.0
checksum: 85131f70ae2830144133b7a6211d56f9ac2603573f4af3d0b66e828af5e13fcdea351f9192f86bb7fed2c64604c8097bf36d50cb77d54e898ce4604c3b7b6b8f
languageName: node
linkType: hard

"stream-combiner@npm:~0.0.4":
version: 0.0.4
resolution: "stream-combiner@npm:0.0.4"
Expand Down Expand Up @@ -9243,6 +9371,15 @@ __metadata:
languageName: node
linkType: hard

"wcwidth@npm:^1.0.1":
version: 1.0.1
resolution: "wcwidth@npm:1.0.1"
dependencies:
defaults: ^1.0.3
checksum: 814e9d1ddcc9798f7377ffa448a5a3892232b9275ebb30a41b529607691c0491de47cba426e917a4d08ded3ee7e9ba2f3fe32e62ee3cd9c7d3bafb7754bd553c
languageName: node
linkType: hard

"web-streams-polyfill@npm:^3.0.3":
version: 3.2.1
resolution: "web-streams-polyfill@npm:3.2.1"
Expand Down

1 comment on commit c1dbd85

@vercel
Copy link

@vercel vercel bot commented on c1dbd85 Aug 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.