1 | 'use strict'
|
2 |
|
3 | const fs = require('fs')
|
4 | const path = require('path')
|
5 | const os = require('os')
|
6 |
|
7 | const configPath = path.join(os.homedir(), '.adarc')
|
8 |
|
9 | module.exports = () => {
|
10 | let config
|
11 |
|
12 | try {
|
13 | const cliConfig = JSON.parse(fs.readFileSync(configPath))
|
14 | config = cliConfig[process.env.NODE_ENV || 'dev']
|
15 | } catch (e) {
|
16 | try {
|
17 | const serverConfig = JSON.parse(fs.readFileSync('./config.json'))
|
18 | config = serverConfig[process.env.NODE_ENV || 'dev']
|
19 | } catch (e) {
|
20 | config = null
|
21 | }
|
22 | }
|
23 |
|
24 | return {
|
25 | get: () => config,
|
26 | configExists: () => !!config,
|
27 | createConfig: (input) => {
|
28 | fs.writeFileSync(configPath, JSON.stringify(input, null, 2))
|
29 | }
|
30 | }
|
31 | }
|