@idealyst/cli 1.0.40 → 1.0.41

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@idealyst/cli",
3
- "version": "1.0.40",
3
+ "version": "1.0.41",
4
4
  "description": "CLI tool for generating Idealyst Framework projects",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
@@ -1,61 +1,28 @@
1
1
  {
2
2
  "name": "{{packageName}}",
3
- "version": "{{version}}",
4
- "description": "{{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
- "exports": {
9
- ".": {
10
- "types": "./dist/index.d.ts",
11
- "import": "./dist/index.js"
12
- },
13
- "./client": {
14
- "types": "./dist/client.d.ts",
15
- "import": "./dist/client.js"
16
- },
17
- "./schemas": {
18
- "types": "./dist/schemas.d.ts",
19
- "import": "./dist/schemas.js"
20
- }
21
- },
22
7
  "scripts": {
23
8
  "build": "tsc",
24
- "test": "jest",
25
- "test:watch": "jest --watch",
26
- "test:coverage": "jest --coverage",
9
+ "dev": "tsc --watch",
27
10
  "db:generate": "prisma generate",
28
11
  "db:push": "prisma db push",
29
- "db:studio": "prisma studio",
30
12
  "db:migrate": "prisma migrate dev",
31
- "db:reset": "prisma migrate reset",
32
- "db:seed": "tsx prisma/seed.ts",
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"
13
+ "db:studio": "prisma studio",
14
+ "db:reset": "prisma migrate reset"
37
15
  },
38
16
  "dependencies": {
39
- "@prisma/client": "^5.7.1",
40
- "zod": "^3.22.4"
17
+ "@prisma/client": "^5.19.1"
41
18
  },
42
19
  "devDependencies": {
43
- "@types/jest": "^29.5.12",
44
- "@types/node": "^20.10.4",
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",
20
+ "@types/node": "^20.10.0",
21
+ "prisma": "^5.19.1",
53
22
  "typescript": "^5.3.3"
54
23
  },
55
- "keywords": [
56
- "database",
57
- "prisma",
58
- "typescript",
59
- "orm"
24
+ "files": [
25
+ "dist/**/*",
26
+ "prisma/**/*"
60
27
  ]
61
28
  }
@@ -1,11 +1,15 @@
1
- // Export Prisma client
2
- export { PrismaClient } from '@prisma/client';
1
+ import { PrismaClient } from '@prisma/client'
3
2
 
4
- // Export database client instance
5
- export { default as db } from './client';
3
+ declare global {
4
+ var __prisma: PrismaClient | undefined
5
+ }
6
6
 
7
- // Export Zod schemas
8
- export * from './schemas';
7
+ export const prisma = globalThis.__prisma || new PrismaClient()
9
8
 
10
- // Export types from Prisma
11
- export type * from '@prisma/client';
9
+ if (process.env.NODE_ENV !== 'production') {
10
+ globalThis.__prisma = prisma
11
+ }
12
+
13
+ export * from '@prisma/client'
14
+ export * from './validators'
15
+ export default prisma
@@ -0,0 +1,10 @@
1
+ // Create model validators for each model defined in the Prisma schema using Zod
2
+ // E.g
3
+ import { z } from 'zod';
4
+
5
+ export const TestValidator = z.object({
6
+ id: z.string().uuid(),
7
+ email: z.string().email(),
8
+ name: z.string().min(2).max(100),
9
+ age: z.number().min(0).optional()
10
+ });
@@ -1,32 +1,18 @@
1
1
  {
2
2
  "compilerOptions": {
3
3
  "target": "ES2020",
4
+ "module": "commonjs",
4
5
  "lib": ["ES2020"],
5
- "module": "ESNext",
6
- "moduleResolution": "node",
7
- "allowSyntheticDefaultImports": true,
8
- "esModuleInterop": true,
9
- "forceConsistentCasingInFileNames": true,
6
+ "outDir": "./dist",
7
+ "rootDir": "./src",
10
8
  "strict": true,
9
+ "esModuleInterop": true,
11
10
  "skipLibCheck": true,
11
+ "forceConsistentCasingInFileNames": true,
12
12
  "declaration": true,
13
13
  "declarationMap": true,
14
- "sourceMap": true,
15
- "outDir": "./dist",
16
- "rootDir": "./src",
17
- "resolveJsonModule": true,
18
- "allowJs": false,
19
- "noUncheckedIndexedAccess": true,
20
- "experimentalDecorators": true,
21
- "emitDecoratorMetadata": true
14
+ "sourceMap": true
22
15
  },
23
- "include": [
24
- "src/**/*",
25
- "prisma/**/*"
26
- ],
27
- "exclude": [
28
- "node_modules",
29
- "dist",
30
- "__tests__"
31
- ]
32
- }
16
+ "include": ["src/**/*"],
17
+ "exclude": ["node_modules", "dist"]
18
+ }
@@ -1,8 +0,0 @@
1
- # Database
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,93 +0,0 @@
1
- # {{projectName}}
2
-
3
- {{description}}
4
-
5
- A database layer built with Prisma and TypeScript, designed to be shared across multiple applications in your monorepo.
6
-
7
- ## Features
8
-
9
- - 🗄️ **Prisma ORM** - Type-safe database access
10
- - 📝 **Zod Schemas** - Runtime validation matching your database models
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
- ```
23
-
24
- 2. **Generate Prisma Client**
25
- ```bash
26
- yarn db:generate
27
- ```
28
-
29
- 3. **Push Schema to Database**
30
- ```bash
31
- yarn db:push
32
- ```
33
-
34
- 4. **Open Prisma Studio** (Optional)
35
- ```bash
36
- yarn db:studio
37
- ```
38
-
39
- ## Usage
40
-
41
- ### In Other Packages
42
-
43
- ```typescript
44
- import { db, schemas } from '@your-org/{{projectName}}';
45
-
46
- // Use the database client
47
- const users = await db.user.findMany();
48
-
49
- // Use Zod schemas for validation
50
- const userData = schemas.createUser.parse(input);
51
- ```
52
-
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
- ## Scripts
61
-
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
- - `yarn db:generate` - Generate Prisma client
67
- - `yarn db:push` - Push schema changes to database
68
- - `yarn db:studio` - Open Prisma Studio
69
- - `yarn db:migrate` - Create and apply migrations
70
- - `yarn db:reset` - Reset database and apply migrations
71
- - `yarn db:seed` - Seed the database
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
@@ -1,14 +0,0 @@
1
- import { describe, it, expect } from '@jest/globals';
2
- import { db } from '../src';
3
-
4
- describe('Database', () => {
5
- it('should export database client', () => {
6
- expect(db).toBeDefined();
7
- });
8
-
9
- it('should connect to database', async () => {
10
- // This is a basic connection test
11
- // Add your own model-specific tests here
12
- expect(db.$connect).toBeDefined();
13
- });
14
- });
@@ -1,19 +0,0 @@
1
- module.exports = {
2
- preset: 'ts-jest',
3
- testEnvironment: 'node',
4
- collectCoverageFrom: [
5
- 'src/**/*.{ts,tsx}',
6
- '!src/**/*.d.ts',
7
- ],
8
- testMatch: [
9
- '**/__tests__/**/*.test.{ts,tsx}',
10
- ],
11
- setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],
12
- moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json'],
13
- transform: {
14
- '^.+\\.(ts|tsx)$': 'ts-jest',
15
- },
16
- moduleNameMapping: {
17
- '^@/(.*)$': '<rootDir>/src/$1',
18
- },
19
- };
@@ -1,11 +0,0 @@
1
- // Global test setup
2
- import { beforeEach, afterEach } from '@jest/globals';
3
-
4
- // Mock environment variables for testing
5
- process.env.NODE_ENV = 'test';
6
- process.env.DATABASE_URL = 'file:./test.db';
7
-
8
- // Clean up after each test
9
- afterEach(async () => {
10
- // Add any cleanup logic here
11
- });
@@ -1,28 +0,0 @@
1
- import { PrismaClient } from '@prisma/client';
2
-
3
- const prisma = new PrismaClient();
4
-
5
- async function main() {
6
- console.log('🌱 Seeding database...');
7
-
8
- // Add your seed data here
9
- // Example:
10
- // const user = await prisma.user.create({
11
- // data: {
12
- // email: 'admin@example.com',
13
- // name: 'Admin User',
14
- // },
15
- // });
16
- // console.log('Created user:', user);
17
-
18
- console.log('✅ Database seeded successfully!');
19
- }
20
-
21
- main()
22
- .catch((e) => {
23
- console.error('❌ Error seeding database:', e);
24
- process.exit(1);
25
- })
26
- .finally(async () => {
27
- await prisma.$disconnect();
28
- });
@@ -1,18 +0,0 @@
1
- import { PrismaClient } from '@prisma/client';
2
-
3
- declare global {
4
- // Prevent multiple instances of Prisma Client in development
5
- var __globalPrisma: PrismaClient | undefined;
6
- }
7
-
8
- const prisma =
9
- globalThis.__globalPrisma ??
10
- new PrismaClient({
11
- log: ['query', 'error', 'warn'],
12
- });
13
-
14
- if (process.env.NODE_ENV !== 'production') {
15
- globalThis.__globalPrisma = prisma;
16
- }
17
-
18
- export default prisma;
@@ -1,26 +0,0 @@
1
- import { z } from 'zod';
2
-
3
- // Add your Zod schemas here to match your Prisma models
4
- // Example:
5
- // export const UserSchema = z.object({
6
- // id: z.string().cuid(),
7
- // email: z.string().email(),
8
- // name: z.string().optional(),
9
- // createdAt: z.date(),
10
- // updatedAt: z.date(),
11
- // });
12
-
13
- // export const CreateUserSchema = UserSchema.omit({
14
- // id: true,
15
- // createdAt: true,
16
- // updatedAt: true,
17
- // });
18
-
19
- // export const UpdateUserSchema = CreateUserSchema.partial();
20
-
21
- // Export all your schemas
22
- export const schemas = {
23
- // user: UserSchema,
24
- // createUser: CreateUserSchema,
25
- // updateUser: UpdateUserSchema,
26
- } as const;
@@ -1,230 +0,0 @@
1
- #!/bin/bash
2
-
3
- # Database backup and restore script for Idealyst workspace
4
- # Usage: ./scripts/docker/db-backup.sh [backup|restore] [filename]
5
-
6
- set -e
7
-
8
- COMMAND=${1:-backup}
9
- FILENAME=${2:-"backup-$(date +%Y%m%d-%H%M%S).sql"}
10
- PROJECT_NAME=${PROJECT_NAME:-idealyst}
11
-
12
- # Source environment variables
13
- if [ -f ".env" ]; then
14
- source .env
15
- fi
16
-
17
- POSTGRES_CONTAINER="${PROJECT_NAME}-postgres"
18
- DATABASE=${POSTGRES_DB:-idealyst_db}
19
- USERNAME=${POSTGRES_USER:-postgres}
20
-
21
- echo "🗄️ Database Operations for Idealyst"
22
- echo "===================================="
23
-
24
- # Function to check if database container is running
25
- check_database() {
26
- if ! docker ps | grep -q "$POSTGRES_CONTAINER"; then
27
- echo "❌ Database container '$POSTGRES_CONTAINER' is not running"
28
- echo "💡 Start it with: docker-compose up -d postgres"
29
- exit 1
30
- fi
31
- }
32
-
33
- # Function to create backup
34
- create_backup() {
35
- local backup_file=$1
36
-
37
- echo "📦 Creating backup of database '$DATABASE'..."
38
- echo "📁 Backup file: $backup_file"
39
-
40
- # Create backups directory if it doesn't exist
41
- mkdir -p backups
42
-
43
- # Create the backup
44
- docker exec "$POSTGRES_CONTAINER" pg_dump \
45
- -U "$USERNAME" \
46
- -d "$DATABASE" \
47
- --clean \
48
- --if-exists \
49
- --create \
50
- --verbose > "backups/$backup_file"
51
-
52
- if [ $? -eq 0 ]; then
53
- echo "✅ Backup created successfully: backups/$backup_file"
54
-
55
- # Show backup info
56
- local size=$(du -h "backups/$backup_file" | cut -f1)
57
- echo "📊 Backup size: $size"
58
-
59
- # Compress the backup
60
- gzip "backups/$backup_file"
61
- echo "🗜️ Backup compressed: backups/$backup_file.gz"
62
-
63
- else
64
- echo "❌ Backup failed"
65
- exit 1
66
- fi
67
- }
68
-
69
- # Function to restore backup
70
- restore_backup() {
71
- local backup_file=$1
72
-
73
- # Check if backup file exists
74
- if [ ! -f "$backup_file" ]; then
75
- # Try with .gz extension
76
- if [ -f "$backup_file.gz" ]; then
77
- echo "📦 Found compressed backup, extracting..."
78
- gunzip "$backup_file.gz"
79
- else
80
- echo "❌ Backup file not found: $backup_file"
81
- echo "📁 Available backups:"
82
- ls -la backups/ 2>/dev/null || echo "No backups directory found"
83
- exit 1
84
- fi
85
- fi
86
-
87
- echo "⚠️ WARNING: This will replace the current database '$DATABASE'"
88
- echo "📁 Restoring from: $backup_file"
89
-
90
- read -p "Are you sure you want to continue? (y/N): " -n 1 -r
91
- echo
92
-
93
- if [[ ! $REPLY =~ ^[Yy]$ ]]; then
94
- echo "❌ Restore cancelled"
95
- exit 1
96
- fi
97
-
98
- echo "🔄 Restoring database..."
99
-
100
- # Stop API container to prevent connections
101
- echo "🛑 Stopping API container..."
102
- docker-compose stop api 2>/dev/null || true
103
-
104
- # Wait a moment for connections to close
105
- sleep 2
106
-
107
- # Restore the backup
108
- docker exec -i "$POSTGRES_CONTAINER" psql \
109
- -U "$USERNAME" \
110
- -d postgres < "$backup_file"
111
-
112
- if [ $? -eq 0 ]; then
113
- echo "✅ Database restored successfully"
114
-
115
- # Restart API container
116
- echo "🚀 Restarting API container..."
117
- docker-compose start api
118
-
119
- else
120
- echo "❌ Restore failed"
121
- echo "🚀 Restarting API container..."
122
- docker-compose start api
123
- exit 1
124
- fi
125
- }
126
-
127
- # Function to list backups
128
- list_backups() {
129
- echo "📁 Available backups:"
130
- echo "===================="
131
-
132
- if [ -d "backups" ]; then
133
- ls -lah backups/ | grep -E '\.(sql|gz)$' || echo "No backup files found"
134
- else
135
- echo "No backups directory found"
136
- fi
137
- }
138
-
139
- # Function to clean old backups
140
- clean_backups() {
141
- local days=${1:-7}
142
-
143
- echo "🧹 Cleaning backups older than $days days..."
144
-
145
- if [ -d "backups" ]; then
146
- find backups/ -name "*.sql.gz" -mtime +$days -delete
147
- find backups/ -name "*.sql" -mtime +$days -delete
148
- echo "✅ Old backups cleaned"
149
- else
150
- echo "No backups directory found"
151
- fi
152
- }
153
-
154
- # Function to show database info
155
- show_db_info() {
156
- echo "📊 Database Information:"
157
- echo "======================="
158
- echo "Container: $POSTGRES_CONTAINER"
159
- echo "Database: $DATABASE"
160
- echo "Username: $USERNAME"
161
- echo ""
162
-
163
- # Show database size
164
- echo "🗄️ Database size:"
165
- docker exec "$POSTGRES_CONTAINER" psql \
166
- -U "$USERNAME" \
167
- -d "$DATABASE" \
168
- -c "SELECT pg_size_pretty(pg_database_size('$DATABASE')) as database_size;"
169
-
170
- echo ""
171
- echo "📋 Tables:"
172
- docker exec "$POSTGRES_CONTAINER" psql \
173
- -U "$USERNAME" \
174
- -d "$DATABASE" \
175
- -c "\dt"
176
- }
177
-
178
- # Main script logic
179
- main() {
180
- case $COMMAND in
181
- "backup")
182
- check_database
183
- create_backup "$FILENAME"
184
- ;;
185
-
186
- "restore")
187
- check_database
188
- if [ -z "$FILENAME" ]; then
189
- echo "❌ Please specify a backup file to restore"
190
- echo "Usage: $0 restore <backup-file>"
191
- exit 1
192
- fi
193
- restore_backup "$FILENAME"
194
- ;;
195
-
196
- "list")
197
- list_backups
198
- ;;
199
-
200
- "clean")
201
- local days=${FILENAME:-7}
202
- clean_backups "$days"
203
- ;;
204
-
205
- "info")
206
- check_database
207
- show_db_info
208
- ;;
209
-
210
- *)
211
- echo "Usage: $0 [backup|restore|list|clean|info] [filename|days]"
212
- echo ""
213
- echo "Commands:"
214
- echo " backup [filename] - Create a database backup"
215
- echo " restore <filename> - Restore from a backup file"
216
- echo " list - List available backups"
217
- echo " clean [days] - Clean backups older than N days (default: 7)"
218
- echo " info - Show database information"
219
- echo ""
220
- echo "Examples:"
221
- echo " $0 backup"
222
- echo " $0 backup my-backup.sql"
223
- echo " $0 restore backups/backup-20240101-120000.sql"
224
- echo " $0 clean 30"
225
- exit 1
226
- ;;
227
- esac
228
- }
229
-
230
- main
@@ -1,212 +0,0 @@
1
- #!/bin/bash
2
-
3
- # Docker deployment script for Idealyst workspace
4
- # Usage: ./scripts/docker/deploy.sh [environment]
5
-
6
- set -e
7
-
8
- ENVIRONMENT=${1:-production}
9
- PROJECT_NAME=${PROJECT_NAME:-idealyst}
10
-
11
- echo "🚀 Deploying Idealyst to $ENVIRONMENT environment..."
12
-
13
- # Validate environment
14
- if [[ ! "$ENVIRONMENT" =~ ^(development|staging|production)$ ]]; then
15
- echo "❌ Invalid environment. Use: development, staging, or production"
16
- exit 1
17
- fi
18
-
19
- # Check if required files exist
20
- if [ ! -f "docker-compose.yml" ]; then
21
- echo "❌ docker-compose.yml not found. Run this script from the project root."
22
- exit 1
23
- fi
24
-
25
- if [ ! -f ".env" ]; then
26
- echo "⚠️ .env file not found. Creating from .env.example..."
27
- cp .env.example .env
28
- echo "📝 Please edit .env with your configuration before proceeding."
29
- exit 1
30
- fi
31
-
32
- # Source environment variables
33
- source .env
34
-
35
- # Function to wait for service health
36
- wait_for_service() {
37
- local service=$1
38
- local max_attempts=30
39
- local attempt=1
40
-
41
- echo "⏳ Waiting for $service to be healthy..."
42
-
43
- while [ $attempt -le $max_attempts ]; do
44
- if docker-compose ps $service | grep -q "healthy\|Up"; then
45
- echo "✅ $service is ready"
46
- return 0
47
- fi
48
-
49
- echo "🔄 Attempt $attempt/$max_attempts - waiting for $service..."
50
- sleep 10
51
- attempt=$((attempt + 1))
52
- done
53
-
54
- echo "❌ $service failed to become healthy"
55
- return 1
56
- }
57
-
58
- # Function to run database migrations
59
- run_migrations() {
60
- echo "🗄️ Running database migrations..."
61
-
62
- # Check if any package has Prisma schema
63
- for package_dir in packages/*/; do
64
- if [ -f "${package_dir}prisma/schema.prisma" ]; then
65
- echo "📦 Running migrations for $(basename "$package_dir")..."
66
- docker-compose exec api yarn workspace $(basename "$package_dir") prisma migrate deploy
67
- fi
68
- done
69
- }
70
-
71
- # Function to build and deploy
72
- deploy() {
73
- case $ENVIRONMENT in
74
- "development")
75
- echo "🔧 Starting development environment..."
76
- docker-compose up --build -d postgres redis
77
- wait_for_service postgres
78
- wait_for_service redis
79
- docker-compose up --build -d dev
80
- ;;
81
-
82
- "staging"|"production")
83
- echo "🏗️ Building application..."
84
- docker-compose build --no-cache
85
-
86
- if [ "$ENVIRONMENT" = "production" ]; then
87
- echo "🚀 Deploying to production..."
88
- docker-compose -f docker-compose.yml -f docker-compose.prod.yml up -d postgres redis
89
- else
90
- echo "🧪 Deploying to staging..."
91
- docker-compose up -d postgres redis
92
- fi
93
-
94
- wait_for_service postgres
95
- wait_for_service redis
96
-
97
- # Run migrations
98
- run_migrations
99
-
100
- if [ "$ENVIRONMENT" = "production" ]; then
101
- docker-compose -f docker-compose.yml -f docker-compose.prod.yml up -d api web nginx
102
- else
103
- docker-compose up -d api web
104
- fi
105
-
106
- wait_for_service api
107
- wait_for_service web
108
- ;;
109
- esac
110
- }
111
-
112
- # Function to show deployment status
113
- show_status() {
114
- echo ""
115
- echo "📊 Deployment Status:"
116
- echo "===================="
117
- docker-compose ps
118
-
119
- echo ""
120
- echo "🌐 Service URLs:"
121
- echo "==============="
122
-
123
- if [ "$ENVIRONMENT" = "development" ]; then
124
- echo "Web App (Dev): http://localhost:3000"
125
- echo "API (Dev): http://localhost:3001"
126
- echo "Database: postgresql://postgres:postgres@localhost:5432/${POSTGRES_DB}"
127
- echo "Redis: redis://localhost:6379"
128
- else
129
- echo "Web App: http://localhost:${WEB_PORT:-80}"
130
- echo "API: http://localhost:${API_PORT:-3001}"
131
-
132
- if [ "$ENVIRONMENT" = "production" ]; then
133
- echo "Nginx: http://localhost"
134
- echo "Monitoring: http://localhost:3002 (Grafana)"
135
- echo "Metrics: http://localhost:9090 (Prometheus)"
136
- fi
137
- fi
138
-
139
- echo ""
140
- echo "📝 Logs:"
141
- echo "========"
142
- echo "View logs: docker-compose logs -f [service]"
143
- echo "Available services: $(docker-compose config --services | tr '\n' ' ')"
144
- }
145
-
146
- # Function to run tests
147
- run_tests() {
148
- echo "🧪 Running tests..."
149
- docker-compose --profile testing run --rm test
150
- }
151
-
152
- # Main deployment process
153
- main() {
154
- echo "🏗️ Environment: $ENVIRONMENT"
155
- echo "📦 Project: $PROJECT_NAME"
156
- echo ""
157
-
158
- # Stop existing containers
159
- echo "🛑 Stopping existing containers..."
160
- docker-compose down
161
-
162
- # Clean up orphaned containers
163
- docker-compose down --remove-orphans
164
-
165
- # Deploy
166
- deploy
167
-
168
- # Show status
169
- show_status
170
-
171
- echo ""
172
- echo "✅ Deployment complete!"
173
- echo ""
174
- echo "💡 Useful commands:"
175
- echo " View logs: docker-compose logs -f"
176
- echo " Stop services: docker-compose down"
177
- echo " Restart service: docker-compose restart [service]"
178
- echo " Run tests: ./scripts/docker/deploy.sh test"
179
- echo ""
180
- }
181
-
182
- # Handle special commands
183
- case $ENVIRONMENT in
184
- "test")
185
- run_tests
186
- exit 0
187
- ;;
188
- "status")
189
- show_status
190
- exit 0
191
- ;;
192
- "logs")
193
- docker-compose logs -f
194
- exit 0
195
- ;;
196
- "stop")
197
- echo "🛑 Stopping all services..."
198
- docker-compose down
199
- echo "✅ All services stopped"
200
- exit 0
201
- ;;
202
- "clean")
203
- echo "🧹 Cleaning up Docker resources..."
204
- docker-compose down -v --remove-orphans
205
- docker system prune -f
206
- echo "✅ Cleanup complete"
207
- exit 0
208
- ;;
209
- esac
210
-
211
- # Run main deployment
212
- main
@@ -1,151 +0,0 @@
1
- #!/bin/bash
2
-
3
- # Docker build helper script for Idealyst workspace
4
- # Handles common issues like missing yarn.lock files
5
-
6
- set -e
7
-
8
- # Colors for output
9
- RED='\033[0;31m'
10
- GREEN='\033[0;32m'
11
- YELLOW='\033[1;33m'
12
- BLUE='\033[0;34m'
13
- NC='\033[0m' # No Color
14
-
15
- echo -e "${BLUE}🐳 Idealyst Docker Build Helper${NC}"
16
- echo ""
17
-
18
- # Check if yarn.lock exists
19
- if [ ! -f "yarn.lock" ]; then
20
- echo -e "${YELLOW}⚠️ yarn.lock not found${NC}"
21
- echo "This can cause Docker build failures with 'immutable' installs."
22
- echo ""
23
- read -p "Would you like to generate yarn.lock now? (y/N): " -n 1 -r
24
- echo ""
25
-
26
- if [[ $REPLY =~ ^[Yy]$ ]]; then
27
- echo -e "${BLUE}📦 Installing dependencies to generate yarn.lock...${NC}"
28
- yarn install
29
- echo -e "${GREEN}✅ yarn.lock generated${NC}"
30
- else
31
- echo -e "${YELLOW}⚠️ Continuing without yarn.lock (may cause build issues)${NC}"
32
- fi
33
- echo ""
34
- fi
35
-
36
- # Check if .env exists
37
- if [ ! -f ".env" ]; then
38
- echo -e "${YELLOW}⚠️ .env file not found${NC}"
39
- if [ -f ".env.example" ]; then
40
- read -p "Would you like to copy .env.example to .env? (y/N): " -n 1 -r
41
- echo ""
42
- if [[ $REPLY =~ ^[Yy]$ ]]; then
43
- cp .env.example .env
44
- echo -e "${GREEN}✅ .env file created from .env.example${NC}"
45
- echo -e "${YELLOW}📝 Please review and update .env with your settings${NC}"
46
- fi
47
- else
48
- echo -e "${YELLOW}📝 Please create a .env file with your configuration${NC}"
49
- fi
50
- echo ""
51
- fi
52
-
53
- # Determine what to build
54
- if [ $# -eq 0 ]; then
55
- echo "What would you like to do?"
56
- echo "1) Build and start development environment"
57
- echo "2) Build and start production services"
58
- echo "3) Build specific service"
59
- echo "4) Just build (no start)"
60
- echo ""
61
- read -p "Choice (1-4): " -n 1 -r
62
- echo ""
63
-
64
- case $REPLY in
65
- 1)
66
- echo -e "${BLUE}🚀 Building and starting development environment...${NC}"
67
- docker-compose build dev
68
- docker-compose up -d postgres redis
69
- docker-compose up dev
70
- ;;
71
- 2)
72
- echo -e "${BLUE}🚀 Building and starting production services...${NC}"
73
- docker-compose build
74
- docker-compose up -d
75
- ;;
76
- 3)
77
- echo "Available services: api, web, dev, postgres, redis"
78
- read -p "Service name: " service
79
- echo -e "${BLUE}🚀 Building ${service}...${NC}"
80
- docker-compose build $service
81
- ;;
82
- 4)
83
- echo -e "${BLUE}🏗️ Building all services...${NC}"
84
- docker-compose build
85
- ;;
86
- *)
87
- echo -e "${RED}❌ Invalid choice${NC}"
88
- exit 1
89
- ;;
90
- esac
91
- else
92
- # Handle command line arguments
93
- case "$1" in
94
- "dev")
95
- echo -e "${BLUE}🚀 Building and starting development environment...${NC}"
96
- docker-compose build dev
97
- docker-compose up -d postgres redis
98
- docker-compose up dev
99
- ;;
100
- "prod"|"production")
101
- echo -e "${BLUE}🚀 Building and starting production services...${NC}"
102
- docker-compose build
103
- docker-compose up -d
104
- ;;
105
- "build")
106
- if [ -n "$2" ]; then
107
- echo -e "${BLUE}🏗️ Building ${2}...${NC}"
108
- docker-compose build $2
109
- else
110
- echo -e "${BLUE}🏗️ Building all services...${NC}"
111
- docker-compose build
112
- fi
113
- ;;
114
- "help"|"-h"|"--help")
115
- echo "Usage: $0 [command] [service]"
116
- echo ""
117
- echo "Commands:"
118
- echo " dev Build and start development environment"
119
- echo " prod Build and start production services"
120
- echo " build [svc] Build all services or specific service"
121
- echo " help Show this help"
122
- echo ""
123
- echo "Services: api, web, dev, postgres, redis"
124
- ;;
125
- *)
126
- echo -e "${RED}❌ Unknown command: $1${NC}"
127
- echo "Use '$0 help' for usage information"
128
- exit 1
129
- ;;
130
- esac
131
- fi
132
-
133
- echo ""
134
- echo -e "${GREEN}🎉 Done!${NC}"
135
-
136
- # Show helpful information
137
- if docker-compose ps | grep -q "Up"; then
138
- echo ""
139
- echo -e "${BLUE}📋 Running services:${NC}"
140
- docker-compose ps
141
- echo ""
142
- echo -e "${BLUE}🔗 Access your application:${NC}"
143
- echo "• Web: http://localhost:3000"
144
- echo "• API: http://localhost:3001"
145
- echo "• Vite Dev: http://localhost:5173"
146
- echo ""
147
- echo -e "${BLUE}💡 Useful commands:${NC}"
148
- echo "• View logs: docker-compose logs -f"
149
- echo "• Stop services: docker-compose down"
150
- echo "• Access dev container: docker-compose exec dev bash"
151
- fi
@@ -1,120 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- /**
4
- * Test runner script for Idealyst workspace
5
- * Provides flexible test execution across all packages
6
- */
7
-
8
- const { execSync } = require('child_process');
9
- const path = require('path');
10
- const fs = require('fs');
11
-
12
- const args = process.argv.slice(2);
13
- const command = args[0] || 'test';
14
-
15
- // Available commands
16
- const commands = {
17
- 'test': 'Run tests in all packages',
18
- 'test:watch': 'Run tests in watch mode',
19
- 'test:coverage': 'Run tests with coverage',
20
- 'test:ci': 'Run tests in CI mode',
21
- 'test:package': 'Run tests for a specific package (usage: test:package <package-name>)',
22
- };
23
-
24
- function showHelp() {
25
- console.log('Idealyst Test Runner\n');
26
- console.log('Available commands:');
27
- Object.entries(commands).forEach(([cmd, desc]) => {
28
- console.log(` ${cmd.padEnd(20)} ${desc}`);
29
- });
30
- console.log('\nExamples:');
31
- console.log(' npm run test');
32
- console.log(' npm run test:watch');
33
- console.log(' npm run test:coverage');
34
- console.log(' node scripts/test-runner.js test:package api');
35
- }
36
-
37
- function getPackages() {
38
- const packagesDir = path.join(process.cwd(), 'packages');
39
- if (!fs.existsSync(packagesDir)) {
40
- return [];
41
- }
42
-
43
- return fs.readdirSync(packagesDir)
44
- .filter(dir => {
45
- const packageJsonPath = path.join(packagesDir, dir, 'package.json');
46
- return fs.existsSync(packageJsonPath);
47
- });
48
- }
49
-
50
- function runCommand(cmd, options = {}) {
51
- try {
52
- console.log(`Running: ${cmd}`);
53
- execSync(cmd, {
54
- stdio: 'inherit',
55
- cwd: process.cwd(),
56
- ...options
57
- });
58
- } catch (error) {
59
- console.error(`Command failed: ${cmd}`);
60
- process.exit(1);
61
- }
62
- }
63
-
64
- function runTestsForPackage(packageName) {
65
- const packages = getPackages();
66
-
67
- if (!packages.includes(packageName)) {
68
- console.error(`Package "${packageName}" not found.`);
69
- console.log('Available packages:', packages.join(', '));
70
- process.exit(1);
71
- }
72
-
73
- const packagePath = path.join('packages', packageName);
74
- console.log(`Running tests for package: ${packageName}`);
75
- runCommand(`yarn workspace @/* run test`, { cwd: packagePath });
76
- }
77
-
78
- // Main execution
79
- switch (command) {
80
- case 'help':
81
- case '--help':
82
- case '-h':
83
- showHelp();
84
- break;
85
-
86
- case 'test':
87
- console.log('Running tests in all packages...');
88
- runCommand('yarn workspaces foreach --include "@/*" run test --passWithNoTests');
89
- break;
90
-
91
- case 'test:watch':
92
- console.log('Running tests in watch mode...');
93
- runCommand('yarn workspaces foreach --include "@/*" run test:watch');
94
- break;
95
-
96
- case 'test:coverage':
97
- console.log('Running tests with coverage...');
98
- runCommand('yarn workspaces foreach --include "@/*" run test:coverage');
99
- break;
100
-
101
- case 'test:ci':
102
- console.log('Running tests in CI mode...');
103
- runCommand('yarn workspaces foreach --include "@/*" --parallel run test --passWithNoTests --watchAll=false');
104
- break;
105
-
106
- case 'test:package':
107
- const packageName = args[1];
108
- if (!packageName) {
109
- console.error('Package name is required for test:package command');
110
- console.log('Usage: node scripts/test-runner.js test:package <package-name>');
111
- process.exit(1);
112
- }
113
- runTestsForPackage(packageName);
114
- break;
115
-
116
- default:
117
- console.error(`Unknown command: ${command}`);
118
- console.log('Run with "help" to see available commands');
119
- process.exit(1);
120
- }
@@ -1,205 +0,0 @@
1
- #!/bin/bash
2
-
3
- # Quick setup script for Idealyst workspace
4
- # Usage: ./setup.sh [development|production]
5
-
6
- set -e
7
-
8
- ENVIRONMENT=${1:-development}
9
- PROJECT_NAME="{{packageName}}"
10
-
11
- echo "🚀 Setting up Idealyst workspace..."
12
- echo "Environment: $ENVIRONMENT"
13
- echo "Project: $PROJECT_NAME"
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
- }
105
-
106
- # Function to check prerequisites
107
- check_prerequisites() {
108
- echo "🔍 Checking prerequisites..."
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
203
- fi
204
-
205
- main