create-fluxstack 1.0.1 → 1.0.2

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 (100) hide show
  1. package/create-fluxstack.ts +2 -3
  2. package/package.json +1 -1
  3. package/.env +0 -30
  4. package/LICENSE +0 -21
  5. package/app/client/README.md +0 -69
  6. package/app/client/frontend-only.ts +0 -12
  7. package/app/client/index.html +0 -13
  8. package/app/client/public/vite.svg +0 -1
  9. package/app/client/src/App.css +0 -883
  10. package/app/client/src/App.tsx +0 -669
  11. package/app/client/src/assets/react.svg +0 -1
  12. package/app/client/src/components/TestPage.tsx +0 -453
  13. package/app/client/src/index.css +0 -51
  14. package/app/client/src/lib/eden-api.ts +0 -110
  15. package/app/client/src/main.tsx +0 -10
  16. package/app/client/src/vite-env.d.ts +0 -1
  17. package/app/client/tsconfig.app.json +0 -43
  18. package/app/client/tsconfig.json +0 -7
  19. package/app/client/tsconfig.node.json +0 -25
  20. package/app/server/app.ts +0 -10
  21. package/app/server/backend-only.ts +0 -15
  22. package/app/server/controllers/users.controller.ts +0 -69
  23. package/app/server/index.ts +0 -104
  24. package/app/server/routes/index.ts +0 -25
  25. package/app/server/routes/users.routes.ts +0 -121
  26. package/app/server/types/index.ts +0 -1
  27. package/app/shared/types/index.ts +0 -18
  28. package/bun.lock +0 -1053
  29. package/core/__tests__/integration.test.ts +0 -227
  30. package/core/build/index.ts +0 -186
  31. package/core/cli/command-registry.ts +0 -334
  32. package/core/cli/index.ts +0 -394
  33. package/core/cli/plugin-discovery.ts +0 -200
  34. package/core/client/standalone.ts +0 -57
  35. package/core/config/__tests__/config-loader.test.ts +0 -591
  36. package/core/config/__tests__/config-merger.test.ts +0 -657
  37. package/core/config/__tests__/env-converter.test.ts +0 -372
  38. package/core/config/__tests__/env-processor.test.ts +0 -431
  39. package/core/config/__tests__/env.test.ts +0 -452
  40. package/core/config/__tests__/integration.test.ts +0 -418
  41. package/core/config/__tests__/loader.test.ts +0 -331
  42. package/core/config/__tests__/schema.test.ts +0 -129
  43. package/core/config/__tests__/validator.test.ts +0 -318
  44. package/core/config/env-dynamic.ts +0 -326
  45. package/core/config/env.ts +0 -597
  46. package/core/config/index.ts +0 -317
  47. package/core/config/loader.ts +0 -546
  48. package/core/config/runtime-config.ts +0 -322
  49. package/core/config/schema.ts +0 -694
  50. package/core/config/validator.ts +0 -540
  51. package/core/framework/__tests__/server.test.ts +0 -233
  52. package/core/framework/client.ts +0 -132
  53. package/core/framework/index.ts +0 -8
  54. package/core/framework/server.ts +0 -501
  55. package/core/framework/types.ts +0 -63
  56. package/core/plugins/__tests__/built-in.test.ts.disabled +0 -366
  57. package/core/plugins/__tests__/manager.test.ts +0 -398
  58. package/core/plugins/__tests__/monitoring.test.ts +0 -401
  59. package/core/plugins/__tests__/registry.test.ts +0 -335
  60. package/core/plugins/built-in/index.ts +0 -142
  61. package/core/plugins/built-in/logger/index.ts +0 -180
  62. package/core/plugins/built-in/monitoring/README.md +0 -193
  63. package/core/plugins/built-in/monitoring/index.ts +0 -912
  64. package/core/plugins/built-in/static/index.ts +0 -289
  65. package/core/plugins/built-in/swagger/index.ts +0 -229
  66. package/core/plugins/built-in/vite/index.ts +0 -316
  67. package/core/plugins/config.ts +0 -348
  68. package/core/plugins/discovery.ts +0 -350
  69. package/core/plugins/executor.ts +0 -351
  70. package/core/plugins/index.ts +0 -195
  71. package/core/plugins/manager.ts +0 -583
  72. package/core/plugins/registry.ts +0 -424
  73. package/core/plugins/types.ts +0 -254
  74. package/core/server/framework.ts +0 -123
  75. package/core/server/index.ts +0 -8
  76. package/core/server/plugins/database.ts +0 -182
  77. package/core/server/plugins/logger.ts +0 -47
  78. package/core/server/plugins/swagger.ts +0 -34
  79. package/core/server/standalone.ts +0 -91
  80. package/core/templates/create-project.ts +0 -455
  81. package/core/types/api.ts +0 -169
  82. package/core/types/build.ts +0 -174
  83. package/core/types/config.ts +0 -68
  84. package/core/types/index.ts +0 -127
  85. package/core/types/plugin.ts +0 -94
  86. package/core/utils/__tests__/errors.test.ts +0 -139
  87. package/core/utils/__tests__/helpers.test.ts +0 -297
  88. package/core/utils/__tests__/logger.test.ts +0 -141
  89. package/core/utils/env-runtime-v2.ts +0 -232
  90. package/core/utils/env-runtime.ts +0 -252
  91. package/core/utils/errors/codes.ts +0 -115
  92. package/core/utils/errors/handlers.ts +0 -63
  93. package/core/utils/errors/index.ts +0 -81
  94. package/core/utils/helpers.ts +0 -180
  95. package/core/utils/index.ts +0 -18
  96. package/core/utils/logger/index.ts +0 -161
  97. package/core/utils/logger.ts +0 -106
  98. package/core/utils/monitoring/index.ts +0 -212
  99. package/tsconfig.json +0 -51
  100. package/vite.config.ts +0 -42
@@ -1,591 +0,0 @@
1
- /**
2
- * Tests for Configuration Loader
3
- * Tests the main configuration loading system, including file loading, caching, and fallbacks
4
- */
5
-
6
- import { describe, test, expect, beforeEach, afterEach, vi } from 'vitest'
7
- import {
8
- getConfig,
9
- getConfigSync,
10
- reloadConfig,
11
- createPluginConfig,
12
- isFeatureEnabled,
13
- createLegacyConfig
14
- } from '../index'
15
- import type { FluxStackConfig } from '../schema'
16
-
17
- // Mock file system operations
18
- vi.mock('fs', () => ({
19
- existsSync: vi.fn(),
20
- promises: {
21
- readFile: vi.fn(),
22
- access: vi.fn()
23
- }
24
- }))
25
-
26
- vi.mock('fs/promises', () => ({
27
- readFile: vi.fn(),
28
- access: vi.fn()
29
- }))
30
-
31
- describe('Configuration Loader', () => {
32
- let originalEnv: NodeJS.ProcessEnv
33
-
34
- beforeEach(() => {
35
- originalEnv = { ...process.env }
36
- // Clear relevant environment variables
37
- for (const key in process.env) {
38
- if (key.startsWith('FLUXSTACK_') || key.startsWith('PORT') || key.startsWith('HOST') ||
39
- key.startsWith('NODE_ENV')) {
40
- delete process.env[key]
41
- }
42
- }
43
-
44
- // Clear any cached configurations
45
- vi.clearAllMocks()
46
- })
47
-
48
- afterEach(() => {
49
- process.env = originalEnv
50
- })
51
-
52
- describe('getConfigSync', () => {
53
- test('loads configuration from environment variables', () => {
54
- process.env.PORT = '4000'
55
- process.env.HOST = 'example.com'
56
- process.env.LOG_LEVEL = 'debug'
57
- process.env.NODE_ENV = 'production'
58
-
59
- const config = getConfigSync()
60
-
61
- expect(config.server?.port).toBe(4000)
62
- expect(config.server?.host).toBe('example.com')
63
- expect(config.logging?.level).toBe('debug')
64
- })
65
-
66
- test('applies environment defaults based on NODE_ENV', () => {
67
- process.env.NODE_ENV = 'production'
68
-
69
- const config = getConfigSync()
70
-
71
- // Should apply production defaults
72
- expect(config.build?.optimization?.minify).toBe(true)
73
- expect(config.monitoring?.enabled).toBe(true)
74
- })
75
-
76
- test('uses development defaults when NODE_ENV not set', () => {
77
- delete process.env.NODE_ENV
78
-
79
- const config = getConfigSync()
80
-
81
- // Should apply development defaults
82
- expect(config.build?.optimization?.minify).toBe(false)
83
- expect(config.monitoring?.enabled).toBe(false)
84
- })
85
-
86
- test('handles custom environment variables with FluxStack prefix', () => {
87
- process.env.FLUXSTACK_PORT = '5000'
88
- process.env.FLUXSTACK_API_PREFIX = '/v2'
89
- process.env.FLUXSTACK_LOG_LEVEL = 'error'
90
-
91
- // Force reload config to pick up new env vars
92
- reloadConfig()
93
- const config = getConfigSync()
94
-
95
- expect(config.server?.port).toBe(5000)
96
- expect(config.server?.apiPrefix).toBe('/v2')
97
- expect(config.logging?.level).toBe('error')
98
- })
99
-
100
- test('merges CORS configuration from environment', () => {
101
- process.env.CORS_ORIGINS = 'http://localhost:3000,https://example.com'
102
- process.env.CORS_METHODS = 'GET,POST,DELETE'
103
- process.env.CORS_CREDENTIALS = 'true'
104
-
105
- const config = getConfigSync()
106
-
107
- expect(config.server?.cors?.origins).toEqual(['http://localhost:3000', 'https://example.com'])
108
- expect(config.server?.cors?.methods).toEqual(['GET', 'POST', 'DELETE'])
109
- expect(config.server?.cors?.credentials).toBe(true)
110
- })
111
-
112
- test('handles database configuration from environment', () => {
113
- process.env.DATABASE_URL = 'postgresql://user:pass@localhost:5432/db'
114
- process.env.DATABASE_HOST = 'db.example.com'
115
- process.env.DATABASE_PORT = '5433'
116
- process.env.DATABASE_SSL = 'true'
117
-
118
- const config = getConfigSync()
119
-
120
- expect(config.database?.url).toBe('postgresql://user:pass@localhost:5432/db')
121
- expect(config.database?.host).toBe('db.example.com')
122
- expect(config.database?.port).toBe(5433)
123
- expect(config.database?.ssl).toBe(true)
124
- })
125
-
126
- test('handles authentication configuration', () => {
127
- process.env.JWT_SECRET = 'my-secret-key'
128
- process.env.JWT_EXPIRES_IN = '7d'
129
- process.env.JWT_ALGORITHM = 'HS256'
130
-
131
- const config = getConfigSync()
132
-
133
- expect(config.auth?.secret).toBe('my-secret-key')
134
- expect(config.auth?.expiresIn).toBe('7d')
135
- expect(config.auth?.algorithm).toBe('HS256')
136
- })
137
-
138
- test('handles email configuration', () => {
139
- process.env.SMTP_HOST = 'smtp.gmail.com'
140
- process.env.SMTP_PORT = '587'
141
- process.env.SMTP_USER = 'user@example.com'
142
- process.env.SMTP_SECURE = 'true'
143
-
144
- const config = getConfigSync()
145
-
146
- expect(config.email?.host).toBe('smtp.gmail.com')
147
- expect(config.email?.port).toBe(587)
148
- expect(config.email?.user).toBe('user@example.com')
149
- expect(config.email?.secure).toBe(true)
150
- })
151
-
152
- test('handles monitoring configuration', () => {
153
- process.env.MONITORING_ENABLED = 'true'
154
- process.env.METRICS_ENABLED = 'false'
155
- process.env.METRICS_INTERVAL = '30000'
156
- process.env.PROFILING_ENABLED = 'true'
157
-
158
- const config = getConfigSync()
159
-
160
- expect(config.monitoring?.enabled).toBe(true)
161
- expect(config.monitoring?.metrics?.enabled).toBe(false)
162
- expect(config.monitoring?.metrics?.collectInterval).toBe(30000)
163
- expect(config.monitoring?.profiling?.enabled).toBe(true)
164
- })
165
-
166
- test('handles build configuration', () => {
167
- process.env.BUILD_TARGET = 'docker'
168
- process.env.BUILD_OUTDIR = 'build'
169
- process.env.BUILD_MINIFY = 'true'
170
- process.env.BUILD_SOURCEMAPS = 'false'
171
-
172
- reloadConfig()
173
- const config = getConfigSync()
174
-
175
- expect(config.build?.target).toBe('docker')
176
- expect(config.build?.outDir).toBe('build')
177
- expect(config.build?.optimization?.minify).toBe(true)
178
- expect(config.build?.sourceMaps).toBe(false)
179
- })
180
-
181
- test('handles plugin configuration', () => {
182
- process.env.FLUXSTACK_PLUGINS_ENABLED = 'plugin1,plugin2,plugin3'
183
- process.env.FLUXSTACK_PLUGINS_DISABLED = 'plugin4'
184
-
185
- reloadConfig()
186
- const config = getConfigSync()
187
-
188
- expect(config.plugins?.enabled).toEqual(['plugin1', 'plugin2', 'plugin3'])
189
- expect(config.plugins?.disabled).toEqual(['plugin4'])
190
- })
191
- })
192
-
193
- describe('createPluginConfig', () => {
194
- test('creates plugin configuration from main config', () => {
195
- const mainConfig: FluxStackConfig = {
196
- app: { name: 'TestApp', version: '1.0.0' },
197
- server: {
198
- port: 3000,
199
- host: 'localhost',
200
- apiPrefix: '/api',
201
- cors: {
202
- origins: ['*'],
203
- methods: ['GET', 'POST'],
204
- headers: ['Content-Type'],
205
- credentials: false,
206
- maxAge: 86400
207
- },
208
- middleware: []
209
- },
210
- client: {
211
- port: 5173,
212
- proxy: { target: 'http://localhost:3000' },
213
- build: {
214
- target: 'es2020',
215
- outDir: 'dist/client',
216
- sourceMaps: true,
217
- minify: false
218
- }
219
- },
220
- build: {
221
- target: 'bun',
222
- outDir: 'dist',
223
- clean: true,
224
- optimization: {
225
- minify: false,
226
- compress: false,
227
- treeshake: false,
228
- splitChunks: false,
229
- bundleAnalyzer: false
230
- },
231
- sourceMaps: true
232
- },
233
- logging: {
234
- level: 'info',
235
- format: 'pretty',
236
- transports: [
237
- { type: 'console', level: 'info', format: 'pretty' }
238
- ]
239
- },
240
- monitoring: {
241
- enabled: false,
242
- metrics: {
243
- enabled: false,
244
- collectInterval: 60000,
245
- httpMetrics: true,
246
- systemMetrics: true,
247
- customMetrics: false
248
- },
249
- profiling: {
250
- enabled: false,
251
- sampleRate: 0.1,
252
- memoryProfiling: false,
253
- cpuProfiling: false
254
- },
255
- exporters: []
256
- },
257
- plugins: {
258
- enabled: [],
259
- disabled: [],
260
- config: {
261
- vite: {
262
- port: 5174,
263
- enabled: true
264
- },
265
- logger: {
266
- logRequests: true,
267
- logResponses: false
268
- }
269
- }
270
- },
271
- custom: {
272
- myPlugin: {
273
- customSetting: 'value'
274
- }
275
- }
276
- } as FluxStackConfig
277
-
278
- // Test plugin config from plugins.config
279
- const viteConfig = createPluginConfig(mainConfig, 'vite')
280
- expect(viteConfig).toEqual({
281
- port: 5174,
282
- enabled: true
283
- })
284
-
285
- // Test plugin config from custom section
286
- const myPluginConfig = createPluginConfig(mainConfig, 'myPlugin')
287
- expect(myPluginConfig).toEqual({
288
- customSetting: 'value'
289
- })
290
-
291
- // Test merging both sections
292
- const combinedConfig: FluxStackConfig = {
293
- ...mainConfig,
294
- plugins: {
295
- ...mainConfig.plugins,
296
- config: {
297
- ...mainConfig.plugins.config,
298
- myPlugin: {
299
- baseSetting: 'base'
300
- }
301
- }
302
- }
303
- }
304
-
305
- const mergedConfig = createPluginConfig(combinedConfig, 'myPlugin')
306
- expect(mergedConfig).toEqual({
307
- baseSetting: 'base',
308
- customSetting: 'value' // custom should override plugins.config
309
- })
310
- })
311
-
312
- test('returns empty object for non-existent plugin', () => {
313
- const mainConfig: FluxStackConfig = {
314
- app: { name: 'TestApp', version: '1.0.0' },
315
- server: {
316
- port: 3000,
317
- host: 'localhost',
318
- apiPrefix: '/api',
319
- cors: {
320
- origins: ['*'],
321
- methods: ['GET', 'POST'],
322
- headers: ['Content-Type'],
323
- credentials: false,
324
- maxAge: 86400
325
- },
326
- middleware: []
327
- },
328
- client: {
329
- port: 5173,
330
- proxy: { target: 'http://localhost:3000' },
331
- build: {
332
- target: 'es2020',
333
- outDir: 'dist/client',
334
- sourceMaps: true,
335
- minify: false
336
- }
337
- },
338
- build: {
339
- target: 'bun',
340
- outDir: 'dist',
341
- clean: true,
342
- optimization: {
343
- minify: false,
344
- compress: false,
345
- treeshake: false,
346
- splitChunks: false,
347
- bundleAnalyzer: false
348
- },
349
- sourceMaps: true
350
- },
351
- logging: {
352
- level: 'info',
353
- format: 'pretty',
354
- transports: [
355
- { type: 'console', level: 'info', format: 'pretty' }
356
- ]
357
- },
358
- monitoring: {
359
- enabled: false,
360
- metrics: {
361
- enabled: false,
362
- collectInterval: 60000,
363
- httpMetrics: true,
364
- systemMetrics: true,
365
- customMetrics: false
366
- },
367
- profiling: {
368
- enabled: false,
369
- sampleRate: 0.1,
370
- memoryProfiling: false,
371
- cpuProfiling: false
372
- },
373
- exporters: []
374
- },
375
- plugins: {
376
- enabled: [],
377
- disabled: [],
378
- config: {}
379
- }
380
- } as FluxStackConfig
381
-
382
- const config = createPluginConfig(mainConfig, 'nonexistent')
383
- expect(config).toEqual({})
384
- })
385
- })
386
-
387
- describe('isFeatureEnabled', () => {
388
- test('checks if feature is enabled in plugins', () => {
389
- const config: FluxStackConfig = {
390
- app: { name: 'TestApp', version: '1.0.0' },
391
- server: {
392
- port: 3000,
393
- host: 'localhost',
394
- apiPrefix: '/api',
395
- cors: {
396
- origins: ['*'],
397
- methods: ['GET', 'POST'],
398
- headers: ['Content-Type'],
399
- credentials: false,
400
- maxAge: 86400
401
- },
402
- middleware: []
403
- },
404
- client: {
405
- port: 5173,
406
- proxy: { target: 'http://localhost:3000' },
407
- build: {
408
- target: 'es2020',
409
- outDir: 'dist/client',
410
- sourceMaps: true,
411
- minify: false
412
- }
413
- },
414
- build: {
415
- target: 'bun',
416
- outDir: 'dist',
417
- clean: true,
418
- optimization: {
419
- minify: false,
420
- compress: false,
421
- treeshake: false,
422
- splitChunks: false,
423
- bundleAnalyzer: false
424
- },
425
- sourceMaps: true
426
- },
427
- logging: {
428
- level: 'info',
429
- format: 'pretty',
430
- transports: [
431
- { type: 'console', level: 'info', format: 'pretty' }
432
- ]
433
- },
434
- monitoring: {
435
- enabled: true,
436
- metrics: {
437
- enabled: true,
438
- collectInterval: 60000,
439
- httpMetrics: true,
440
- systemMetrics: true,
441
- customMetrics: false
442
- },
443
- profiling: {
444
- enabled: false,
445
- sampleRate: 0.1,
446
- memoryProfiling: false,
447
- cpuProfiling: false
448
- },
449
- exporters: []
450
- },
451
- plugins: {
452
- enabled: ['plugin1', 'plugin2'],
453
- disabled: ['plugin3'],
454
- config: {}
455
- },
456
- custom: {
457
- customFeature: true
458
- }
459
- } as FluxStackConfig
460
-
461
- expect(isFeatureEnabled(config, 'plugin1')).toBe(true)
462
- expect(isFeatureEnabled(config, 'plugin2')).toBe(true)
463
- expect(isFeatureEnabled(config, 'plugin3')).toBe(false) // disabled
464
- expect(isFeatureEnabled(config, 'plugin4')).toBe(false) // not in enabled
465
- expect(isFeatureEnabled(config, 'monitoring')).toBe(true)
466
- expect(isFeatureEnabled(config, 'metrics')).toBe(true)
467
- expect(isFeatureEnabled(config, 'profiling')).toBe(false)
468
- expect(isFeatureEnabled(config, 'customFeature')).toBe(true)
469
- expect(isFeatureEnabled(config, 'nonexistent')).toBe(false)
470
- })
471
- })
472
-
473
- describe('createLegacyConfig', () => {
474
- test('creates legacy configuration format', () => {
475
- const config: FluxStackConfig = {
476
- app: { name: 'TestApp', version: '1.0.0' },
477
- server: {
478
- port: 4000,
479
- host: 'localhost',
480
- apiPrefix: '/v2',
481
- cors: {
482
- origins: ['http://localhost:3000', 'https://example.com'],
483
- methods: ['GET', 'POST', 'PUT'],
484
- headers: ['Content-Type', 'Authorization'],
485
- credentials: true,
486
- maxAge: 86400
487
- },
488
- middleware: []
489
- },
490
- client: {
491
- port: 5174,
492
- proxy: { target: 'http://localhost:3000' },
493
- build: {
494
- target: 'es2020',
495
- outDir: 'dist/client',
496
- sourceMaps: true,
497
- minify: false
498
- }
499
- },
500
- build: {
501
- target: 'docker',
502
- outDir: 'build',
503
- clean: true,
504
- optimization: {
505
- minify: false,
506
- compress: false,
507
- treeshake: false,
508
- splitChunks: false,
509
- bundleAnalyzer: false
510
- },
511
- sourceMaps: true
512
- },
513
- logging: {
514
- level: 'info',
515
- format: 'pretty',
516
- transports: [
517
- { type: 'console', level: 'info', format: 'pretty' }
518
- ]
519
- },
520
- monitoring: {
521
- enabled: false,
522
- metrics: {
523
- enabled: false,
524
- collectInterval: 60000,
525
- httpMetrics: true,
526
- systemMetrics: true,
527
- customMetrics: false
528
- },
529
- profiling: {
530
- enabled: false,
531
- sampleRate: 0.1,
532
- memoryProfiling: false,
533
- cpuProfiling: false
534
- },
535
- exporters: []
536
- },
537
- plugins: {
538
- enabled: [],
539
- disabled: [],
540
- config: {}
541
- }
542
- } as FluxStackConfig
543
-
544
- const legacyConfig = createLegacyConfig(config)
545
-
546
- expect(legacyConfig).toEqual({
547
- port: 4000,
548
- vitePort: 5174,
549
- clientPath: 'app/client',
550
- apiPrefix: '/v2',
551
- cors: {
552
- origins: ['http://localhost:3000', 'https://example.com'],
553
- methods: ['GET', 'POST', 'PUT'],
554
- headers: ['Content-Type', 'Authorization']
555
- },
556
- build: {
557
- outDir: 'build',
558
- target: 'docker'
559
- }
560
- })
561
- })
562
- })
563
-
564
- describe('error handling and warnings', () => {
565
- test('handles configuration with warnings gracefully', () => {
566
- // Test with invalid environment variables that should generate warnings
567
- process.env.PORT = 'invalid-port' // Should fall back to default
568
- process.env.LOG_LEVEL = 'invalid-level' // Should fall back to default
569
- process.env.BUILD_TARGET = 'invalid-target' // Should fall back to default
570
-
571
- expect(() => {
572
- const config = getConfigSync()
573
- // Should not throw, but use defaults
574
- expect(typeof config.server?.port).toBe('number')
575
- expect(['debug', 'info', 'warn', 'error']).toContain(config.logging?.level)
576
- expect(['bun', 'node', 'docker']).toContain(config.build?.target)
577
- }).not.toThrow()
578
- })
579
-
580
- test('handles missing optional configurations', () => {
581
- // No environment variables set
582
- const config = getConfigSync()
583
-
584
- // Should have default values and structure
585
- expect(config).toBeDefined()
586
- expect(config.app).toBeDefined()
587
- expect(config.server).toBeDefined()
588
- expect(config.plugins).toBeDefined()
589
- })
590
- })
591
- })