1
1
mirror of https://github.com/leon-ai/leon.git synced 2024-12-27 10:43:12 +03:00
leon/scripts/setup/setup-core.js
2019-02-10 20:26:50 +08:00

39 lines
1.1 KiB
JavaScript

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()
})