Authored by 毕凯

Merge remote-tracking branch 'origin/feature/yoho-lint' into release/5.8.1

const shelljs = require('shelljs');
const path = require('path');
const ext = process.platform === 'win32' ? '.cmd' : ''; // Windows 平台需要加后缀
const lintPath = {
js: path.resolve('./node_modules/.bin/eslint'),
css: path.resolve('./node_modules/.bin/stylelint')
};
const jsfiles = ['.', 'public/vue'];
const cssfiles = ['public/scss/**/*.css', 'public/vue/**/*.vue'];
jsfiles.forEach(function(filepath) {
console.log(`JS ${filepath} 检查结果:`);
shelljs.exec(`${lintPath.js}${ext} -f table -c .eslintrc --cache ${filepath}`);
});
cssfiles.forEach(function(filepath) {
console.log(`CSS ${filepath} 检查结果:`);
shelljs.exec(`${lintPath.css}${ext} --syntax scss --cache --config .stylelintrc --custom-formatter ./node_modules/stylelint-formatter-table/index.js "${filepath}"`); // eslint-disable-line
});
const shelljs = require('shelljs');
const path = require('path');
const changeFiles = {
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,
vue: shelljs.exec('git diff --cached --name-only --diff-filter=ACM | grep .vue$', {silent: true}).stdout,
};
const lintPath = {
js: path.resolve('./node_modules/.bin/eslint'),
css: path.resolve('./node_modules/.bin/stylelint')
};
const lintResult = {
js: {},
css: {},
vueScript: {},
vueStyle: {}
};
const ext = process.platform === 'win32' ? '.cmd' : ''; // Windows 平台需要加后缀
// 在执行检查脚本的时候,不显示 NPM 错误日志
if (!shelljs.grep('npm run -s', path.resolve('./.git/hooks/pre-commit')).stdout.trim()) {
shelljs.sed('-i', 'npm run', 'npm run -s', path.resolve('./.git/hooks/pre-commit'));
}
if (changeFiles.js) {
changeFiles.js = changeFiles.js.replace(/\n/g, ' ');
lintResult.js = shelljs.exec(`${lintPath.js}${ext} -c .eslintrc --cache ${changeFiles.js}`);
}
if (changeFiles.css) {
changeFiles.css = changeFiles.css.replace(/\n/g, ' ');
lintResult.css = shelljs.exec(`${lintPath.css}${ext} --syntax scss --config .stylelintrc ${changeFiles.css}`);
}
if (changeFiles.vue) {
changeFiles.vue = changeFiles.vue.replace(/\n/g, ' ');
lintResult.vueScript = shelljs.exec(`${lintPath.js}${ext} -c .eslintrc --cache ${changeFiles.vue}`);
lintResult.vueStyle = shelljs.exec(`${lintPath.css}${ext} --syntax scss --extract --config .stylelintrc ${changeFiles.vue}`); // eslint-disable-line
}
const errorCode = lintResult.js.code || lintResult.css.code || lintResult.vueScript.code || lintResult.vueStyle.code;
if (errorCode) {
process.exit(errorCode); // eslint-disable-line
}
... ... @@ -13,12 +13,29 @@
"static": "webpack-dev-server --config ./public/build/webpack.dev.config.js",
"build": "webpack --config ./public/build/webpack.prod.config.js",
"debug": "DEBUG=\"express:*\" nodemon -e js,hbs -i public/ app.js",
"lint-js": "eslint -c .eslintrc --cache .",
"lint-css": "stylelint --syntax scss --cache --config .stylelintrc 'public/scss/**/*.css'",
"lint-vue-js": "eslint -c .eslintrc --cache public/vue",
"lint-vue-css": "stylelint --syntax scss --extract --cache --config .stylelintrc 'public/scss/**/*.vue'",
"lint-all": "node lint-all.js",
"precommit": "node lint-commit.js"
"lint-js": "lint-js",
"lint-css": "lint-css",
"lint-all": "lint-all",
"precommit": "lint-commit"
},
"config": {
"lintJs": [
{
"title": "JS",
"path": [
"."
]
}
],
"lintCss": [
{
"title": "CSS",
"path": [
"public/scss/**/*.css",
"public/**/*.vue"
]
}
]
},
"license": "MIT",
"dependencies": {
... ... @@ -109,6 +126,7 @@
"yoho-jquery": "^2.2.4",
"yoho-jquery-lazyload": "^1.9.12",
"yoho-jquery-qrcode": "^0.14.0",
"yoho-lint": "^1.0.1",
"yoho-mlellipsis": "0.0.3",
"yoho-qs": "^1.0.1",
"yoho-swiper": "^3.3.1",
... ...