Skip to content

Commit 61b93a6

Browse files
committed
refactor: improve installation progress
1 parent f0ad260 commit 61b93a6

File tree

6 files changed

+45
-60
lines changed

6 files changed

+45
-60
lines changed

packages/@vue/cli-plugin-unit-mocha/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"execa": "^0.9.0",
2525
"jsdom": "^11.6.1",
2626
"jsdom-global": "^3.0.2",
27-
"mocha": "^5.0.0",
27+
"mocha": "^4.1.0",
2828
"mocha-webpack": "^1.0.1",
2929
"webpack-node-externals": "^1.6.0"
3030
},

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

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
const path = require('path')
21
const chalk = require('chalk')
32
const debug = require('debug')
43
const execa = require('execa')
4+
const axios = require('axios')
55
const resolve = require('resolve')
66
const inquirer = require('inquirer')
77
const Generator = require('./Generator')
@@ -85,36 +85,52 @@ module.exports = class Creator {
8585
(hasYarn ? 'yarn' : 'npm')
8686
)
8787

88-
// write base package.json to disk
8988
clearConsole()
90-
logWithSpinner('✨', `Creating project in ${chalk.yellow(context)}.`)
89+
logWithSpinner(`✨`, `Creating project in ${chalk.yellow(context)}.`)
90+
91+
// get latest CLI version
92+
let latestCLIVersion
93+
if (!isTestOrDebug) {
94+
const res = await axios.get(`https://registry.npmjs.org/@vue%2Fcli/`)
95+
latestCLIVersion = res.data['dist-tags'].latest
96+
} else {
97+
latestCLIVersion = require('../package.json').version
98+
}
99+
// generate package.json with plugin dependencies
100+
const pkg = {
101+
name,
102+
version: '0.1.0',
103+
private: true,
104+
devDependencies: {}
105+
}
106+
const deps = Object.keys(options.plugins)
107+
deps.forEach(dep => {
108+
pkg.devDependencies[dep] = `^${latestCLIVersion}`
109+
})
110+
// write package.json
91111
await writeFileTree(context, {
92-
'package.json': JSON.stringify({
93-
name,
94-
version: '0.1.0',
95-
private: true
96-
}, null, 2)
112+
'package.json': JSON.stringify(pkg, null, 2)
97113
})
98114

99-
// intilaize git repository
115+
// intilaize git repository before installing deps
116+
// so that vue-cli-service can setup git hooks.
100117
if (hasGit) {
101-
logWithSpinner('🗃', `Initializing git repository...`)
118+
logWithSpinner(`🗃`, `Initializing git repository...`)
102119
await run('git init')
103120
}
104121

105122
// install plugins
106-
logWithSpinner('⚙', `Installing CLI plugins. This might take a while...`)
107-
const deps = Object.keys(options.plugins)
123+
stopSpinner()
124+
log(`⚙ Installing CLI plugins. This might take a while...`)
108125
if (isTestOrDebug) {
109126
// in development, avoid installation process
110-
await setupDevProject(context, deps)
127+
await setupDevProject(context)
111128
} else {
112-
await installDeps(context, packageManager, deps, cliOptions.registry)
129+
await installDeps(context, packageManager, cliOptions.registry)
113130
}
114131

115132
// run generator
116-
logWithSpinner('🚀', `Invoking generators...`)
117-
const pkg = require(path.join(context, 'package.json'))
133+
log(`🚀 Invoking generators...`)
118134
const plugins = this.resolvePlugins(options.plugins)
119135
const generator = new Generator(
120136
context,
@@ -125,9 +141,9 @@ module.exports = class Creator {
125141
await generator.generate()
126142

127143
// install additional deps (injected by generators)
128-
logWithSpinner('📦', `Installing additional dependencies...`)
144+
log(`📦 Installing additional dependencies...`)
129145
if (!isTestOrDebug) {
130-
await installDeps(context, packageManager, null, cliOptions.registry)
146+
await installDeps(context, packageManager, cliOptions.registry)
131147
}
132148

133149
// run complete cbs if any (injected by generators)

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

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -74,17 +74,12 @@ const shouldUseTaobao = async (command) => {
7474
return save(useTaobaoRegistry)
7575
}
7676

77-
module.exports = async function installDeps (targetDir, command, deps, cliRegistry) {
77+
module.exports = async function installDeps (targetDir, command, cliRegistry) {
7878
const args = []
7979
if (command === 'npm') {
8080
args.push('install', '--loglevel', 'error')
81-
if (deps) {
82-
args.push('--save-dev')
83-
}
8481
} else if (command === 'yarn') {
85-
if (deps) {
86-
args.push('add', '--dev')
87-
}
82+
// do nothing
8883
} else {
8984
throw new Error(`unknown package manager: ${command}`)
9085
}
@@ -104,30 +99,18 @@ module.exports = async function installDeps (targetDir, command, deps, cliRegist
10499
}
105100
}
106101

107-
if (deps) {
108-
args.push.apply(args, deps)
109-
}
110-
111102
debug(`command: `, command)
112103
debug(`args: `, args)
113104

114105
await new Promise((resolve, reject) => {
115106
const child = execa(command, args, {
116107
cwd: targetDir,
117-
stdio: 'pipe'
118-
})
119-
120-
let stderr = ''
121-
child.stderr.on('data', buf => {
122-
stderr += buf.toString()
108+
stdio: 'inherit'
123109
})
124110

125111
child.on('close', code => {
126112
if (code !== 0) {
127-
reject(
128-
`command failed: ${command} ${args.join(' ')}\n` +
129-
stderr
130-
)
113+
reject(`command failed: ${command} ${args.join(' ')}`)
131114
return
132115
}
133116
resolve()

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

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,9 @@
11
// dev only
22

3-
const fs = require('fs')
43
const path = require('path')
54
const { linkBin } = require('@vue/cli-shared-utils')
65

7-
module.exports = function setupDevProject (targetDir, deps) {
8-
const pkg = require(path.resolve(targetDir, 'package.json'))
9-
pkg.devDependencies = {}
10-
deps.forEach(dep => {
11-
pkg.devDependencies[dep] = require(path.resolve(
12-
__dirname,
13-
'../../../../',
14-
dep,
15-
'package.json'
16-
)).version
17-
})
18-
fs.writeFileSync(
19-
path.resolve(targetDir, 'package.json'),
20-
JSON.stringify(pkg, null, 2)
21-
)
6+
module.exports = function setupDevProject (targetDir) {
227
return linkBin(
238
require.resolve('@vue/cli-service/bin/vue-cli-service'),
249
path.join(targetDir, 'node_modules', '.bin', 'vue-cli-service')

packages/@vue/cli/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
},
2929
"dependencies": {
3030
"@vue/cli-shared-utils": "^3.0.0-alpha.3",
31+
"axios": "^0.17.1",
3132
"chalk": "^2.3.0",
3233
"commander": "^2.12.2",
3334
"ejs": "^2.5.7",

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3491,7 +3491,7 @@ eslint-plugin-vue-libs@^2.1.0:
34913491
dependencies:
34923492
eslint-plugin-html "^4.0.1"
34933493

3494-
eslint-plugin-vue@^4.0.0, eslint-plugin-vue@^4.2.0:
3494+
eslint-plugin-vue@^4.2.0:
34953495
version "4.2.0"
34963496
resolved "https://registry.yarnpkg.com/eslint-plugin-vue/-/eslint-plugin-vue-4.2.0.tgz#25fade387bf9a97377cf0e5cd17ef0d60ac9da57"
34973497
dependencies:
@@ -10058,9 +10058,9 @@ vue-hot-reload-api@^2.2.0:
1005810058
version "2.2.4"
1005910059
resolved "https://registry.yarnpkg.com/vue-hot-reload-api/-/vue-hot-reload-api-2.2.4.tgz#683bd1d026c0d3b3c937d5875679e9a87ec6cd8f"
1006010060

10061-
vue-jest@vuejs/vue-jest#master:
10062-
version "1.4.0"
10063-
resolved "https://codeload.github.com/vuejs/vue-jest/tar.gz/6ad9553e7d8cf27aec69c96c2681075aa8504c68"
10061+
vue-jest@^2.0.0:
10062+
version "2.0.0"
10063+
resolved "https://registry.yarnpkg.com/vue-jest/-/vue-jest-2.0.0.tgz#fd85ffde96d1ea8640a240fa898f7cc55464cb2e"
1006410064
dependencies:
1006510065
babel-plugin-transform-es2015-modules-commonjs "^6.26.0"
1006610066
chalk "^2.1.0"

0 commit comments

Comments
 (0)