@nevr/cli
v0.2.2
Published
CLI for Nevr - Nevr write boilerplate again
Maintainers
Readme
@nevr/cli
Command-line interface for Nevr — Generate Prisma schemas and typed clients from your entities
📦 Installation
# Global installation
npm install -g @nevr/cli
# Or use directly with npx (recommended)
npx @nevr/cli generate🚀 Quick Start
- Create a config file (
nevr.config.ts):
import { entity, string, text, belongsTo } from "nevr"
export const user = entity("user", {
email: string.unique(),
name: string.min(1).max(100),
}).build()
export const post = entity("post", {
title: string.min(1).max(200),
body: text,
author: belongsTo(() => user),
})
.ownedBy("author")
.build()
export default {
entities: [user, post],
}- Generate everything:
npx @nevr/cli generate- Push to database:
npx prisma db push --schema=./generated/prisma/schema.prisma📖 Commands
nevr generate
Generate Prisma schema, TypeScript types, and API client from your entity definitions.
nevr generate [options]Options:
| Option | Description | Default |
|--------|-------------|---------|
| -c, --config <path> | Path to nevr config file | ./nevr.config.ts |
| -o, --out <dir> | Output directory | ./generated |
| -p, --provider <db> | Database provider: sqlite, postgresql, mysql | sqlite |
Examples:
# Default configuration
nevr generate
# PostgreSQL with custom output
nevr generate --provider postgresql --out ./src/generated
# Custom config file
nevr generate --config ./config/api.config.tsnevr init
Display help for initializing a new nevr project.
nevr init💡 Tip: For full project scaffolding with a complete setup, use:
npm create nevr@latest
📁 Generated Output
Running nevr generate creates the following structure:
generated/
├── prisma/
│ └── schema.prisma # Prisma database schema
├── types.ts # TypeScript interfaces
└── client.ts # Type-safe API clientschema.prisma
Complete Prisma schema with all your entities, relations, and indexes:
// Generated by @nevr/cli - DO NOT EDIT
datasource db {
provider = "sqlite"
url = env("DATABASE_URL")
}
generator client {
provider = "prisma-client-js"
}
model User {
id String @id @default(cuid())
email String @unique
name String
posts Post[]
}
model Post {
id String @id @default(cuid())
title String
body String
authorId String
author User @relation(fields: [authorId], references: [id])
}types.ts
Type-safe interfaces for all entities:
// Generated by @nevr/cli - DO NOT EDIT
export interface User {
id: string
email: string
name: string
}
export interface Post {
id: string
title: string
body: string
authorId: string
}client.ts
Ready-to-use API client for your frontend:
// Generated by @nevr/cli - DO NOT EDIT
import type { User, Post } from "./types"
export const api = {
users: {
list: () => fetch("/api/users").then(r => r.json()) as Promise<User[]>,
get: (id: string) => fetch(`/api/users/${id}`).then(r => r.json()) as Promise<User>,
create: (data: Omit<User, "id">) => /* ... */,
update: (id: string, data: Partial<User>) => /* ... */,
delete: (id: string) => /* ... */,
},
posts: { /* ... */ },
}⚙️ Configuration Reference
Full configuration options in nevr.config.ts:
import { entity, string, text, int, bool, datetime, belongsTo } from "nevr"
import { auth } from "nevr/plugins/auth"
import { timestamps } from "nevr/plugins/timestamps"
// Define entities
export const user = entity("user", {
email: string.unique(),
name: string,
}).build()
export const post = entity("post", {
title: string.min(1).max(200),
content: text,
published: bool.default(false),
author: belongsTo(() => user),
})
.ownedBy("author")
.rules({
create: ["authenticated"],
read: ["everyone"],
update: ["owner"],
delete: ["owner", "admin"],
})
.build()
// Export configuration
export default {
entities: [user, post],
plugins: [
auth({ emailAndPassword: true }),
timestamps(),
],
}🔄 Workflow
Typical development workflow with the CLI:
# 1. Edit your entities in nevr.config.ts
# 2. Regenerate everything
npx @nevr/cli generate
# 3. Apply database changes
npx prisma db push --schema=./generated/prisma/schema.prisma
# 4. (Optional) View your database
npx prisma studio --schema=./generated/prisma/schema.prisma📚 Related Packages
| Package | Description |
|---------|-------------|
| nevr | Core framework |
| @nevr/generator | Generator library (used internally) |
| create-nevr | Project scaffolder |
🤝 Contributing
We welcome contributions! See our Contributing Guide.
📄 License
MIT © Nevr Contributors
