Skip to content

Commit 52dad9d

Browse files
committed
feat: improve generator hasPlugin check + invoke output
1 parent fbc5f6b commit 52dad9d

File tree

4 files changed

+36
-5
lines changed

4 files changed

+36
-5
lines changed

packages/@vue/cli-plugin-eslint/generator.js

+14
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,20 @@ module.exports = (api, { config, lintOn = [] }) => {
5353

5454
api.extendPackage(pkg)
5555

56+
if (api.hasPlugin('unit-mocha')) {
57+
api.render(files => {
58+
files['test/unit/.eslintrc'] = JSON.stringify({
59+
env: { mocha: true }
60+
}, null, 2)
61+
})
62+
} else if (api.hasPlugin('unit-jest')) {
63+
api.render(files => {
64+
files['test/unit/.eslintrc'] = JSON.stringify({
65+
env: { jest: true }
66+
}, null, 2)
67+
})
68+
}
69+
5670
// lint & fix after create to ensure files adhere to chosen config
5771
if (config && config !== 'base') {
5872
api.onCreateComplete(() => {

packages/@vue/cli/lib/Generator.js

+11
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,15 @@ module.exports = class Generator {
8787
}
8888
debug('vue:cli-files')(this.files)
8989
}
90+
91+
hasPlugin (_id) {
92+
const prefixRE = /^(@vue\/|vue-)cli-plugin-/
93+
return [
94+
...this.plugins.map(p => p.id),
95+
...Object.keys(this.pkg.devDependencies || {}),
96+
...Object.keys(this.pkg.dependencies || {})
97+
].some(id => {
98+
return id === _id || id.replace(prefixRE, '') === _id
99+
})
100+
}
90101
}

packages/@vue/cli/lib/GeneratorAPI.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,8 @@ module.exports = class GeneratorAPI {
101101
return path.resolve(this.generator.context, _path)
102102
}
103103

104-
hasPlugin (_id) {
105-
const prefixRE = /^(@vue\/|vue-)cli-plugin-/
106-
return this.generator.plugins.some(({ id }) => {
107-
return id === _id || id.replace(prefixRE, '') === _id
108-
})
104+
hasPlugin (id) {
105+
return this.generator.hasPlugin(id)
109106
}
110107
}
111108

packages/@vue/cli/lib/invoke.js

+9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const fs = require('fs')
22
const path = require('path')
3+
const execa = require('execa')
34
const chalk = require('chalk')
45
const resolve = require('resolve')
56
const Generator = require('./Generator')
@@ -9,6 +10,7 @@ const {
910
log,
1011
error,
1112
hasYarn,
13+
hasGit,
1214
logWithSpinner,
1315
stopSpinner
1416
} = require('@vue/cli-shared-utils')
@@ -87,8 +89,15 @@ async function invoke (pluginName, options) {
8789
}
8890

8991
stopSpinner()
92+
9093
log()
9194
log(` Successfully invoked generator for plugin: ${chalk.cyan(id)}`)
95+
if (hasGit) {
96+
const { stdout } = await execa('git', ['ls-files', '--exclude-standard', '--modified', '--others'])
97+
log(` The following files have been updated / added:\n`)
98+
log(chalk.red(stdout.split(/\r?\n/g).map(line => ` ${line}`).join('\n')))
99+
log()
100+
}
92101
log(` You should review and commit the changes.`)
93102
log()
94103
}

0 commit comments

Comments
 (0)