-
Notifications
You must be signed in to change notification settings - Fork 44
/
.eslintrc.js
70 lines (60 loc) · 1.79 KB
/
.eslintrc.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/* eslint-disable import/no-commonjs, import/unambiguous */
/* global module:false, __dirname:false */
const {execSync} = require('child_process');
const fs = require('fs');
const path = require('path');
const yaml = require('js-yaml');
const _ = require('lodash');
const resolve = require('resolve');
// Returns the path to the Indico source package/repo
const PATH_COMMAND = `python -c 'from flask.helpers import get_root_path; print(get_root_path("indico"))'`;
let indicoBaseDir = null;
const indicoPathFile = path.join(__dirname, '.indico_source');
// If there's an .indico_source file in the same dir, let's use it
if (fs.existsSync(indicoPathFile)) {
indicoBaseDir = fs
.readFileSync(indicoPathFile)
.toString()
.trim();
}
// Otherwise, let's use Python to figure it out
if (!indicoBaseDir) {
// Figure out where the Indico code base has been set up
indicoBaseDir = path.join(
execSync(PATH_COMMAND, {
encoding: 'utf8',
}).trim(),
'..'
);
}
let currentMap = [];
let defaultConfig = {};
try {
defaultConfig = yaml.safeLoad(fs.readFileSync(path.join(indicoBaseDir, '.eslintrc.yml')));
currentMap = defaultConfig.settings['import/resolver'].alias.map;
} catch (e) {
console.error(e);
}
const reactPath = resolve.sync('react', {basedir: indicoBaseDir});
const react = require(reactPath);
const babelConfigFile = path.join(indicoBaseDir, 'babel.config.js');
module.exports = _.merge(defaultConfig, {
settings: {
'react': {
version: react.version,
},
'import/resolver': {
alias: {
map: currentMap.map(([k, v]) => [k, path.resolve(indicoBaseDir, v)]),
},
node: {
paths: path.join(indicoBaseDir, 'node_modules'),
},
},
},
parserOptions: {
babelOptions: {
configFile: babelConfigFile,
},
},
});