Authored by xuqi

new lint

Showing 1 changed file with 12 additions and 7 deletions
1 const shelljs = require('shelljs'); 1 const shelljs = require('shelljs');
  2 +const path = require('path');
2 3
3 const changeFiles = { 4 const changeFiles = {
4 - js: shelljs.exec('git diff --cached --name-only --diff-filter=ACM | grep .js$').stdout,  
5 - css: shelljs.exec('git diff --cached --name-only --diff-filter=ACM | grep .css$').stdout 5 + js: shelljs.exec('git diff --cached --name-only --diff-filter=ACM | grep .js$', {silent: true})
  6 + .stdout,
  7 + css: shelljs.exec('git diff --cached --name-only --diff-filter=ACM | grep .css$', {silent: true}).stdout
6 }; 8 };
7 const lintResult = { 9 const lintResult = {
8 js: {}, 10 js: {},
9 css: {} 11 css: {}
10 }; 12 };
  13 +const lintPath = {
  14 + js: path.resolve('./node_modules/.bin/eslint'),
  15 + css: path.resolve('./node_modules/.bin/stylelint')
  16 +}
11 17
12 const ext = process.platform === 'win32' ? '.cmd' : ''; // Windows 平台需要加后缀 18 const ext = process.platform === 'win32' ? '.cmd' : ''; // Windows 平台需要加后缀
13 19
14 -  
15 if (changeFiles.js) { 20 if (changeFiles.js) {
16 - changeFiles.js = changeFiles.js.split('\n');  
17 - lintResult.js = shelljs.exec(`node_modules/.bin/eslint${ext} -c .eslintrc --cache --fix ${changeFiles.js}`); 21 + changeFiles.js = changeFiles.js.replace(/\n/g, ' ');
  22 + lintResult.js = shelljs.exec(`${lintPath.js}${ext} -c .eslintrc --cache --fix ${changeFiles.js}`);
18 } 23 }
19 24
20 if (changeFiles.css) { 25 if (changeFiles.css) {
21 - changeFiles.css = changeFiles.css.split('\n');  
22 - lintResult.css = shelljs.exec(`node_modules/.bin/stylelint${ext} --config .stylelintrc ${changeFiles.css}`); 26 + changeFiles.css = changeFiles.css.replace(/\n/g, ' ');
  27 + lintResult.css = shelljs.exec(`${lintPath.css}${ext} --config .stylelintrc ${changeFiles.css}`);
23 } 28 }
24 29
25 if (lintResult.js.code || lintResult.css.code) { 30 if (lintResult.js.code || lintResult.css.code) {