Skip to content

Commit

Permalink
feat: improve generator hasPlugin check + invoke output
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Jan 15, 2018
1 parent fbc5f6b commit 52dad9d
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 5 deletions.
14 changes: 14 additions & 0 deletions packages/@vue/cli-plugin-eslint/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,20 @@ module.exports = (api, { config, lintOn = [] }) => {

api.extendPackage(pkg)

if (api.hasPlugin('unit-mocha')) {
api.render(files => {
files['test/unit/.eslintrc'] = JSON.stringify({
env: { mocha: true }
}, null, 2)
})
} else if (api.hasPlugin('unit-jest')) {
api.render(files => {
files['test/unit/.eslintrc'] = JSON.stringify({
env: { jest: true }
}, null, 2)
})
}

// lint & fix after create to ensure files adhere to chosen config
if (config && config !== 'base') {
api.onCreateComplete(() => {
Expand Down
11 changes: 11 additions & 0 deletions packages/@vue/cli/lib/Generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,15 @@ module.exports = class Generator {
}
debug('vue:cli-files')(this.files)
}

hasPlugin (_id) {
const prefixRE = /^(@vue\/|vue-)cli-plugin-/
return [
...this.plugins.map(p => p.id),
...Object.keys(this.pkg.devDependencies || {}),
...Object.keys(this.pkg.dependencies || {})
].some(id => {
return id === _id || id.replace(prefixRE, '') === _id
})
}
}
7 changes: 2 additions & 5 deletions packages/@vue/cli/lib/GeneratorAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,8 @@ module.exports = class GeneratorAPI {
return path.resolve(this.generator.context, _path)
}

hasPlugin (_id) {
const prefixRE = /^(@vue\/|vue-)cli-plugin-/
return this.generator.plugins.some(({ id }) => {
return id === _id || id.replace(prefixRE, '') === _id
})
hasPlugin (id) {
return this.generator.hasPlugin(id)
}
}

Expand Down
9 changes: 9 additions & 0 deletions packages/@vue/cli/lib/invoke.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const fs = require('fs')
const path = require('path')
const execa = require('execa')
const chalk = require('chalk')
const resolve = require('resolve')
const Generator = require('./Generator')
Expand All @@ -9,6 +10,7 @@ const {
log,
error,
hasYarn,
hasGit,
logWithSpinner,
stopSpinner
} = require('@vue/cli-shared-utils')
Expand Down Expand Up @@ -87,8 +89,15 @@ async function invoke (pluginName, options) {
}

stopSpinner()

log()
log(` Successfully invoked generator for plugin: ${chalk.cyan(id)}`)
if (hasGit) {
const { stdout } = await execa('git', ['ls-files', '--exclude-standard', '--modified', '--others'])
log(` The following files have been updated / added:\n`)
log(chalk.red(stdout.split(/\r?\n/g).map(line => ` ${line}`).join('\n')))
log()
}
log(` You should review and commit the changes.`)
log()
}
Expand Down

0 comments on commit 52dad9d

Please sign in to comment.