@idealyst/cli 1.0.40 → 1.0.43
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/generators/api.js +1 -2
- package/dist/generators/api.js.map +1 -1
- package/dist/generators/database.js +1 -2
- package/dist/generators/database.js.map +1 -1
- package/dist/generators/fullstack.js +371 -0
- package/dist/generators/fullstack.js.map +1 -0
- package/dist/generators/index.js +5 -0
- package/dist/generators/index.js.map +1 -1
- package/dist/generators/native.js +2 -1
- package/dist/generators/native.js.map +1 -1
- package/dist/generators/shared.js +1 -2
- package/dist/generators/shared.js.map +1 -1
- package/dist/generators/utils.js +71 -7
- package/dist/generators/utils.js.map +1 -1
- package/dist/generators/web.js +1 -2
- package/dist/generators/web.js.map +1 -1
- package/dist/generators/workspace.js +56 -2
- package/dist/generators/workspace.js.map +1 -1
- package/dist/index.js +50 -2
- package/dist/index.js.map +1 -1
- package/dist/templates/database/.env.example +1 -8
- package/dist/templates/database/README.md +29 -74
- package/dist/templates/database/package.json +20 -34
- package/dist/templates/database/prisma/seed.ts +11 -11
- package/dist/templates/database/schema.prisma +97 -0
- package/dist/templates/database/src/index.ts +12 -8
- package/dist/templates/database/src/validators.ts +10 -0
- package/dist/templates/database/tsconfig.json +9 -23
- package/dist/templates/native/src/App-with-trpc-and-shared.tsx +266 -0
- package/dist/templates/shared/package.json +28 -3
- package/dist/templates/shared/src/components/index.ts +392 -0
- package/dist/templates/shared/src/index.ts +59 -1
- package/dist/templates/shared/src/types/index.ts +148 -0
- package/dist/templates/shared/src/utils/index.ts +278 -0
- package/dist/templates/web/package.json +2 -2
- package/dist/templates/web/src/App-with-trpc-and-shared.tsx +304 -0
- package/dist/templates/workspace/.devcontainer/Dockerfile +1 -1
- package/dist/templates/workspace/.devcontainer/devcontainer.json +7 -2
- package/dist/templates/workspace/.devcontainer/docker-compose.yml +14 -0
- package/dist/templates/workspace/.devcontainer/figma-mcp.sh +32 -0
- package/dist/templates/workspace/.devcontainer/setup.sh +3 -0
- package/dist/templates/workspace/setup.sh +22 -197
- package/dist/templates/workspace/tsconfig.json +32 -0
- package/dist/types/generators/fullstack.d.ts +2 -0
- package/dist/types/generators/index.d.ts +1 -0
- package/dist/types/generators/utils.d.ts +4 -1
- package/dist/types/types.d.ts +3 -1
- package/package.json +1 -1
- package/templates/database/.env.example +1 -8
- package/templates/database/README.md +29 -74
- package/templates/database/package.json +20 -34
- package/templates/database/prisma/seed.ts +11 -11
- package/templates/database/schema.prisma +97 -0
- package/templates/database/src/index.ts +12 -8
- package/templates/database/src/validators.ts +10 -0
- package/templates/database/tsconfig.json +9 -23
- package/templates/native/src/App-with-trpc-and-shared.tsx +266 -0
- package/templates/shared/package.json +28 -3
- package/templates/shared/src/components/index.ts +392 -0
- package/templates/shared/src/index.ts +59 -1
- package/templates/shared/src/types/index.ts +148 -0
- package/templates/shared/src/utils/index.ts +278 -0
- package/templates/web/package.json +1 -1
- package/templates/web/src/App-with-trpc-and-shared.tsx +304 -0
- package/templates/workspace/.devcontainer/devcontainer.json +7 -2
- package/templates/workspace/.devcontainer/docker-compose.yml +14 -0
- package/templates/workspace/.devcontainer/figma-mcp.sh +32 -0
- package/templates/workspace/.devcontainer/setup.sh +3 -0
- package/templates/workspace/setup.sh +22 -197
- package/templates/workspace/tsconfig.json +32 -0
- package/dist/templates/database/__tests__/database.test.ts +0 -14
- package/dist/templates/database/jest.config.js +0 -19
- package/dist/templates/database/jest.setup.js +0 -11
- package/dist/templates/database/prisma/schema.prisma +0 -21
- package/dist/templates/database/src/client.ts +0 -18
- package/dist/templates/database/src/schemas.ts +0 -26
- package/dist/templates/workspace/scripts/docker/db-backup.sh +0 -230
- package/dist/templates/workspace/scripts/docker/deploy.sh +0 -212
- package/dist/templates/workspace/scripts/test-runner.js +0 -120
- package/templates/database/__tests__/database.test.ts +0 -14
- package/templates/database/jest.config.js +0 -19
- package/templates/database/jest.setup.js +0 -11
- package/templates/database/prisma/schema.prisma +0 -21
- package/templates/database/src/client.ts +0 -18
- package/templates/database/src/schemas.ts +0 -26
- package/templates/workspace/scripts/docker/db-backup.sh +0 -230
- package/templates/workspace/scripts/docker/deploy.sh +0 -212
- package/templates/workspace/scripts/docker-build.sh +0 -151
- package/templates/workspace/scripts/test-runner.js +0 -120
|
@@ -1,205 +1,30 @@
|
|
|
1
1
|
#!/bin/bash
|
|
2
2
|
|
|
3
|
-
#
|
|
4
|
-
#
|
|
3
|
+
# Idealyst Framework Workspace Setup Script
|
|
4
|
+
# This script sets up the development environment for your workspace
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
echo "🏗️ Setting up Idealyst Framework workspace..."
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
# Install dependencies
|
|
9
|
+
echo "📦 Installing dependencies..."
|
|
10
|
+
yarn install
|
|
10
11
|
|
|
11
|
-
|
|
12
|
-
echo "
|
|
13
|
-
|
|
14
|
-
echo ""
|
|
15
|
-
|
|
16
|
-
# Function to generate random password
|
|
17
|
-
generate_password() {
|
|
18
|
-
openssl rand -base64 32 | tr -d "=+/" | cut -c1-25
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
# Function to generate JWT secret
|
|
22
|
-
generate_jwt_secret() {
|
|
23
|
-
openssl rand -base64 64 | tr -d "=+/" | cut -c1-50
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
# Function to setup development environment
|
|
27
|
-
setup_development() {
|
|
28
|
-
echo "🔧 Setting up development environment..."
|
|
29
|
-
|
|
30
|
-
if [ ! -f ".env" ]; then
|
|
31
|
-
echo "📝 Creating .env from template..."
|
|
32
|
-
cp .env.example .env
|
|
33
|
-
echo "✅ Created .env file"
|
|
34
|
-
else
|
|
35
|
-
echo "⚠️ .env file already exists, skipping..."
|
|
36
|
-
fi
|
|
37
|
-
|
|
38
|
-
echo ""
|
|
39
|
-
echo "🐳 Starting development containers..."
|
|
40
|
-
if command -v docker-compose &> /dev/null; then
|
|
41
|
-
docker-compose up -d postgres redis
|
|
42
|
-
echo "✅ Database and Redis started"
|
|
43
|
-
|
|
44
|
-
echo "⏳ Waiting for services to be ready..."
|
|
45
|
-
sleep 10
|
|
46
|
-
|
|
47
|
-
echo "🚀 Starting development environment..."
|
|
48
|
-
echo "💡 You can now:"
|
|
49
|
-
echo " - Run 'docker-compose up -d dev' for full dev container"
|
|
50
|
-
echo " - Run 'yarn dev' for local development"
|
|
51
|
-
echo " - Open in VS Code and select 'Reopen in Container'"
|
|
52
|
-
else
|
|
53
|
-
echo "❌ Docker Compose not found. Please install Docker and Docker Compose."
|
|
54
|
-
exit 1
|
|
55
|
-
fi
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
# Function to setup production environment
|
|
59
|
-
setup_production() {
|
|
60
|
-
echo "🏭 Setting up production environment..."
|
|
61
|
-
|
|
62
|
-
if [ ! -f ".env" ]; then
|
|
63
|
-
echo "📝 Creating .env from production template..."
|
|
64
|
-
cp .env.production .env
|
|
65
|
-
|
|
66
|
-
# Generate secure passwords and secrets
|
|
67
|
-
echo "🔐 Generating secure credentials..."
|
|
68
|
-
|
|
69
|
-
DB_PASSWORD=$(generate_password)
|
|
70
|
-
JWT_SECRET=$(generate_jwt_secret)
|
|
71
|
-
SESSION_SECRET=$(generate_jwt_secret)
|
|
72
|
-
ENCRYPTION_KEY=$(openssl rand -base64 32 | cut -c1-32)
|
|
73
|
-
GRAFANA_PASSWORD=$(generate_password)
|
|
74
|
-
|
|
75
|
-
# Replace placeholders in .env file
|
|
76
|
-
sed -i "s/CHANGE_THIS_STRONG_PASSWORD/$DB_PASSWORD/g" .env
|
|
77
|
-
sed -i "s/CHANGE_THIS_VERY_STRONG_JWT_SECRET_MINIMUM_32_CHARACTERS/$JWT_SECRET/g" .env
|
|
78
|
-
sed -i "s/CHANGE_THIS_VERY_STRONG_SESSION_SECRET/$SESSION_SECRET/g" .env
|
|
79
|
-
sed -i "s/CHANGE_THIS_32_CHARACTER_ENCRYPTION_KEY/$ENCRYPTION_KEY/g" .env
|
|
80
|
-
sed -i "s/CHANGE_THIS_STRONG_PASSWORD/$GRAFANA_PASSWORD/g" .env
|
|
81
|
-
|
|
82
|
-
echo "✅ Created .env with secure credentials"
|
|
83
|
-
echo ""
|
|
84
|
-
echo "🔐 Generated Credentials (save these securely!):"
|
|
85
|
-
echo " Database Password: $DB_PASSWORD"
|
|
86
|
-
echo " JWT Secret: $JWT_SECRET"
|
|
87
|
-
echo " Grafana Password: $GRAFANA_PASSWORD"
|
|
88
|
-
echo ""
|
|
89
|
-
echo "⚠️ IMPORTANT: Edit .env to configure your domain and other settings!"
|
|
90
|
-
|
|
91
|
-
else
|
|
92
|
-
echo "⚠️ .env file already exists. Please verify production settings."
|
|
93
|
-
fi
|
|
94
|
-
|
|
95
|
-
echo ""
|
|
96
|
-
echo "📋 Production Checklist:"
|
|
97
|
-
echo " [ ] Edit .env with your domain name"
|
|
98
|
-
echo " [ ] Configure SSL certificates"
|
|
99
|
-
echo " [ ] Set up DNS records"
|
|
100
|
-
echo " [ ] Configure firewall rules"
|
|
101
|
-
echo " [ ] Set up monitoring (optional)"
|
|
102
|
-
echo ""
|
|
103
|
-
echo "🚀 Deploy with: ./scripts/docker/deploy.sh production"
|
|
104
|
-
}
|
|
12
|
+
# Build all packages
|
|
13
|
+
echo "🔨 Building packages..."
|
|
14
|
+
yarn build:packages
|
|
105
15
|
|
|
106
|
-
#
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
# Check Docker
|
|
111
|
-
if ! command -v docker &> /dev/null; then
|
|
112
|
-
echo "❌ Docker not found. Please install Docker."
|
|
113
|
-
exit 1
|
|
114
|
-
fi
|
|
115
|
-
|
|
116
|
-
# Check Docker Compose
|
|
117
|
-
if ! command -v docker-compose &> /dev/null; then
|
|
118
|
-
echo "❌ Docker Compose not found. Please install Docker Compose."
|
|
119
|
-
exit 1
|
|
120
|
-
fi
|
|
121
|
-
|
|
122
|
-
# Check if Docker is running
|
|
123
|
-
if ! docker info &> /dev/null; then
|
|
124
|
-
echo "❌ Docker is not running. Please start Docker."
|
|
125
|
-
exit 1
|
|
126
|
-
fi
|
|
127
|
-
|
|
128
|
-
echo "✅ Prerequisites check passed"
|
|
129
|
-
echo ""
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
# Function to show post-setup instructions
|
|
133
|
-
show_instructions() {
|
|
134
|
-
echo ""
|
|
135
|
-
echo "🎉 Setup complete!"
|
|
136
|
-
echo ""
|
|
137
|
-
echo "Next steps:"
|
|
138
|
-
|
|
139
|
-
if [ "$ENVIRONMENT" = "development" ]; then
|
|
140
|
-
echo " 1. Install dependencies: yarn install"
|
|
141
|
-
echo " 2. Start development:"
|
|
142
|
-
echo " - Full container: docker-compose up -d dev"
|
|
143
|
-
echo " - VS Code: Open in Container"
|
|
144
|
-
echo " - Local: yarn dev"
|
|
145
|
-
echo " 3. Access your app:"
|
|
146
|
-
echo " - Web: http://localhost:3000"
|
|
147
|
-
echo " - API: http://localhost:3001"
|
|
148
|
-
echo " - Database: postgresql://postgres:postgres@localhost:5432/idealyst_db"
|
|
149
|
-
else
|
|
150
|
-
echo " 1. Edit .env with your production settings"
|
|
151
|
-
echo " 2. Configure SSL certificates"
|
|
152
|
-
echo " 3. Deploy: ./scripts/docker/deploy.sh production"
|
|
153
|
-
echo " 4. Set up monitoring (optional)"
|
|
154
|
-
fi
|
|
155
|
-
|
|
156
|
-
echo ""
|
|
157
|
-
echo "📚 Documentation:"
|
|
158
|
-
echo " - DOCKER.md - Complete Docker guide"
|
|
159
|
-
echo " - TESTING.md - Testing documentation"
|
|
160
|
-
echo " - README.md - General workspace info"
|
|
161
|
-
echo ""
|
|
162
|
-
echo "🆘 Need help? Check the documentation or run:"
|
|
163
|
-
echo " ./scripts/docker/deploy.sh --help"
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
# Main setup process
|
|
167
|
-
main() {
|
|
168
|
-
check_prerequisites
|
|
169
|
-
|
|
170
|
-
case $ENVIRONMENT in
|
|
171
|
-
"development"|"dev")
|
|
172
|
-
setup_development
|
|
173
|
-
;;
|
|
174
|
-
"production"|"prod")
|
|
175
|
-
setup_production
|
|
176
|
-
;;
|
|
177
|
-
*)
|
|
178
|
-
echo "❌ Invalid environment. Use 'development' or 'production'"
|
|
179
|
-
echo "Usage: $0 [development|production]"
|
|
180
|
-
exit 1
|
|
181
|
-
;;
|
|
182
|
-
esac
|
|
183
|
-
|
|
184
|
-
show_instructions
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
# Handle help
|
|
188
|
-
if [[ "$1" == "--help" ]] || [[ "$1" == "-h" ]] || [[ "$1" == "help" ]]; then
|
|
189
|
-
echo "Idealyst Workspace Setup Script"
|
|
190
|
-
echo ""
|
|
191
|
-
echo "Usage: $0 [environment]"
|
|
192
|
-
echo ""
|
|
193
|
-
echo "Environments:"
|
|
194
|
-
echo " development (default) - Set up for local development"
|
|
195
|
-
echo " production - Set up for production deployment"
|
|
196
|
-
echo ""
|
|
197
|
-
echo "Examples:"
|
|
198
|
-
echo " $0 # Development setup"
|
|
199
|
-
echo " $0 development # Development setup"
|
|
200
|
-
echo " $0 production # Production setup"
|
|
201
|
-
echo ""
|
|
202
|
-
exit 0
|
|
16
|
+
# Set up git hooks (if using husky)
|
|
17
|
+
if [ -f "package.json" ] && grep -q "husky" package.json; then
|
|
18
|
+
echo "🪝 Setting up git hooks..."
|
|
19
|
+
yarn prepare
|
|
203
20
|
fi
|
|
204
21
|
|
|
205
|
-
|
|
22
|
+
echo "✅ Workspace setup complete!"
|
|
23
|
+
echo ""
|
|
24
|
+
echo "🚀 Quick start:"
|
|
25
|
+
echo " • Run 'yarn dev' to start development mode"
|
|
26
|
+
echo " • Run 'yarn build' to build all packages"
|
|
27
|
+
echo " • Run 'yarn test' to run tests"
|
|
28
|
+
echo " • Use 'idealyst create <type> <name>' to add new projects"
|
|
29
|
+
echo ""
|
|
30
|
+
echo "📚 Check README.md and DOCKER.md for more information."
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2020",
|
|
4
|
+
"lib": ["ES2020"],
|
|
5
|
+
"module": "commonjs",
|
|
6
|
+
"moduleResolution": "node",
|
|
7
|
+
"esModuleInterop": true,
|
|
8
|
+
"allowSyntheticDefaultImports": true,
|
|
9
|
+
"strict": true,
|
|
10
|
+
"skipLibCheck": true,
|
|
11
|
+
"forceConsistentCasingInFileNames": true,
|
|
12
|
+
"declaration": true,
|
|
13
|
+
"declarationMap": true,
|
|
14
|
+
"sourceMap": true,
|
|
15
|
+
"outDir": "./dist",
|
|
16
|
+
"rootDir": "./src"
|
|
17
|
+
},
|
|
18
|
+
"include": [
|
|
19
|
+
"packages/*/src/**/*"
|
|
20
|
+
],
|
|
21
|
+
"exclude": [
|
|
22
|
+
"node_modules",
|
|
23
|
+
"dist",
|
|
24
|
+
"**/*.test.ts",
|
|
25
|
+
"**/*.spec.ts"
|
|
26
|
+
],
|
|
27
|
+
"references": [
|
|
28
|
+
{
|
|
29
|
+
"path": "./packages/*"
|
|
30
|
+
}
|
|
31
|
+
]
|
|
32
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { TemplateData } from '../types';
|
|
2
2
|
export declare function validateProjectName(name: string): boolean;
|
|
3
|
+
export declare function getTemplatePath(templateName: string): string;
|
|
3
4
|
export declare function createPackageName(name: string): string;
|
|
4
5
|
export declare function updateWorkspacePackageJson(workspacePath: string, directory: string): Promise<void>;
|
|
5
6
|
export declare function copyTemplate(templatePath: string, destPath: string, data: TemplateData): Promise<void>;
|
|
@@ -16,7 +17,8 @@ export declare function getTemplateData(projectName: string, description?: strin
|
|
|
16
17
|
*/
|
|
17
18
|
export declare function isWorkspaceRoot(directory: string): Promise<boolean>;
|
|
18
19
|
/**
|
|
19
|
-
* Gets the workspace
|
|
20
|
+
* Gets the workspace scope from the workspace root's package.json
|
|
21
|
+
* Extracts just the scope name (without @) from scoped package names
|
|
20
22
|
*/
|
|
21
23
|
export declare function getWorkspaceName(directory: string): Promise<string | null>;
|
|
22
24
|
/**
|
|
@@ -38,5 +40,6 @@ export declare function promptForAppName(projectName: string): Promise<string>;
|
|
|
38
40
|
export declare function promptForTrpcIntegration(): Promise<boolean>;
|
|
39
41
|
export declare function copyTrpcFiles(templatePath: string, projectPath: string, data: TemplateData): Promise<void>;
|
|
40
42
|
export declare function copyTrpcAppComponent(templatePath: string, projectPath: string, data: TemplateData): Promise<void>;
|
|
43
|
+
export declare function addTrpcDependencies(projectPath: string): Promise<void>;
|
|
41
44
|
export declare function removeTrpcDependencies(projectPath: string): Promise<void>;
|
|
42
45
|
export declare function configureAndroidVectorIcons(projectPath: string): Promise<void>;
|
package/dist/types/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type ProjectType = 'native' | 'web' | 'shared' | 'workspace' | 'api' | 'database';
|
|
1
|
+
export type ProjectType = 'native' | 'web' | 'shared' | 'workspace' | 'api' | 'database' | 'fullstack';
|
|
2
2
|
export interface GenerateProjectOptions {
|
|
3
3
|
name: string;
|
|
4
4
|
type: ProjectType;
|
|
@@ -6,6 +6,7 @@ export interface GenerateProjectOptions {
|
|
|
6
6
|
skipInstall: boolean;
|
|
7
7
|
appName?: string;
|
|
8
8
|
withTrpc?: boolean;
|
|
9
|
+
figmaToken?: string;
|
|
9
10
|
}
|
|
10
11
|
export interface TemplateData {
|
|
11
12
|
projectName: string;
|
|
@@ -13,4 +14,5 @@ export interface TemplateData {
|
|
|
13
14
|
version: string;
|
|
14
15
|
description: string;
|
|
15
16
|
appName?: string;
|
|
17
|
+
workspaceScope?: string;
|
|
16
18
|
}
|
package/package.json
CHANGED
|
@@ -1,8 +1 @@
|
|
|
1
|
-
|
|
2
|
-
DATABASE_URL="file:./dev.db"
|
|
3
|
-
|
|
4
|
-
# Optional: PostgreSQL example
|
|
5
|
-
# DATABASE_URL="postgresql://username:password@localhost:5432/mydb?schema=public"
|
|
6
|
-
|
|
7
|
-
# Optional: MySQL example
|
|
8
|
-
# DATABASE_URL="mysql://username:password@localhost:3306/mydb"
|
|
1
|
+
DATABASE_URL="sqlite:./dev.db"
|
|
@@ -1,93 +1,48 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Database Package
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
This package provides database access and validation schemas for the workspace.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
## Setup
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
- 📦 **Exportable Client** - Share database access across packages
|
|
12
|
-
- 🔒 **TypeScript** - Full type safety
|
|
13
|
-
- 🧪 **Testing Setup** - Jest configuration for database testing
|
|
14
|
-
- 🔄 **Migration Scripts** - Database versioning and seeding
|
|
15
|
-
|
|
16
|
-
## Getting Started
|
|
17
|
-
|
|
18
|
-
1. **Environment Setup**
|
|
19
|
-
```bash
|
|
20
|
-
cp .env.example .env
|
|
21
|
-
# Edit .env with your database URL
|
|
22
|
-
```
|
|
7
|
+
1. Install dependencies:
|
|
8
|
+
```bash
|
|
9
|
+
yarn install
|
|
10
|
+
```
|
|
23
11
|
|
|
24
|
-
2.
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
12
|
+
2. Set up your environment:
|
|
13
|
+
```bash
|
|
14
|
+
cp .env.example .env
|
|
15
|
+
# Edit .env with your database URL
|
|
16
|
+
```
|
|
28
17
|
|
|
29
|
-
3.
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
18
|
+
3. Generate the Prisma client:
|
|
19
|
+
```bash
|
|
20
|
+
yarn db:generate
|
|
21
|
+
```
|
|
33
22
|
|
|
34
|
-
4.
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
23
|
+
4. Push the schema to your database:
|
|
24
|
+
```bash
|
|
25
|
+
yarn db:push
|
|
26
|
+
```
|
|
38
27
|
|
|
39
28
|
## Usage
|
|
40
29
|
|
|
41
|
-
### In Other Packages
|
|
42
|
-
|
|
43
30
|
```typescript
|
|
44
|
-
import {
|
|
31
|
+
import { prisma, User, TestValidator } from '@{{workspaceScope}}/{{name}}';
|
|
45
32
|
|
|
46
33
|
// Use the database client
|
|
47
|
-
const users = await
|
|
34
|
+
const users = await prisma.user.findMany();
|
|
48
35
|
|
|
49
|
-
// Use
|
|
50
|
-
const
|
|
36
|
+
// Use validators
|
|
37
|
+
const validatedData = TestValidator.parse(userData);
|
|
51
38
|
```
|
|
52
39
|
|
|
53
|
-
### Adding Models
|
|
54
|
-
|
|
55
|
-
1. Update `prisma/schema.prisma` with your models
|
|
56
|
-
2. Update `src/schemas.ts` with corresponding Zod schemas
|
|
57
|
-
3. Run `yarn db:generate` to update the client
|
|
58
|
-
4. Run `yarn db:push` to update the database
|
|
59
|
-
|
|
60
40
|
## Scripts
|
|
61
41
|
|
|
62
|
-
- `yarn build` - Build the package for distribution
|
|
63
|
-
- `yarn dev` - Run in development mode with file watching
|
|
64
|
-
- `yarn test` - Run tests
|
|
65
|
-
- `yarn test:watch` - Run tests in watch mode
|
|
66
42
|
- `yarn db:generate` - Generate Prisma client
|
|
67
|
-
- `yarn db:push` - Push schema
|
|
43
|
+
- `yarn db:push` - Push schema to database
|
|
44
|
+
- `yarn db:migrate` - Create and run migrations
|
|
68
45
|
- `yarn db:studio` - Open Prisma Studio
|
|
69
|
-
- `yarn db:
|
|
70
|
-
- `yarn
|
|
71
|
-
- `yarn
|
|
72
|
-
|
|
73
|
-
## Project Structure
|
|
74
|
-
|
|
75
|
-
```
|
|
76
|
-
src/
|
|
77
|
-
├── index.ts # Main exports
|
|
78
|
-
├── client.ts # Prisma client setup
|
|
79
|
-
└── schemas.ts # Zod validation schemas
|
|
80
|
-
prisma/
|
|
81
|
-
├── schema.prisma # Database schema
|
|
82
|
-
└── migrations/ # Database migrations
|
|
83
|
-
__tests__/
|
|
84
|
-
└── database.test.ts # Database tests
|
|
85
|
-
```
|
|
86
|
-
|
|
87
|
-
## Best Practices
|
|
88
|
-
|
|
89
|
-
- Always update Zod schemas when changing Prisma models
|
|
90
|
-
- Use meaningful migration names
|
|
91
|
-
- Test database operations
|
|
92
|
-
- Export only what's needed from the main index
|
|
93
|
-
- Keep the client singleton pattern for performance
|
|
46
|
+
- `yarn db:reset` - Reset the database
|
|
47
|
+
- `yarn build` - Build the package
|
|
48
|
+
- `yarn dev` - Build in watch mode
|
|
@@ -1,61 +1,47 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "{{packageName}}",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "
|
|
5
|
-
"type": "module",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Database layer with Prisma",
|
|
6
5
|
"main": "dist/index.js",
|
|
7
6
|
"types": "dist/index.d.ts",
|
|
8
7
|
"exports": {
|
|
9
8
|
".": {
|
|
10
9
|
"types": "./dist/index.d.ts",
|
|
11
|
-
"import": "./dist/index.js"
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"require": "./dist/index.js"
|
|
12
12
|
},
|
|
13
13
|
"./client": {
|
|
14
|
-
"types": "./
|
|
15
|
-
"import": "./
|
|
14
|
+
"types": "./generated/client/index.d.ts",
|
|
15
|
+
"import": "./generated/client/index.js",
|
|
16
|
+
"require": "./generated/client/index.js"
|
|
16
17
|
},
|
|
17
18
|
"./schemas": {
|
|
18
|
-
"types": "./dist/
|
|
19
|
-
"import": "./dist/
|
|
19
|
+
"types": "./dist/validators.d.ts",
|
|
20
|
+
"import": "./dist/validators.js",
|
|
21
|
+
"require": "./dist/validators.js"
|
|
20
22
|
}
|
|
21
23
|
},
|
|
22
24
|
"scripts": {
|
|
23
25
|
"build": "tsc",
|
|
24
|
-
"
|
|
25
|
-
"test:watch": "jest --watch",
|
|
26
|
-
"test:coverage": "jest --coverage",
|
|
26
|
+
"dev": "tsc --watch",
|
|
27
27
|
"db:generate": "prisma generate",
|
|
28
28
|
"db:push": "prisma db push",
|
|
29
|
-
"db:studio": "prisma studio",
|
|
30
29
|
"db:migrate": "prisma migrate dev",
|
|
31
|
-
"db:
|
|
32
|
-
"db:
|
|
33
|
-
"lint": "eslint src --ext .ts,.tsx",
|
|
34
|
-
"lint:fix": "eslint src --ext .ts,.tsx --fix",
|
|
35
|
-
"type-check": "tsc --noEmit",
|
|
36
|
-
"dev": "tsx watch src/index.ts"
|
|
30
|
+
"db:studio": "prisma studio",
|
|
31
|
+
"db:reset": "prisma migrate reset"
|
|
37
32
|
},
|
|
38
33
|
"dependencies": {
|
|
39
|
-
"@prisma/client": "^5.
|
|
34
|
+
"@prisma/client": "^5.19.1",
|
|
40
35
|
"zod": "^3.22.4"
|
|
41
36
|
},
|
|
42
37
|
"devDependencies": {
|
|
43
|
-
"@types/
|
|
44
|
-
"
|
|
45
|
-
"@typescript-eslint/eslint-plugin": "^6.13.1",
|
|
46
|
-
"@typescript-eslint/parser": "^6.13.1",
|
|
47
|
-
"dotenv": "^16.3.1",
|
|
48
|
-
"eslint": "^8.54.0",
|
|
49
|
-
"jest": "^29.7.0",
|
|
50
|
-
"prisma": "^5.7.1",
|
|
51
|
-
"ts-jest": "^29.1.2",
|
|
52
|
-
"tsx": "^4.6.2",
|
|
38
|
+
"@types/node": "^20.10.0",
|
|
39
|
+
"prisma": "^5.19.1",
|
|
53
40
|
"typescript": "^5.3.3"
|
|
54
41
|
},
|
|
55
|
-
"
|
|
56
|
-
"
|
|
57
|
-
"prisma",
|
|
58
|
-
"
|
|
59
|
-
"orm"
|
|
42
|
+
"files": [
|
|
43
|
+
"dist/**/*",
|
|
44
|
+
"prisma/**/*",
|
|
45
|
+
"generated/**/*"
|
|
60
46
|
]
|
|
61
47
|
}
|
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
import { PrismaClient } from '
|
|
1
|
+
import { PrismaClient } from '../generated/client';
|
|
2
2
|
|
|
3
3
|
const prisma = new PrismaClient();
|
|
4
4
|
|
|
5
5
|
async function main() {
|
|
6
|
-
console.log('🌱 Seeding database...');
|
|
7
|
-
|
|
8
6
|
// Add your seed data here
|
|
9
|
-
|
|
7
|
+
console.log('🌱 Seeding database...');
|
|
8
|
+
|
|
9
|
+
// Example seed data
|
|
10
10
|
// const user = await prisma.user.create({
|
|
11
11
|
// data: {
|
|
12
12
|
// email: 'admin@example.com',
|
|
13
13
|
// name: 'Admin User',
|
|
14
14
|
// },
|
|
15
15
|
// });
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
console.log('✅ Database seeded successfully!');
|
|
16
|
+
|
|
17
|
+
console.log('✅ Seeding completed');
|
|
19
18
|
}
|
|
20
19
|
|
|
21
20
|
main()
|
|
22
|
-
.
|
|
23
|
-
|
|
24
|
-
process.exit(1);
|
|
21
|
+
.then(async () => {
|
|
22
|
+
await prisma.$disconnect();
|
|
25
23
|
})
|
|
26
|
-
.
|
|
24
|
+
.catch(async (e) => {
|
|
25
|
+
console.error(e);
|
|
27
26
|
await prisma.$disconnect();
|
|
27
|
+
process.exit(1);
|
|
28
28
|
});
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
// This is your Prisma schema file,
|
|
2
|
+
// learn more about it in the docs: https://pris.ly/d/prisma-schema
|
|
3
|
+
|
|
4
|
+
generator client {
|
|
5
|
+
provider = "prisma-client-js"
|
|
6
|
+
output = "./generated/client"
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
datasource db {
|
|
10
|
+
provider = "sqlite"
|
|
11
|
+
url = env("DATABASE_URL")
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// Demo User model with profile information
|
|
15
|
+
model User {
|
|
16
|
+
id String @id @default(cuid())
|
|
17
|
+
email String @unique
|
|
18
|
+
name String?
|
|
19
|
+
avatar String? // URL to profile image
|
|
20
|
+
bio String? // User biography
|
|
21
|
+
location String? // User location
|
|
22
|
+
website String? // Personal website
|
|
23
|
+
|
|
24
|
+
// Posts created by this user
|
|
25
|
+
posts Post[]
|
|
26
|
+
|
|
27
|
+
// Comments made by this user
|
|
28
|
+
comments Comment[]
|
|
29
|
+
|
|
30
|
+
// User preferences and settings
|
|
31
|
+
settings UserSettings?
|
|
32
|
+
|
|
33
|
+
createdAt DateTime @default(now())
|
|
34
|
+
updatedAt DateTime @updatedAt
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Demo Post model for a simple blog/social feed
|
|
38
|
+
model Post {
|
|
39
|
+
id String @id @default(cuid())
|
|
40
|
+
title String
|
|
41
|
+
content String
|
|
42
|
+
excerpt String? // Short description
|
|
43
|
+
published Boolean @default(false)
|
|
44
|
+
tags String? // Comma-separated tag strings
|
|
45
|
+
|
|
46
|
+
// Author relationship
|
|
47
|
+
author User @relation(fields: [authorId], references: [id], onDelete: Cascade)
|
|
48
|
+
authorId String
|
|
49
|
+
|
|
50
|
+
// Comments on this post
|
|
51
|
+
comments Comment[]
|
|
52
|
+
|
|
53
|
+
// Post metadata
|
|
54
|
+
views Int @default(0)
|
|
55
|
+
likes Int @default(0)
|
|
56
|
+
|
|
57
|
+
createdAt DateTime @default(now())
|
|
58
|
+
updatedAt DateTime @updatedAt
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Demo Comment model
|
|
62
|
+
model Comment {
|
|
63
|
+
id String @id @default(cuid())
|
|
64
|
+
content String
|
|
65
|
+
|
|
66
|
+
// Author relationship
|
|
67
|
+
author User @relation(fields: [authorId], references: [id], onDelete: Cascade)
|
|
68
|
+
authorId String
|
|
69
|
+
|
|
70
|
+
// Post relationship
|
|
71
|
+
post Post @relation(fields: [postId], references: [id], onDelete: Cascade)
|
|
72
|
+
postId String
|
|
73
|
+
|
|
74
|
+
// Parent comment for nested threading
|
|
75
|
+
parent Comment? @relation("CommentThread", fields: [parentId], references: [id])
|
|
76
|
+
parentId String?
|
|
77
|
+
children Comment[] @relation("CommentThread")
|
|
78
|
+
|
|
79
|
+
createdAt DateTime @default(now())
|
|
80
|
+
updatedAt DateTime @updatedAt
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// User settings and preferences
|
|
84
|
+
model UserSettings {
|
|
85
|
+
id String @id @default(cuid())
|
|
86
|
+
theme String @default("auto") // "light", "dark", "auto"
|
|
87
|
+
notifications Boolean @default(true)
|
|
88
|
+
emailUpdates Boolean @default(false)
|
|
89
|
+
publicProfile Boolean @default(true)
|
|
90
|
+
|
|
91
|
+
// User relationship (one-to-one)
|
|
92
|
+
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
93
|
+
userId String @unique
|
|
94
|
+
|
|
95
|
+
createdAt DateTime @default(now())
|
|
96
|
+
updatedAt DateTime @updatedAt
|
|
97
|
+
}
|