Skip to content

fix(invoke): issue #1037 invoke binary files #1038

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 27, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 30 additions & 10 deletions packages/@vue/cli/lib/invoke.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const execa = require('execa')
const chalk = require('chalk')
const globby = require('globby')
const inquirer = require('inquirer')
const isBinary = require('isbinaryfile')
const Generator = require('./Generator')
const { loadOptions } = require('./options')
const { installDeps } = require('./util/installDeps')
Expand All @@ -27,7 +28,10 @@ async function readFiles (context) {
})
const res = {}
for (const file of files) {
res[file] = fs.readFileSync(path.resolve(context, file), 'utf-8')
const name = path.resolve(context, file)
res[file] = isBinary.sync(name)
? fs.readFileSync(name)
: fs.readFileSync(name, 'utf-8')
}
return res
}
Expand All @@ -48,11 +52,11 @@ async function invoke (pluginName, options = {}, context = process.cwd()) {
if (!deps) return
let name
// official
if (deps[name = `@vue/cli-plugin-${pluginName}`]) {
if (deps[(name = `@vue/cli-plugin-${pluginName}`)]) {
return name
}
// full id, scoped short, or default short
if (deps[name = resolvePluginId(pluginName)]) {
if (deps[(name = resolvePluginId(pluginName))]) {
return name
}
}
Expand All @@ -61,7 +65,7 @@ async function invoke (pluginName, options = {}, context = process.cwd()) {
if (!id) {
throw new Error(
`Cannot resolve plugin ${chalk.yellow(pluginName)} from package.json. ` +
`Did you forget to install it?`
`Did you forget to install it?`
)
}

Expand Down Expand Up @@ -102,14 +106,14 @@ async function invoke (pluginName, options = {}, context = process.cwd()) {

const newDeps = generator.pkg.dependencies
const newDevDeps = generator.pkg.devDependencies
const depsChanged = (
const depsChanged =
JSON.stringify(newDeps) !== JSON.stringify(pkg.dependencies) ||
JSON.stringify(newDevDeps) !== JSON.stringify(pkg.devDependencies)
)

if (!isTestOrDebug && depsChanged) {
logWithSpinner('📦', `Installing additional dependencies...`)
const packageManager = loadOptions().packageManager || (hasYarn() ? 'yarn' : 'npm')
const packageManager =
loadOptions().packageManager || (hasYarn() ? 'yarn' : 'npm')
await installDeps(context, packageManager)
}

Expand All @@ -125,14 +129,30 @@ async function invoke (pluginName, options = {}, context = process.cwd()) {
log()
log(` Successfully invoked generator for plugin: ${chalk.cyan(id)}`)
if (!process.env.VUE_CLI_TEST && hasGit()) {
const { stdout } = await execa('git', ['ls-files', '--exclude-standard', '--modified', '--others'])
const { stdout } = await execa('git', [
'ls-files',
'--exclude-standard',
'--modified',
'--others'
])
if (stdout.trim()) {
log(` The following files have been updated / added:\n`)
log(chalk.red(stdout.split(/\r?\n/g).map(line => ` ${line}`).join('\n')))
log(
chalk.red(
stdout
.split(/\r?\n/g)
.map(line => ` ${line}`)
.join('\n')
)
)
log()
}
}
log(` You should review these changes with ${chalk.cyan(`git diff`)} and commit them.`)
log(
` You should review these changes with ${chalk.cyan(
`git diff`
)} and commit them.`
)
log()

generator.printExitLogs()
Expand Down