Skip to content

Comments

feat(codegen): add CLI entry point generation option (cli.entryPoint)#739

Merged
pyramation merged 2 commits intomainfrom
devin/1771960154-cli-entry-point
Feb 24, 2026
Merged

feat(codegen): add CLI entry point generation option (cli.entryPoint)#739
pyramation merged 2 commits intomainfrom
devin/1771960154-cli-entry-point

Conversation

@pyramation
Copy link
Contributor

@pyramation pyramation commented Feb 24, 2026

feat(codegen): add CLI entry point generation option (cli.entryPoint)

Summary

Adds a new opt-in entryPoint boolean to CliConfig (default false). When enabled, codegen generates an index.ts entry point file that bootstraps the CLI using inquirerer, handling --version, --tty false, and error reporting.

This follows the existing template-copy pattern used by cli-utils.ts and node-fetch.ts — the template lives in src/core/codegen/templates/cli-entry.ts and is read/header-replaced at codegen time.

Wired into both generateCli() (single-target) and generateMultiTargetCli() (multi-target) code paths, and passed through generateMulti() in generate.ts.

Motivation: Eliminates the runtime entry point generation hack in the constructive-hub CLI e2e test script (lines 44–69 of test-cli-e2e.sh), which manually creates this file at test time.

Updates since last revision

  • Replaced hardcoded '0.0.1' version with getPackageJson(__dirname) from inquirerer, matching the exact pattern used by cnc and pgpm CLIs. The generated entry point now reads the actual version from the nearest package.json at runtime.

Review & Testing Checklist for Human

  • getPackageJson(__dirname) runtime behavior — the generated index.ts calls getPackageJson(__dirname) to resolve the version for --version. Verify that when the generated CLI is compiled/bundled (e.g. via tsx or tsc), __dirname resolves to a path where a package.json is discoverable. If the CLI is run directly from source (e.g. npx tsx cli/index.ts), the nearest package.json might be the workspace root rather than the CLI-specific one.
  • No new tests — 301 existing tests pass, but none exercise entryPoint: true. Consider adding a snapshot test that verifies the generated index.ts content.
  • index.ts filename collision — verify no other codegen output produces an index.ts in the CLI output directory, since generateEntryPointFile() writes to index.ts.
  • Single-target path guard — in generateCli(), the check is typeof cliConfig === 'object' && !!cliConfig.entryPoint. Confirm this is correct for all call sites (when cliConfig is true vs an object).

Suggested test plan

  1. Add entryPoint: true to a codegen config YAML and run generation
  2. Verify the generated index.ts contains the expected imports (getPackageJson) and CLI bootstrap
  3. Verify entryPoint: false (or omitted) produces no index.ts
  4. Run the generated CLI with --version and confirm it prints the version from the nearest package.json

Notes

- Add cli-entry.ts template with CLI bootstrap code (inquirerer, --version, --tty)
- Add generateEntryPointFile() to utils-generator.ts (template-copy pattern)
- Add entryPoint option to CliConfig interface (default: false)
- Wire up in generateCli() and generateMultiTargetCli()
- Pass entryPoint through generateMulti() for unified CLI
- When enabled, generates index.ts in cli/ output directory

This removes the last remaining hack from the constructive-hub
CLI e2e test script (manual index.ts generation at test time).
@devin-ai-integration
Copy link
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

…0.0.1'

Uses getPackageJson(__dirname) from inquirerer to read the actual
package.json version at runtime, matching the pattern used by cnc
and pgpm CLIs.
@pyramation pyramation merged commit dac6dce into main Feb 24, 2026
44 checks passed
@pyramation pyramation deleted the devin/1771960154-cli-entry-point branch February 24, 2026 19:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant