mirror of
https://github.com/Hessenuk/DiscordTickets.git
synced 2025-09-01 16:31:25 +03:00
Improve prisma scripts
This commit is contained in:
@@ -1,11 +1,16 @@
|
||||
require('dotenv').config();
|
||||
const fs = require('fs-extra');
|
||||
// const { promisify } = require('util');
|
||||
// const exec = promisify(require('child_process').exec);
|
||||
const { spawnSync } = require('child_process');
|
||||
|
||||
|
||||
const providers = ['mysql', 'postgresql', 'sqlite'];
|
||||
const provider = process.env.DB_PROVIDER;
|
||||
|
||||
if (!provider) {
|
||||
console.log('[postinstall] environment not set, exiting.');
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
if (!providers.includes(provider)) throw new Error(`DB_PROVIDER must be one of: ${providers}`);
|
||||
|
||||
if (!fs.existsSync('./prisma')) fs.mkdirSync('./prisma');
|
||||
@@ -15,6 +20,7 @@ npx('prisma generate');
|
||||
npx('prisma migrate deploy');
|
||||
|
||||
function npx(cmd) {
|
||||
console.log(`[postinstall] > ${cmd}`);
|
||||
const child = spawnSync('npx', cmd.split(/\s/));
|
||||
if (child.stdout) console.log(child.stdout.toString());
|
||||
if (child.stderr) console.log(child.stderr.toString());
|
23
scripts/preinstall.js
Normal file
23
scripts/preinstall.js
Normal file
@@ -0,0 +1,23 @@
|
||||
const { randomBytes } = require('crypto');
|
||||
const fs = require('fs');
|
||||
|
||||
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'),
|
||||
HTTP_BIND: 8080,
|
||||
HTTP_EXTERNAL: 'http://localhost:8080',
|
||||
PORTAL: '',
|
||||
SUPER: '319467558166069248',
|
||||
};
|
||||
|
||||
// check DISCORD_TOKEN because we don't want to force use of the .env file
|
||||
if (!process.env.DISCORD_TOKEN && !fs.existsSync('./.env')) {
|
||||
console.log('[preinstall] Generating ENCRYPTION_KEY');
|
||||
fs.writeFileSync('./.env', Object.entries(env).map(([k, v]) => `${k}=${v}`).join('\n'));
|
||||
console.log('[preinstall] Created .env file');
|
||||
} else {
|
||||
console.log('[preinstall] Nothing to do');
|
||||
}
|
Reference in New Issue
Block a user