lint.js
798 Bytes
const shelljs = require('shelljs');
const changeFiles = {
js: shelljs.exec('git diff --cached --name-only --diff-filter=ACM | grep .js$').stdout,
css: shelljs.exec('git diff --cached --name-only --diff-filter=ACM | grep .css$').stdout
};
const lintResult = {
js: {},
css: {}
};
const ext = process.platform === 'win32' ? '.cmd' : ''; // Windows 平台需要加后缀
if (changeFiles.js) {
lintResult.js = shelljs.exec(`node_modules/.bin/eslint${ext} -c .eslintrc --cache --fix ${changeFiles.js}`);
}
if (changeFiles.css) {
lintResult.css = shelljs.exec(`node_modules/.bin/stylelint${ext} --config .stylelintrc ${changeFiles.css}`);
}
if (lintResult.js.code || lintResult.css.code) {
process.exit(lintResult.js.code || lintResult.css.code); // eslint-disable-line
}