@idealyst/cli 1.0.27 → 1.0.29

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.
Files changed (42) hide show
  1. package/dist/index.js +43 -13
  2. package/dist/types/generators/utils.d.ts +6 -1
  3. package/package.json +1 -1
  4. package/templates/api/__tests__/api.test.ts +26 -0
  5. package/templates/api/jest.config.js +23 -0
  6. package/templates/api/jest.setup.js +9 -0
  7. package/templates/api/package.json +13 -0
  8. package/templates/native/__tests__/App.test.tsx +156 -0
  9. package/templates/native/__tests__/components.test.tsx +300 -0
  10. package/templates/native/jest.config.js +21 -0
  11. package/templates/native/jest.setup.js +12 -0
  12. package/templates/native/package.json +34 -0
  13. package/templates/native/src/App-with-trpc.tsx +0 -13
  14. package/templates/shared/__tests__/shared.test.ts +39 -0
  15. package/templates/shared/jest.config.js +22 -0
  16. package/templates/shared/package.json +10 -0
  17. package/templates/web/__tests__/App.test.tsx +342 -0
  18. package/templates/web/__tests__/components.test.tsx +564 -0
  19. package/templates/web/jest.config.js +27 -0
  20. package/templates/web/jest.setup.js +24 -0
  21. package/templates/web/package.json +11 -1
  22. package/templates/web/src/App-with-trpc.tsx +0 -13
  23. package/templates/workspace/.devcontainer/devcontainer.json +150 -0
  24. package/templates/workspace/.devcontainer/post-create.sh +129 -0
  25. package/templates/workspace/.dockerignore +151 -0
  26. package/templates/workspace/.env.example +36 -0
  27. package/templates/workspace/.env.production +56 -0
  28. package/templates/workspace/DOCKER.md +385 -0
  29. package/templates/workspace/Dockerfile +100 -0
  30. package/templates/workspace/README.md +93 -0
  31. package/templates/workspace/docker/nginx/prod.conf +238 -0
  32. package/templates/workspace/docker/nginx.conf +131 -0
  33. package/templates/workspace/docker/postgres/init.sql +41 -0
  34. package/templates/workspace/docker/prometheus/prometheus.yml +52 -0
  35. package/templates/workspace/docker-compose.prod.yml +146 -0
  36. package/templates/workspace/docker-compose.yml +144 -0
  37. package/templates/workspace/jest.config.js +20 -0
  38. package/templates/workspace/package.json +11 -1
  39. package/templates/workspace/scripts/docker/db-backup.sh +230 -0
  40. package/templates/workspace/scripts/docker/deploy.sh +212 -0
  41. package/templates/workspace/scripts/test-runner.js +120 -0
  42. package/templates/workspace/setup.sh +205 -0
@@ -0,0 +1,385 @@
1
+ # Docker Configuration Guide
2
+
3
+ This workspace includes comprehensive Docker support for development, staging, and production environments.
4
+
5
+ ## Quick Start
6
+
7
+ ### Development Environment
8
+ ```bash
9
+ # Copy environment file
10
+ cp .env.example .env
11
+
12
+ # Start development environment
13
+ ./scripts/docker/deploy.sh development
14
+
15
+ # Or use Docker Compose directly
16
+ docker-compose up -d dev
17
+ ```
18
+
19
+ ### Production Deployment
20
+ ```bash
21
+ # Copy and configure production environment
22
+ cp .env.production .env
23
+ # Edit .env with your production settings
24
+
25
+ # Deploy to production
26
+ ./scripts/docker/deploy.sh production
27
+ ```
28
+
29
+ ## Architecture
30
+
31
+ ### Services Overview
32
+ - **postgres**: PostgreSQL database with initialization scripts
33
+ - **redis**: Redis cache for sessions and caching
34
+ - **api**: Backend API service
35
+ - **web**: Frontend web application
36
+ - **nginx**: Reverse proxy and load balancer (production)
37
+ - **dev**: Development container with all tools
38
+ - **test**: Test runner container
39
+
40
+ ### Development vs Production
41
+
42
+ #### Development
43
+ - Single container with all development tools
44
+ - File watching and hot reload
45
+ - Debug logging enabled
46
+ - Development database
47
+
48
+ #### Production
49
+ - Multi-container architecture
50
+ - Optimized builds
51
+ - Load balancing with Nginx
52
+ - Health checks and monitoring
53
+ - Secure configurations
54
+
55
+ ## File Structure
56
+
57
+ ```
58
+ workspace/
59
+ ├── Dockerfile # Multi-stage Dockerfile
60
+ ├── docker-compose.yml # Main compose configuration
61
+ ├── docker-compose.prod.yml # Production overrides
62
+ ├── .dockerignore # Build context exclusions
63
+ ├── .env.example # Development environment template
64
+ ├── .env.production # Production environment template
65
+ ├── .devcontainer/ # VS Code dev container config
66
+ │ ├── devcontainer.json
67
+ │ └── post-create.sh
68
+ ├── docker/ # Docker configuration files
69
+ │ ├── nginx.conf # Development nginx config
70
+ │ ├── nginx/
71
+ │ │ └── prod.conf # Production nginx config
72
+ │ ├── postgres/
73
+ │ │ └── init.sql # Database initialization
74
+ │ └── prometheus/
75
+ │ └── prometheus.yml # Monitoring configuration
76
+ └── scripts/docker/ # Management scripts
77
+ ├── deploy.sh # Deployment script
78
+ └── db-backup.sh # Database backup/restore
79
+ ```
80
+
81
+ ## Environment Configuration
82
+
83
+ ### Required Environment Variables
84
+
85
+ ```bash
86
+ # Project
87
+ PROJECT_NAME=your-project-name
88
+
89
+ # Database
90
+ POSTGRES_DB=your_database
91
+ POSTGRES_USER=your_user
92
+ POSTGRES_PASSWORD=strong_password
93
+
94
+ # API
95
+ JWT_SECRET=very_strong_jwt_secret
96
+ API_PORT=3001
97
+
98
+ # Web
99
+ WEB_PORT=80
100
+ ```
101
+
102
+ ### Security Considerations
103
+
104
+ For production, ensure you:
105
+ 1. Change all default passwords
106
+ 2. Use strong, unique secrets
107
+ 3. Configure SSL certificates
108
+ 4. Set up proper firewall rules
109
+ 5. Enable monitoring and logging
110
+
111
+ ## Development Container
112
+
113
+ ### VS Code Integration
114
+
115
+ The workspace includes a complete VS Code dev container configuration:
116
+
117
+ 1. **Open in VS Code**: Use "Reopen in Container" when prompted
118
+ 2. **Automatic Setup**: Dependencies and tools are installed automatically
119
+ 3. **Database**: PostgreSQL and Redis are available immediately
120
+ 4. **Port Forwarding**: All development ports are automatically forwarded
121
+
122
+ ### Features Included
123
+ - Node.js 20 with Yarn
124
+ - TypeScript and development tools
125
+ - Git and GitHub CLI
126
+ - Docker-in-Docker support
127
+ - VS Code extensions for React, TypeScript, and more
128
+
129
+ ### Manual Setup
130
+ ```bash
131
+ # Start dev container
132
+ docker-compose up -d dev
133
+
134
+ # Access the container
135
+ docker-compose exec dev bash
136
+
137
+ # Install dependencies (if not already done)
138
+ yarn install
139
+
140
+ # Start development servers
141
+ yarn dev
142
+ ```
143
+
144
+ ## Deployment Scripts
145
+
146
+ ### Deploy Script (`./scripts/docker/deploy.sh`)
147
+
148
+ ```bash
149
+ # Development
150
+ ./scripts/docker/deploy.sh development
151
+
152
+ # Production
153
+ ./scripts/docker/deploy.sh production
154
+
155
+ # View status
156
+ ./scripts/docker/deploy.sh status
157
+
158
+ # View logs
159
+ ./scripts/docker/deploy.sh logs
160
+
161
+ # Stop all services
162
+ ./scripts/docker/deploy.sh stop
163
+
164
+ # Clean up everything
165
+ ./scripts/docker/deploy.sh clean
166
+ ```
167
+
168
+ ### Database Management (`./scripts/docker/db-backup.sh`)
169
+
170
+ ```bash
171
+ # Create backup
172
+ ./scripts/docker/db-backup.sh backup
173
+
174
+ # Restore backup
175
+ ./scripts/docker/db-backup.sh restore backups/backup-file.sql
176
+
177
+ # List backups
178
+ ./scripts/docker/db-backup.sh list
179
+
180
+ # Clean old backups
181
+ ./scripts/docker/db-backup.sh clean 30
182
+
183
+ # Show database info
184
+ ./scripts/docker/db-backup.sh info
185
+ ```
186
+
187
+ ## Production Deployment
188
+
189
+ ### Prerequisites
190
+ 1. Docker and Docker Compose installed
191
+ 2. Domain name configured
192
+ 3. SSL certificates (Let's Encrypt recommended)
193
+ 4. Environment variables configured
194
+
195
+ ### Steps
196
+ 1. **Prepare Environment**
197
+ ```bash
198
+ cp .env.production .env
199
+ # Edit .env with your settings
200
+ ```
201
+
202
+ 2. **Deploy**
203
+ ```bash
204
+ ./scripts/docker/deploy.sh production
205
+ ```
206
+
207
+ 3. **Configure SSL** (if using Let's Encrypt)
208
+ ```bash
209
+ # Install certbot
210
+ docker run -it --rm \
211
+ -v /etc/letsencrypt:/etc/letsencrypt \
212
+ -v /var/lib/letsencrypt:/var/lib/letsencrypt \
213
+ certbot/certbot certonly --standalone \
214
+ -d yourdomain.com
215
+
216
+ # Copy certificates
217
+ mkdir -p docker/nginx/ssl
218
+ cp /etc/letsencrypt/live/yourdomain.com/fullchain.pem docker/nginx/ssl/cert.pem
219
+ cp /etc/letsencrypt/live/yourdomain.com/privkey.pem docker/nginx/ssl/key.pem
220
+ ```
221
+
222
+ 4. **Restart with SSL**
223
+ ```bash
224
+ docker-compose -f docker-compose.yml -f docker-compose.prod.yml restart nginx
225
+ ```
226
+
227
+ ### Scaling Services
228
+
229
+ ```bash
230
+ # Scale API service
231
+ docker-compose -f docker-compose.yml -f docker-compose.prod.yml up -d --scale api=3
232
+
233
+ # Scale web service
234
+ docker-compose -f docker-compose.yml -f docker-compose.prod.yml up -d --scale web=2
235
+ ```
236
+
237
+ ## Monitoring and Logging
238
+
239
+ ### Built-in Monitoring (Optional)
240
+ - **Prometheus**: Metrics collection (http://localhost:9090)
241
+ - **Grafana**: Visualization dashboard (http://localhost:3002)
242
+
243
+ ```bash
244
+ # Start with monitoring
245
+ docker-compose --profile monitoring -f docker-compose.yml -f docker-compose.prod.yml up -d
246
+ ```
247
+
248
+ ### Log Management
249
+ ```bash
250
+ # View logs for all services
251
+ docker-compose logs -f
252
+
253
+ # View logs for specific service
254
+ docker-compose logs -f api
255
+
256
+ # Export logs
257
+ docker-compose logs --no-color > application.log
258
+ ```
259
+
260
+ ### Health Checks
261
+ All services include health checks:
262
+ - API: `/health` endpoint
263
+ - Web: HTTP status check
264
+ - Database: `pg_isready` check
265
+ - Redis: `redis-cli ping` check
266
+
267
+ ## Troubleshooting
268
+
269
+ ### Common Issues
270
+
271
+ 1. **Port Conflicts**
272
+ ```bash
273
+ # Check what's using the port
274
+ lsof -i :3000
275
+
276
+ # Change port in .env file
277
+ WEB_PORT=3001
278
+ ```
279
+
280
+ 2. **Database Connection Issues**
281
+ ```bash
282
+ # Check database logs
283
+ docker-compose logs postgres
284
+
285
+ # Test connection
286
+ docker-compose exec postgres psql -U postgres -d idealyst_db
287
+ ```
288
+
289
+ 3. **Build Failures**
290
+ ```bash
291
+ # Clean build cache
292
+ docker system prune -a
293
+
294
+ # Rebuild without cache
295
+ docker-compose build --no-cache
296
+ ```
297
+
298
+ 4. **Permission Issues**
299
+ ```bash
300
+ # Fix file permissions
301
+ sudo chown -R $USER:$USER .
302
+
303
+ # Reset container permissions
304
+ docker-compose down
305
+ docker-compose up -d
306
+ ```
307
+
308
+ ### Debugging
309
+
310
+ ```bash
311
+ # Access running container
312
+ docker-compose exec api bash
313
+ docker-compose exec web sh
314
+
315
+ # Run commands in container
316
+ docker-compose exec api yarn test
317
+ docker-compose exec api npm run migrate
318
+
319
+ # Check service status
320
+ docker-compose ps
321
+ docker-compose top
322
+ ```
323
+
324
+ ## Performance Optimization
325
+
326
+ ### Production Optimizations
327
+ - Multi-stage builds reduce image size
328
+ - Nginx caching for static assets
329
+ - Gzip compression enabled
330
+ - Connection pooling for database
331
+ - Health checks for reliability
332
+
333
+ ### Development Optimizations
334
+ - Volume mounts for hot reload
335
+ - Development dependencies included
336
+ - Debug logging enabled
337
+ - File watching optimized
338
+
339
+ ## Security Best Practices
340
+
341
+ 1. **Never commit `.env` files**
342
+ 2. **Use strong, unique passwords**
343
+ 3. **Rotate secrets regularly**
344
+ 4. **Enable SSL in production**
345
+ 5. **Configure firewalls properly**
346
+ 6. **Regular security updates**
347
+ 7. **Monitor logs for suspicious activity**
348
+
349
+ ## Backup and Recovery
350
+
351
+ ### Automated Backups
352
+ ```bash
353
+ # Setup cron job for daily backups
354
+ 0 2 * * * /path/to/workspace/scripts/docker/db-backup.sh backup
355
+ 0 3 * * 0 /path/to/workspace/scripts/docker/db-backup.sh clean 30
356
+ ```
357
+
358
+ ### Disaster Recovery
359
+ 1. **Data Backup**: Regular database and file backups
360
+ 2. **Image Registry**: Push images to Docker registry
361
+ 3. **Configuration Backup**: Version control all configs
362
+ 4. **Documentation**: Keep deployment notes updated
363
+
364
+ ## Updates and Maintenance
365
+
366
+ ### Updating Services
367
+ ```bash
368
+ # Pull latest images
369
+ docker-compose pull
370
+
371
+ # Rebuild and restart
372
+ docker-compose up -d --build
373
+
374
+ # Clean old images
375
+ docker image prune
376
+ ```
377
+
378
+ ### Database Migrations
379
+ ```bash
380
+ # Run migrations
381
+ docker-compose exec api yarn migrate
382
+
383
+ # Rollback if needed
384
+ docker-compose exec api yarn migrate:rollback
385
+ ```
@@ -0,0 +1,100 @@
1
+ # Multi-stage Dockerfile for Idealyst Workspace
2
+ # Supports web apps, API services, and can be used for staging/production
3
+
4
+ # Base stage with Node.js and build tools
5
+ FROM node:20-alpine AS base
6
+ RUN apk add --no-cache libc6-compat git
7
+ WORKDIR /app
8
+
9
+ # Enable corepack for yarn
10
+ RUN corepack enable
11
+
12
+ # Dependencies stage - install all dependencies
13
+ FROM base AS deps
14
+ COPY package.json yarn.lock* .yarnrc.yml ./
15
+ COPY .yarn .yarn
16
+ RUN yarn install --immutable
17
+
18
+ # Build stage - build all packages
19
+ FROM base AS builder
20
+ COPY --from=deps /app/node_modules ./node_modules
21
+ COPY . .
22
+
23
+ # Build all packages
24
+ RUN yarn build:all
25
+
26
+ # Production API stage
27
+ FROM base AS api-runner
28
+ RUN addgroup --system --gid 1001 nodejs
29
+ RUN adduser --system --uid 1001 apiuser
30
+
31
+ # Copy built API and dependencies
32
+ COPY --from=builder /app/packages/*/dist ./packages/
33
+ COPY --from=builder /app/node_modules ./node_modules
34
+ COPY --from=builder /app/package.json ./
35
+
36
+ USER apiuser
37
+ EXPOSE 3001
38
+ ENV NODE_ENV=production
39
+ ENV PORT=3001
40
+
41
+ # Health check for API
42
+ HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
43
+ CMD node -e "require('http').get('http://localhost:3001/health', (res) => { process.exit(res.statusCode === 200 ? 0 : 1) })"
44
+
45
+ CMD ["node", "packages/api/dist/server.js"]
46
+
47
+ # Production Web stage
48
+ FROM nginx:alpine AS web-runner
49
+ COPY --from=builder /app/packages/web/dist /usr/share/nginx/html
50
+ COPY docker/nginx.conf /etc/nginx/nginx.conf
51
+
52
+ EXPOSE 80
53
+ CMD ["nginx", "-g", "daemon off;"]
54
+
55
+ # Development stage - for use with dev containers
56
+ FROM base AS dev
57
+ RUN apk add --no-cache \
58
+ docker \
59
+ docker-compose \
60
+ bash \
61
+ zsh \
62
+ fish \
63
+ git \
64
+ curl \
65
+ wget \
66
+ vim \
67
+ nano
68
+
69
+ # Install global development tools
70
+ RUN npm install -g @types/node typescript ts-node nodemon
71
+
72
+ # Copy package files
73
+ COPY package.json yarn.lock* .yarnrc.yml ./
74
+ COPY .yarn .yarn
75
+
76
+ # Install dependencies including dev dependencies
77
+ RUN yarn install
78
+
79
+ # Create non-root user for development
80
+ RUN addgroup --system --gid 1001 devuser
81
+ RUN adduser --system --uid 1001 --ingroup devuser devuser
82
+ RUN chown -R devuser:devuser /app
83
+
84
+ USER devuser
85
+
86
+ # Set up shell
87
+ RUN echo 'alias ll="ls -la"' >> ~/.bashrc
88
+ RUN echo 'alias la="ls -la"' >> ~/.bashrc
89
+
90
+ EXPOSE 3000 3001 5173 8080 19006
91
+
92
+ CMD ["tail", "-f", "/dev/null"]
93
+
94
+ # Test runner stage
95
+ FROM base AS test-runner
96
+ COPY --from=deps /app/node_modules ./node_modules
97
+ COPY . .
98
+
99
+ # Run tests
100
+ CMD ["yarn", "test:ci"]
@@ -19,6 +19,50 @@ This workspace contains your Idealyst Framework packages and applications.
19
19
  └── shared-lib/ # Shared library (generated)
20
20
  ```
21
21
 
22
+ ## Testing
23
+
24
+ This workspace is pre-configured with Jest testing framework across all packages. Each package includes sample tests and Jest configuration.
25
+
26
+ ### Quick Start
27
+
28
+ ```bash
29
+ # Run all tests across all packages
30
+ yarn test
31
+
32
+ # Run tests in watch mode
33
+ yarn test:watch
34
+
35
+ # Run tests with coverage reports
36
+ yarn test:coverage
37
+
38
+ # Run tests in CI mode (for automated builds)
39
+ yarn test:ci
40
+
41
+ # Run tests for a specific package
42
+ node scripts/test-runner.js test:package <package-name>
43
+ ```
44
+
45
+ ### Test Structure
46
+
47
+ Each package contains:
48
+ - `jest.config.js` - Jest configuration tailored to the project type
49
+ - `__tests__/` - Directory for test files with comprehensive examples
50
+ - Sample tests demonstrating testing patterns specific to each template
51
+
52
+ ### Package-Specific Testing
53
+
54
+ - **API packages**: Node.js environment, async/database testing patterns
55
+ - **Web packages**: React Testing Library, DOM testing, user interactions
56
+ - **Native packages**: React Native Testing Library, component rendering
57
+ - **Shared packages**: TypeScript utility testing patterns
58
+
59
+ ### Adding Tests
60
+
61
+ 1. Create test files in the `__tests__` directory or alongside your source files with `.test.ts` or `.spec.ts` extension
62
+ 2. Tests are automatically discovered and run by Jest
63
+ 3. Each template includes comprehensive sample tests as starting points
64
+ 4. See the Component Testing Guide for detailed patterns and best practices
65
+
22
66
  ### Development
23
67
 
24
68
  Install dependencies:
@@ -77,4 +121,53 @@ yarn version:minor
77
121
  Update major version for all packages:
78
122
  ```bash
79
123
  yarn version:major
124
+ ```
125
+
126
+ ## Docker & Containerization
127
+
128
+ This workspace includes comprehensive Docker support for development, staging, and production environments.
129
+
130
+ ### Quick Start with Docker
131
+
132
+ ```bash
133
+ # Development environment
134
+ cp .env.example .env
135
+ ./scripts/docker/deploy.sh development
136
+
137
+ # Production deployment
138
+ cp .env.production .env
139
+ # Edit .env with your settings
140
+ ./scripts/docker/deploy.sh production
141
+ ```
142
+
143
+ ### VS Code Dev Container
144
+
145
+ Open this workspace in VS Code and select "Reopen in Container" for a fully configured development environment with:
146
+ - Node.js, TypeScript, and all development tools pre-installed
147
+ - PostgreSQL and Redis databases ready to use
148
+ - Automatic port forwarding and extension installation
149
+ - Hot reload and debugging support
150
+
151
+ ### Services Available
152
+
153
+ - **Web App**: React application with hot reload
154
+ - **API Server**: Backend with database connections
155
+ - **PostgreSQL**: Database with initialization scripts
156
+ - **Redis**: Caching and session storage
157
+ - **Nginx**: Reverse proxy and load balancer (production)
158
+
159
+ ### Management Scripts
160
+
161
+ ```bash
162
+ # Deployment
163
+ ./scripts/docker/deploy.sh [development|production|staging]
164
+
165
+ # Database management
166
+ ./scripts/docker/db-backup.sh [backup|restore|list|clean]
167
+
168
+ # View status
169
+ ./scripts/docker/deploy.sh status
170
+
171
+ # View logs
172
+ ./scripts/docker/deploy.sh logs
80
173
  ```