#!/usr/bin/env node "use strict"; // Load the vendored CLI bundle without running main(), then call the // in-bundle getSevenGovernorsChart(date, location, options) that the CLI // itself never forwards flags into. process.env.VITEST = "1"; const fs = require("fs"); const path = require("path"); const Module = require("module"); const cliPath = path.resolve(__dirname, "..", "vendor", "stem-branch", "dist", "cli.cjs"); if (!fs.existsSync(cliPath)) { process.stderr.write("vendored seven-governors CLI is missing\n"); process.exit(2); } const source = fs.readFileSync(cliPath, "utf8").replace( "if (!process.env?.VITEST) {\n main();\n}", "module.exports.getSevenGovernorsChart = getSevenGovernorsChart;\nif (!process.env?.VITEST) {\n main();\n}", ); const loaded = new Module(cliPath); loaded.filename = cliPath; loaded.paths = Module._nodeModulePaths(path.dirname(cliPath)); loaded._compile(source, cliPath); const getSevenGovernorsChart = loaded.exports.getSevenGovernorsChart; if (typeof getSevenGovernorsChart !== "function") { process.stderr.write("getSevenGovernorsChart is not available from the vendored CLI\n"); process.exit(2); } const input = JSON.parse(fs.readFileSync(0, "utf8")); const date = new Date(input.date); if (Number.isNaN(date.getTime())) { process.stderr.write("invalid date\n"); process.exit(2); } const chart = getSevenGovernorsChart( date, { lat: Number(input.lat), lon: Number(input.lng) }, { ketuMode: input.ketuMode || "apogee", siderealMode: input.siderealMode || { type: "modern" }, }, ); process.stdout.write(JSON.stringify({ sevenGovernors: chart }));