@buenojs/bueno 0.8.0

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 (120) hide show
  1. package/.env.example +109 -0
  2. package/.github/workflows/ci.yml +31 -0
  3. package/LICENSE +21 -0
  4. package/README.md +892 -0
  5. package/architecture.md +652 -0
  6. package/bun.lock +70 -0
  7. package/dist/cli/index.js +3233 -0
  8. package/dist/index.js +9014 -0
  9. package/package.json +77 -0
  10. package/src/cache/index.ts +795 -0
  11. package/src/cli/ARCHITECTURE.md +837 -0
  12. package/src/cli/bin.ts +10 -0
  13. package/src/cli/commands/build.ts +425 -0
  14. package/src/cli/commands/dev.ts +248 -0
  15. package/src/cli/commands/generate.ts +541 -0
  16. package/src/cli/commands/help.ts +55 -0
  17. package/src/cli/commands/index.ts +112 -0
  18. package/src/cli/commands/migration.ts +355 -0
  19. package/src/cli/commands/new.ts +804 -0
  20. package/src/cli/commands/start.ts +208 -0
  21. package/src/cli/core/args.ts +283 -0
  22. package/src/cli/core/console.ts +349 -0
  23. package/src/cli/core/index.ts +60 -0
  24. package/src/cli/core/prompt.ts +424 -0
  25. package/src/cli/core/spinner.ts +265 -0
  26. package/src/cli/index.ts +135 -0
  27. package/src/cli/templates/deploy.ts +295 -0
  28. package/src/cli/templates/docker.ts +307 -0
  29. package/src/cli/templates/index.ts +24 -0
  30. package/src/cli/utils/fs.ts +428 -0
  31. package/src/cli/utils/index.ts +8 -0
  32. package/src/cli/utils/strings.ts +197 -0
  33. package/src/config/env.ts +408 -0
  34. package/src/config/index.ts +506 -0
  35. package/src/config/loader.ts +329 -0
  36. package/src/config/merge.ts +285 -0
  37. package/src/config/types.ts +320 -0
  38. package/src/config/validation.ts +441 -0
  39. package/src/container/forward-ref.ts +143 -0
  40. package/src/container/index.ts +386 -0
  41. package/src/context/index.ts +360 -0
  42. package/src/database/index.ts +1142 -0
  43. package/src/database/migrations/index.ts +371 -0
  44. package/src/database/schema/index.ts +619 -0
  45. package/src/frontend/api-routes.ts +640 -0
  46. package/src/frontend/bundler.ts +643 -0
  47. package/src/frontend/console-client.ts +419 -0
  48. package/src/frontend/console-stream.ts +587 -0
  49. package/src/frontend/dev-server.ts +846 -0
  50. package/src/frontend/file-router.ts +611 -0
  51. package/src/frontend/frameworks/index.ts +106 -0
  52. package/src/frontend/frameworks/react.ts +85 -0
  53. package/src/frontend/frameworks/solid.ts +104 -0
  54. package/src/frontend/frameworks/svelte.ts +110 -0
  55. package/src/frontend/frameworks/vue.ts +92 -0
  56. package/src/frontend/hmr-client.ts +663 -0
  57. package/src/frontend/hmr.ts +728 -0
  58. package/src/frontend/index.ts +342 -0
  59. package/src/frontend/islands.ts +552 -0
  60. package/src/frontend/isr.ts +555 -0
  61. package/src/frontend/layout.ts +475 -0
  62. package/src/frontend/ssr/react.ts +446 -0
  63. package/src/frontend/ssr/solid.ts +523 -0
  64. package/src/frontend/ssr/svelte.ts +546 -0
  65. package/src/frontend/ssr/vue.ts +504 -0
  66. package/src/frontend/ssr.ts +699 -0
  67. package/src/frontend/types.ts +2274 -0
  68. package/src/health/index.ts +604 -0
  69. package/src/index.ts +410 -0
  70. package/src/lock/index.ts +587 -0
  71. package/src/logger/index.ts +444 -0
  72. package/src/logger/transports/index.ts +969 -0
  73. package/src/metrics/index.ts +494 -0
  74. package/src/middleware/built-in.ts +360 -0
  75. package/src/middleware/index.ts +94 -0
  76. package/src/modules/filters.ts +458 -0
  77. package/src/modules/guards.ts +405 -0
  78. package/src/modules/index.ts +1256 -0
  79. package/src/modules/interceptors.ts +574 -0
  80. package/src/modules/lazy.ts +418 -0
  81. package/src/modules/lifecycle.ts +478 -0
  82. package/src/modules/metadata.ts +90 -0
  83. package/src/modules/pipes.ts +626 -0
  84. package/src/router/index.ts +339 -0
  85. package/src/router/linear.ts +371 -0
  86. package/src/router/regex.ts +292 -0
  87. package/src/router/tree.ts +562 -0
  88. package/src/rpc/index.ts +1263 -0
  89. package/src/security/index.ts +436 -0
  90. package/src/ssg/index.ts +631 -0
  91. package/src/storage/index.ts +456 -0
  92. package/src/telemetry/index.ts +1097 -0
  93. package/src/testing/index.ts +1586 -0
  94. package/src/types/index.ts +236 -0
  95. package/src/types/optional-deps.d.ts +219 -0
  96. package/src/validation/index.ts +276 -0
  97. package/src/websocket/index.ts +1004 -0
  98. package/tests/integration/cli.test.ts +1016 -0
  99. package/tests/integration/fullstack.test.ts +234 -0
  100. package/tests/unit/cache.test.ts +174 -0
  101. package/tests/unit/cli-commands.test.ts +892 -0
  102. package/tests/unit/cli.test.ts +1258 -0
  103. package/tests/unit/container.test.ts +279 -0
  104. package/tests/unit/context.test.ts +221 -0
  105. package/tests/unit/database.test.ts +183 -0
  106. package/tests/unit/linear-router.test.ts +280 -0
  107. package/tests/unit/lock.test.ts +336 -0
  108. package/tests/unit/middleware.test.ts +184 -0
  109. package/tests/unit/modules.test.ts +142 -0
  110. package/tests/unit/pubsub.test.ts +257 -0
  111. package/tests/unit/regex-router.test.ts +265 -0
  112. package/tests/unit/router.test.ts +373 -0
  113. package/tests/unit/rpc.test.ts +1248 -0
  114. package/tests/unit/security.test.ts +174 -0
  115. package/tests/unit/telemetry.test.ts +371 -0
  116. package/tests/unit/test-cache.test.ts +110 -0
  117. package/tests/unit/test-database.test.ts +282 -0
  118. package/tests/unit/tree-router.test.ts +325 -0
  119. package/tests/unit/validation.test.ts +794 -0
  120. package/tsconfig.json +27 -0
@@ -0,0 +1,307 @@
1
+ /**
2
+ * Docker Templates
3
+ *
4
+ * Template functions for generating Docker-related files
5
+ */
6
+
7
+ /**
8
+ * Get Dockerfile template
9
+ *
10
+ * Multi-stage build using oven/bun image for production
11
+ */
12
+ export function getDockerfileTemplate(projectName: string, database?: string): string {
13
+ return `# ${projectName} - Production Dockerfile
14
+ # Multi-stage build for optimized production image
15
+
16
+ # Stage 1: Install dependencies
17
+ FROM oven/bun:1 AS deps
18
+
19
+ WORKDIR /app
20
+
21
+ # Copy package files first for better layer caching
22
+ COPY package.json bun.lock* ./
23
+
24
+ # Install dependencies
25
+ RUN bun install --frozen-lockfile --production
26
+
27
+ # Stage 2: Build the application
28
+ FROM oven/bun:1 AS builder
29
+
30
+ WORKDIR /app
31
+
32
+ # Copy package files
33
+ COPY package.json bun.lock* ./
34
+
35
+ # Install all dependencies (including devDependencies for build)
36
+ RUN bun install --frozen-lockfile
37
+
38
+ # Copy source code
39
+ COPY . .
40
+
41
+ # Build the application
42
+ RUN bun run build
43
+
44
+ # Stage 3: Production image
45
+ FROM oven/bun:1 AS runner
46
+
47
+ WORKDIR /app
48
+
49
+ # Set production environment
50
+ ENV NODE_ENV=production
51
+ ENV BUN_ENV=production
52
+
53
+ # Create non-root user for security
54
+ RUN addgroup --system --gid 1001 bunjs \\
55
+ && adduser --system --uid 1001 --ingroup bunjs bunuser
56
+
57
+ # Copy built application from builder
58
+ COPY --from=builder /app/dist ./dist
59
+ COPY --from=builder /app/node_modules ./node_modules
60
+ COPY --from=builder /app/package.json ./
61
+
62
+ # Copy config files if they exist
63
+ COPY --from=builder /app/bueno.config.ts* ./
64
+
65
+ # Set proper ownership
66
+ RUN chown -R bunuser:bunjs /app
67
+
68
+ # Switch to non-root user
69
+ USER bunuser
70
+
71
+ # Expose the application port
72
+ EXPOSE 3000
73
+
74
+ # Health check
75
+ HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \\
76
+ CMD curl -f http://localhost:3000/health || exit 1
77
+
78
+ # Start the application
79
+ CMD ["bun", "run", "dist/main.js"]
80
+ `;
81
+ }
82
+
83
+ /**
84
+ * Get .dockerignore template
85
+ *
86
+ * Patterns to exclude from Docker build context
87
+ */
88
+ export function getDockerignoreTemplate(): string {
89
+ return `# Dependencies
90
+ node_modules/
91
+
92
+ # Build output
93
+ dist/
94
+
95
+ # Environment files
96
+ .env
97
+ .env.local
98
+ .env.*.local
99
+
100
+ # IDE
101
+ .idea/
102
+ .vscode/
103
+ *.swp
104
+ *.swo
105
+
106
+ # OS
107
+ .DS_Store
108
+ Thumbs.db
109
+
110
+ # Git
111
+ .git/
112
+ .gitignore
113
+
114
+ # Docker
115
+ Dockerfile
116
+ docker-compose*.yml
117
+ .dockerignore
118
+
119
+ # Test files
120
+ tests/
121
+ coverage/
122
+ *.test.ts
123
+ *.spec.ts
124
+
125
+ # Documentation
126
+ *.md
127
+ !README.md
128
+
129
+ # Database files (local)
130
+ *.db
131
+ *.sqlite
132
+ *.sqlite3
133
+
134
+ # Logs
135
+ *.log
136
+ logs/
137
+
138
+ # Misc
139
+ .editorconfig
140
+ .eslintrc*
141
+ .prettierrc*
142
+ tsconfig.json
143
+ `;
144
+ }
145
+
146
+ /**
147
+ * Get docker-compose.yml template
148
+ *
149
+ * Local development setup with optional database services
150
+ */
151
+ export function getDockerComposeTemplate(projectName: string, database?: string): string {
152
+ const kebabName = projectName.toLowerCase().replace(/[^a-z0-9-]/g, '-');
153
+
154
+ let databaseServices = '';
155
+ let dependsOn = '';
156
+
157
+ if (database === 'postgresql') {
158
+ databaseServices = `
159
+ # PostgreSQL Database
160
+ postgres:
161
+ image: postgres:16-alpine
162
+ container_name: ${kebabName}-postgres
163
+ restart: unless-stopped
164
+ environment:
165
+ POSTGRES_USER: \${POSTGRES_USER:-postgres}
166
+ POSTGRES_PASSWORD: \${POSTGRES_PASSWORD:-postgres}
167
+ POSTGRES_DB: \${POSTGRES_DB:-${kebabName}}
168
+ volumes:
169
+ - postgres_data:/var/lib/postgresql/data
170
+ ports:
171
+ - "\${POSTGRES_PORT:-5432}:5432"
172
+ healthcheck:
173
+ test: ["CMD-SHELL", "pg_isready -U \${POSTGRES_USER:-postgres} -d \${POSTGRES_DB:-${kebabName}}"]
174
+ interval: 10s
175
+ timeout: 5s
176
+ retries: 5
177
+ networks:
178
+ - bueno-network
179
+
180
+ `;
181
+ dependsOn = `
182
+ depends_on:
183
+ postgres:
184
+ condition: service_healthy
185
+ `;
186
+ } else if (database === 'mysql') {
187
+ databaseServices = `
188
+ # MySQL Database
189
+ mysql:
190
+ image: mysql:8.0
191
+ container_name: ${kebabName}-mysql
192
+ restart: unless-stopped
193
+ environment:
194
+ MYSQL_ROOT_PASSWORD: \${MYSQL_ROOT_PASSWORD:-root}
195
+ MYSQL_USER: \${MYSQL_USER:-mysql}
196
+ MYSQL_PASSWORD: \${MYSQL_PASSWORD:-mysql}
197
+ MYSQL_DATABASE: \${MYSQL_DATABASE:-${kebabName}}
198
+ volumes:
199
+ - mysql_data:/var/lib/mysql
200
+ ports:
201
+ - "\${MYSQL_PORT:-3306}:3306"
202
+ healthcheck:
203
+ test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-u", "root", "-p\${MYSQL_ROOT_PASSWORD:-root}"]
204
+ interval: 10s
205
+ timeout: 5s
206
+ retries: 5
207
+ networks:
208
+ - bueno-network
209
+
210
+ `;
211
+ dependsOn = `
212
+ depends_on:
213
+ mysql:
214
+ condition: service_healthy
215
+ `;
216
+ }
217
+
218
+ const volumes = database === 'postgresql'
219
+ ? `\nvolumes:
220
+ postgres_data:
221
+ driver: local
222
+ `
223
+ : database === 'mysql'
224
+ ? `\nvolumes:
225
+ mysql_data:
226
+ driver: local
227
+ `
228
+ : '';
229
+
230
+ const databaseEnv = database === 'postgresql'
231
+ ? ` DATABASE_URL: postgresql://\${POSTGRES_USER:-postgres}:\${POSTGRES_PASSWORD:-postgres}@postgres:5432/\${POSTGRES_DB:-${kebabName}}
232
+ `
233
+ : database === 'mysql'
234
+ ? ` DATABASE_URL: mysql://\${MYSQL_USER:-mysql}:\${MYSQL_PASSWORD:-mysql}@mysql:3306/\${MYSQL_DATABASE:-${kebabName}}
235
+ `
236
+ : '';
237
+
238
+ return `# ${projectName} - Docker Compose for Local Development
239
+ # Usage: docker-compose up -d
240
+
241
+ services:
242
+ # Application Service
243
+ app:
244
+ build:
245
+ context: .
246
+ dockerfile: Dockerfile
247
+ container_name: ${kebabName}-app
248
+ restart: unless-stopped
249
+ ports:
250
+ - "\${APP_PORT:-3000}:3000"
251
+ environment:
252
+ NODE_ENV: production
253
+ BUN_ENV: production
254
+ ${databaseEnv}${dependsOn} networks:
255
+ - bueno-network
256
+ healthcheck:
257
+ test: ["CMD", "curl", "-f", "http://localhost:3000/health"]
258
+ interval: 30s
259
+ timeout: 10s
260
+ retries: 3
261
+ start_period: 10s
262
+ ${databaseServices}networks:
263
+ bueno-network:
264
+ driver: bridge
265
+ ${volumes}
266
+ `;
267
+ }
268
+
269
+ /**
270
+ * Get Docker environment variables template
271
+ *
272
+ * Environment variables for Docker Compose
273
+ */
274
+ export function getDockerEnvTemplate(projectName: string, database?: string): string {
275
+ const kebabName = projectName.toLowerCase().replace(/[^a-z0-9-]/g, '-');
276
+
277
+ let dbEnv = '';
278
+
279
+ if (database === 'postgresql') {
280
+ dbEnv = `
281
+ # PostgreSQL Configuration
282
+ POSTGRES_USER=postgres
283
+ POSTGRES_PASSWORD=postgres
284
+ POSTGRES_DB=${kebabName}
285
+ POSTGRES_PORT=5432
286
+ DATABASE_URL=postgresql://postgres:postgres@localhost:5432/${kebabName}
287
+ `;
288
+ } else if (database === 'mysql') {
289
+ dbEnv = `
290
+ # MySQL Configuration
291
+ MYSQL_ROOT_PASSWORD=root
292
+ MYSQL_USER=mysql
293
+ MYSQL_PASSWORD=mysql
294
+ MYSQL_DATABASE=${kebabName}
295
+ MYSQL_PORT=3306
296
+ DATABASE_URL=mysql://mysql:mysql@localhost:3306/${kebabName}
297
+ `;
298
+ }
299
+
300
+ return `# ${projectName} - Docker Environment Variables
301
+ # Copy this file to .env and update values as needed
302
+
303
+ # Application
304
+ APP_PORT=3000
305
+ NODE_ENV=production
306
+ ${dbEnv}`;
307
+ }
@@ -0,0 +1,24 @@
1
+ /**
2
+ * CLI Templates
3
+ *
4
+ * Export all template functions for project scaffolding
5
+ */
6
+
7
+ // Docker templates
8
+ export {
9
+ getDockerfileTemplate,
10
+ getDockerignoreTemplate,
11
+ getDockerComposeTemplate,
12
+ getDockerEnvTemplate,
13
+ } from './docker';
14
+
15
+ // Cloud platform deployment templates
16
+ export {
17
+ type DeployPlatform,
18
+ getRenderYamlTemplate,
19
+ getFlyTomlTemplate,
20
+ getRailwayTomlTemplate,
21
+ getDeployTemplate,
22
+ getDeployFilename,
23
+ getDeployPlatformName,
24
+ } from './deploy';