mirror of
https://github.com/Hessenuk/DiscordTickets.git
synced 2024-11-17 09:23:07 +02:00
why
This commit is contained in:
parent
c2fe7f73d1
commit
8b55c351ad
@ -1,6 +1,17 @@
|
||||
require('dotenv').config();
|
||||
const fs = require('fs-extra');
|
||||
const { spawnSync } = require('child_process');
|
||||
const util = require('util');
|
||||
const exec = util.promisify(require('child_process').exec);
|
||||
|
||||
async function npx(cmd) {
|
||||
console.log(`[postinstall] > ${cmd}`);
|
||||
const {
|
||||
stderr,
|
||||
stdout,
|
||||
} = await exec('npx ' + cmd);
|
||||
if (stdout) console.log(stdout.toString());
|
||||
if (stderr) console.log(stderr.toString());
|
||||
}
|
||||
|
||||
const providers = ['mysql', 'postgresql', 'sqlite'];
|
||||
const provider = process.env.DB_PROVIDER;
|
||||
@ -12,16 +23,14 @@ if (!provider) {
|
||||
|
||||
if (!providers.includes(provider)) throw new Error(`DB_PROVIDER must be one of: ${providers}`);
|
||||
|
||||
console.log(`[postinstall] provider=${provider}`);
|
||||
console.log(`[postinstall] copying ${provider} schema & migrations`);
|
||||
|
||||
if (!fs.existsSync('./prisma')) fs.mkdirSync('./prisma');
|
||||
fs.copySync(`./db/${provider}`, './prisma'); // copy schema & migrations
|
||||
|
||||
npx('prisma generate');
|
||||
npx('prisma migrate deploy');
|
||||
(async () => {
|
||||
await npx('prisma generate');
|
||||
// await 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());
|
||||
if (child.status) process.exit(child.status);
|
||||
}
|
18
src/stdin/npx.js
Normal file
18
src/stdin/npx.js
Normal file
@ -0,0 +1,18 @@
|
||||
const { StdinCommand } = require('@eartharoid/dbf');
|
||||
const { spawn } = require('child_process');
|
||||
|
||||
module.exports = class extends StdinCommand {
|
||||
constructor(client, options) {
|
||||
super(client, {
|
||||
...options,
|
||||
id: 'npx',
|
||||
});
|
||||
}
|
||||
|
||||
async run(input) {
|
||||
if (!input[0]) return this.client.log.warn('Usage: npx <command> [args]');
|
||||
const child = spawn('npx', input, { shell: true });
|
||||
for await (const data of child.stdout) this.client.log.info('npx:', data.toString());
|
||||
for await (const data of child.stderr) this.client.warn.info('npx:', data.toString());
|
||||
}
|
||||
};
|
Loading…
Reference in New Issue
Block a user