#!/usr/bin/env node /** * cli:derive-job-specs — entry point. * * Invocation: * npx --prefer-offline tsx skills/ba-develop/cli/derive-job-specs/index.ts \ * --spec '{"moduleRoot":".smartstack/ba//","appCode":"flotte"}' * * Splice `report.jobs` into the entity specs: `scheduledJobs[]` on * scaffold-business AND scaffold-controller (the entity each job's UC belongs * to). scaffold-business then emits the Run{X}Async service method + the * Program.cs RECURRING-JOBS registration; scaffold-controller the manual * POST `jobs/{slug}/run` trigger (permission `.execute`, `?date=` replay). */ import { parseArgs } from 'node:util' import { validate } from './validate.js' import { deriveJobSpecs } from './derive.js' import { executeEnvelope, failExecute, printEnvelope } from '../../../lib/output.js' import type { DeriveJobSpecsReport } from './types.js' const COMMAND = 'derive-job-specs' function main(): void { const { values } = parseArgs({ options: { spec: { type: 'string' } }, strict: true }) if (!values.spec) { printEnvelope(failExecute(COMMAND, ['--spec is required'])) process.exit(1) } let raw: unknown try { raw = JSON.parse(values.spec) } catch { printEnvelope(failExecute(COMMAND, ['Invalid JSON in --spec'])) process.exit(1) } const validation = validate(raw) if (!validation.valid || !validation.spec) { printEnvelope(failExecute(COMMAND, validation.errors)) process.exit(1) } const report = deriveJobSpecs(validation.spec) printEnvelope(executeEnvelope(COMMAND, { report, warnings: report.warnings, nextSteps: report.jobs.length > 0 ? [ 'Splice report.jobs as `scheduledJobs[]` into the owning entity\'s scaffold-business AND scaffold-controller specs.', 'Re-run scaffold-business (emits the service method + the Program.cs RECURRING-JOBS line) then scaffold-controller (the POST jobs/{slug}/run trigger).', ] : [], })) } main()