1
1
mirror of https://github.com/leon-ai/leon.git synced 2025-01-03 06:06:06 +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
/**
* Set up Leon's core configuration
2019-02-10 15:26:50 +03:00
*/
2022-09-03 14:12:41 +03:00
export default () =>
2023-04-02 21:34:50 +03:00
new Promise(async (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'
2023-04-02 21:34:50 +03:00
const list = async (dir) => {
const entities = await fs.promises.readdir(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])
2023-04-02 21:34:50 +03:00
if ((await fs.promises.stat(way)).isDirectory()) {
await list(way)
2022-09-03 14:12:41 +03:00
} 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
}
}
2023-04-02 21:34:50 +03:00
await list(dir)
2022-09-03 14:12:41 +03:00
resolve()
})