-
-
Notifications
You must be signed in to change notification settings - Fork 61
/
Copy pathget-config.js
40 lines (36 loc) · 1.19 KB
/
get-config.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
import path from 'path'
import UseConfig from 'use-config'
import chalk from 'chalk'
import findBabelConfig from 'find-babel-config'
import logger from './logger'
import BiliError from './bili-error'
export function getBabelConfig(cwd, disableBabelRc, babelOptions) {
// Only find babelrc one level deep
const { file } = findBabelConfig.sync(cwd, 1)
const babelConfig = {
babelrc: false,
runtimeHelpers: true
}
if (file && !disableBabelRc) {
logger.debug(`${chalk.bold('Babel config')}:\n${file}`)
babelConfig.extends = file
}
if (!babelConfig.extends) {
// Use our default preset when no babelrc was found
babelConfig.presets = [[require.resolve('./babel'), babelOptions]]
}
return babelConfig
}
export function getBiliConfig(_config) {
const useConfig = new UseConfig({
name: 'bili',
files: _config ? [_config] : ['package.json', '{name}.config.js', '.{name}rc']
})
const { path: configPath, config } = useConfig.loadSync()
if (configPath) {
logger.debug(chalk.bold(`Bili config file: ${path.relative(process.cwd(), configPath)}`))
} else if (_config) {
throw new BiliError(`Cannot find Bili config file at ${_config}`)
}
return config
}