#!/usr/bin/env tsx
/**
* HTMX surface analyzer — CLI entry point.
*
* Inventories the `hx-*` surface of a Deco storefront so the engineer
* (or the next codemod wave) knows exactly what shapes are out there
* before starting the rewrite to React. Per D2 in the migration
* tooling policy, all htmx is rewritten on migration; no runtime is
* shipped in `@decocms/start`.
*
* Usage (from a site directory):
* npx -p @decocms/start deco-htmx-analyze
* npx -p @decocms/start deco-htmx-analyze --source /path/to/site
* npx -p @decocms/start deco-htmx-analyze --json
*
* Options:
* --source
Site directory to analyze (default: current directory)
* --json Emit machine-readable JSON instead of pretty text
* --top Show top N files by occurrence count (default: 20)
* --help, -h Show this help
*
* Wave 13-A. Read-only. Codemods land in Wave 14.
*/
import * as path from "node:path";
import { realFsAdapter } from "./migrate/post-cleanup/runner";
import {
analyzeHtmx,
type HtmxCategory,
type HtmxInventory,
} from "./migrate/analyzers/htmx-analyze";
import { banner, bold, cyan, gray, green, red, yellow } from "./migrate/colors";
interface CliOpts {
source: string;
json: boolean;
top: number;
help: boolean;
}
function parseArgs(args: string[]): CliOpts {
let source = ".";
let json = false;
let top = 20;
let help = false;
for (let i = 0; i < args.length; i++) {
switch (args[i]) {
case "--source":
source = args[++i];
break;
case "--json":
json = true;
break;
case "--top":
top = Number.parseInt(args[++i] ?? "20", 10);
if (Number.isNaN(top) || top < 0) top = 20;
break;
case "--help":
case "-h":
help = true;
break;
default:
console.error(`Unknown argument: ${args[i]}`);
process.exit(1);
}
}
return { source, json, top, help };
}
function printHelp(): void {
console.log(`deco-htmx-analyze
Inventory the htmx surface (hx-* attributes) of a Deco storefront.
Usage:
npx -p @decocms/start deco-htmx-analyze [options]
Options:
--source Site directory to analyze (default: cwd)
--json Emit machine-readable JSON
--top Top N files by occurrence count (default: 20)
--help, -h Show this help
The output is read-only. Codemods that rewrite htmx to React are a
planned follow-up — see the deco-to-tanstack-migration skill for the
per-pattern rewrite recipes.
`);
}
const CATEGORY_DESCRIPTIONS: Record = {
"event-handler": "hx-on:* with no fetch attr — pure client-side handler",
"form-swap": "hx-post on a