1 | #!/usr/bin/env node
|
2 |
|
3 | const fs = require('fs')
|
4 | const path = require('path');
|
5 |
|
6 | const binPath = path.join('node_modules', 'eslint', 'bin', 'eslint.js');
|
7 |
|
8 | const fileExists = function (path) {
|
9 | let exists;
|
10 | try {
|
11 | fs.accessSync(path, fs.F_OK);
|
12 | exists = true;
|
13 | } catch (e) {
|
14 | exists = false;
|
15 | }
|
16 | return exists;
|
17 | };
|
18 |
|
19 | const findBin = function (search) {
|
20 | const searchPath = path.join(search, binPath);
|
21 | const exists = fileExists(searchPath);
|
22 | if (!exists) {
|
23 | const nextSearchPath = path.join(search, '..');
|
24 | if (nextSearchPath === '/') return null;
|
25 | return findBin(nextSearchPath);
|
26 | }
|
27 | return searchPath;
|
28 | };
|
29 |
|
30 | const bin = findBin(__dirname);
|
31 | if (!bin) throw new Error(`Unable to find ESLint executable. Did you run 'npm install'?`);
|
32 |
|
33 | module.exports = require(bin); |
\ | No newline at end of file |