Skip to content

Commit

Permalink
Hackily automigrate
Browse files Browse the repository at this point in the history
  • Loading branch information
brettimus committed Jun 5, 2024
1 parent e473d66 commit 6d2c9ae
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions api/bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,31 @@ import path from "node:path";
const args = process.argv.slice(2);
const script = args[0];

// HACK - if no script is specified, migrate then open studio
const scripts = !script ? ["migrate", "studio"] : [script];

const validScripts = {
migrate: "dist/migrate.js",
studio: "dist/src/index.node.js",
};

if (!validScripts[script]) {
console.error(
`Invalid script "${script}". Valid scripts are: ${Object.keys(validScripts).join(", ")}`,
);
process.exit(1);
}
scripts.forEach(runScript);

function runScript(scriptName) {
const scriptPath = validScripts[scriptName];
if (!scriptPath) {
console.error(
`Invalid script "${scriptName}". Valid scripts are: ${Object.keys(validScripts).join(", ")}`,
);
process.exit(1);
}

// Get the root directory of this script's project
const scriptDir = path.resolve(__dirname, "../");
// Get the root directory of this script's project
const scriptDir = path.resolve(__dirname, "../");

// Construct the command to run the appropriate script in the `dist` folder
const command = `node ${path.join(scriptDir, validScripts[script])}`;
// Construct the command to run the appropriate script in the `dist` folder
const command = `node ${path.join(scriptDir, scriptPath)}`;

execSync(command, { stdio: "inherit" });
}

execSync(command, { stdio: "inherit" });

0 comments on commit 6d2c9ae

Please sign in to comment.