1
1
const chalk = require ( 'chalk' )
2
2
const semver = require ( 'semver' )
3
3
const invoke = require ( './invoke' )
4
+ const inquirer = require ( 'inquirer' )
5
+ const { loadModule } = require ( '@vue/cli-shared-utils' )
4
6
5
7
const PackageManager = require ( './util/ProjectPackageManager' )
6
8
const {
@@ -16,6 +18,18 @@ async function add (pluginName, options = {}, context = process.cwd()) {
16
18
return
17
19
}
18
20
21
+ // for `vue add` command in 3.x projects
22
+ const servicePkg = loadModule ( '@vue/cli-service/package.json' , context )
23
+ if ( semver . satisfies ( servicePkg . version , '3.x' ) ) {
24
+ // special internal "plugins"
25
+ if ( / ^ ( @ v u e \/ ) ? r o u t e r $ / . test ( pluginName ) ) {
26
+ return addRouter ( context )
27
+ }
28
+ if ( / ^ ( @ v u e \/ ) ? v u e x $ / . test ( pluginName ) ) {
29
+ return addVuex ( context )
30
+ }
31
+ }
32
+
19
33
const packageName = resolvePluginId ( pluginName )
20
34
21
35
log ( )
@@ -45,3 +59,23 @@ module.exports = (...args) => {
45
59
}
46
60
} )
47
61
}
62
+
63
+ async function addRouter ( context ) {
64
+ const options = await inquirer . prompt ( [ {
65
+ name : 'routerHistoryMode' ,
66
+ type : 'confirm' ,
67
+ message : `Use history mode for router? ${ chalk . yellow ( `(Requires proper server setup for index fallback in production)` ) } `
68
+ } ] )
69
+ invoke . runGenerator ( context , {
70
+ id : 'core:router' ,
71
+ apply : loadModule ( '@vue/cli-service/generator/router' , context ) ,
72
+ options
73
+ } )
74
+ }
75
+
76
+ async function addVuex ( context ) {
77
+ invoke . runGenerator ( context , {
78
+ id : 'core:vuex' ,
79
+ apply : loadModule ( '@vue/cli-service/generator/vuex' , context )
80
+ } )
81
+ }
0 commit comments