2021-06-23 13:20:20 -05:00
|
|
|
const { spawn } = require('child_process');
|
|
|
|
const { join } = require('path');
|
|
|
|
|
2021-08-28 13:32:09 -05:00
|
|
|
module.exports = (url, args, nostdout = false) => {
|
2021-06-23 13:20:20 -05:00
|
|
|
return new Promise((res, rej) => {
|
|
|
|
const proc = spawn(join(process.cwd(), 'node_modules', '.bin', 'prisma'), args, {
|
|
|
|
env: {
|
|
|
|
DATABASE_URL: url,
|
|
|
|
...process.env
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2021-08-25 11:58:48 -05:00
|
|
|
let a = '';
|
|
|
|
|
|
|
|
proc.stdout.on('data', d => {
|
2021-08-28 13:32:09 -05:00
|
|
|
if (!nostdout) console.log(d.toString());
|
2021-08-25 11:58:48 -05:00
|
|
|
a += d.toString();
|
|
|
|
});
|
2021-06-23 13:20:20 -05:00
|
|
|
proc.stderr.on('data', d => {
|
2021-08-28 13:32:09 -05:00
|
|
|
if (!nostdout) console.log(d.toString());
|
2021-06-23 13:20:20 -05:00
|
|
|
rej(d.toString());
|
|
|
|
});
|
2021-08-25 11:58:48 -05:00
|
|
|
proc.stdout.on('end', () => res(a));
|
|
|
|
proc.stdout.on('close', () => res(a));
|
2021-06-23 13:20:20 -05:00
|
|
|
});
|
|
|
|
};
|