@@ -4,6 +4,7 @@ const execa = require('execa')
4
4
const chalk = require ( 'chalk' )
5
5
const globby = require ( 'globby' )
6
6
const inquirer = require ( 'inquirer' )
7
+ const isBinary = require ( 'isbinaryfile' )
7
8
const Generator = require ( './Generator' )
8
9
const { loadOptions } = require ( './options' )
9
10
const { installDeps } = require ( './util/installDeps' )
@@ -27,7 +28,10 @@ async function readFiles (context) {
27
28
} )
28
29
const res = { }
29
30
for ( const file of files ) {
30
- res [ file ] = fs . readFileSync ( path . resolve ( context , file ) , 'utf-8' )
31
+ const name = path . resolve ( context , file )
32
+ res [ file ] = isBinary . sync ( name )
33
+ ? fs . readFileSync ( name )
34
+ : fs . readFileSync ( name , 'utf-8' )
31
35
}
32
36
return res
33
37
}
@@ -48,11 +52,11 @@ async function invoke (pluginName, options = {}, context = process.cwd()) {
48
52
if ( ! deps ) return
49
53
let name
50
54
// official
51
- if ( deps [ name = `@vue/cli-plugin-${ pluginName } ` ] ) {
55
+ if ( deps [ ( name = `@vue/cli-plugin-${ pluginName } ` ) ] ) {
52
56
return name
53
57
}
54
58
// full id, scoped short, or default short
55
- if ( deps [ name = resolvePluginId ( pluginName ) ] ) {
59
+ if ( deps [ ( name = resolvePluginId ( pluginName ) ) ] ) {
56
60
return name
57
61
}
58
62
}
@@ -61,7 +65,7 @@ async function invoke (pluginName, options = {}, context = process.cwd()) {
61
65
if ( ! id ) {
62
66
throw new Error (
63
67
`Cannot resolve plugin ${ chalk . yellow ( pluginName ) } from package.json. ` +
64
- `Did you forget to install it?`
68
+ `Did you forget to install it?`
65
69
)
66
70
}
67
71
@@ -102,14 +106,14 @@ async function invoke (pluginName, options = {}, context = process.cwd()) {
102
106
103
107
const newDeps = generator . pkg . dependencies
104
108
const newDevDeps = generator . pkg . devDependencies
105
- const depsChanged = (
109
+ const depsChanged =
106
110
JSON . stringify ( newDeps ) !== JSON . stringify ( pkg . dependencies ) ||
107
111
JSON . stringify ( newDevDeps ) !== JSON . stringify ( pkg . devDependencies )
108
- )
109
112
110
113
if ( ! isTestOrDebug && depsChanged ) {
111
114
logWithSpinner ( '📦' , `Installing additional dependencies...` )
112
- const packageManager = loadOptions ( ) . packageManager || ( hasYarn ( ) ? 'yarn' : 'npm' )
115
+ const packageManager =
116
+ loadOptions ( ) . packageManager || ( hasYarn ( ) ? 'yarn' : 'npm' )
113
117
await installDeps ( context , packageManager )
114
118
}
115
119
@@ -125,14 +129,30 @@ async function invoke (pluginName, options = {}, context = process.cwd()) {
125
129
log ( )
126
130
log ( ` Successfully invoked generator for plugin: ${ chalk . cyan ( id ) } ` )
127
131
if ( ! process . env . VUE_CLI_TEST && hasGit ( ) ) {
128
- const { stdout } = await execa ( 'git' , [ 'ls-files' , '--exclude-standard' , '--modified' , '--others' ] )
132
+ const { stdout } = await execa ( 'git' , [
133
+ 'ls-files' ,
134
+ '--exclude-standard' ,
135
+ '--modified' ,
136
+ '--others'
137
+ ] )
129
138
if ( stdout . trim ( ) ) {
130
139
log ( ` The following files have been updated / added:\n` )
131
- log ( chalk . red ( stdout . split ( / \r ? \n / g) . map ( line => ` ${ line } ` ) . join ( '\n' ) ) )
140
+ log (
141
+ chalk . red (
142
+ stdout
143
+ . split ( / \r ? \n / g)
144
+ . map ( line => ` ${ line } ` )
145
+ . join ( '\n' )
146
+ )
147
+ )
132
148
log ( )
133
149
}
134
150
}
135
- log ( ` You should review these changes with ${ chalk . cyan ( `git diff` ) } and commit them.` )
151
+ log (
152
+ ` You should review these changes with ${ chalk . cyan (
153
+ `git diff`
154
+ ) } and commit them.`
155
+ )
136
156
log ( )
137
157
138
158
generator . printExitLogs ( )
0 commit comments