Skip to content

Refactor CLI - #1174

Merged
AbhinRustagi merged 22 commits into
mainfrom
cli/refactor
Sep 18, 2026
Merged

AbhinRustagi merged 22 commits into
mainfrom
cli/refactor

Conversation

@AbhinRustagi

@AbhinRustagi AbhinRustagi commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

What

Restructure @openuidev/cli so a new command is a folder + one registry line. Same four commands, still Commander.

Placement: one command owns it → that command’s folder. Two or more owners (or a later command will) → src/lib/.

packages/openui-cli/src/
  index.ts                         # shebang, runProgram()
  program.ts                       # globals, telemetry init, process error catch
  commands/
    index.ts                       # addCommand list — new command = one line
    create/
      command.ts                   # flags + help
      run.ts                       # orchestrator (resolve → env → scaffold → install)
      lib/                         # create-only: catalogs, overlays, stages, examples
    deploy/
      command.ts
      run.ts
      lib/                         # deploy-only: project env, vercel target, vercel-env
    generate/
      command.ts
      run.ts
      lib/                         # worker + delimiter (do not import worker from run)
    generate-api-key/
      command.ts
      run.ts
  lib/
    context.ts                     # cwd / argv / telemetry / verbose
    telemetry.ts                   # PostHog session; commands extend Telemetry
    errors.ts                      # CreateError, mapping, throwCommandFailure
    auth/                          # create + generate-api-key
    scaffold/                      # checkout/copy/rewrite for a future init
    env.ts                         # generic parse / upsert / remove
    checkout.ts, process-runner.ts, spinner.ts, …

Context: one CliContext (cwd, argv, telemetry, verbose) is set on the program, then passed top-down into every run* function. Commands read process state from ctx instead of reaching for globals.

Telemetry: one Telemetry class owns the PostHog session (init / capture / shutdown). Each command extends it with typed methods (CreateTelemetryClient.trackStarted(...), etc.) so event names and payloads live on the subclass, not as stringly-typed capture("cli_…") at call sites. new CreateTelemetryClient(ctx.telemetry) shares the same session.

Breaking

Removed normalizeTemplate / normalizeBackendFramework. --template and --backend-framework match catalog keys only — short names no longer resolve.

Flag Was (also accepted) Now
--template cloud, self-hosted openui-cloud, openui-self-hosted
--backend-framework eve, none, vercel, ai-sdk, lang-graph default, langgraph, vercel-ai-sdk, vercel-eve

--auth manual is unchanged.

Other

  • --verbose is global (openui --verbose create and openui create --verbose). --no-interactive stays per-command.

Test Plan

  • Verified locally
  • pnpm --filter @openuidev/cli run ci
  • --help for root + each command
  • --verbose before and after the subcommand
  • create --template cloud errors with the catalog key list

Checklist

  • I linked a related issue, if applicable
  • I updated docs/README when needed
  • I considered backwards compatibility

Adding a command is now one folder plus a registry line, without changing flags, help, or telemetry.
Create, deploy, and generate keep the files only they use; shared auth moves to lib/auth.
Create is now an orchestrator over resolve, env, install, and messages. Checkout, copy, and rewrite live in lib/scaffold for a future init.
Keep PostHog event names and property keys, but stop command code from calling capture() with raw strings. Errors move out of the store; wrapCommand goes away now that context is a singleton passed from command.ts.
Importing the worker from run.ts executed its main() on every CLI process and treated the command name as an entry file.
Short names like cloud, eve, and ai-sdk no longer map. Unknown values use the existing catalog error strings. --auth manual is unchanged.
@vercel

vercel Bot commented Sep 15, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
openui-docs Ready Ready Preview Sep 18, 2026 10:02am UTC

Request Review

abhithesys
abhithesys previously approved these changes Sep 18, 2026
@AbhinRustagi
AbhinRustagi merged commit ac1176a into main Sep 18, 2026
44 checks passed
@AbhinRustagi
AbhinRustagi deleted the cli/refactor branch September 18, 2026 10:09

This branch was successfully deployed

1 active deployment
Preview — 23f684cf Deployed Sep 18, 2026 by vercel[bot]
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.

2 participants