fix(cli): should exit process when lint failed

This commit is contained in:
陈嘉涵 2019-12-19 14:10:09 +08:00
parent 5cfa9ac808
commit 46a7aefc65

View File

@ -22,28 +22,36 @@ function lintScript() {
const formatted = formatter(report.results); const formatted = formatter(report.results);
if (formatted) { if (formatted) {
stepper.error('ESLint Failed', '\n' + formatter(report.results)); stepper.error('ESLint Failed', '\n' + formatter(report.results));
} else { return false;
stepper.success('ESLint Passed');
} }
stepper.success('ESLint Passed');
return true;
} }
function lintStyle() { async function lintStyle(): Promise<boolean> {
stepper.start('Stylelint Start'); stepper.start('Stylelint Start');
stylelint({ return stylelint({
fix: true, fix: true,
formatter: 'string', formatter: 'string',
files: ['src/**/*.css', 'src/**/*.less', 'src/**/*.scss', 'src/**/*.vue'] files: ['src/**/*.css', 'src/**/*.less', 'src/**/*.scss', 'src/**/*.vue']
}).then(result => { }).then(result => {
if (result.errored) { if (result.errored) {
stepper.error('Stylelint Failed', '\n' + result.output); stepper.error('Stylelint Failed', '\n' + result.output);
} else { return false;
stepper.success('Stylelint Passed');
} }
stepper.success('Stylelint Passed');
return true;
}); });
} }
export function lint() { export async function lint() {
lintScript(); const scriptPassed = lintScript();
lintStyle(); const stylePassed = await lintStyle();
if (!scriptPassed || !stylePassed) {
process.exit(1);
}
} }