38 lines
1.0 KiB
TypeScript
38 lines
1.0 KiB
TypeScript
import { formatCmd } from "node_modules/zx/build/util";
|
|
import { $, minimist } from "zx";
|
|
|
|
const args = minimist(process.argv.slice(2));
|
|
if (!args.dbCommand) {
|
|
throw new Error("dbCommand is required");
|
|
}
|
|
|
|
const filteredKeys = new Set(["_", "dbCommand", "db", "$0", "db-command"]);
|
|
const positionalArgs = Object.entries(args)
|
|
.filter(([key]) => !filteredKeys.has(key))
|
|
.map(([key, value]) => {
|
|
if (typeof value === "boolean") {
|
|
return `--${key}`;
|
|
}
|
|
|
|
return `--${key}=${value}`;
|
|
})
|
|
.concat(args._);
|
|
|
|
console.log(formatCmd(args.dbCommand));
|
|
const dbProcess = $({ quote: (arg) => arg })`${args.dbCommand}`.nothrow();
|
|
|
|
$.env = {
|
|
PATH: process.env.PATH,
|
|
HOME: process.env.HOME,
|
|
TURSO_URL: process.env.TURSO_URL ?? "http://127.0.0.1:3001",
|
|
TURSO_AUTH_TOKEN: process.env.TURSO_AUTH_TOKEN ?? "asd",
|
|
SHOULD_LOG_ERRORS: process.env.SHOULD_LOG_ERRORS ?? "true",
|
|
};
|
|
await $`bun db:migrate`.nothrow();
|
|
await $({
|
|
verbose: true,
|
|
quote: (arg) => arg,
|
|
})`FORCE_COLOR=1 bun test ${positionalArgs.join(" ")}`.nothrow();
|
|
|
|
await dbProcess.kill("SIGINT");
|