@@ -9,12 +9,46 @@ const isString = val => typeof val === 'string'
99const isFunction = val => typeof val === 'function'
1010const isObject = val => val && typeof val === 'object'
1111
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+
1225module . exports = class GeneratorAPI {
1326 constructor ( id , generator , options , rootOptions ) {
1427 this . id = id
1528 this . generator = generator
1629 this . options = options
1730 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 )
1852 }
1953
2054 injectFileMiddleware ( middleware ) {
@@ -52,10 +86,7 @@ module.exports = class GeneratorAPI {
5286 if ( isString ( fileDir ) ) {
5387 fileDir = path . resolve ( baseDir , fileDir )
5488 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 )
5990 const _files = await globby ( [ '**/*' ] , { cwd : fileDir } )
6091 for ( const rawPath of _files ) {
6192 let filename = path . basename ( rawPath )
@@ -75,10 +106,7 @@ module.exports = class GeneratorAPI {
75106 } )
76107 } else if ( isObject ( fileDir ) ) {
77108 this . injectFileMiddleware ( files => {
78- const data = Object . assign ( {
79- options : this . options ,
80- rootOptions : this . rootOptions
81- } , additionalData )
109+ const data = this . _resolveData ( additionalData )
82110 for ( const targetPath in fileDir ) {
83111 const sourcePath = path . resolve ( baseDir , fileDir [ targetPath ] )
84112 const content = renderFile ( sourcePath , data , ejsOptions )
0 commit comments