#!/usr/bin/env node import { resolve } from "node:path"; import { scaffold } from "../generator/generator.js"; import { answersForFixture } from "../prompt/prompt.js"; import type { PromptAnswers } from "../prompt/prompt.types.js"; interface ParsedArgs { readonly name: string; readonly force: boolean; readonly fixture: | "trusted-postgres-full" | "isolated-sqlite-rest-only" | "sandboxed-none-rest-only"; readonly targetDir: string; } export function parseArgs(argv: readonly string[]): ParsedArgs { let name = ""; let force = false; let fixture: ParsedArgs["fixture"] = "sandboxed-none-rest-only"; let targetDir = ""; for (let i = 0; i < argv.length; i++) { const arg = argv[i]; if (arg === "--force") { force = true; continue; } if (arg === "--fixture") { const v = argv[i + 1]; i++; if ( v === "trusted-postgres-full" || v === "isolated-sqlite-rest-only" || v === "sandboxed-none-rest-only" ) { fixture = v; } continue; } if (arg === "--dir") { targetDir = argv[i + 1] ?? ""; i++; continue; } if (arg && !arg.startsWith("--") && name === "") { name = arg; } } if (targetDir === "") targetDir = resolve(process.cwd(), name); return { name, force, fixture, targetDir }; } export function run(argv: readonly string[]): PromptAnswers { const parsed = parseArgs(argv); const answers = answersForFixture(parsed.fixture, parsed.name); scaffold({ answers, targetDir: parsed.targetDir, force: parsed.force }); return answers; } /* c8 ignore start */ if ( typeof process !== "undefined" && Array.isArray(process.argv) && process.argv[1] && /create-suaveplan-plugin\.(js|ts)$/.test(process.argv[1]) ) { run(process.argv.slice(2)); } /* c8 ignore stop */