Skip to content

Added 3 more CLI commands #345

Merged
yash-pouranik merged 11 commits into
geturbackend:mainfrom
Ayush4958:cli-PR-4
Jun 30, 2026
Merged

Added 3 more CLI commands #345
yash-pouranik merged 11 commits into
geturbackend:mainfrom
Ayush4958:cli-PR-4

Conversation

@Ayush4958

@Ayush4958 Ayush4958 commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

🚀 Pull Request Description

Added 3 more CLI commands

Command Description
ub init Initialize a local workspace (.ub/) and link it to a specific urBackend project
ub pull Fetch the latest collection schemas from the dashboard API into local JSON files
ub generate Generate a strict urbackend.d.ts TypeScript definitions file from local schemas

Changed the lint script in sdks/urbackend-cli/package.json from "eslint src" to "tsc --noEmit". Change this because the CLI package wasn't configured with @typescript-eslint, which caused ESLint to throw fake syntax errors anytime it saw standard TypeScript keywords like interface or type.
Switching the script to tsc --noEmit natively and perfectly validates the type-safety of the entire CLI workspace in our CI/CD pipeline ....

🛠️ Type of Change

  • 🐛 Bug fix (non-breaking change which fixes an issue)
  • ✨ New feature (non-breaking change which adds functionality)
  • 💥 Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • 📝 Documentation update
  • 🎨 UI/UX improvement (Frontend only)
  • ⚙️ Refactor / Chore

🧪 Testing & Validation

Backend Verification:

  • I have run npm test in the backend/ directory and all tests passed.
  • I have verified the API endpoints using Postman/Thunder Client.
  • New unit tests have been added (if applicable).

Frontend Verification:

  • I have run npm run lint in the frontend/ directory.
  • Verified the UI changes on different screen sizes (Responsive).
  • Checked for any console errors in the browser dev tools.

✅ Checklist

  • My code follows the code style of this project.
  • I have performed a self-review of my code.
  • I have commented my code, particularly in hard-to-understand areas.
  • My changes generate no new warnings or errors.
  • I have updated the documentation (README/Docs) accordingly.

Summary by CodeRabbit

  • New Features

    • Added ub init [projectIdOrName], ub pull, and ub generate workspace commands to set up a local workspace, download schemas, and generate urbackend.d.ts.
    • Workspace data is stored under a hidden .ub directory (config + per-collection schema JSON files).
  • Bug Fixes

    • Improved error handling with clearer guidance (including login/token and missing-project scenarios) and consistent non-zero exit behavior.
    • Schema file handling is more resilient, skipping individual malformed schema files and validating collection names for safer writes.
  • Chores

    • Updated CLI version to 0.2.0 and switched linting to tsc --noEmit type-checking.

@coderabbitai

coderabbitai Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@Ayush4958, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 6 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 6d6f1f5c-77ae-46d5-b6cc-3e67af8a055f

📥 Commits

Reviewing files that changed from the base of the PR and between 79e016b and f522177.

📒 Files selected for processing (2)
  • sdks/urbackend-cli/src/commands/pull/index.ts
  • sdks/urbackend-cli/src/core/workspace.ts
📝 Walkthrough

Walkthrough

Three new urbackend-cli commands are added: init, pull, and generate. The CLI now manages a local .ub workspace with config and schema files, adds a WorkspaceConfig type, and switches lint to tsc --noEmit.

Changes

Workspace Commands

Layer / File(s) Summary
WorkspaceConfig and workspace utilities
sdks/urbackend-cli/src/types/config.ts, sdks/urbackend-cli/src/core/workspace.ts
Defines WorkspaceConfig and implements .ub path helpers, config load/save, schema file validation and persistence, schema enumeration, and schema file clearing.
init command
sdks/urbackend-cli/src/commands/init/index.ts
Implements initCommand with token checks, project selection, workspace config persistence, .gitignore updates for .ub, and API error handling.
pull and generate commands
sdks/urbackend-cli/src/commands/pull/index.ts, sdks/urbackend-cli/src/commands/generate/index.ts
Implements pullCommand to fetch and store collection schemas locally, and generateCommand to turn local schemas into urbackend.d.ts.
CLI entrypoint wiring and lint script
sdks/urbackend-cli/src/index.ts, sdks/urbackend-cli/package.json
Registers the new commands in the CLI entrypoint and updates the package version plus lint script.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • geturbackend/urBackend#340: Introduces the broader @urbackend/cli groundwork that this PR extends with workspace commands and supporting utilities.

Suggested reviewers

  • yash-pouranik

Poem

🐇 I hop through .ub with glee,
Schemas snug as they can be,
init, pull, then types take flight,
generate turns the dark to light.
A tidy burrow, swift and neat —
TypeScript dreams with rabbit feet.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title matches the main change: the PR adds three new CLI commands to the urBackend CLI.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@sdks/urbackend-cli/src/commands/generate/index.ts`:
- Around line 38-46: The generated TypeScript in parseFields and the top-level
model emission is writing CollectionField.key as a bare property name, which
breaks for keys containing spaces or hyphens. Update the field serialization in
parseFields and the surrounding model loop in generate/index.ts to quote or
otherwise safely emit any non-identifier keys, so urbackend.d.ts stays valid for
names like user-name or display name.

In `@sdks/urbackend-cli/src/commands/init/index.ts`:
- Around line 69-80: The .gitignore update logic in the init command is matching
by substring, so it can miss cases where .ub is not actually ignored. In the
init flow around the .gitignore handling, change the check in the existing file
branch to detect a real ignore entry by line, using the .ub rule itself and not
a broad includes(".ub") substring search. Keep the logic in the same init
command path and preserve the append/write behavior in the .gitignore update
block.

In `@sdks/urbackend-cli/src/commands/pull/index.ts`:
- Around line 36-44: The pull flow in the command handler still leaves deleted
or renamed collection schema files behind, so the local cache can become stale.
Add a cleanup step in the pull path (around the loop in the command’s main
handler, alongside saveSchemaFile) that removes existing .json files from the
schemas directory before writing the current project.collections, using a helper
like clearSchemaFiles to keep only the latest remote schemas.

In `@sdks/urbackend-cli/src/core/workspace.ts`:
- Around line 45-52: The saveSchemaFile() helper is using collectionName
directly as a filename, which allows path traversal outside the schemas
directory. Update saveSchemaFile() (and any caller that passes collectionName)
to validate or sanitize names so only safe basename-style identifiers are
accepted, and reject absolute paths or any value containing path separators/..
segments before constructing the path. Ensure the final resolved file path stays
under getSchemasDir() before calling fs.writeFileSync.

In `@sdks/urbackend-cli/src/index.ts`:
- Around line 101-104: The init command is not declaring its optional positional
argument, so Commander passes trailing command data into initCommand and
projectIdOrName can become an object. Update the program.command("init")
declaration to accept [projectIdOrName] (or explicitly forward that positional)
so initCommand receives the expected string and can safely call toLowerCase().
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: fd78bc21-ba1c-4327-a50b-1de0b5444581

📥 Commits

Reviewing files that changed from the base of the PR and between 1c0dcc1 and 338de85.

📒 Files selected for processing (7)
  • sdks/urbackend-cli/package.json
  • sdks/urbackend-cli/src/commands/generate/index.ts
  • sdks/urbackend-cli/src/commands/init/index.ts
  • sdks/urbackend-cli/src/commands/pull/index.ts
  • sdks/urbackend-cli/src/core/workspace.ts
  • sdks/urbackend-cli/src/index.ts
  • sdks/urbackend-cli/src/types/config.ts

Comment thread sdks/urbackend-cli/src/commands/generate/index.ts
Comment thread sdks/urbackend-cli/src/commands/init/index.ts
Comment thread sdks/urbackend-cli/src/commands/pull/index.ts
Comment thread sdks/urbackend-cli/src/core/workspace.ts
Comment thread sdks/urbackend-cli/src/index.ts Outdated
@Ayush4958

Copy link
Copy Markdown
Contributor Author

@yash-pouranik
PR is ready for review ....

@yash-pouranik

Copy link
Copy Markdown
Member

looks good
Hope u have tested all the command on ur local
??
@Ayush4958

@Ayush4958

Copy link
Copy Markdown
Contributor Author

looks good Hope u have tested all the command on ur local ?? @Ayush4958

yes!!! all 3works

Comment thread sdks/urbackend-cli/src/index.ts Outdated
Comment thread sdks/urbackend-cli/package.json Outdated
@Ayush4958

Copy link
Copy Markdown
Contributor Author

@yash-pouranik
Changes applied

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@sdks/urbackend-cli/src/core/workspace.ts`:
- Around line 46-48: The new collection name validation in workspace helpers is
happening too late in the pull flow, after `.ub/schemas` has already been
cleared. Update `pullCommand()` to validate all remote collection names up front
before calling `clearSchemaFiles()`, or otherwise stage schema writes and only
replace the local schemas after all `saveSchemaFile()` calls succeed, so a bad
name does not leave the workspace partially emptied.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 12db994a-10fc-4547-b7d3-dbe67f968987

📥 Commits

Reviewing files that changed from the base of the PR and between 338de85 and 79e016b.

📒 Files selected for processing (6)
  • sdks/urbackend-cli/package.json
  • sdks/urbackend-cli/src/commands/generate/index.ts
  • sdks/urbackend-cli/src/commands/init/index.ts
  • sdks/urbackend-cli/src/commands/pull/index.ts
  • sdks/urbackend-cli/src/core/workspace.ts
  • sdks/urbackend-cli/src/index.ts
🚧 Files skipped from review as they are similar to previous changes (5)
  • sdks/urbackend-cli/src/index.ts
  • sdks/urbackend-cli/package.json
  • sdks/urbackend-cli/src/commands/pull/index.ts
  • sdks/urbackend-cli/src/commands/generate/index.ts
  • sdks/urbackend-cli/src/commands/init/index.ts

Comment thread sdks/urbackend-cli/src/core/workspace.ts Outdated
@Ayush4958

Copy link
Copy Markdown
Contributor Author

@yash-pouranik
PR is ready for review

@yash-pouranik yash-pouranik merged commit 869d208 into geturbackend:main Jun 30, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants