-
-
Notifications
You must be signed in to change notification settings - Fork 11
feat: add "create-zenstack" and "init" command #20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Warning Rate limit exceeded@ymc9 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 3 minutes and 44 seconds before requesting another review. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📒 Files selected for processing (2)
WalkthroughThis update introduces a new CLI tool, Changes
Sequence Diagram(s)1.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 5
🔭 Outside diff range comments (1)
packages/create-zenstack/src/templates.ts (1)
1-53:⚠️ Potential issueCritical: Incorrect template re-export
This file currently inlines or misreferences the CLI templates instead of properly re-exporting them. It should simply re-export the constants from the CLI package.Apply this diff to fix it:
- ../../cli/src/actions/templates.ts - - /// A sample data source using local sqlite db. - datasource db { - provider = 'sqlite' - url = 'file:./dev.db' - } - - /// User model - model User { - id String @id @default(cuid()) - email String @unique @email @length(6, 32) - posts Post[] - } - - /// Post model - model Post { - id String @id @default(cuid()) - createdAt DateTime @default(now()) - updatedAt DateTime @updatedAt - title String @length(1, 256) - content String - published Boolean @default(false) - author User @relation(fields: [authorId], references: [id]) - authorId String - } - `; - - export const STARTER_MAIN_TS = `import { ZenStackClient } from '@zenstackhq/runtime'; - import { schema } from './zenstack/schema'; - - async function main() { - const client = new ZenStackClient(schema); - const user = await client.user.create({ - data: { - email: 'test@zenstack.dev', - posts: { - create: [ - { - title: 'Hello World', - content: 'This is a test post', - }, - ], - }, - }, - include: { posts: true } - }); - console.log('User created:', user); - } - - main(); - `; + export { STARTER_ZMODEL, STARTER_MAIN_TS } from '../../cli/src/actions/templates';This ensures the templates stay canonical and avoids duplication.
🧹 Nitpick comments (8)
packages/create-zenstack/bin/cli (1)
1-3: Verify CLI script shebang and executable permissions
The shebang with--no-warningssuppresses Node.js warnings; confirm this is intentional and compatible across environments. Also ensure this file is marked as executable (chmod +x) and correctly listed underbininpackage.json.packages/create-zenstack/tsconfig.json (1)
1-7: Consider generating type declarations
You may want to enable"declaration": trueundercompilerOptionsto emit.d.tsfiles for improved IDE support and downstream type safety:+ "compilerOptions": { + "outDir": "dist", + "declaration": true + },packages/cli/src/actions/action-utils.ts (1)
37-47: Consider broadening the exit-code extraction logic
spawnSyncand many process-execution helpers (e.g.execa) signal failure via either a numericstatusor a stringcode(e.g.'ENOENT'). Exiting with1for non-numeric codes can discard useful information in CI logs.- if ( - err instanceof Error && - 'status' in err && - typeof err.status === 'number' - ) { - process.exit(err.status); - } else { - process.exit(1); - } + if (err && typeof err === 'object') { + const anyErr = err as Record<string, unknown>; + if (typeof anyErr.status === 'number') { + process.exit(anyErr.status); + } + if (typeof anyErr.code === 'string') { + // map common string codes to conventional exit codes, fall back to 1 + process.exit(anyErr.code === 'ENOENT' ? 127 : 1); + } + } + process.exit(1);Keeps the current behaviour while preserving extra diagnostics when available.
packages/cli/package.json (1)
31-41: Check Node 20 type stubs & new dependency reachUpgrading
@types/nodeto^20and addingpackage-manager-detectorpulls in Node-20-specific types and extra transitive deps. Make sure the minimum supported runtime in docs/engines aligns (Node 20) and that the new package is bundled only where needed to keep the CLI’s install size lean.packages/cli/src/index.ts (1)
21-28: Avoid wrapper indirection – pass the action handlers directly
infoAction/initActionare just one-liners delegating to the real action functions. Commander happily accepts async functions, so you can exportactions.info/actions.initdirectly and drop the extra delegates.
This removes 8 lines, one level of indirection, and keeps stack-traces shorter.-const infoAction = async (projectPath: string): Promise<void> => { - await actions.info(projectPath); -}; - -const initAction = async (projectPath: string): Promise<void> => { - await actions.init(projectPath); -}; +const infoAction = actions.info; +const initAction = actions.init;packages/create-zenstack/package.json (1)
34-37: Re-evaluate dependency choices (security & footprint)
colors@1.4.0was at the center of the January-2022 self-sabotage incident; the package is stable now but effectively unmaintained.chalk(actively maintained, ESM-first, typings built-in) is a drop-in replacement.Switching reduces supply-chain risk and removes the need for
@types/colors.No action required for this PR, but consider migrating in a follow-up.
packages/cli/src/actions/init.ts (1)
73-75: Minor typo – duplicated word
'compile the the schema'➜'compile the schema'packages/create-zenstack/src/index.ts (1)
64-66: Guard against existingzenstackdirectoryIf a user re-runs the tool in the same folder,
fs.mkdirSync('zenstack')will throw. Either checkexistsSyncor callmkdirSync('zenstack', { recursive: true }).
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (25)
package.json(1 hunks)packages/cli/package.json(4 hunks)packages/cli/src/actions/action-utils.ts(1 hunks)packages/cli/src/actions/common.ts(0 hunks)packages/cli/src/actions/db.ts(1 hunks)packages/cli/src/actions/generate.ts(1 hunks)packages/cli/src/actions/index.ts(1 hunks)packages/cli/src/actions/info.ts(1 hunks)packages/cli/src/actions/init.ts(1 hunks)packages/cli/src/actions/templates.ts(1 hunks)packages/cli/src/index.ts(2 hunks)packages/create-zenstack/bin/cli(1 hunks)packages/create-zenstack/package.json(1 hunks)packages/create-zenstack/src/index.ts(1 hunks)packages/create-zenstack/src/templates.ts(1 hunks)packages/create-zenstack/tsconfig.json(1 hunks)packages/create-zenstack/tsup.config.ts(1 hunks)packages/language/package.json(2 hunks)packages/runtime/package.json(1 hunks)packages/sdk/package.json(2 hunks)packages/tanstack-query/package.json(1 hunks)packages/testtools/package.json(2 hunks)packages/zod/package.json(1 hunks)pnpm-workspace.yaml(1 hunks)samples/blog/package.json(1 hunks)
💤 Files with no reviewable changes (1)
- packages/cli/src/actions/common.ts
🧰 Additional context used
🧬 Code Graph Analysis (4)
packages/create-zenstack/src/templates.ts (1)
packages/cli/src/actions/templates.ts (1)
STARTER_ZMODEL(1-27)
packages/create-zenstack/src/index.ts (3)
packages/cli/src/utils/exec-utils.ts (1)
execSync(6-18)packages/create-zenstack/src/templates.ts (2)
STARTER_ZMODEL(1-27)STARTER_MAIN_TS(29-52)packages/cli/src/actions/templates.ts (2)
STARTER_ZMODEL(1-27)STARTER_MAIN_TS(29-52)
packages/cli/src/actions/templates.ts (1)
packages/create-zenstack/src/templates.ts (2)
STARTER_ZMODEL(1-27)STARTER_MAIN_TS(29-52)
packages/cli/src/actions/init.ts (3)
packages/cli/src/cli-error.ts (1)
CliError(4-4)packages/cli/src/utils/exec-utils.ts (1)
execSync(6-18)packages/cli/src/actions/templates.ts (1)
STARTER_ZMODEL(1-27)
🔇 Additional comments (18)
package.json (1)
3-3: Confirm the intentional version downgrade
The rootversionwas downgraded from3.0.0-alpha.1to3.0.0-alpha.0. Ensure this aligns with your release strategy and that all monorepo packages remain synchronized.packages/tanstack-query/package.json (1)
3-3: Approve version alignment
The package version was downgraded to3.0.0-alpha.0to match the rest of the monorepo. This change is consistent and requires no further action.packages/runtime/package.json (1)
3-3: Approve version alignment
The package version was downgraded to3.0.0-alpha.0to match the rest of the monorepo. This change is consistent and requires no further action.packages/zod/package.json (1)
3-3: Approve version alignment
The package version was downgraded to3.0.0-alpha.0to match the rest of the monorepo. This change is consistent and requires no further action.packages/language/package.json (1)
4-4: Approve version alignment
The package version was downgraded to3.0.0-alpha.0in line with the monorepo-wide version sync.packages/sdk/package.json (2)
50-50: Update Node types to v20
Upgrading@types/nodeto^20.0.0may impact CI/build images—ensure your pipelines and local environments target Node v20+.
3-3:✅ Verification successful
Confirm SDK version rollback
The version was downgraded from3.0.0-alpha.1to3.0.0-alpha.0. Please verify that this rollback is intentional and synchronized across all packages to prevent mismatches during publishing.Run this to check consistency:
🏁 Script executed:
rg -n '"version": "3\.0\.0-alpha\.\d"' --glob 'packages/*/package.json'Length of output: 591
All packages synchronized to version 3.0.0-alpha.0
All eight packages use"version": "3.0.0-alpha.0", confirming the rollback is applied consistently. No further action required.
- packages/create-zenstack/package.json
- packages/testtools/package.json
- packages/zod/package.json
- packages/tanstack-query/package.json
- packages/runtime/package.json
- packages/sdk/package.json
- packages/cli/package.json
- packages/language/package.json
pnpm-workspace.yaml (1)
6-6: Include new package in workspace
Addingpackages/create-zenstackintegrates the new CLI tool into the monorepo correctly.packages/testtools/package.json (2)
3-3: Confirm testtools version rollback
The version was downgraded from3.0.0-alpha.1to3.0.0-alpha.0. Ensure this aligns with the intended release strategy and matches other packages.
32-32: Sync Node types update
Upgrading@types/nodeto^20.0.0here too—please verify that all development environments are updated to Node 20.packages/cli/src/actions/templates.ts (2)
1-27: Approve starter schema template
TheSTARTER_ZMODELconstant provides a clear, self-contained schema for new projects. The content and formatting look good.
29-52: Approve examplemain.tsusage snippet
TheSTARTER_MAIN_TSconstant correctly illustrates client initialization and nested create/query usage.packages/cli/src/actions/generate.ts (1)
43-43: Consistent client identifier rename
Renamingdbtoclientaligns generated snippets with your starter templates and improves clarity for users.packages/cli/src/actions/db.ts (1)
3-3:✅ Verification successful
Confirm
handleSubProcessErrorexport path
The import moved fromcommontoaction-utils. Verify that no other files still reference./commonand thatcommon.tscan be removed if it's now unused.
🏁 Script executed:
#!/bin/bash # Search for residual imports from actions/common rg "from '\.\/common'" -n packages/cli/src/actionsLength of output: 150
🏁 Script executed:
#!/bin/bash # Correctly search for residual imports from ./common in the actions directory rg -n "from './common'" packages/cli/src/actions rg -n 'from "./common"' packages/cli/src/actions # Check for any remaining references to common.ts across the repo rg -n "common\.ts" .Length of output: 130
🏁 Script executed:
#!/bin/bash # Check if common.ts still exists in the actions directory find packages/cli/src/actions -maxdepth 1 -type f -name 'common.ts'Length of output: 67
🏁 Script executed:
#!/bin/bash # Search for any common.ts files in the repository find . -type f -name 'common.ts'Length of output: 77
🏁 Script executed:
#!/bin/bash # Verify that handleSubProcessError is exported from action-utils rg -n "export .*handleSubProcessError" packages/cli/src/actions/action-utils.tsLength of output: 138
Review Completed: handleSubProcessError import and common.ts removal verified
- No residual
from './common'imports inpackages/cli/src/actions.handleSubProcessErroris exported frompackages/cli/src/actions/action-utils.ts(line 37).- No
common.tsfile exists underpackages/cli/src/actions; it’s been removed.- The only remaining
common.tsis inpackages/language/src/validators, which is outside the CLI scope and should remain.samples/blog/package.json (1)
21-22:✅ Verification successful
Update devDependencies for new CLI and Prisma
Addingprismaand moving the CLI to@zenstackhq/cliis correct. Ensure that@zenstackhq/clistill exposes thezenstackbinary so that existing npm scripts (zenstack generate,zenstack migrate) work without modification.
🏁 Script executed:
#!/bin/bash # Confirm `zenstack` CLI is available in node_modules/.bin pnpm exec which zenstackLength of output: 99
🏁 Script executed:
#!/bin/bash # Locate and inspect the "bin" field in the @zenstackhq/cli package.json rg '"name"\s*:\s*"@zenstackhq/cli"' -l \ | while read -r PKG_JSON; do echo "Inspecting $PKG_JSON" jq '.bin' "$PKG_JSON" doneLength of output: 225
Confirmed:
zenstackbinary exposed by @zenstackhq/cli
Thebinfield inpackages/cli/package.jsonmaps"zenstack": "bin/cli", so thezenstackexecutable is available and existing npm scripts (zenstack generate,zenstack migrate) will continue to work without any changes.packages/cli/src/actions/index.ts (1)
4-7: LGTM – newinitaction is correctly wiredThe import/export looks consistent with the existing pattern.
packages/create-zenstack/tsup.config.ts (1)
1-13: Build config looks saneNo issues spotted – defaults match typical CLIs (single entry, dual format, DTS).
packages/cli/package.json (1)
6-6: Version bump direction is reversed – verify semantic intentThe version changes from
3.0.0-alpha.1to3.0.0-alpha.0, i.e. a lower pre-release tag. Package managers treat this as a downgrade, which can break publishes or installs that already consumedalpha.1.Confirm this is intentional; otherwise bump to
alpha.2or higher.
Summary by CodeRabbit
New Features
create-zenstack, for scaffolding new ZenStack projects with starter files and automated setup.initcommand to the ZenStack CLI to initialize ZenStack in existing projects with starter schema and dependencies.Improvements
Dependency Updates
@types/nodeto v20 in several packages.package-manager-detectordependency to the CLI package.Chores
3.0.0-alpha.1to3.0.0-alpha.0across multiple packages.create-zenstackpackage to the workspace configuration.