make linc script cross platform (#11447)
* make linc script cross platform * fix typo * attempt to fix long command error * use eslint node api * Update linc.js
Joe Lim committed
Nov 4, 2017 at 11:09 UTC
743201387246d0cde523700c151550786f0afc2e
2 files changed
+42
-1
package.json
+1
-1
@@ -98,7 +98,7 @@
98
},
99
"scripts": {
100
"build": "npm run version-check && node scripts/rollup/build.js",
101
- "linc": "git diff --name-only --diff-filter=ACMRTUB `git merge-base HEAD master` | grep '\\.js$' | xargs eslint --",
101
+ "linc": "node ./scripts/tasks/linc.js",
102
"lint": "node ./scripts/tasks/eslint.js",
103
"postinstall": "node node_modules/fbjs-scripts/node/check-dev-engines.js package.json",
104
"test": "jest",
scripts/tasks/linc.js
new
+41
@@ -0,0 +1,41 @@
1
+/**
2
+ * Copyright (c) 2013-present, Facebook, Inc.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+'use strict';
9
+
10
+const execFileSync = require('child_process').execFileSync;
11
+const CLIEngine = require('eslint').CLIEngine;
12
+
13
+const cli = new CLIEngine();
14
+const formatter = cli.getFormatter();
15
+
16
+const mergeBase = execFileSync('git', ['merge-base', 'HEAD', 'master'], {
17
+ stdio: 'pipe',
18
+ encoding: 'utf-8',
19
+}).trim();
20
+const changedFiles = execFileSync(
21
+ 'git',
22
+ ['diff', '--name-only', '--diff-filter=ACMRTUB', mergeBase],
23
+ {
24
+ stdio: 'pipe',
25
+ encoding: 'utf-8',
26
+ }
27
+)
28
+ .trim()
29
+ .toString()
30
+ .split('\n');
31
+const jsFiles = changedFiles.filter(file => file.match(/.js$/g));
32
+
33
+const report = cli.executeOnFiles(jsFiles);
34
+console.log(formatter(report.results));
35
+
36
+if (report.errorCount > 0) {
37
+ console.log('Lint failed for changed files.');
38
+ process.exit(1);
39
+} else {
40
+ console.log('Lint passed for changed files.');
41
+}