@agametis/create-app-for-fm
Version:
Tool for selecting a starter project for FileMaker applications
62 lines (53 loc) • 1.47 kB
JavaScript
import {program} from "commander";
import {t} from "./i18n.js";
import {
createProject,
initProject,
listTemplates,
showTemplateInfo,
} from "./commands.js";
import { VERSION } from "./config.js";
import { cancelOnce } from "./utils.js";
program.version(`${VERSION}`).description(t("cli.mainDescription"));
// Include version in the default help output (e.g., when run with no args)
program.addHelpText('before', () => `\n${program.name()} v${VERSION}\n`);
// Centralized SIGINT handling for the entire CLI
process.once("SIGINT", () => {
cancelOnce(1);
});
program
.command("create")
.description(t("cli.createDescription"))
.action(async () => {
try {
await createProject();
} catch (error) {
console.error(t("common.error") + (error?.message ?? String(error)));
process.exit(1);
}
});
program
.command("list")
.description(t("cli.listDescription"))
.action(listTemplates);
program
.command("info <template>")
.description(t("cli.infoDescription"))
.action(showTemplateInfo);
program
.command("init")
.description(t("cli.initDescription"))
.action(async () => {
try {
await initProject();
} catch (error) {
console.error(t("common.error") + (error?.message ?? String(error)));
process.exit(1);
}
});
// If no command is provided, default to 'create'
if (process.argv.length <= 2) {
process.argv.push('create');
}
program.parse(process.argv);