@@ -4,6 +4,7 @@ const execa = require('execa')
44const chalk = require ( 'chalk' )
55const globby = require ( 'globby' )
66const inquirer = require ( 'inquirer' )
7+ const isBinary = require ( 'isbinaryfile' )
78const Generator = require ( './Generator' )
89const { loadOptions } = require ( './options' )
910const { installDeps } = require ( './util/installDeps' )
@@ -27,7 +28,10 @@ async function readFiles (context) {
2728 } )
2829 const res = { }
2930 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' )
3135 }
3236 return res
3337}
@@ -48,11 +52,11 @@ async function invoke (pluginName, options = {}, context = process.cwd()) {
4852 if ( ! deps ) return
4953 let name
5054 // official
51- if ( deps [ name = `@vue/cli-plugin-${ pluginName } ` ] ) {
55+ if ( deps [ ( name = `@vue/cli-plugin-${ pluginName } ` ) ] ) {
5256 return name
5357 }
5458 // full id, scoped short, or default short
55- if ( deps [ name = resolvePluginId ( pluginName ) ] ) {
59+ if ( deps [ ( name = resolvePluginId ( pluginName ) ) ] ) {
5660 return name
5761 }
5862 }
@@ -61,7 +65,7 @@ async function invoke (pluginName, options = {}, context = process.cwd()) {
6165 if ( ! id ) {
6266 throw new Error (
6367 `Cannot resolve plugin ${ chalk . yellow ( pluginName ) } from package.json. ` +
64- `Did you forget to install it?`
68+ `Did you forget to install it?`
6569 )
6670 }
6771
@@ -102,14 +106,14 @@ async function invoke (pluginName, options = {}, context = process.cwd()) {
102106
103107 const newDeps = generator . pkg . dependencies
104108 const newDevDeps = generator . pkg . devDependencies
105- const depsChanged = (
109+ const depsChanged =
106110 JSON . stringify ( newDeps ) !== JSON . stringify ( pkg . dependencies ) ||
107111 JSON . stringify ( newDevDeps ) !== JSON . stringify ( pkg . devDependencies )
108- )
109112
110113 if ( ! isTestOrDebug && depsChanged ) {
111114 logWithSpinner ( '📦' , `Installing additional dependencies...` )
112- const packageManager = loadOptions ( ) . packageManager || ( hasYarn ( ) ? 'yarn' : 'npm' )
115+ const packageManager =
116+ loadOptions ( ) . packageManager || ( hasYarn ( ) ? 'yarn' : 'npm' )
113117 await installDeps ( context , packageManager )
114118 }
115119
@@ -125,14 +129,30 @@ async function invoke (pluginName, options = {}, context = process.cwd()) {
125129 log ( )
126130 log ( ` Successfully invoked generator for plugin: ${ chalk . cyan ( id ) } ` )
127131 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+ ] )
129138 if ( stdout . trim ( ) ) {
130139 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+ )
132148 log ( )
133149 }
134150 }
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+ )
136156 log ( )
137157
138158 generator . printExitLogs ( )
0 commit comments