Skip to content

Commit 4045a0f

Browse files
committed
tweak cli output
1 parent f6ea76c commit 4045a0f

File tree

7 files changed

+72
-51
lines changed

7 files changed

+72
-51
lines changed

packages/@vue/cli/lib/Creator.js

+12-9
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@ const os = require('os')
33
const path = require('path')
44
const chalk = require('chalk')
55
const debug = require('debug')
6+
const emoji = require('node-emoji')
67
const inquirer = require('inquirer')
78
const Generator = require('./Generator')
89
const installDeps = require('./util/installDeps')
910
const PromptModuleAPI = require('./PromptModuleAPI')
1011
const writeFileTree = require('./util/writeFileTree')
12+
const { logWithSpinner, stopSpinner } = require('./util/spinner')
1113

1214
const {
13-
info,
1415
error,
1516
hasYarn,
1617
clearConsole
@@ -53,15 +54,15 @@ module.exports = class Creator {
5354
} else if (answers.mode === 'default') {
5455
options = defaultOptions
5556
} else {
57+
// manual
5658
options = {
5759
packageManager: answers.packageManager,
5860
plugins: {}
5961
}
62+
// run cb registered by prompt modules to finalize the options
63+
this.promptCompleteCbs.forEach(cb => cb(answers, options))
6064
}
6165

62-
// run cb registered by prompt modules to finalize the options
63-
this.promptCompleteCbs.forEach(cb => cb(answers, options))
64-
6566
// save options
6667
if (answers.mode === 'manual' && answers.save) {
6768
this.saveOptions(options)
@@ -75,7 +76,7 @@ module.exports = class Creator {
7576
debug('options')(options)
7677

7778
// write base package.json to disk
78-
info(`Creating project in ${chalk.cyan(targetDir)}.`)
79+
logWithSpinner(emoji.get('sparkles'), `Creating project in ${chalk.green(targetDir)}.`)
7980
writeFileTree(targetDir, {
8081
'package.json': JSON.stringify({
8182
name,
@@ -85,7 +86,7 @@ module.exports = class Creator {
8586
})
8687

8788
// install deps
88-
info(`Installing dependencies with ${options.packageManager}. This may take a while...`)
89+
logWithSpinner(emoji.get('electric_plug'), `Installing CLI plugins. This might take a while...`)
8990
const deps = Object.keys(options.plugins)
9091
if (process.env.VUE_CLI_DEBUG) {
9192
// in development, use linked packages
@@ -95,21 +96,23 @@ module.exports = class Creator {
9596
await installDeps(options.packageManager, targetDir, deps)
9697
}
9798

99+
logWithSpinner(emoji.get('gear'), `Invoking generators...`)
98100
// run generator
99101
const generator = new Generator(targetDir, options)
100102
await generator.generate()
101103

102104
// install deps again (new deps injected by generators)
105+
logWithSpinner(emoji.get('package'), `Installing additional dependencies...`)
103106
await installDeps(options.packageManager, targetDir)
104-
105-
// TODO run vue-cli-service init
107+
stopSpinner()
108+
console.log(`${chalk.green('✔')} Successfully created project ${chalk.green(name)}.`)
106109
}
107110

108111
resolveIntroPrompts () {
109112
const modePrompt = {
110113
name: 'mode',
111114
type: 'list',
112-
message: `Hi there! Please pick a project creation mode:`,
115+
message: `Please pick a project creation mode:`,
113116
choices: [
114117
{
115118
name: 'Zero-configuration with defaults',

packages/@vue/cli/lib/Generator.js

-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ const path = require('path')
33
const debug = require('debug')
44
const resolve = require('resolve')
55
const GeneratorAPI = require('./GeneratorAPI')
6-
const { success } = require('@vue/cli-shared-utils')
76
const writeFileTree = require('./util/writeFileTree')
87

98
module.exports = class Generator {
@@ -34,7 +33,6 @@ module.exports = class Generator {
3433
this.files['package.json'] = JSON.stringify(this.pkg, null, 2)
3534
// write file tree to disk
3635
await writeFileTree(this.context, this.files)
37-
success(`Successfully generated project files.`)
3836
}
3937

4038
resolvePkg () {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = cli => {
2+
cli.onPromptComplete((answers, options) => {
3+
if (!answers.features.includes('ts')) {
4+
options.plugins['@vue/cli-plugin-babel'] = {}
5+
}
6+
})
7+
}

packages/@vue/cli/lib/util/installDeps.js

+11-3
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,21 @@ module.exports = function installDeps (command, targetDir, deps) {
2121

2222
const child = spawn(command, args, {
2323
cwd: targetDir,
24-
stdio: 'inherit'
24+
stdio: 'pipe'
2525
})
26+
27+
let stderr = ''
28+
child.stderr.on('data', buf => {
29+
stderr += buf.toString()
30+
})
31+
2632
child.on('close', code => {
2733
if (code !== 0) {
28-
return reject(
29-
`command failed: ${command} ${args.join(' ')}`
34+
reject(
35+
`command failed: ${command} ${args.join(' ')}\n` +
36+
stderr
3037
)
38+
return
3139
}
3240
resolve()
3341
})

packages/@vue/cli/lib/util/spinner.js

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
const ora = require('ora')
2+
3+
const spinner = ora()
4+
let lastMsg
5+
6+
exports.logWithSpinner = (symbol, msg) => {
7+
if (lastMsg) {
8+
spinner.stopAndPersist({
9+
symbol: lastMsg.symbol,
10+
text: lastMsg.text
11+
})
12+
}
13+
spinner.text = ' ' + msg
14+
lastMsg = {
15+
symbol: symbol + ' ',
16+
text: msg
17+
}
18+
spinner.start()
19+
}
20+
21+
exports.stopSpinner = () => {
22+
if (lastMsg) {
23+
spinner.stopAndPersist({
24+
symbol: lastMsg.symbol,
25+
text: lastMsg.text
26+
})
27+
} else {
28+
spinner.stop()
29+
}
30+
}

packages/@vue/cli/package.json

+2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
"isbinaryfile": "^3.0.2",
3636
"klaw-sync": "^3.0.2",
3737
"mkdirp": "^0.5.1",
38+
"node-emoji": "^1.8.1",
39+
"ora": "^1.3.0",
3840
"resolve": "^1.5.0",
3941
"rimraf": "^2.6.2",
4042
"semver": "^5.4.1"

yarn.lock

+10-37
Original file line numberDiff line numberDiff line change
@@ -271,10 +271,6 @@ assert@^1.1.1:
271271
dependencies:
272272
util "0.10.3"
273273

274-
assertion-error@^1.0.1:
275-
version "1.0.2"
276-
resolved "https://registry.yarnpkg.com/assertion-error/-/assertion-error-1.0.2.tgz#13ca515d86206da0bac66e834dd397d87581094c"
277-
278274
astral-regex@^1.0.0:
279275
version "1.0.0"
280276
resolved "https://registry.yarnpkg.com/astral-regex/-/astral-regex-1.0.0.tgz#6c8c3fb827dd43ee3918f27b82782ab7658a6fd9"
@@ -1207,17 +1203,6 @@ center-align@^0.1.1:
12071203
align-text "^0.1.3"
12081204
lazy-cache "^1.0.3"
12091205

1210-
chai@^4.1.2:
1211-
version "4.1.2"
1212-
resolved "https://registry.yarnpkg.com/chai/-/chai-4.1.2.tgz#0f64584ba642f0f2ace2806279f4f06ca23ad73c"
1213-
dependencies:
1214-
assertion-error "^1.0.1"
1215-
check-error "^1.0.1"
1216-
deep-eql "^3.0.0"
1217-
get-func-name "^2.0.0"
1218-
pathval "^1.0.0"
1219-
type-detect "^4.0.0"
1220-
12211206
chalk@^1.0.0, chalk@^1.1.1, chalk@^1.1.3:
12221207
version "1.1.3"
12231208
resolved "https://registry.yarnpkg.com/chalk/-/chalk-1.1.3.tgz#a8115c55e4a702fe4d150abd3872822a7e09fc98"
@@ -1240,10 +1225,6 @@ chardet@^0.4.0:
12401225
version "0.4.2"
12411226
resolved "https://registry.yarnpkg.com/chardet/-/chardet-0.4.2.tgz#b5473b33dc97c424e5d98dc87d55d4d8a29c8bf2"
12421227

1243-
check-error@^1.0.1:
1244-
version "1.0.2"
1245-
resolved "https://registry.yarnpkg.com/check-error/-/check-error-1.0.2.tgz#574d312edd88bb5dd8912e9286dd6c0aed4aac82"
1246-
12471228
chokidar@^1.6.0, chokidar@^1.6.1, chokidar@^1.7.0:
12481229
version "1.7.0"
12491230
resolved "https://registry.yarnpkg.com/chokidar/-/chokidar-1.7.0.tgz#798e689778151c8076b4b360e5edd28cda2bb468"
@@ -1935,12 +1916,6 @@ dedent@^0.7.0:
19351916
version "0.7.0"
19361917
resolved "https://registry.yarnpkg.com/dedent/-/dedent-0.7.0.tgz#2495ddbaf6eb874abb0e1be9df22d2e5a544326c"
19371918

1938-
deep-eql@^3.0.0:
1939-
version "3.0.1"
1940-
resolved "https://registry.yarnpkg.com/deep-eql/-/deep-eql-3.0.1.tgz#dfc9404400ad1c8fe023e7da1df1c147c4b444df"
1941-
dependencies:
1942-
type-detect "^4.0.0"
1943-
19441919
deep-equal@^1.0.1:
19451920
version "1.0.1"
19461921
resolved "https://registry.yarnpkg.com/deep-equal/-/deep-equal-1.0.1.tgz#f5d260292b660e084eff4cdbc9f08ad3247448b5"
@@ -2897,10 +2872,6 @@ get-caller-file@^1.0.1:
28972872
version "1.0.2"
28982873
resolved "https://registry.yarnpkg.com/get-caller-file/-/get-caller-file-1.0.2.tgz#f702e63127e7e231c160a80c1554acb70d5047e5"
28992874

2900-
get-func-name@^2.0.0:
2901-
version "2.0.0"
2902-
resolved "https://registry.yarnpkg.com/get-func-name/-/get-func-name-2.0.0.tgz#ead774abee72e20409433a066366023dd6887a41"
2903-
29042875
get-own-enumerable-property-symbols@^2.0.1:
29052876
version "2.0.1"
29062877
resolved "https://registry.yarnpkg.com/get-own-enumerable-property-symbols/-/get-own-enumerable-property-symbols-2.0.1.tgz#5c4ad87f2834c4b9b4e84549dc1e0650fb38c24b"
@@ -4425,6 +4396,10 @@ lodash.templatesettings@^4.0.0:
44254396
dependencies:
44264397
lodash._reinterpolate "~3.0.0"
44274398

4399+
lodash.toarray@^4.4.0:
4400+
version "4.4.0"
4401+
resolved "https://registry.yarnpkg.com/lodash.toarray/-/lodash.toarray-4.4.0.tgz#24c4bfcd6b2fba38bfd0594db1179d8e9b656561"
4402+
44284403
lodash.uniq@^4.5.0:
44294404
version "4.5.0"
44304405
resolved "https://registry.yarnpkg.com/lodash.uniq/-/lodash.uniq-4.5.0.tgz#d0225373aeb652adc1bc82e4945339a842754773"
@@ -4769,6 +4744,12 @@ no-case@^2.2.0:
47694744
dependencies:
47704745
lower-case "^1.1.1"
47714746

4747+
node-emoji@^1.8.1:
4748+
version "1.8.1"
4749+
resolved "https://registry.yarnpkg.com/node-emoji/-/node-emoji-1.8.1.tgz#6eec6bfb07421e2148c75c6bba72421f8530a826"
4750+
dependencies:
4751+
lodash.toarray "^4.4.0"
4752+
47724753
47734754
version "0.6.33"
47744755
resolved "https://registry.yarnpkg.com/node-forge/-/node-forge-0.6.33.tgz#463811879f573d45155ad6a9f43dc296e8e85ebc"
@@ -5226,10 +5207,6 @@ path-type@^3.0.0:
52265207
dependencies:
52275208
pify "^3.0.0"
52285209

5229-
pathval@^1.0.0:
5230-
version "1.1.0"
5231-
resolved "https://registry.yarnpkg.com/pathval/-/pathval-1.1.0.tgz#b942e6d4bde653005ef6b71361def8727d0645e0"
5232-
52335210
pbkdf2@^3.0.3:
52345211
version "3.0.14"
52355212
resolved "https://registry.yarnpkg.com/pbkdf2/-/pbkdf2-3.0.14.tgz#a35e13c64799b06ce15320f459c230e68e73bade"
@@ -6829,10 +6806,6 @@ type-check@~0.3.2:
68296806
dependencies:
68306807
prelude-ls "~1.1.2"
68316808

6832-
type-detect@^4.0.0:
6833-
version "4.0.5"
6834-
resolved "https://registry.yarnpkg.com/type-detect/-/type-detect-4.0.5.tgz#d70e5bc81db6de2a381bcaca0c6e0cbdc7635de2"
6835-
68366809
type-is@~1.6.15:
68376810
version "1.6.15"
68386811
resolved "https://registry.yarnpkg.com/type-is/-/type-is-1.6.15.tgz#cab10fb4909e441c82842eafe1ad646c81804410"

0 commit comments

Comments
 (0)