1- const path = require ( 'path' )
21const chalk = require ( 'chalk' )
32const debug = require ( 'debug' )
43const execa = require ( 'execa' )
4+ const axios = require ( 'axios' )
55const resolve = require ( 'resolve' )
66const inquirer = require ( 'inquirer' )
77const 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)
0 commit comments