-
Notifications
You must be signed in to change notification settings - Fork 2
/
options.js
61 lines (53 loc) · 1.73 KB
/
options.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
var path = require('path')
var json5 = require('json5')
var fs = require('fs')
var pkg = require('./package.json')
module.exports = {
// cmd, homepage, bugs all pulled from package.json
cmd: 'tsdocstandard',
version: pkg.version,
homepage: pkg.homepage,
bugs: pkg.bugs.url,
tagline: 'JavaScript + Typescript + JSDoc',
eslint: require('eslint'),
extensions: [
'.js',
'.jsx',
'.mjs',
'.cjs',
'.d.ts'
],
eslintConfig: {
configFile: path.join(__dirname, 'eslintrc.json')
},
parseOpts: (opts, packageOpts, rootDir) => {
opts.eslintConfig = opts.eslintConfig || {}
opts.eslintConfig.parserOptions = opts.eslintConfig.parserOptions || {}
const cwd = opts.cwd || process.cwd()
opts.eslintConfig.parserOptions.tsconfigRootDir = cwd
const tsExist = fs.existsSync(path.join(cwd, 'tsconfig.json'))
const jsExists = fs.existsSync(path.join(cwd, 'jsconfig.json'))
let fileName = null
if (tsExist) fileName = 'tsconfig.json'
else if (jsExists) fileName = 'jsconfig.json'
if (fileName) {
opts.eslintConfig.parserOptions.project = `./${fileName}`
const tsconfigText = fs.readFileSync(
path.join(cwd, fileName)
)
const obj = json5.parse(tsconfigText)
if (!obj.extends) {
if (!obj.compilerOptions || !obj.compilerOptions.allowJs) {
throw new Error("Expected your tsconfig.json to contain \"allowJs\": true")
}
if (!obj.compilerOptions || !obj.compilerOptions.checkJs) {
throw new Error("Expected your tsconfig.json to contain \"checkJs\": true")
}
}
}
if (opts.filename && opts.filename.indexOf('file://') === 0) {
opts.filename = opts.filename.slice(7)
}
return opts
}
}