-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
54 lines (37 loc) · 1.37 KB
/
index.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
// -------------------------------------------------------------------- EXPORTS
const fs = require('fs')
const detail_handler = require('./detail_sys')
// -------------------------------------------------------------------- METHODS
// ------------------- FILES
function load(filename) {
return JSON.parse(fs.readFileSync(filename, 'utf8'))
}
function save(filename, config) {
return fs.writeFileSync(filename, JSON.stringify(config, null, 4),)
}
// ------------------- BASE CONFIG HANDLER
function handles_input(config, path=[]) {
config = create_detail(config)
let detail =config['@detail']
let input_type = detail.input_type
return detail_map[input_type](detail, path)
}
// -------------------------------------------------------------------- CORE
function load_config(
force_reset=false,
conf_file='config.json',
base_conf_file='base_config.json',
config_title='FIRST CONFIGURATION',
use_config_title=true) {
if (!fs.existsSync(conf_file) || force_reset) {
if (use_config_title) {
console.log('\n' + config_title + '\n')
}
let base_config = load(base_conf_file)
let config = detail_handler(base_config)
save(conf_file, config)
}
return load(conf_file)
}
// -------------------------------------------------------------------- EXPORTS
module.exports = load_config