feat(cli): add interactive area build menu
This commit is contained in:
49
scripts/interactive-build.js
Normal file
49
scripts/interactive-build.js
Normal file
@@ -0,0 +1,49 @@
|
||||
#!/usr/bin/env node
|
||||
"use strict";
|
||||
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const { spawnSync } = require("child_process");
|
||||
const { STAGES, resolveStages, canonicalStages } = require("./lib/build-stages");
|
||||
|
||||
const repoRoot = path.resolve(__dirname, "..");
|
||||
|
||||
function areaConfigs() {
|
||||
return fs.readdirSync(path.join(repoRoot, "config", "areas"))
|
||||
.filter((file) => file.endsWith(".json"))
|
||||
.sort()
|
||||
.map((file) => path.join(repoRoot, "config", "areas", file));
|
||||
}
|
||||
|
||||
function requireTty(input = process.stdin, output = process.stdout) {
|
||||
if (!input.isTTY || !output.isTTY) throw new Error("Interactive build requires a TTY. Use npm run build:area -- --config <area> --stages <stages> instead.");
|
||||
}
|
||||
|
||||
async function main() {
|
||||
requireTty();
|
||||
const configs = areaConfigs();
|
||||
if (!configs.length) throw new Error("No area configs found in config/areas.");
|
||||
const { select, checkbox } = await import("@inquirer/prompts");
|
||||
const config = await select({
|
||||
message: "Choose an area",
|
||||
choices: configs.map((file) => ({ name: path.basename(file, ".json"), value: file })),
|
||||
});
|
||||
const chosen = await checkbox({
|
||||
message: "Choose build stages",
|
||||
choices: STAGES.map((stage) => ({ name: `${stage.id} - ${stage.description}`, value: stage.id })),
|
||||
required: true,
|
||||
});
|
||||
if (!chosen.length) throw new Error("Choose at least one build stage.");
|
||||
const stages = canonicalStages(resolveStages({}, chosen));
|
||||
console.log(`Area: ${path.basename(config)}`);
|
||||
console.log(`Stages: ${stages.join(", ")}`);
|
||||
const result = spawnSync(process.execPath, [path.join(__dirname, "build-area.js"), "--config", config, "--stages", stages.join(",")], { stdio: "inherit" });
|
||||
if (result.error) throw result.error;
|
||||
process.exitCode = result.status || 0;
|
||||
}
|
||||
|
||||
if (require.main === module) main().catch((error) => {
|
||||
if (error.name !== "ExitPromptError") console.error(`Error: ${error.message}`);
|
||||
process.exitCode = error.name === "ExitPromptError" ? 0 : 1;
|
||||
});
|
||||
module.exports = { areaConfigs, requireTty };
|
||||
Reference in New Issue
Block a user