agentleFS
ukanhaupaukanhaupa/projx/cli/CLAUDE.md

projx / cli

CLAUDE.md71 starsChanged 4 months agoMITView on GitHub

Stack-scoped notes. The root ../CLAUDE.md is the primary reference for the CLI's behavior (commands, template engine, ORM addons, feature templates) — this file carries the local dev shapes. Read both. Unlike the sibling stack dirs, cli/ is not a copied template — it's the engine. It's excluded from the component copy (EXCLUDE in src/utils.ts) and is the only section that gates the CLI itself.

The file

Files
CLAUDE.md

cli — create-projx CLI source (projx engine)

Stack-scoped notes. The root ../CLAUDE.md is the primary reference for the CLI's behavior (commands, template engine, ORM addons, feature templates) — this file carries the local dev shapes. Read both.

Unlike the sibling stack dirs, cli/ is not a copied template — it's the engine. It's excluded from the component copy (EXCLUDE in src/utils.ts) and is the only section that gates the CLI itself.

Stack

  • Runtime — Node, TypeScript ESM
  • Build — tsup (--format esm --target node18)
  • Test — Vitest + v8 coverage; ≥80% enforced (statements/branches/functions/lines) in vitest.config.ts
  • Lint / format — eslint + prettier
  • Published as — create-projx (npm); package.json#files ships only dist + src/templates

Layout

PathWhat it holds
src/index.tsparseArgs + subcommand dispatch (create/update/add/init/pin/unpin/diff/doctor/gen/sync)
src/scaffold.tsBase scaffold flow (copy components, render templates, install)
src/baseline.tsapplyOrmAddon — ORM addon dispatch (Node packageOverrides / Go gomodOverrides)
src/gen.tsEntity generators incl. append<Orm>Entity
src/features.tsFeature-overlay application (--<feature>=<targets>)
src/detect.ts, src/doctor.ts, src/diff.ts, src/sync.ts, src/pin.ts, src/init.ts, src/add.ts, src/update.tsOne file per subcommand / concern
src/prompts.tsInteractive prompts (@clack/prompts)
src/utils.tsHand-rolled template engine (render), provider constants, copy filters (EXCLUDE/EXCLUDE_FILES), pm commands
src/templates/*.ejsShared scaffold files rendered at scaffold time (ci.yml, setup.sh, docker-compose, pre-commit, README)
tests/*.test.tsOne suite per src/ module

Conventions

  • The template engine is intentionally minimal — render() in src/utils.ts supports only <% if %>, <% for %>, <%= expr %>. Do not add a dependency on real EJS.
  • Subcommands, flags, ORM addons, and feature templates are documented once in root — extend there when adding behavior. Adding an ORM/feature touches ORM_PROVIDERS/KNOWN_FEATURES in src/utils.ts and the help string in src/index.ts.
  • Addons / features / component dirs are fetched from the repo tarball at runtime, not bundled — use --local <path> during dev.
  • pnpm is the default package manager (DEFAULT_PACKAGE_MANAGER in src/utils.ts) for new JS scaffolds — create/init default to it; npm/yarn/bun stay selectable. On scaffold, JS components get "packageManager": "pnpm@<PNPM_VERSION>" stamped into package.json (stampPackageManager in src/baseline.ts, pnpm-only). The pinned version lives once as pmCommands(pm).version (PNPM_VERSION, currently pnpm@11.5.2+sha512…) and also renders the Dockerfile corepack prepare line — including the ORM-addon Dockerfile in ormNodeDockerfileSource (pm.version, not a literal) — so don't re-hardcode it. pnpm-specific config lives in each template's pnpm-workspace.yaml (overrides: for security pins, allowBuilds: for build-script approval), not the package.json pnpm field — pnpm 11 stopped reading that field, and a frozen install mismatches a lockfile that recorded the old pnpm.overrides. Back-compat: add/update/gen/diff still read the PM from the project's .projx (missing field → npm), so existing projects never flip.
  • Shipped artifacts never hard-code a component directory (root §"Never hard-code a component directory in a shipped artifact"). Rendered .ejs use <%= paths.<type> %> / iterate *Instances; resolvePrimarySourceDirs(paths) in src/utils.ts is injected into every renderEjsInDir call as backendSourceDir / frontendSourceDir (for infra's single-pipeline / tfvars assumption). Static shell (scripts/projx-dirs.sh, validate-nginx-config.sh) is added to the staticScripts copy list in src/utils.ts. Covered by tests/instance-aware-dirs.test.ts.

Testing — the CLI test pattern

  • Never vi.mock('@clack/prompts') — it pollutes the module cache across files. Spy on utilsModule instead (see existing suites).
  • Mirror one tests/<name>.test.ts per src/<name>.ts. New behavior ships with a failing test first (root §"TDD").
  • The entrypoint guard is only exercisable via the built binary — tests/entrypoint.test.ts runs dist/index.js through a symlink (the npx/.bin path); function-importing unit tests bypass it. Build first, and never assert CLI behavior only by real-path invocation.

Quality gates (root §"Local development loop")

pnpm --dir cli build → pnpm --dir cli exec tsc --noEmit → pnpm --dir cli exec eslint src/ tests/ → pnpm --dir cli test (vitest, v8 ≥80%). Green or not done.

Things that bite

  • pnpm exec after a pipe (| tail/head) masks exit codes — use ${PIPESTATUS[0]} or no pipe when verifying success.
  • The 80% coverage threshold is hard — new src/ code without tests drops the aggregate and fails the gate.
  • In production the CLI is only reached through a bin symlink (npx create-projx, npm create projx, a global install → node_modules/.bin/create-projx → dist/index.js), but every gate invokes it by its real path (node cli/dist/index.js — the dev loop, scripts/scaffold-fuzz.py, the dispatch tests) or imports its functions directly. So an entrypoint break is invisible to CI. The isMainEntrypoint() guard in src/index.ts must realpathSync(process.argv[1]) before comparing to import.meta.url — through a symlink the two differ, a naive compare is always false, and main() never runs, so every command silently exits 0 with no output. This was latent from v1.7.4 to v1.9.3. Regression-guarded by tests/entrypoint.test.ts.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.