|
|
const shelljs = require('shelljs');
|
|
|
const path = require('path');
|
|
|
|
|
|
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
|
|
|
js: shelljs.exec('git diff --cached --name-only --diff-filter=ACM | grep .js$', {silent: true})
|
|
|
.stdout,
|
|
|
css: shelljs.exec('git diff --cached --name-only --diff-filter=ACM | grep .css$', {silent: true}).stdout
|
|
|
};
|
|
|
const lintResult = {
|
|
|
js: {},
|
|
|
css: {}
|
|
|
};
|
|
|
const lintPath = {
|
|
|
js: path.resolve('./node_modules/.bin/eslint'),
|
|
|
css: path.resolve('./node_modules/.bin/stylelint')
|
|
|
}
|
|
|
|
|
|
const ext = process.platform === 'win32' ? '.cmd' : ''; // Windows 平台需要加后缀
|
|
|
|
|
|
|
|
|
if (changeFiles.js) {
|
|
|
changeFiles.js = changeFiles.js.split('\n');
|
|
|
lintResult.js = shelljs.exec(`node_modules/.bin/eslint${ext} -c .eslintrc --cache --fix ${changeFiles.js}`);
|
|
|
changeFiles.js = changeFiles.js.replace(/\n/g, ' ');
|
|
|
lintResult.js = shelljs.exec(`${lintPath.js}${ext} -c .eslintrc --cache --fix ${changeFiles.js}`);
|
|
|
}
|
|
|
|
|
|
if (changeFiles.css) {
|
|
|
changeFiles.css = changeFiles.css.split('\n');
|
|
|
lintResult.css = shelljs.exec(`node_modules/.bin/stylelint${ext} --config .stylelintrc ${changeFiles.css}`);
|
|
|
changeFiles.css = changeFiles.css.replace(/\n/g, ' ');
|
|
|
lintResult.css = shelljs.exec(`${lintPath.css}${ext} --config .stylelintrc ${changeFiles.css}`);
|
|
|
}
|
|
|
|
|
|
if (lintResult.js.code || lintResult.css.code) {
|
...
|
...
|
|