Showing
1 changed file
with
17 additions
and
5 deletions
@@ -3,15 +3,19 @@ const path = require('path'); | @@ -3,15 +3,19 @@ const path = require('path'); | ||
3 | 3 | ||
4 | const changeFiles = { | 4 | const changeFiles = { |
5 | js: shelljs.exec('git diff --cached --name-only --diff-filter=ACM | grep .js$', {silent: true}).stdout, | 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 | 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, | ||
7 | }; | 8 | }; |
9 | + | ||
8 | const lintPath = { | 10 | const lintPath = { |
9 | js: path.resolve('./node_modules/.bin/eslint'), | 11 | js: path.resolve('./node_modules/.bin/eslint'), |
10 | css: path.resolve('./node_modules/.bin/stylelint') | 12 | css: path.resolve('./node_modules/.bin/stylelint') |
11 | }; | 13 | }; |
12 | const lintResult = { | 14 | const lintResult = { |
13 | js: {}, | 15 | js: {}, |
14 | - css: {} | 16 | + css: {}, |
17 | + vueScript: {}, | ||
18 | + vueStyle: {} | ||
15 | }; | 19 | }; |
16 | 20 | ||
17 | const ext = process.platform === 'win32' ? '.cmd' : ''; // Windows 平台需要加后缀 | 21 | const ext = process.platform === 'win32' ? '.cmd' : ''; // Windows 平台需要加后缀 |
@@ -28,9 +32,17 @@ if (changeFiles.js) { | @@ -28,9 +32,17 @@ if (changeFiles.js) { | ||
28 | 32 | ||
29 | if (changeFiles.css) { | 33 | if (changeFiles.css) { |
30 | changeFiles.css = changeFiles.css.replace(/\n/g, ' '); | 34 | changeFiles.css = changeFiles.css.replace(/\n/g, ' '); |
31 | - lintResult.css = shelljs.exec(`${lintPath.css}${ext} --config .stylelintrc ${changeFiles.css}`); | 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 --fix ${changeFiles.vue}`); | ||
41 | + lintResult.vueStyle = shelljs.exec(`${lintPath.css}${ext} --syntax scss --extract --config .stylelintrc ${changeFiles.vue}`); // eslint-disable-line | ||
32 | } | 42 | } |
33 | 43 | ||
34 | -if (lintResult.js.code || lintResult.css.code) { | ||
35 | - process.exit(lintResult.js.code || lintResult.css.code); // eslint-disable-line | 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 | ||
36 | } | 48 | } |
-
Please register or login to post a comment