2022-09-26 18:28:25 +03:00
|
|
|
import fs from 'node:fs'
|
|
|
|
import path from 'node:path'
|
2019-02-10 15:26:50 +03:00
|
|
|
|
2022-09-26 16:29:56 +03:00
|
|
|
import { LogHelper } from '@/helpers/log-helper'
|
2019-02-10 15:26:50 +03:00
|
|
|
|
|
|
|
/**
|
2022-11-13 19:49:24 +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) => {
|
2022-09-26 16:29:56 +03:00
|
|
|
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
|
|
|
|
2022-09-26 16:29:56 +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}`)
|
|
|
|
) {
|
2022-09-26 16:29:56 +03:00
|
|
|
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()
|
|
|
|
})
|