@@ -9,12 +9,46 @@ const isString = val => typeof val === 'string'
9
9
const isFunction = val => typeof val === 'function'
10
10
const isObject = val => val && typeof val === 'object'
11
11
12
+ // get link for a 3rd party plugin.
13
+ function getLink ( id ) {
14
+ let pkg = { }
15
+ try {
16
+ pkg = require ( `${ id } /package.json` )
17
+ } catch ( e ) { }
18
+ return (
19
+ pkg . homepage ||
20
+ ( pkg . repository && pkg . repository . url ) ||
21
+ `https://www.npmjs.com/package/${ id . replace ( `/` , `%2F` ) } `
22
+ )
23
+ }
24
+
12
25
module . exports = class GeneratorAPI {
13
26
constructor ( id , generator , options , rootOptions ) {
14
27
this . id = id
15
28
this . generator = generator
16
29
this . options = options
17
30
this . rootOptions = rootOptions
31
+
32
+ this . pluginsData = generator . plugins
33
+ . filter ( ( { id } ) => id !== `@vue/cli-service` )
34
+ . map ( ( { id } ) => {
35
+ const name = id . replace ( / ^ ( @ v u e | v u e - ) \/ c l i - p l u g i n - / , '' )
36
+ const isOfficial = / ^ @ v u e / . test ( id )
37
+ return {
38
+ name : name ,
39
+ link : isOfficial
40
+ ? `https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-${ name } `
41
+ : getLink ( id )
42
+ }
43
+ } )
44
+ }
45
+
46
+ _resolveData ( additionalData ) {
47
+ return Object . assign ( {
48
+ options : this . options ,
49
+ rootOptions : this . rootOptions ,
50
+ plugins : this . pluginsData
51
+ } , additionalData )
18
52
}
19
53
20
54
injectFileMiddleware ( middleware ) {
@@ -52,10 +86,7 @@ module.exports = class GeneratorAPI {
52
86
if ( isString ( fileDir ) ) {
53
87
fileDir = path . resolve ( baseDir , fileDir )
54
88
this . injectFileMiddleware ( async ( files ) => {
55
- const data = Object . assign ( {
56
- options : this . options ,
57
- rootOptions : this . rootOptions
58
- } , additionalData )
89
+ const data = this . _resolveData ( additionalData )
59
90
const _files = await globby ( [ '**/*' ] , { cwd : fileDir } )
60
91
for ( const rawPath of _files ) {
61
92
let filename = path . basename ( rawPath )
@@ -75,10 +106,7 @@ module.exports = class GeneratorAPI {
75
106
} )
76
107
} else if ( isObject ( fileDir ) ) {
77
108
this . injectFileMiddleware ( files => {
78
- const data = Object . assign ( {
79
- options : this . options ,
80
- rootOptions : this . rootOptions
81
- } , additionalData )
109
+ const data = this . _resolveData ( additionalData )
82
110
for ( const targetPath in fileDir ) {
83
111
const sourcePath = path . resolve ( baseDir , fileDir [ targetPath ] )
84
112
const content = renderFile ( sourcePath , data , ejsOptions )
0 commit comments