2019-02-10 15:26:50 +03:00
|
|
|
import { prompt } from 'inquirer'
|
|
|
|
import fs from 'fs'
|
|
|
|
|
2022-09-16 20:36:58 +03:00
|
|
|
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...')
|
|
|
|
|
|
|
|
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()
|
|
|
|
}
|
|
|
|
})
|