wip: lint

This commit is contained in:
Evan You
2017-12-31 16:18:41 -05:00
parent c72570d025
commit 557a25a3d7
13 changed files with 253 additions and 37 deletions
+59 -1
View File
@@ -1,3 +1,61 @@
module.exports = (api, options) => {
module.exports = (api, { config, lintOnSave, lintOnCommit }) => {
const pkg = {
scripts: {
lint: 'eslint src --ext .js,.vue --format codeframe --fix'
},
eslintConfig: {
extends: ['plugin:vue/essential'],
parserOptions: {
parser: 'babel-eslint'
}
},
devDependencies: {
'eslint': '^4.14.0',
'babel-eslint': '^8.1.2',
'eslint-plugin-vue': '4 || ^4.0.0-beta || ^4.0.0-rc'
}
}
if (config === 'airbnb') {
pkg.eslintConfig.extends.unshift('airbnb-base')
Object.assign(pkg.devDependencies, {
'eslint-config-airbnb-base': '^11.3.0',
'eslint-import-resolver-webpack': '^0.8.3',
'eslint-plugin-import': '^2.7.0'
})
} else if (config === 'standard') {
pkg.eslintConfig.extends.unshift('standard')
Object.assign(pkg.devDependencies, {
'eslint-config-standard': '^10.2.1',
'eslint-plugin-promise': '^3.4.0',
'eslint-plugin-standard': '^3.0.1',
'eslint-plugin-import': '^2.7.0',
'eslint-plugin-node': '^5.2.0'
})
} else if (config === 'prettier') {
// TODO
}
if (lintOnSave) {
pkg.vue = {
lintOnSave: true // eslint-loader configured in runtime plugin
}
}
if (lintOnCommit) {
Object.assign(pkg.devDependencies, {
'husky': '^0.14.3',
'lint-staged': '^6.0.0'
})
pkg['lint-staged'] = {
'*.js': ['eslint --fix --format codeframe', 'git add'],
'*.vue': ['eslint --fix --format codeframe', 'git add']
}
}
api.extendPackage(pkg)
api.onCreateComplete(() => {
// run fix after creation
})
}
+16 -1
View File
@@ -1,3 +1,18 @@
module.exports = (api, options) => {
module.exports = (api, { lintOnSave }) => {
api.registerCommand('lint', {
descriptions: 'lint source files',
usage: 'vue-cli-service lint [options] [...files]',
options: {
'--fix': 'auto fix lint errors in-place'
},
details: 'For more options, see https://eslint.org/docs/user-guide/command-line-interface#options'
}, args => {
})
if (lintOnSave) {
api.chainWebpack(webpackConfig => {
})
}
}
@@ -20,5 +20,8 @@
"homepage": "https://github.com/vuejs/vue-cli/packages/@vue/cli-plugin-eslint#readme",
"publishConfig": {
"access": "public"
},
"dependencies": {
"eslint-loader": "^1.9.0"
}
}
@@ -10,6 +10,10 @@ module.exports = class PluginAPI {
return path.resolve(this.service.context, _path)
}
hasPlugin (id) {
return this.service.plugins.some(p => p.id === id)
}
// set project mode.
// this should be called by any registered command as early as possible.
setMode (mode) {
+2 -1
View File
@@ -29,7 +29,8 @@ module.exports = class Service {
this.loadEnv()
// install plugins
this.resolvePlugins().forEach(({ id, apply }) => {
this.plugins = this.resolvePlugins()
this.plugins.forEach(({ id, apply }) => {
apply(new PluginAPI(id, this), this.projectOptions)
})
+1 -1
View File
@@ -6,7 +6,7 @@ module.exports = api => {
const WatchMissingNodeModulesPlugin = require('../util/WatchMissingNodeModulesPlugin')
webpackConfig
.devtool('cheap-module-source-map')
.devtool('cheap-module-eval-source-map')
webpackConfig
.plugin('hmr')
+20 -19
View File
@@ -3,13 +3,13 @@ const os = require('os')
const path = require('path')
const chalk = require('chalk')
const debug = require('debug')
const emoji = require('node-emoji')
const inquirer = require('inquirer')
const Generator = require('./Generator')
const installDeps = require('./util/installDeps')
const clearConsole = require('./util/clearConsole')
const PromptModuleAPI = require('./PromptModuleAPI')
const writeFileTree = require('./util/writeFileTree')
const formatFeatures = require('./util/formatfeatures')
const updatePackageForDev = require('./util/updatePackageForDev')
const {
@@ -31,6 +31,7 @@ module.exports = class Creator {
this.outroPrompts = this.resolveOutroPrompts()
this.injectedPrompts = []
this.promptCompleteCbs = []
this.createCompleteCbs = []
const api = new PromptModuleAPI(this)
modules.forEach(m => m(api))
@@ -44,7 +45,7 @@ module.exports = class Creator {
let options
if (answers.mode === 'saved') {
options = this.loadSavedOptions()
options = this.savedOptions // this is loaded when resolving prompts
} else if (answers.mode === 'default') {
options = defaultOptions
} else {
@@ -71,7 +72,7 @@ module.exports = class Creator {
// write base package.json to disk
clearConsole()
logWithSpinner(emoji.get('sparkles'), `Creating project in ${chalk.yellow(targetDir)}.`)
logWithSpinner('✨', `Creating project in ${chalk.yellow(targetDir)}.`)
writeFileTree(targetDir, {
'package.json': JSON.stringify({
name,
@@ -81,7 +82,7 @@ module.exports = class Creator {
})
// install plugins
logWithSpinner(emoji.get('electric_plug'), `Installing CLI plugins. This might take a while...`)
logWithSpinner('⚙', `Installing CLI plugins. This might take a while...`)
const deps = Object.keys(options.plugins)
if (process.env.VUE_CLI_DEBUG) {
// in development, use linked packages
@@ -92,28 +93,25 @@ module.exports = class Creator {
}
// run generator
logWithSpinner(emoji.get('gear'), `Invoking generators...`)
const generator = new Generator(targetDir, options)
logWithSpinner('🚀', `Invoking generators...`)
const generator = new Generator(targetDir, options, this)
await generator.generate()
// install additional deps (injected by generators)
logWithSpinner(emoji.get('package'), `Installing additional dependencies...`)
logWithSpinner('📦', `Installing additional dependencies...`)
await installDeps(options.packageManager, targetDir)
// run complete cbs if any
for (const cb of this.createCompleteCbs) {
await cb()
}
// log instructions
stopSpinner()
console.log()
console.log(`${chalk.green('✔')} Successfully created project ${chalk.yellow(name)} with the following plugins:`)
console.log()
deps.forEach(dep => {
if (dep !== '@vue/cli-service') {
dep = dep.replace(/^(@vue\/|vue-)cli-plugin-/, '')
console.log(` ${chalk.gray('-')} ${dep}`)
}
})
console.log()
console.log(`🎉 Successfully created project ${chalk.yellow(name)}.`)
console.log(
`${emoji.get('point_right')} Get started with the following commands:\n\n` +
`👉 Get started with the following commands:\n\n` +
chalk.cyan(` ${chalk.gray('$')} cd ${name}\n`) +
chalk.cyan(` ${chalk.gray('$')} ${options.packageManager === 'yarn' ? 'yarn dev' : 'npm run dev'}`)
)
@@ -121,13 +119,14 @@ module.exports = class Creator {
}
resolveIntroPrompts () {
const defualtFeatures = formatFeatures(defaultOptions.plugins)
const modePrompt = {
name: 'mode',
type: 'list',
message: `Please pick a project creation mode:`,
choices: [
{
name: 'Zero-configuration with defaults',
name: `Zero-configuration with defaults (${defualtFeatures})`,
value: 'default'
},
{
@@ -137,8 +136,10 @@ module.exports = class Creator {
]
}
if (fs.existsSync(rcPath)) {
this.savedOptions = this.loadSavedOptions()
const savedFeatures = formatFeatures(this.savedOptions.plugins)
modePrompt.choices.unshift({
name: 'Use previously saved preferences',
name: `Use previously saved preferences (${savedFeatures})`,
value: 'saved'
})
}
+2 -1
View File
@@ -6,9 +6,10 @@ const GeneratorAPI = require('./GeneratorAPI')
const writeFileTree = require('./util/writeFileTree')
module.exports = class Generator {
constructor (context, options) {
constructor (context, options, creator) {
this.context = context
this.options = options
this.creator = creator
this.pkg = require(path.resolve(context, 'package.json'))
// for conflict resolution
this.depSources = {}
+4
View File
@@ -82,6 +82,10 @@ module.exports = class GeneratorAPI {
this.injectFileMiddleware(fileDir)
}
}
onCreateComplete (cb) {
this.generator.creator.createCompleteCbs.push(cb)
}
}
function extractCallDir () {
@@ -0,0 +1,11 @@
const chalk = require('chalk')
module.exports = function formatFeatures (plugins, lead, joiner) {
return Object.keys(plugins)
.filter(dep => dep !== '@vue/cli-service')
.map(dep => {
dep = dep.replace(/^(@vue\/|vue-)cli-plugin-/, '')
return `${lead || ''}${chalk.yellow(dep)}`
})
.join(joiner || ', ')
}
-1
View File
@@ -36,7 +36,6 @@
"isbinaryfile": "^3.0.2",
"klaw-sync": "^3.0.2",
"mkdirp": "^0.5.1",
"node-emoji": "^1.8.1",
"resolve": "^1.5.0",
"rimraf": "^2.6.2",
"semver": "^5.4.1"
+1 -1
View File
@@ -7,7 +7,7 @@ const globby = require('globby')
const { execSync } = require('child_process')
const localPackageRE = /'(@vue\/[\w-]+)': '\^(\d+\.\d+\.\d+)'/g
const npmPackageRE = /'(vue|vue-template-compiler|vuex|vue-router|vue-test-utils)': '\^(\d+\.\d+\.\d+)'/g
const npmPackageRE = /'(vue|vue-template-compiler|vuex|vue-router|vue-test-utils)': '\^(\d+\.\d+\.\d+[^']*)'/g
;(async () => {
const paths = await globby(['packages/@vue/**/*.js'])
+130 -11
View File
@@ -2,6 +2,14 @@
# yarn lockfile v1
"@babel/code-frame@7.0.0-beta.31":
version "7.0.0-beta.31"
resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.0.0-beta.31.tgz#473d021ecc573a2cce1c07d5b509d5215f46ba35"
dependencies:
chalk "^2.0.0"
esutils "^2.0.2"
js-tokens "^3.0.0"
"@babel/code-frame@7.0.0-beta.36", "@babel/code-frame@^7.0.0-beta.35":
version "7.0.0-beta.36"
resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.0.0-beta.36.tgz#2349d7ec04b3a06945ae173280ef8579b63728e4"
@@ -75,6 +83,15 @@
"@babel/traverse" "7.0.0-beta.36"
"@babel/types" "7.0.0-beta.36"
"@babel/helper-function-name@7.0.0-beta.31":
version "7.0.0-beta.31"
resolved "https://registry.yarnpkg.com/@babel/helper-function-name/-/helper-function-name-7.0.0-beta.31.tgz#afe63ad799209989348b1109b44feb66aa245f57"
dependencies:
"@babel/helper-get-function-arity" "7.0.0-beta.31"
"@babel/template" "7.0.0-beta.31"
"@babel/traverse" "7.0.0-beta.31"
"@babel/types" "7.0.0-beta.31"
"@babel/helper-function-name@7.0.0-beta.36":
version "7.0.0-beta.36"
resolved "https://registry.yarnpkg.com/@babel/helper-function-name/-/helper-function-name-7.0.0-beta.36.tgz#366e3bc35147721b69009f803907c4d53212e88d"
@@ -83,6 +100,12 @@
"@babel/template" "7.0.0-beta.36"
"@babel/types" "7.0.0-beta.36"
"@babel/helper-get-function-arity@7.0.0-beta.31":
version "7.0.0-beta.31"
resolved "https://registry.yarnpkg.com/@babel/helper-get-function-arity/-/helper-get-function-arity-7.0.0-beta.31.tgz#1176d79252741218e0aec872ada07efb2b37a493"
dependencies:
"@babel/types" "7.0.0-beta.31"
"@babel/helper-get-function-arity@7.0.0-beta.36":
version "7.0.0-beta.36"
resolved "https://registry.yarnpkg.com/@babel/helper-get-function-arity/-/helper-get-function-arity-7.0.0-beta.36.tgz#f5383bac9a96b274828b10d98900e84ee43e32b8"
@@ -502,6 +525,15 @@
core-js "^2.4.0"
regenerator-runtime "^0.11.1"
"@babel/template@7.0.0-beta.31":
version "7.0.0-beta.31"
resolved "https://registry.yarnpkg.com/@babel/template/-/template-7.0.0-beta.31.tgz#577bb29389f6c497c3e7d014617e7d6713f68bda"
dependencies:
"@babel/code-frame" "7.0.0-beta.31"
"@babel/types" "7.0.0-beta.31"
babylon "7.0.0-beta.31"
lodash "^4.2.0"
"@babel/template@7.0.0-beta.36":
version "7.0.0-beta.36"
resolved "https://registry.yarnpkg.com/@babel/template/-/template-7.0.0-beta.36.tgz#02e903de5d68bd7899bce3c5b5447e59529abb00"
@@ -511,6 +543,19 @@
babylon "7.0.0-beta.36"
lodash "^4.2.0"
"@babel/traverse@7.0.0-beta.31":
version "7.0.0-beta.31"
resolved "https://registry.yarnpkg.com/@babel/traverse/-/traverse-7.0.0-beta.31.tgz#db399499ad74aefda014f0c10321ab255134b1df"
dependencies:
"@babel/code-frame" "7.0.0-beta.31"
"@babel/helper-function-name" "7.0.0-beta.31"
"@babel/types" "7.0.0-beta.31"
babylon "7.0.0-beta.31"
debug "^3.0.1"
globals "^10.0.0"
invariant "^2.2.0"
lodash "^4.2.0"
"@babel/traverse@7.0.0-beta.36":
version "7.0.0-beta.36"
resolved "https://registry.yarnpkg.com/@babel/traverse/-/traverse-7.0.0-beta.36.tgz#1dc6f8750e89b6b979de5fe44aa993b1a2192261"
@@ -524,6 +569,14 @@
invariant "^2.2.0"
lodash "^4.2.0"
"@babel/types@7.0.0-beta.31":
version "7.0.0-beta.31"
resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.0.0-beta.31.tgz#42c9c86784f674c173fb21882ca9643334029de4"
dependencies:
esutils "^2.0.2"
lodash "^4.2.0"
to-fast-properties "^2.0.0"
"@babel/types@7.0.0-beta.36":
version "7.0.0-beta.36"
resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.0.0-beta.36.tgz#64f2004353de42adb72f9ebb4665fc35b5499d23"
@@ -920,6 +973,17 @@ babel-core@^6.0.0, babel-core@^6.25.0, babel-core@^6.26.0:
slash "^1.0.0"
source-map "^0.5.6"
babel-eslint@^8.1.2:
version "8.1.2"
resolved "https://registry.yarnpkg.com/babel-eslint/-/babel-eslint-8.1.2.tgz#a39230b0c20ecbaa19a35d5633bf9b9ca2c8116f"
dependencies:
"@babel/code-frame" "7.0.0-beta.31"
"@babel/traverse" "7.0.0-beta.31"
"@babel/types" "7.0.0-beta.31"
babylon "7.0.0-beta.31"
eslint-scope "~3.7.1"
eslint-visitor-keys "^1.0.0"
babel-generator@^6.18.0, babel-generator@^6.26.0:
version "6.26.0"
resolved "https://registry.yarnpkg.com/babel-generator/-/babel-generator-6.26.0.tgz#ac1ae20070b79f6e3ca1d3269613053774f20dc5"
@@ -1449,6 +1513,10 @@ babel-types@^6.18.0, babel-types@^6.19.0, babel-types@^6.24.1, babel-types@^6.26
lodash "^4.17.4"
to-fast-properties "^1.0.3"
babylon@7.0.0-beta.31:
version "7.0.0-beta.31"
resolved "https://registry.yarnpkg.com/babylon/-/babylon-7.0.0-beta.31.tgz#7ec10f81e0e456fd0f855ad60fa30c2ac454283f"
babylon@7.0.0-beta.36:
version "7.0.0-beta.36"
resolved "https://registry.yarnpkg.com/babylon/-/babylon-7.0.0-beta.36.tgz#3a3683ba6a9a1e02b0aa507c8e63435e39305b9e"
@@ -3198,6 +3266,16 @@ escope@^3.6.0:
esrecurse "^4.1.0"
estraverse "^4.1.1"
eslint-loader@^1.9.0:
version "1.9.0"
resolved "https://registry.yarnpkg.com/eslint-loader/-/eslint-loader-1.9.0.tgz#7e1be9feddca328d3dcfaef1ad49d5beffe83a13"
dependencies:
loader-fs-cache "^1.0.0"
loader-utils "^1.0.2"
object-assign "^4.0.1"
object-hash "^1.1.4"
rimraf "^2.6.1"
eslint-plugin-html@^4.0.1:
version "4.0.1"
resolved "https://registry.yarnpkg.com/eslint-plugin-html/-/eslint-plugin-html-4.0.1.tgz#fc70072263cc938496fbbc9cf648660e41fa269a"
@@ -3210,7 +3288,14 @@ eslint-plugin-vue-libs@^2.1.0:
dependencies:
eslint-plugin-html "^4.0.1"
eslint-scope@^3.7.1:
"eslint-plugin-vue@4 || ^4.0.0-beta || ^4.0.0-rc":
version "4.0.0"
resolved "https://registry.yarnpkg.com/eslint-plugin-vue/-/eslint-plugin-vue-4.0.0.tgz#b93f2b21c32d4b88794962a56ce662621b268acd"
dependencies:
require-all "^2.2.0"
vue-eslint-parser "^2.0.1"
eslint-scope@^3.7.1, eslint-scope@~3.7.1:
version "3.7.1"
resolved "https://registry.yarnpkg.com/eslint-scope/-/eslint-scope-3.7.1.tgz#3d63c3edfda02e06e01a452ad88caacc7cdcb6e8"
dependencies:
@@ -3609,6 +3694,14 @@ find-babel-config@^1.1.0:
json5 "^0.5.1"
path-exists "^3.0.0"
find-cache-dir@^0.1.1:
version "0.1.1"
resolved "https://registry.yarnpkg.com/find-cache-dir/-/find-cache-dir-0.1.1.tgz#c8defae57c8a52a8a784f9e31c57c742e993a0b9"
dependencies:
commondir "^1.0.1"
mkdirp "^0.5.1"
pkg-dir "^1.0.0"
find-cache-dir@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/find-cache-dir/-/find-cache-dir-1.0.0.tgz#9288e3e9e3cc3748717d39eade17cf71fc30ee6f"
@@ -3919,6 +4012,10 @@ global-dirs@^0.1.0:
dependencies:
ini "^1.3.4"
globals@^10.0.0:
version "10.4.0"
resolved "https://registry.yarnpkg.com/globals/-/globals-10.4.0.tgz#5c477388b128a9e4c5c5d01c7a2aca68c68b2da7"
globals@^11.0.1, globals@^11.1.0:
version "11.1.0"
resolved "https://registry.yarnpkg.com/globals/-/globals-11.1.0.tgz#632644457f5f0e3ae711807183700ebf2e4633e4"
@@ -5398,6 +5495,13 @@ load-json-file@^4.0.0:
pify "^3.0.0"
strip-bom "^3.0.0"
loader-fs-cache@^1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/loader-fs-cache/-/loader-fs-cache-1.0.1.tgz#56e0bf08bd9708b26a765b68509840c8dec9fdbc"
dependencies:
find-cache-dir "^0.1.1"
mkdirp "0.5.1"
loader-runner@^2.3.0:
version "2.3.0"
resolved "https://registry.yarnpkg.com/loader-runner/-/loader-runner-2.3.0.tgz#f482aea82d543e07921700d5a46ef26fdac6b8a2"
@@ -5459,10 +5563,6 @@ lodash.templatesettings@^4.0.0:
dependencies:
lodash._reinterpolate "~3.0.0"
lodash.toarray@^4.4.0:
version "4.4.0"
resolved "https://registry.yarnpkg.com/lodash.toarray/-/lodash.toarray-4.4.0.tgz#24c4bfcd6b2fba38bfd0594db1179d8e9b656561"
lodash.uniq@^4.5.0:
version "4.5.0"
resolved "https://registry.yarnpkg.com/lodash.uniq/-/lodash.uniq-4.5.0.tgz#d0225373aeb652adc1bc82e4945339a842754773"
@@ -5875,12 +5975,6 @@ node-cache@^4.1.1:
clone "2.x"
lodash "4.x"
node-emoji@^1.8.1:
version "1.8.1"
resolved "https://registry.yarnpkg.com/node-emoji/-/node-emoji-1.8.1.tgz#6eec6bfb07421e2148c75c6bba72421f8530a826"
dependencies:
lodash.toarray "^4.4.0"
node-forge@0.6.33:
version "0.6.33"
resolved "https://registry.yarnpkg.com/node-forge/-/node-forge-0.6.33.tgz#463811879f573d45155ad6a9f43dc296e8e85ebc"
@@ -6057,6 +6151,10 @@ object-assign@^4.0.1, object-assign@^4.1.0, object-assign@^4.1.1:
version "4.1.1"
resolved "https://registry.yarnpkg.com/object-assign/-/object-assign-4.1.1.tgz#2109adc7965887cfc05cbbd442cac8bfbb360863"
object-hash@^1.1.4:
version "1.2.0"
resolved "https://registry.yarnpkg.com/object-hash/-/object-hash-1.2.0.tgz#e96af0e96981996a1d47f88ead8f74f1ebc4422b"
object-keys@^1.0.8:
version "1.0.11"
resolved "https://registry.yarnpkg.com/object-keys/-/object-keys-1.0.11.tgz#c54601778ad560f1142ce0e01bcca8b56d13426d"
@@ -6403,6 +6501,12 @@ pinkie@^2.0.0:
version "2.0.4"
resolved "https://registry.yarnpkg.com/pinkie/-/pinkie-2.0.4.tgz#72556b80cfa0d48a974e80e77248e80ed4f7f870"
pkg-dir@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/pkg-dir/-/pkg-dir-1.0.0.tgz#7a4b508a8d5bb2d629d447056ff4e9c9314cf3d4"
dependencies:
find-up "^1.0.0"
pkg-dir@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/pkg-dir/-/pkg-dir-2.0.0.tgz#f6d5d1109e19d63edf428e0bd57e12777615334b"
@@ -7227,6 +7331,10 @@ request@^2.67.0, request@^2.83.0:
tunnel-agent "^0.6.0"
uuid "^3.1.0"
require-all@^2.2.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/require-all/-/require-all-2.2.0.tgz#b4420c233ac0282d0ff49b277fb880a8b5de0894"
require-directory@^2.1.1:
version "2.1.1"
resolved "https://registry.yarnpkg.com/require-directory/-/require-directory-2.1.1.tgz#8c64ad5fd30dab1c976e2344ffe7f792a6a6df42"
@@ -8465,6 +8573,17 @@ vue-cli@^2.9.2:
user-home "^2.0.0"
validate-npm-package-name "^3.0.0"
vue-eslint-parser@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/vue-eslint-parser/-/vue-eslint-parser-2.0.1.tgz#30135771c4fad00fdbac4542a2d59f3b1d776834"
dependencies:
debug "^3.1.0"
eslint-scope "^3.7.1"
eslint-visitor-keys "^1.0.0"
espree "^3.5.2"
esquery "^1.0.0"
lodash "^4.17.4"
vue-hot-reload-api@^2.2.0:
version "2.2.4"
resolved "https://registry.yarnpkg.com/vue-hot-reload-api/-/vue-hot-reload-api-2.2.4.tgz#683bd1d026c0d3b3c937d5875679e9a87ec6cd8f"