1
1
mirror of https://github.com/leon-ai/leon.git synced 2025-01-05 08:29:12 +03:00
leon/scripts/setup/setup-core.js

46 lines
1.3 KiB
JavaScript
Raw Normal View History

import fs from 'node:fs'
import path from 'node:path'
2019-02-10 15:26:50 +03:00
import { LogHelper } from '@/helpers/log-helper'
2019-02-10 15:26:50 +03:00
/**
* Setup Leon's core configuration
*/
2022-09-03 14:12:41 +03:00
export default () =>
new Promise((resolve) => {
LogHelper.info('Configuring core...')
2019-02-10 15:26:50 +03:00
2022-09-03 14:12:41 +03:00
const dir = 'core/config'
const list = (dir) => {
const entities = fs.readdirSync(dir)
2019-02-10 15:26:50 +03:00
2022-09-03 14:12:41 +03:00
// 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}`)
)
2019-02-10 15:26:50 +03:00
LogHelper.success(`${file} file created`)
2022-09-03 14:12:41 +03:00
} else if (
entities[i].indexOf('.sample.json') !== -1 &&
fs.existsSync(`${dir}/${file}`)
) {
LogHelper.success(`${file} already exists`)
2022-09-03 14:12:41 +03:00
}
2019-02-10 15:26:50 +03:00
}
}
2022-09-03 14:12:41 +03:00
list(dir)
resolve()
})