Showing
3 changed files
with
24 additions
and
75 deletions
lint-all.js
deleted
100644 → 0
1 | -const shelljs = require('shelljs'); | ||
2 | -const path = require('path'); | ||
3 | - | ||
4 | -const ext = process.platform === 'win32' ? '.cmd' : ''; // Windows 平台需要加后缀 | ||
5 | -const lintPath = { | ||
6 | - js: path.resolve('./node_modules/.bin/eslint'), | ||
7 | - css: path.resolve('./node_modules/.bin/stylelint') | ||
8 | -}; | ||
9 | - | ||
10 | -const jsfiles = ['.', 'public/vue']; | ||
11 | -const cssfiles = ['public/scss/**/*.css', 'public/vue/**/*.vue']; | ||
12 | - | ||
13 | -jsfiles.forEach(function(filepath) { | ||
14 | - console.log(`JS ${filepath} 检查结果:`); | ||
15 | - shelljs.exec(`${lintPath.js}${ext} -f table -c .eslintrc --cache ${filepath}`); | ||
16 | -}); | ||
17 | - | ||
18 | -cssfiles.forEach(function(filepath) { | ||
19 | - console.log(`CSS ${filepath} 检查结果:`); | ||
20 | - shelljs.exec(`${lintPath.css}${ext} --syntax scss --cache --config .stylelintrc --custom-formatter ./node_modules/stylelint-formatter-table/index.js "${filepath}"`); // eslint-disable-line | ||
21 | -}); |
lint-commit.js
deleted
100644 → 0
1 | -const shelljs = require('shelljs'); | ||
2 | -const path = require('path'); | ||
3 | - | ||
4 | -const changeFiles = { | ||
5 | - js: shelljs.exec('git diff --cached --name-only --diff-filter=ACM | grep .js$', {silent: true}).stdout, | ||
6 | - css: shelljs.exec('git diff --cached --name-only --diff-filter=ACM | grep .css$', {silent: true}).stdout, | ||
7 | - vue: shelljs.exec('git diff --cached --name-only --diff-filter=ACM | grep .vue$', {silent: true}).stdout, | ||
8 | -}; | ||
9 | - | ||
10 | -const lintPath = { | ||
11 | - js: path.resolve('./node_modules/.bin/eslint'), | ||
12 | - css: path.resolve('./node_modules/.bin/stylelint') | ||
13 | -}; | ||
14 | -const lintResult = { | ||
15 | - js: {}, | ||
16 | - css: {}, | ||
17 | - vueScript: {}, | ||
18 | - vueStyle: {} | ||
19 | -}; | ||
20 | - | ||
21 | -const ext = process.platform === 'win32' ? '.cmd' : ''; // Windows 平台需要加后缀 | ||
22 | - | ||
23 | -// 在执行检查脚本的时候,不显示 NPM 错误日志 | ||
24 | -if (!shelljs.grep('npm run -s', path.resolve('./.git/hooks/pre-commit')).stdout.trim()) { | ||
25 | - shelljs.sed('-i', 'npm run', 'npm run -s', path.resolve('./.git/hooks/pre-commit')); | ||
26 | -} | ||
27 | - | ||
28 | -if (changeFiles.js) { | ||
29 | - changeFiles.js = changeFiles.js.replace(/\n/g, ' '); | ||
30 | - lintResult.js = shelljs.exec(`${lintPath.js}${ext} -c .eslintrc --cache ${changeFiles.js}`); | ||
31 | -} | ||
32 | - | ||
33 | -if (changeFiles.css) { | ||
34 | - changeFiles.css = changeFiles.css.replace(/\n/g, ' '); | ||
35 | - lintResult.css = shelljs.exec(`${lintPath.css}${ext} --syntax scss --config .stylelintrc ${changeFiles.css}`); | ||
36 | -} | ||
37 | - | ||
38 | -if (changeFiles.vue) { | ||
39 | - changeFiles.vue = changeFiles.vue.replace(/\n/g, ' '); | ||
40 | - lintResult.vueScript = shelljs.exec(`${lintPath.js}${ext} -c .eslintrc --cache ${changeFiles.vue}`); | ||
41 | - lintResult.vueStyle = shelljs.exec(`${lintPath.css}${ext} --syntax scss --extract --config .stylelintrc ${changeFiles.vue}`); // eslint-disable-line | ||
42 | -} | ||
43 | - | ||
44 | -const errorCode = lintResult.js.code || lintResult.css.code || lintResult.vueScript.code || lintResult.vueStyle.code; | ||
45 | - | ||
46 | -if (errorCode) { | ||
47 | - process.exit(errorCode); // eslint-disable-line | ||
48 | -} |
@@ -13,12 +13,29 @@ | @@ -13,12 +13,29 @@ | ||
13 | "static": "webpack-dev-server --config ./public/build/webpack.dev.config.js", | 13 | "static": "webpack-dev-server --config ./public/build/webpack.dev.config.js", |
14 | "build": "webpack --config ./public/build/webpack.prod.config.js", | 14 | "build": "webpack --config ./public/build/webpack.prod.config.js", |
15 | "debug": "DEBUG=\"express:*\" nodemon -e js,hbs -i public/ app.js", | 15 | "debug": "DEBUG=\"express:*\" nodemon -e js,hbs -i public/ app.js", |
16 | - "lint-js": "eslint -c .eslintrc --cache .", | ||
17 | - "lint-css": "stylelint --syntax scss --cache --config .stylelintrc 'public/scss/**/*.css'", | ||
18 | - "lint-vue-js": "eslint -c .eslintrc --cache public/vue", | ||
19 | - "lint-vue-css": "stylelint --syntax scss --extract --cache --config .stylelintrc 'public/scss/**/*.vue'", | ||
20 | - "lint-all": "node lint-all.js", | ||
21 | - "precommit": "node lint-commit.js" | 16 | + "lint-js": "lint-js", |
17 | + "lint-css": "lint-css", | ||
18 | + "lint-all": "lint-all", | ||
19 | + "precommit": "lint-commit" | ||
20 | + }, | ||
21 | + "config": { | ||
22 | + "lintJs": [ | ||
23 | + { | ||
24 | + "title": "JS", | ||
25 | + "path": [ | ||
26 | + "." | ||
27 | + ] | ||
28 | + } | ||
29 | + ], | ||
30 | + "lintCss": [ | ||
31 | + { | ||
32 | + "title": "CSS", | ||
33 | + "path": [ | ||
34 | + "public/scss/**/*.css", | ||
35 | + "public/**/*.vue" | ||
36 | + ] | ||
37 | + } | ||
38 | + ] | ||
22 | }, | 39 | }, |
23 | "license": "MIT", | 40 | "license": "MIT", |
24 | "dependencies": { | 41 | "dependencies": { |
@@ -105,6 +122,7 @@ | @@ -105,6 +122,7 @@ | ||
105 | "yoho-jquery": "^2.2.4", | 122 | "yoho-jquery": "^2.2.4", |
106 | "yoho-jquery-lazyload": "^1.9.10", | 123 | "yoho-jquery-lazyload": "^1.9.10", |
107 | "yoho-jquery-qrcode": "^0.14.0", | 124 | "yoho-jquery-qrcode": "^0.14.0", |
125 | + "yoho-lint": "^1.0.1", | ||
108 | "yoho-mlellipsis": "0.0.3", | 126 | "yoho-mlellipsis": "0.0.3", |
109 | "yoho-qs": "^1.0.1", | 127 | "yoho-qs": "^1.0.1", |
110 | "yoho-swiper": "^3.3.1", | 128 | "yoho-swiper": "^3.3.1", |
-
Please register or login to post a comment