mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-25 02:41:46 +08:00
feat(cli): improve linter logging
This commit is contained in:
parent
a98e9b29f9
commit
923dbbb0f2
@ -30,7 +30,6 @@
|
|||||||
"vue-template-compiler": "^2.5.22"
|
"vue-template-compiler": "^2.5.22"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/eslint": "^6.1.3",
|
|
||||||
"@types/fs-extra": "^8.0.1",
|
"@types/fs-extra": "^8.0.1",
|
||||||
"@types/html-webpack-plugin": "^3.2.1",
|
"@types/html-webpack-plugin": "^3.2.1",
|
||||||
"@types/lodash": "^4.14.149",
|
"@types/lodash": "^4.14.149",
|
||||||
@ -39,7 +38,6 @@
|
|||||||
"@types/shelljs": "^0.8.6",
|
"@types/shelljs": "^0.8.6",
|
||||||
"@types/signale": "^1.2.1",
|
"@types/signale": "^1.2.1",
|
||||||
"@types/source-map": "^0.5.7",
|
"@types/source-map": "^0.5.7",
|
||||||
"@types/stylelint": "^9.10.1",
|
|
||||||
"@types/webpack": "^4.41.2",
|
"@types/webpack": "^4.41.2",
|
||||||
"@types/webpack-dev-server": "^3.9.0",
|
"@types/webpack-dev-server": "^3.9.0",
|
||||||
"@types/webpack-merge": "^4.1.5"
|
"@types/webpack-merge": "^4.1.5"
|
||||||
@ -87,6 +85,7 @@
|
|||||||
"less-loader": "^5.0.0",
|
"less-loader": "^5.0.0",
|
||||||
"lint-staged": "^9.5.0",
|
"lint-staged": "^9.5.0",
|
||||||
"lodash": "^4.17.15",
|
"lodash": "^4.17.15",
|
||||||
|
"ora": "^4.0.3",
|
||||||
"portfinder": "^1.0.25",
|
"portfinder": "^1.0.25",
|
||||||
"postcss": "^7.0.26",
|
"postcss": "^7.0.26",
|
||||||
"postcss-loader": "^3.0.0",
|
"postcss-loader": "^3.0.0",
|
||||||
|
@ -1,57 +1,66 @@
|
|||||||
import { lint as stylelint } from 'stylelint';
|
// @ts-ignore
|
||||||
import { CLIEngine } from 'eslint';
|
import execa from 'execa';
|
||||||
import { getStepper } from '../common/logger';
|
import { ora } from '../common/logger';
|
||||||
import { SCRIPT_EXTS } from '../common/constant';
|
import { SCRIPT_EXTS } from '../common/constant';
|
||||||
|
|
||||||
const stepper = getStepper(4);
|
type RunCommandMessages = {
|
||||||
|
start: string;
|
||||||
|
succeed: string;
|
||||||
|
failed: string;
|
||||||
|
};
|
||||||
|
|
||||||
function lintScript() {
|
function runCommand(
|
||||||
stepper.start('ESLint Start');
|
cmd: string,
|
||||||
|
options: string[],
|
||||||
|
messages: RunCommandMessages
|
||||||
|
) {
|
||||||
|
const spinner = ora(messages.start).start();
|
||||||
|
|
||||||
const cli = new CLIEngine({
|
return new Promise(resolve => {
|
||||||
fix: true,
|
execa(cmd, options, {
|
||||||
extensions: SCRIPT_EXTS
|
env: { FORCE_COLOR: true }
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
spinner.succeed(messages.succeed);
|
||||||
|
resolve(true);
|
||||||
|
})
|
||||||
|
.catch((err: any) => {
|
||||||
|
spinner.fail(messages.failed);
|
||||||
|
console.log(err.stdout);
|
||||||
|
resolve(false);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
const report = cli.executeOnFiles(['src/']);
|
|
||||||
const formatter = cli.getFormatter();
|
|
||||||
|
|
||||||
CLIEngine.outputFixes(report);
|
|
||||||
|
|
||||||
// output lint errors
|
|
||||||
const formatted = formatter(report.results);
|
|
||||||
if (formatted) {
|
|
||||||
stepper.error('ESLint Failed', '\n' + formatter(report.results));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
stepper.success('ESLint Passed');
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function lintStyle(): Promise<boolean> {
|
function eslint() {
|
||||||
stepper.start('Stylelint Start');
|
return runCommand(
|
||||||
|
'eslint',
|
||||||
return stylelint({
|
['./src', '--fix', '--ext', SCRIPT_EXTS.join(',')],
|
||||||
fix: true,
|
{
|
||||||
formatter: 'string',
|
start: 'Running eslint...',
|
||||||
files: ['src/**/*.css', 'src/**/*.less', 'src/**/*.scss', 'src/**/*.vue']
|
succeed: 'ESLint Passed.',
|
||||||
}).then(result => {
|
failed: 'ESLint failed!'
|
||||||
if (result.errored) {
|
|
||||||
stepper.error('Stylelint Failed', '\n' + result.output);
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
stepper.success('Stylelint Passed');
|
function stylelint() {
|
||||||
return true;
|
return runCommand(
|
||||||
});
|
'stylelint',
|
||||||
|
['src/**/*.css', 'src/**/*.vue', 'src/**/*.less', 'src/**/*.sass', '--fix'],
|
||||||
|
{
|
||||||
|
start: 'Running stylelint...',
|
||||||
|
succeed: 'Stylelint Passed.',
|
||||||
|
failed: 'Stylelint failed!'
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function lint() {
|
export async function lint() {
|
||||||
const scriptPassed = lintScript();
|
const eslintPassed = await eslint();
|
||||||
const stylePassed = await lintStyle();
|
const stylelintPassed = await stylelint();
|
||||||
|
|
||||||
if (!scriptPassed || !stylePassed) {
|
if (!eslintPassed || !stylelintPassed) {
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1291,19 +1291,6 @@
|
|||||||
resolved "https://registry.npm.taobao.org/@types/eslint-visitor-keys/download/@types/eslint-visitor-keys-1.0.0.tgz?cache=0&sync_timestamp=1572470950582&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2F%40types%2Feslint-visitor-keys%2Fdownload%2F%40types%2Feslint-visitor-keys-1.0.0.tgz#1ee30d79544ca84d68d4b3cdb0af4f205663dd2d"
|
resolved "https://registry.npm.taobao.org/@types/eslint-visitor-keys/download/@types/eslint-visitor-keys-1.0.0.tgz?cache=0&sync_timestamp=1572470950582&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2F%40types%2Feslint-visitor-keys%2Fdownload%2F%40types%2Feslint-visitor-keys-1.0.0.tgz#1ee30d79544ca84d68d4b3cdb0af4f205663dd2d"
|
||||||
integrity sha1-HuMNeVRMqE1o1LPNsK9PIFZj3S0=
|
integrity sha1-HuMNeVRMqE1o1LPNsK9PIFZj3S0=
|
||||||
|
|
||||||
"@types/eslint@^6.1.3":
|
|
||||||
version "6.1.3"
|
|
||||||
resolved "https://registry.npm.taobao.org/@types/eslint/download/@types/eslint-6.1.3.tgz#ec2a66e445a48efaa234020eb3b6e8f06afc9c61"
|
|
||||||
integrity sha1-7Cpm5EWkjvqiNAIOs7bo8Gr8nGE=
|
|
||||||
dependencies:
|
|
||||||
"@types/estree" "*"
|
|
||||||
"@types/json-schema" "*"
|
|
||||||
|
|
||||||
"@types/estree@*":
|
|
||||||
version "0.0.39"
|
|
||||||
resolved "https://registry.npm.taobao.org/@types/estree/download/@types/estree-0.0.39.tgz#e177e699ee1b8c22d23174caaa7422644389509f"
|
|
||||||
integrity sha1-4Xfmme4bjCLSMXTKqnQiZEOJUJ8=
|
|
||||||
|
|
||||||
"@types/events@*":
|
"@types/events@*":
|
||||||
version "3.0.0"
|
version "3.0.0"
|
||||||
resolved "https://registry.npm.taobao.org/@types/events/download/@types/events-3.0.0.tgz#2862f3f58a9a7f7c3e78d79f130dd4d71c25c2a7"
|
resolved "https://registry.npm.taobao.org/@types/events/download/@types/events-3.0.0.tgz#2862f3f58a9a7f7c3e78d79f130dd4d71c25c2a7"
|
||||||
@ -1403,7 +1390,7 @@
|
|||||||
dependencies:
|
dependencies:
|
||||||
jest-diff "^24.3.0"
|
jest-diff "^24.3.0"
|
||||||
|
|
||||||
"@types/json-schema@*", "@types/json-schema@^7.0.3":
|
"@types/json-schema@^7.0.3":
|
||||||
version "7.0.3"
|
version "7.0.3"
|
||||||
resolved "https://registry.npm.taobao.org/@types/json-schema/download/@types/json-schema-7.0.3.tgz#bdfd69d61e464dcc81b25159c270d75a73c1a636"
|
resolved "https://registry.npm.taobao.org/@types/json-schema/download/@types/json-schema-7.0.3.tgz#bdfd69d61e464dcc81b25159c270d75a73c1a636"
|
||||||
integrity sha1-vf1p1h5GTcyBslFZwnDXWnPBpjY=
|
integrity sha1-vf1p1h5GTcyBslFZwnDXWnPBpjY=
|
||||||
@ -1498,13 +1485,6 @@
|
|||||||
resolved "https://registry.npm.taobao.org/@types/stack-utils/download/@types/stack-utils-1.0.1.tgz#0a851d3bd96498fa25c33ab7278ed3bd65f06c3e"
|
resolved "https://registry.npm.taobao.org/@types/stack-utils/download/@types/stack-utils-1.0.1.tgz#0a851d3bd96498fa25c33ab7278ed3bd65f06c3e"
|
||||||
integrity sha1-CoUdO9lkmPolwzq3J47TvWXwbD4=
|
integrity sha1-CoUdO9lkmPolwzq3J47TvWXwbD4=
|
||||||
|
|
||||||
"@types/stylelint@^9.10.1":
|
|
||||||
version "9.10.1"
|
|
||||||
resolved "https://registry.npm.taobao.org/@types/stylelint/download/@types/stylelint-9.10.1.tgz#211832381e43fd0774217b59f02ab389d82643ea"
|
|
||||||
integrity sha1-IRgyOB5D/Qd0IXtZ8CqzidgmQ+o=
|
|
||||||
dependencies:
|
|
||||||
postcss "7.x.x"
|
|
||||||
|
|
||||||
"@types/tapable@*":
|
"@types/tapable@*":
|
||||||
version "1.0.4"
|
version "1.0.4"
|
||||||
resolved "https://registry.npm.taobao.org/@types/tapable/download/@types/tapable-1.0.4.tgz#b4ffc7dc97b498c969b360a41eee247f82616370"
|
resolved "https://registry.npm.taobao.org/@types/tapable/download/@types/tapable-1.0.4.tgz#b4ffc7dc97b498c969b360a41eee247f82616370"
|
||||||
@ -8956,7 +8936,7 @@ postcss-value-parser@^4.0.0, postcss-value-parser@^4.0.2:
|
|||||||
resolved "https://registry.npm.taobao.org/postcss-value-parser/download/postcss-value-parser-4.0.2.tgz#482282c09a42706d1fc9a069b73f44ec08391dc9"
|
resolved "https://registry.npm.taobao.org/postcss-value-parser/download/postcss-value-parser-4.0.2.tgz#482282c09a42706d1fc9a069b73f44ec08391dc9"
|
||||||
integrity sha1-SCKCwJpCcG0fyaBptz9E7Ag5Hck=
|
integrity sha1-SCKCwJpCcG0fyaBptz9E7Ag5Hck=
|
||||||
|
|
||||||
postcss@7.x.x, postcss@^7.0.0, postcss@^7.0.1, postcss@^7.0.13, postcss@^7.0.14, postcss@^7.0.16, postcss@^7.0.17, postcss@^7.0.2, postcss@^7.0.21, postcss@^7.0.5, postcss@^7.0.6, postcss@^7.0.7:
|
postcss@^7.0.0, postcss@^7.0.1, postcss@^7.0.13, postcss@^7.0.14, postcss@^7.0.16, postcss@^7.0.17, postcss@^7.0.2, postcss@^7.0.21, postcss@^7.0.5, postcss@^7.0.6, postcss@^7.0.7:
|
||||||
version "7.0.21"
|
version "7.0.21"
|
||||||
resolved "https://registry.npm.taobao.org/postcss/download/postcss-7.0.21.tgz#06bb07824c19c2021c5d056d5b10c35b989f7e17"
|
resolved "https://registry.npm.taobao.org/postcss/download/postcss-7.0.21.tgz#06bb07824c19c2021c5d056d5b10c35b989f7e17"
|
||||||
integrity sha1-BrsHgkwZwgIcXQVtWxDDW5iffhc=
|
integrity sha1-BrsHgkwZwgIcXQVtWxDDW5iffhc=
|
||||||
|
Loading…
x
Reference in New Issue
Block a user