zipline/scripts/prisma-run.js

27 lines
675 B
JavaScript
Raw Normal View History

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
},
});
let a = '';
proc.stdout.on('data', d => {
2021-08-28 13:32:09 -05:00
if (!nostdout) console.log(d.toString());
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());
});
proc.stdout.on('end', () => res(a));
proc.stdout.on('close', () => res(a));
2021-06-23 13:20:20 -05:00
});
};