v3.0.0/src/setup.js

92 lines
2.2 KiB
JavaScript
Raw Normal View History

2020-07-07 01:02:59 +02:00
/* eslint-disable no-console */
2019-02-19 15:52:24 +01:00
const jetpack = require('fs-jetpack');
2019-02-19 03:30:10 +01:00
const qoa = require('qoa');
2020-07-07 01:02:59 +02:00
2019-02-19 03:30:10 +01:00
qoa.config({
prefix: '>',
2020-12-24 09:40:50 +01:00
underlineQuery: false
2019-02-19 03:30:10 +01:00
});
async function start() {
2019-02-21 15:49:29 +01:00
console.log();
console.log('You can manually edit .env file after the wizard to edit values');
console.log();
2019-02-19 03:30:10 +01:00
const wizard = [
2021-06-17 18:45:10 +02:00
{
type: 'input',
query: 'Full domain this instance is gonna be running on (Ex: https://my-super-chibisafe.xyz):',
handle: 'DOMAIN'
},
2019-02-19 03:30:10 +01:00
{
type: 'input',
2021-06-14 17:12:26 +02:00
query: 'Port to run chibisafe in? (default: 5000)',
2020-12-24 09:40:50 +01:00
handle: 'SERVER_PORT'
2019-02-19 03:30:10 +01:00
},
2019-02-22 01:31:55 +01:00
{
type: 'interactive',
2021-06-14 17:12:26 +02:00
query: 'Which database do you want to use? (select sqlite3 if not sure)',
2019-02-22 01:31:55 +01:00
handle: 'DB_CLIENT',
symbol: '>',
menu: [
'sqlite3',
2019-02-22 01:31:55 +01:00
'pg',
2020-12-24 09:40:50 +01:00
'mysql'
]
2019-02-22 01:31:55 +01:00
},
2019-02-21 15:49:29 +01:00
{
type: 'input',
2021-06-14 17:12:26 +02:00
query: 'Database host (Leave blank if you selected sqlite3):',
2020-12-24 09:40:50 +01:00
handle: 'DB_HOST'
2019-02-21 15:49:29 +01:00
},
{
type: 'input',
2021-06-14 17:12:26 +02:00
query: 'Database user (Leave blank if you selected sqlite3):',
2020-12-24 09:40:50 +01:00
handle: 'DB_USER'
2019-02-21 15:49:29 +01:00
},
{
type: 'input',
2021-06-14 17:12:26 +02:00
query: 'Database password (Leave blank if you selected sqlite3):',
2020-12-24 09:40:50 +01:00
handle: 'DB_PASSWORD'
2019-02-21 15:49:29 +01:00
},
{
type: 'input',
2021-06-14 17:12:26 +02:00
query: 'Database name (Leave blank if you selected sqlite3):',
2020-12-24 09:40:50 +01:00
handle: 'DB_DATABASE'
}
2019-02-19 03:30:10 +01:00
];
const response = await qoa.prompt(wizard);
2019-02-19 15:52:24 +01:00
let envfile = '';
const defaultSettings = {
2021-06-17 18:45:10 +02:00
DOMAIN: response.DOMAIN,
2020-12-27 21:06:08 +01:00
SERVER_PORT: response.SERVER_PORT || 5000,
DB_CLIENT: response.DB_CLIENT,
DB_HOST: response.DB_HOST || null,
DB_USER: response.DB_USER || null,
DB_PASSWORD: response.DB_PASSWORD || null,
2021-06-14 17:12:26 +02:00
DB_DATABASE: response.DB_DATABASE || null
2019-02-19 15:52:24 +01:00
};
2020-12-27 21:06:08 +01:00
const keys = Object.keys(defaultSettings);
2019-02-19 15:52:24 +01:00
for (const item of keys) {
2021-06-14 17:12:26 +02:00
envfile += `${item}=${defaultSettings[item]}\n`;
2019-02-19 15:52:24 +01:00
}
jetpack.write('.env', envfile);
jetpack.dir('database');
2019-02-19 15:52:24 +01:00
console.log();
2021-06-14 17:12:26 +02:00
console.log('=====================================================');
console.log('== .env file generated successfully. ==');
console.log('=====================================================');
console.log(`== Both your initial user and password are 'admin' ==`);
console.log('== MAKE SURE TO CHANGE IT AFTER YOUR FIRST LOGIN ==');
console.log('=====================================================');
2019-02-19 15:52:24 +01:00
console.log();
2020-12-27 21:06:08 +01:00
setTimeout(() => {}, 1000);
2019-02-19 03:30:10 +01:00
}
start();