1
- const path = require ( 'path' )
2
1
const chalk = require ( 'chalk' )
3
2
const debug = require ( 'debug' )
4
3
const execa = require ( 'execa' )
4
+ const axios = require ( 'axios' )
5
5
const resolve = require ( 'resolve' )
6
6
const inquirer = require ( 'inquirer' )
7
7
const Generator = require ( './Generator' )
@@ -85,36 +85,52 @@ module.exports = class Creator {
85
85
( hasYarn ? 'yarn' : 'npm' )
86
86
)
87
87
88
- // write base package.json to disk
89
88
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
91
111
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 )
97
113
} )
98
114
99
- // intilaize git repository
115
+ // intilaize git repository before installing deps
116
+ // so that vue-cli-service can setup git hooks.
100
117
if ( hasGit ) {
101
- logWithSpinner ( '🗃' , `Initializing git repository...` )
118
+ logWithSpinner ( `🗃` , `Initializing git repository...` )
102
119
await run ( 'git init' )
103
120
}
104
121
105
122
// 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...` )
108
125
if ( isTestOrDebug ) {
109
126
// in development, avoid installation process
110
- await setupDevProject ( context , deps )
127
+ await setupDevProject ( context )
111
128
} else {
112
- await installDeps ( context , packageManager , deps , cliOptions . registry )
129
+ await installDeps ( context , packageManager , cliOptions . registry )
113
130
}
114
131
115
132
// run generator
116
- logWithSpinner ( '🚀' , `Invoking generators...` )
117
- const pkg = require ( path . join ( context , 'package.json' ) )
133
+ log ( `🚀 Invoking generators...` )
118
134
const plugins = this . resolvePlugins ( options . plugins )
119
135
const generator = new Generator (
120
136
context ,
@@ -125,9 +141,9 @@ module.exports = class Creator {
125
141
await generator . generate ( )
126
142
127
143
// install additional deps (injected by generators)
128
- logWithSpinner ( '📦' , ` Installing additional dependencies...`)
144
+ log ( `📦 Installing additional dependencies...`)
129
145
if ( ! isTestOrDebug ) {
130
- await installDeps ( context , packageManager , null , cliOptions . registry )
146
+ await installDeps ( context , packageManager , cliOptions . registry )
131
147
}
132
148
133
149
// run complete cbs if any (injected by generators)
0 commit comments