UNPKG

@blitzjs/cli

Version:
69 lines (68 loc) 2.25 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PrismaCommand = exports.runPrismaExitOnError = exports.runPrisma = void 0; const tslib_1 = require("tslib"); const command_1 = require("@oclif/command"); const getPrismaBin = () => (0, tslib_1.__awaiter)(void 0, void 0, void 0, function* () { let bin; try { bin = require("@blitzjs/server").resolveBinAsync("prisma", "prisma"); } catch (_a) { // legacy compatability bin = require("@blitzjs/server").resolveBinAsync("@prisma/cli", "prisma"); } return bin; }); let prismaBin; const runPrisma = (args, silent = false) => (0, tslib_1.__awaiter)(void 0, void 0, void 0, function* () { if (!prismaBin) { try { prismaBin = yield getPrismaBin(); } catch (err) { throw err; } } const cp = require("cross-spawn").spawn(prismaBin, args, { stdio: silent ? "pipe" : "inherit", env: process.env, }); const cp_stderr = []; if (silent) { cp.stderr.on("data", (chunk) => { cp_stderr.push(chunk.toString()); }); } const code = yield require("p-event")(cp, "exit", { rejectionEvents: [] }); return { success: code === 0, stderr: silent ? cp_stderr.join("") : undefined, }; }); exports.runPrisma = runPrisma; const runPrismaExitOnError = (...args) => (0, tslib_1.__awaiter)(void 0, void 0, void 0, function* () { const result = yield (0, exports.runPrisma)(...args); if (!result.success) { process.exit(1); } }); exports.runPrismaExitOnError = runPrismaExitOnError; class PrismaCommand extends command_1.Command { run() { return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () { const { argv } = this.parse(PrismaCommand); yield (0, exports.runPrismaExitOnError)(argv); }); } } exports.PrismaCommand = PrismaCommand; PrismaCommand.description = "Loads env variables then proxies all args to Prisma CLI"; PrismaCommand.aliases = ["p"]; PrismaCommand.flags = { env: command_1.flags.string({ char: "e", description: "Set app environment name", }), }; PrismaCommand.strict = false;