1
1
mirror of https://github.com/leon-ai/leon.git synced 2024-12-20 23:31:30 +03:00
leon/scripts/setup/setup-dotenv.js

41 lines
866 B
JavaScript
Raw Normal View History

import fs from 'node:fs'
2019-02-10 15:26:50 +03:00
import { prompt } from 'inquirer'
import { LogHelper } from '@/helpers/log-helper'
2019-02-10 15:26:50 +03:00
/**
* Duplicate the .env.sample to .env file
*/
2022-09-03 14:12:41 +03:00
export default () =>
new Promise(async (resolve) => {
LogHelper.info('.env file creation...')
2022-09-03 14:12:41 +03:00
const createDotenv = () => {
fs.createReadStream('.env.sample').pipe(fs.createWriteStream('.env'))
LogHelper.success('.env file created')
2019-02-10 15:26:50 +03:00
}
2022-09-03 14:12:41 +03:00
if (!fs.existsSync('.env')) {
createDotenv()
resolve()
} else if (process.env.IS_DOCKER === 'true') {
resolve()
} else {
const answer = await prompt({
type: 'confirm',
name: 'dotenv.overwrite',
message: '.env file already exists, overwrite:',
default: false
})
if (answer.dotenv.overwrite === true) {
createDotenv()
}
resolve()
}
})