DiscordTickets/scripts/preinstall.js

43 lines
1.2 KiB
JavaScript
Raw Normal View History

2023-02-01 23:19:48 +02:00
/* eslint-disable no-console */
2022-07-23 15:27:32 +03:00
const { randomBytes } = require('crypto');
const fs = require('fs');
2023-02-01 23:19:48 +02:00
const { short } = require('leeks.js');
function log (...strings) {
console.log(short('&9[preinstall]&r'), ...strings);
}
2022-07-23 15:27:32 +03:00
if (process.env.CI) {
log('CI detected, skipping');
process.exit(0);
}
2022-07-23 15:27:32 +03:00
const env = {
DB_CONNECTION_URL: '',
DB_PROVIDER: '', // don't default to sqlite, postinstall checks if empty
DISCORD_SECRET: '',
DISCORD_TOKEN: '',
ENCRYPTION_KEY: randomBytes(24).toString('hex'),
2023-03-11 01:47:43 +02:00
HTTP_EXTERNAL: 'http://127.0.0.1:8169',
2023-02-18 22:08:14 +02:00
HTTP_HOST: '0.0.0.0',
2024-01-20 22:50:35 +02:00
HTTP_INTERNAL: '',
2023-03-11 01:47:43 +02:00
HTTP_PORT: 8169,
2023-02-01 23:19:48 +02:00
HTTP_TRUST_PROXY: false,
2024-01-21 05:06:40 +02:00
INVALIDATE_TOKENS: '',
2023-02-24 02:18:38 +02:00
NODE_ENV: 'production', // not bot-specific
2023-02-01 23:19:48 +02:00
OVERRIDE_ARCHIVE: '',
PUBLIC_BOT: false,
PUBLISH_COMMANDS: false,
2022-07-23 15:27:32 +03:00
SUPER: '319467558166069248',
};
2023-02-01 23:19:48 +02:00
// check ENCRYPTION_KEY because we don't want to force use of the .env file
if (!process.env.ENCRYPTION_KEY && !fs.existsSync('./.env')) {
log('generating ENCRYPTION_KEY');
2022-07-23 15:27:32 +03:00
fs.writeFileSync('./.env', Object.entries(env).map(([k, v]) => `${k}=${v}`).join('\n'));
2023-02-01 23:19:48 +02:00
log('created .env file');
2023-02-13 15:14:51 +02:00
log(short('&r&0&!e WARNING &r &e&lkeep your environment variables safe, don\'t lose your encryption key or you will lose data'));
2022-07-23 15:27:32 +03:00
} else {
2023-02-01 23:19:48 +02:00
log('nothing to do');
2024-01-20 22:50:35 +02:00
}