forked from vuejs/vue-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
248 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"rules": { | ||
"vue-libs/no-async-functions": 0 | ||
} | ||
} |
83 changes: 83 additions & 0 deletions
83
packages/@vue/cli-plugin-eslint/__tests__/generator.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
const generateWithPlugin = require('@vue/cli-test-utils/generateWithPlugin') | ||
|
||
it('base', async () => { | ||
const { pkg } = await generateWithPlugin({ | ||
id: 'eslint', | ||
apply: require('../generator'), | ||
options: {} | ||
}) | ||
|
||
expect(pkg.scripts.lint).toBeTruthy() | ||
expect(pkg.eslintConfig).toEqual({ | ||
extends: ['plugin:vue/essential', 'eslint:recommended'] | ||
}) | ||
expect(pkg.devDependencies).toHaveProperty('eslint-plugin-vue') | ||
}) | ||
|
||
it('airbnb', async () => { | ||
const { pkg } = await generateWithPlugin({ | ||
id: 'eslint', | ||
apply: require('../generator'), | ||
options: { | ||
config: 'airbnb' | ||
} | ||
}) | ||
|
||
expect(pkg.scripts.lint).toBeTruthy() | ||
expect(pkg.eslintConfig).toEqual({ | ||
extends: ['plugin:vue/essential', '@vue/airbnb'] | ||
}) | ||
expect(pkg.devDependencies).toHaveProperty('eslint-plugin-vue') | ||
expect(pkg.devDependencies).toHaveProperty('@vue/eslint-config-airbnb') | ||
}) | ||
|
||
it('standard', async () => { | ||
const { pkg } = await generateWithPlugin({ | ||
id: 'eslint', | ||
apply: require('../generator'), | ||
options: { | ||
config: 'standard' | ||
} | ||
}) | ||
|
||
expect(pkg.scripts.lint).toBeTruthy() | ||
expect(pkg.eslintConfig).toEqual({ | ||
extends: ['plugin:vue/essential', '@vue/standard'] | ||
}) | ||
expect(pkg.devDependencies).toHaveProperty('eslint-plugin-vue') | ||
expect(pkg.devDependencies).toHaveProperty('@vue/eslint-config-standard') | ||
}) | ||
|
||
it('lint on save', async () => { | ||
const { pkg } = await generateWithPlugin({ | ||
id: 'eslint', | ||
apply: require('../generator'), | ||
options: { | ||
lintOn: 'save' | ||
} | ||
}) | ||
|
||
expect(pkg.vue).toEqual({ | ||
lintOnSave: true | ||
}) | ||
}) | ||
|
||
it('lint on commit', async () => { | ||
const { pkg } = await generateWithPlugin({ | ||
id: 'eslint', | ||
apply: require('../generator'), | ||
options: { | ||
lintOn: 'commit' | ||
} | ||
}) | ||
expect(pkg.scripts.precommit).toBe('lint-staged') | ||
expect(pkg.devDependencies).toHaveProperty('lint-staged') | ||
expect(pkg['lint-staged']).toEqual({ | ||
'*.js': ['vue-cli-service lint', 'git add'], | ||
'*.vue': ['vue-cli-service lint', 'git add'] | ||
}) | ||
}) | ||
|
||
it('prettier', async () => { | ||
// TODO | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
const create = require('@vue/cli-test-utils/createTestProjectWithOptions') | ||
|
||
it('should work', async () => { | ||
const { read, write, exec } = await create('eslint', { | ||
plugins: { | ||
'@vue/cli-plugin-babel': {}, | ||
'@vue/cli-plugin-eslint': { | ||
config: 'airbnb', | ||
lintOn: 'commit' | ||
} | ||
} | ||
}) | ||
// should've applied airbnb autofix | ||
const main = await read('src/main.js') | ||
expect(main).toContain(';') | ||
// remove semicolons | ||
await write('src/main.js', main.replace(/;/g, '')) | ||
// lint | ||
await exec('node_modules/.bin/vue-cli-service lint') | ||
expect(await read('src/main.js')).toContain(';') | ||
|
||
// TODO lint-on-commit | ||
|
||
// TODO lint-on-save | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"rules": { | ||
"vue-libs/no-async-functions": 0 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
63 changes: 63 additions & 0 deletions
63
packages/@vue/cli-test-utils/createTestProjectWithOptions.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
const fs = require('fs') | ||
const path = require('path') | ||
const { promisify } = require('util') | ||
const childProcess = require('child_process') | ||
const cliBinPath = require.resolve('@vue/cli/bin/vue') | ||
const { spawn } = childProcess | ||
|
||
const readFile = promisify(fs.readFile) | ||
const writeFile = promisify(fs.writeFile) | ||
const _exec = promisify(childProcess.exec) | ||
const mkdirp = promisify(require('mkdirp')) | ||
|
||
module.exports = function createTestProjectWithOptions (name, config, cwd) { | ||
cwd = cwd || path.resolve(__dirname, '../../test') | ||
|
||
config = Object.assign({ | ||
packageManager: 'yarn', | ||
useTaobaoRegistry: false, | ||
plugins: {} | ||
}, config) | ||
|
||
const read = file => { | ||
return readFile(path.resolve(cwd, name, file), 'utf-8') | ||
} | ||
|
||
const write = (file, content) => { | ||
const targetPath = path.resolve(cwd, name, file) | ||
const dir = path.dirname(targetPath) | ||
return mkdirp(dir).then(() => writeFile(targetPath, content)) | ||
} | ||
|
||
const exec = command => { | ||
return _exec(command, { cwd: path.resolve(cwd, name) }) | ||
} | ||
|
||
return new Promise((resolve, reject) => { | ||
const child = spawn(cliBinPath, [ | ||
'create', | ||
name, | ||
'--force', | ||
'--config', | ||
JSON.stringify(config) | ||
], { | ||
cwd, | ||
env: process.env, | ||
stdio: 'inherit' | ||
}) | ||
|
||
child.on('exit', code => { | ||
if (code !== 0) { | ||
reject(`cli creation failed with code ${code}`) | ||
} else { | ||
resolve({ | ||
read, | ||
write, | ||
exec | ||
}) | ||
} | ||
}) | ||
|
||
child.on('error', reject) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
const Generator = require('@vue/cli/lib/Generator') | ||
|
||
module.exports = async function generateWithPlugin (plugin, pkg) { | ||
process.env.VUE_CLI_SKIP_WRITE = true | ||
const generator = new Generator('/', pkg || {}, [].concat(plugin)) | ||
await generator.generate() | ||
return { | ||
pkg: generator.pkg, | ||
files: generator.files | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,16 @@ | ||
const fs = require('fs') | ||
const path = require('path') | ||
const mkdirp = require('mkdirp') | ||
const { promisify } = require('util') | ||
const mkdirp = promisify(require('mkdirp')) | ||
const write = promisify(fs.writeFile) | ||
|
||
module.exports = function writeFileTree (dir, files) { | ||
for (const name in files) { | ||
const filePath = path.join(dir, name) | ||
mkdirp.sync(path.dirname(filePath)) | ||
fs.writeFileSync(filePath, files[name]) | ||
if (process.env.VUE_CLI_SKIP_WRITE) { | ||
return | ||
} | ||
return Promise.all(Object.keys(files).map(async (name) => { | ||
const filePath = path.join(dir, name) | ||
await mkdirp(path.dirname(filePath)) | ||
await write(filePath, files[name]) | ||
})) | ||
} |