forked from leon-ai/leon
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup-core.js
More file actions
38 lines (32 loc) 路 1.12 KB
/
Copy pathsetup-core.js
File metadata and controls
38 lines (32 loc) 路 1.12 KB
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
import fs from 'fs'
import path from 'path'
import log from '@/helpers/log'
/**
* Setup Leon's core configuration
*/
export default () => new Promise((resolve) => {
log.info('Configuring core...')
const dir = 'server/src/config'
const list = (dir) => {
const entities = fs.readdirSync(dir)
// Browse core config entities
for (let i = 0; i < entities.length; i += 1) {
const file = `${entities[i].replace('.sample.json', '.json')}`
// Recursive if the entity is a directory
const way = path.join(dir, entities[i])
if (fs.statSync(way).isDirectory()) {
list(way)
} else if (entities[i].indexOf('.sample.json') !== -1 &&
!fs.existsSync(`${dir}/${file}`)) { // Clone config from sample in case there is no existing config file
fs.createReadStream(`${dir}/${entities[i]}`)
.pipe(fs.createWriteStream(`${dir}/${file}`))
log.success(`${file} file created`)
} else if (entities[i].indexOf('.sample.json') !== -1 &&
fs.existsSync(`${dir}/${file}`)) {
log.success(`${file} already exists`)
}
}
}
list(dir)
resolve()
})