2019-02-10 15:26:50 +03:00
|
|
|
import { prompt } from 'inquirer'
|
2022-09-26 18:28:25 +03:00
|
|
|
import fs from 'node:fs'
|
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
|
|
|
|
|
|
|
/**
|
|
|
|
* Duplicate the .env.sample to .env file
|
|
|
|
*/
|
2022-09-03 14:12:41 +03:00
|
|
|
export default () =>
|
|
|
|
new Promise(async (resolve) => {
|
2022-09-26 16:29:56 +03:00
|
|
|
LogHelper.info('.env file creation...')
|
2022-09-03 14:12:41 +03:00
|
|
|
|
|
|
|
const createDotenv = () => {
|
|
|
|
fs.createReadStream('.env.sample').pipe(fs.createWriteStream('.env'))
|
|
|
|
|
2022-09-26 16:29:56 +03:00
|
|
|
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()
|
|
|
|
}
|
|
|
|
})
|