@@ -3,9 +3,13 @@ const path = require('path')
3
3
const chalk = require ( 'chalk' )
4
4
const resolve = require ( 'resolve' )
5
5
const Generator = require ( './Generator' )
6
+ const { loadOptions } = require ( './options' )
7
+ const installDeps = require ( './util/installDeps' )
8
+ const clearConsole = require ( './util/clearConsole' )
6
9
const {
7
10
log,
8
11
error,
12
+ hasYarn,
9
13
logWithSpinner,
10
14
stopSpinner
11
15
} = require ( '@vue/cli-shared-utils' )
@@ -58,13 +62,25 @@ async function invoke (pluginName, options) {
58
62
createCompleteCbs
59
63
)
60
64
65
+ clearConsole ( )
66
+ logWithSpinner ( '🚀' , `Invoking generator for ${ resolvedPluginName } ...` )
61
67
await generator . generate ( )
62
68
63
- // TODO check if package.json was changed,
64
- // if yes installDeps
65
- logWithSpinner ( '📦' , `Installing additional dependencies...` )
69
+ const isTestOrDebug = process . env . VUE_CLI_TEST || process . env . VUE_CLI_DEBUG
70
+ const newDeps = generator . pkg . dependencies
71
+ const newDevDeps = generator . pkg . devDependencies
72
+ const depsChanged = (
73
+ JSON . stringify ( newDeps ) !== JSON . stringify ( pkg . dependencies ) ||
74
+ JSON . stringify ( newDevDeps ) !== JSON . stringify ( pkg . devDependencies )
75
+ )
76
+
77
+ if ( ! isTestOrDebug && depsChanged ) {
78
+ logWithSpinner ( '📦' , `Installing additional dependencies...` )
79
+ const packageManager = loadOptions ( ) . packageManager || ( hasYarn ? 'yarn' : 'npm' )
80
+ await installDeps ( context , packageManager )
81
+ }
66
82
67
- if ( createCompleteCbs . lenght ) {
83
+ if ( createCompleteCbs . length ) {
68
84
logWithSpinner ( '⚓' , `Running completion hooks...` )
69
85
for ( const cb of createCompleteCbs ) {
70
86
await cb ( )
@@ -73,8 +89,8 @@ async function invoke (pluginName, options) {
73
89
74
90
stopSpinner ( )
75
91
log ( )
76
- log ( ` Successfully invoked generator for plugin: ${ chalk . cyan ( resolvedPluginName ) } ` )
77
- log ( ` You should review and commit the changes.` )
92
+ log ( ` Successfully invoked generator for plugin: ${ chalk . cyan ( resolvedPluginName ) } ` )
93
+ log ( ` You should review and commit the changes.` )
78
94
log ( )
79
95
}
80
96
0 commit comments