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

40 lines
835 B
JavaScript
Raw Normal View History

2019-02-10 15:26:50 +03:00
import { prompt } from 'inquirer'
import fs from 'fs'
import { LOG } from '@/helpers/log'
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) => {
LOG.info('.env file creation...')
2022-09-03 14:12:41 +03:00
const createDotenv = () => {
fs.createReadStream('.env.sample').pipe(fs.createWriteStream('.env'))
LOG.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()
}
})