create-fluxstack 1.0.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 (101) hide show
  1. package/.env +30 -0
  2. package/LICENSE +21 -0
  3. package/README.md +214 -0
  4. package/app/client/README.md +69 -0
  5. package/app/client/frontend-only.ts +12 -0
  6. package/app/client/index.html +13 -0
  7. package/app/client/public/vite.svg +1 -0
  8. package/app/client/src/App.css +883 -0
  9. package/app/client/src/App.tsx +669 -0
  10. package/app/client/src/assets/react.svg +1 -0
  11. package/app/client/src/components/TestPage.tsx +453 -0
  12. package/app/client/src/index.css +51 -0
  13. package/app/client/src/lib/eden-api.ts +110 -0
  14. package/app/client/src/main.tsx +10 -0
  15. package/app/client/src/vite-env.d.ts +1 -0
  16. package/app/client/tsconfig.app.json +43 -0
  17. package/app/client/tsconfig.json +7 -0
  18. package/app/client/tsconfig.node.json +25 -0
  19. package/app/server/app.ts +10 -0
  20. package/app/server/backend-only.ts +15 -0
  21. package/app/server/controllers/users.controller.ts +69 -0
  22. package/app/server/index.ts +104 -0
  23. package/app/server/routes/index.ts +25 -0
  24. package/app/server/routes/users.routes.ts +121 -0
  25. package/app/server/types/index.ts +1 -0
  26. package/app/shared/types/index.ts +18 -0
  27. package/bun.lock +1053 -0
  28. package/core/__tests__/integration.test.ts +227 -0
  29. package/core/build/index.ts +186 -0
  30. package/core/cli/command-registry.ts +334 -0
  31. package/core/cli/index.ts +394 -0
  32. package/core/cli/plugin-discovery.ts +200 -0
  33. package/core/client/standalone.ts +57 -0
  34. package/core/config/__tests__/config-loader.test.ts +591 -0
  35. package/core/config/__tests__/config-merger.test.ts +657 -0
  36. package/core/config/__tests__/env-converter.test.ts +372 -0
  37. package/core/config/__tests__/env-processor.test.ts +431 -0
  38. package/core/config/__tests__/env.test.ts +452 -0
  39. package/core/config/__tests__/integration.test.ts +418 -0
  40. package/core/config/__tests__/loader.test.ts +331 -0
  41. package/core/config/__tests__/schema.test.ts +129 -0
  42. package/core/config/__tests__/validator.test.ts +318 -0
  43. package/core/config/env-dynamic.ts +326 -0
  44. package/core/config/env.ts +597 -0
  45. package/core/config/index.ts +317 -0
  46. package/core/config/loader.ts +546 -0
  47. package/core/config/runtime-config.ts +322 -0
  48. package/core/config/schema.ts +694 -0
  49. package/core/config/validator.ts +540 -0
  50. package/core/framework/__tests__/server.test.ts +233 -0
  51. package/core/framework/client.ts +132 -0
  52. package/core/framework/index.ts +8 -0
  53. package/core/framework/server.ts +501 -0
  54. package/core/framework/types.ts +63 -0
  55. package/core/plugins/__tests__/built-in.test.ts.disabled +366 -0
  56. package/core/plugins/__tests__/manager.test.ts +398 -0
  57. package/core/plugins/__tests__/monitoring.test.ts +401 -0
  58. package/core/plugins/__tests__/registry.test.ts +335 -0
  59. package/core/plugins/built-in/index.ts +142 -0
  60. package/core/plugins/built-in/logger/index.ts +180 -0
  61. package/core/plugins/built-in/monitoring/README.md +193 -0
  62. package/core/plugins/built-in/monitoring/index.ts +912 -0
  63. package/core/plugins/built-in/static/index.ts +289 -0
  64. package/core/plugins/built-in/swagger/index.ts +229 -0
  65. package/core/plugins/built-in/vite/index.ts +316 -0
  66. package/core/plugins/config.ts +348 -0
  67. package/core/plugins/discovery.ts +350 -0
  68. package/core/plugins/executor.ts +351 -0
  69. package/core/plugins/index.ts +195 -0
  70. package/core/plugins/manager.ts +583 -0
  71. package/core/plugins/registry.ts +424 -0
  72. package/core/plugins/types.ts +254 -0
  73. package/core/server/framework.ts +123 -0
  74. package/core/server/index.ts +8 -0
  75. package/core/server/plugins/database.ts +182 -0
  76. package/core/server/plugins/logger.ts +47 -0
  77. package/core/server/plugins/swagger.ts +34 -0
  78. package/core/server/standalone.ts +91 -0
  79. package/core/templates/create-project.ts +455 -0
  80. package/core/types/api.ts +169 -0
  81. package/core/types/build.ts +174 -0
  82. package/core/types/config.ts +68 -0
  83. package/core/types/index.ts +127 -0
  84. package/core/types/plugin.ts +94 -0
  85. package/core/utils/__tests__/errors.test.ts +139 -0
  86. package/core/utils/__tests__/helpers.test.ts +297 -0
  87. package/core/utils/__tests__/logger.test.ts +141 -0
  88. package/core/utils/env-runtime-v2.ts +232 -0
  89. package/core/utils/env-runtime.ts +252 -0
  90. package/core/utils/errors/codes.ts +115 -0
  91. package/core/utils/errors/handlers.ts +63 -0
  92. package/core/utils/errors/index.ts +81 -0
  93. package/core/utils/helpers.ts +180 -0
  94. package/core/utils/index.ts +18 -0
  95. package/core/utils/logger/index.ts +161 -0
  96. package/core/utils/logger.ts +106 -0
  97. package/core/utils/monitoring/index.ts +212 -0
  98. package/create-fluxstack.ts +231 -0
  99. package/package.json +43 -0
  100. package/tsconfig.json +51 -0
  101. package/vite.config.ts +42 -0
@@ -0,0 +1,366 @@
1
+ /**
2
+ * Tests for Built-in Plugins
3
+ */
4
+
5
+ import { describe, it, expect, beforeEach, vi } from 'vitest'
6
+ import {
7
+ loggerPlugin,
8
+ swaggerPlugin,
9
+ vitePlugin,
10
+ staticPlugin,
11
+ monitoringPlugin,
12
+ builtInPlugins,
13
+ builtInPluginsList,
14
+ getDefaultPlugins,
15
+ getBuiltInPlugin,
16
+ isBuiltInPlugin
17
+ } from '../built-in'
18
+ import type { PluginContext, RequestContext, ResponseContext, ErrorContext } from '../types'
19
+ import type { Logger } from '../../utils/logger/index'
20
+ import type { FluxStackConfig } from '../../config/schema'
21
+
22
+ // Mock logger
23
+ const mockLogger: Logger = {
24
+ debug: vi.fn(),
25
+ info: vi.fn(),
26
+ warn: vi.fn(),
27
+ error: vi.fn(),
28
+ child: vi.fn(() => mockLogger),
29
+ time: vi.fn(),
30
+ timeEnd: vi.fn(),
31
+ request: vi.fn()
32
+ }
33
+
34
+ // Mock app
35
+ const mockApp = {
36
+ use: vi.fn(),
37
+ get: vi.fn(),
38
+ post: vi.fn(),
39
+ put: vi.fn(),
40
+ delete: vi.fn()
41
+ }
42
+
43
+ // Mock config
44
+ const mockConfig: FluxStackConfig = {
45
+ app: { name: 'test-app', version: '1.0.0' },
46
+ server: {
47
+ port: 3000,
48
+ host: 'localhost',
49
+ apiPrefix: '/api',
50
+ cors: {
51
+ origins: ['*'],
52
+ methods: ['GET', 'POST'],
53
+ headers: ['Content-Type']
54
+ },
55
+ middleware: []
56
+ },
57
+ client: {
58
+ port: 5173,
59
+ proxy: { target: 'http://localhost:3000' },
60
+ build: {
61
+ sourceMaps: true,
62
+ minify: false,
63
+ target: 'esnext',
64
+ outDir: 'dist/client'
65
+ }
66
+ },
67
+ build: {
68
+ target: 'bun',
69
+ outDir: 'dist',
70
+ optimization: {
71
+ minify: false,
72
+ treeshake: false,
73
+ compress: false,
74
+ splitChunks: false,
75
+ bundleAnalyzer: false
76
+ },
77
+ sourceMaps: true,
78
+ clean: true
79
+ },
80
+ plugins: {
81
+ enabled: [],
82
+ disabled: [],
83
+ config: {}
84
+ },
85
+ logging: {
86
+ level: 'info',
87
+ format: 'pretty',
88
+ transports: []
89
+ },
90
+ monitoring: {
91
+ enabled: false,
92
+ metrics: {
93
+ enabled: false,
94
+ collectInterval: 5000,
95
+ httpMetrics: false,
96
+ systemMetrics: false,
97
+ customMetrics: false
98
+ },
99
+ profiling: {
100
+ enabled: false,
101
+ sampleRate: 0.1,
102
+ memoryProfiling: false,
103
+ cpuProfiling: false
104
+ },
105
+ exporters: []
106
+ }
107
+ }
108
+
109
+ // Mock utils
110
+ const mockUtils = {
111
+ createTimer: vi.fn(() => ({ end: vi.fn(() => 100) })),
112
+ formatBytes: vi.fn((bytes: number) => `${bytes} bytes`),
113
+ isProduction: vi.fn(() => false),
114
+ isDevelopment: vi.fn(() => true),
115
+ getEnvironment: vi.fn(() => 'development'),
116
+ createHash: vi.fn(() => 'hash123'),
117
+ deepMerge: vi.fn((a, b) => ({ ...a, ...b })),
118
+ validateSchema: vi.fn(() => ({ valid: true, errors: [] }))
119
+ }
120
+
121
+ describe.skip('Built-in Plugins', () => {
122
+ let context: PluginContext
123
+
124
+ beforeEach(() => {
125
+ context = {
126
+ config: mockConfig,
127
+ logger: mockLogger,
128
+ app: mockApp,
129
+ utils: mockUtils
130
+ }
131
+ vi.clearAllMocks()
132
+ })
133
+
134
+ describe('Plugin Structure', () => {
135
+ it('should export all built-in plugins', () => {
136
+ expect(builtInPlugins).toBeDefined()
137
+ expect(builtInPlugins.logger).toBe(loggerPlugin)
138
+ expect(builtInPlugins.swagger).toBe(swaggerPlugin)
139
+ expect(builtInPlugins.vite).toBe(vitePlugin)
140
+ expect(builtInPlugins.static).toBe(staticPlugin)
141
+ expect(builtInPlugins.monitoring).toBe(monitoringPlugin)
142
+ })
143
+
144
+ it('should export plugins as array', () => {
145
+ expect(builtInPluginsList).toHaveLength(5)
146
+ expect(builtInPluginsList).toContain(loggerPlugin)
147
+ expect(builtInPluginsList).toContain(swaggerPlugin)
148
+ expect(builtInPluginsList).toContain(vitePlugin)
149
+ expect(builtInPluginsList).toContain(staticPlugin)
150
+ expect(builtInPluginsList).toContain(monitoringPlugin)
151
+ })
152
+
153
+ it('should have valid plugin structure', () => {
154
+ for (const plugin of builtInPluginsList) {
155
+ expect(plugin.name).toBeDefined()
156
+ expect(typeof plugin.name).toBe('string')
157
+ expect(plugin.version).toBeDefined()
158
+ expect(plugin.description).toBeDefined()
159
+ expect(plugin.author).toBeDefined()
160
+ expect(plugin.setup).toBeDefined()
161
+ expect(typeof plugin.setup).toBe('function')
162
+ }
163
+ })
164
+ })
165
+
166
+ describe('Logger Plugin', () => {
167
+ it('should have correct metadata', () => {
168
+ expect(loggerPlugin.name).toBe('logger')
169
+ expect(loggerPlugin.priority).toBe('highest')
170
+ expect(loggerPlugin.category).toBe('core')
171
+ expect(loggerPlugin.configSchema).toBeDefined()
172
+ expect(loggerPlugin.defaultConfig).toBeDefined()
173
+ })
174
+
175
+ it('should setup successfully', async () => {
176
+ await loggerPlugin.setup!(context)
177
+ expect(mockLogger.info).toHaveBeenCalledWith(
178
+ 'Enhanced logger plugin initialized',
179
+ expect.any(Object)
180
+ )
181
+ })
182
+
183
+ it('should handle server start', async () => {
184
+ await loggerPlugin.onServerStart!(context)
185
+ expect(mockLogger.info).toHaveBeenCalledWith(
186
+ 'Logger plugin: Server started',
187
+ expect.any(Object)
188
+ )
189
+ })
190
+
191
+ it('should handle server stop', async () => {
192
+ await loggerPlugin.onServerStop!(context)
193
+ expect(mockLogger.info).toHaveBeenCalledWith('Logger plugin: Server stopped')
194
+ })
195
+
196
+ it('should handle request logging', async () => {
197
+ const requestContext: RequestContext = {
198
+ request: new Request('http://localhost:3000/test'),
199
+ path: '/test',
200
+ method: 'GET',
201
+ headers: { 'user-agent': 'test' },
202
+ query: {},
203
+ params: {},
204
+ startTime: Date.now()
205
+ }
206
+
207
+ await loggerPlugin.onRequest!(requestContext)
208
+ // Logger function would be called if available in context
209
+ })
210
+
211
+ it('should handle response logging', async () => {
212
+ const responseContext: ResponseContext = {
213
+ request: new Request('http://localhost:3000/test'),
214
+ path: '/test',
215
+ method: 'GET',
216
+ headers: {},
217
+ query: {},
218
+ params: {},
219
+ startTime: Date.now(),
220
+ response: new Response('OK'),
221
+ statusCode: 200,
222
+ duration: 100
223
+ }
224
+
225
+ await loggerPlugin.onResponse!(responseContext)
226
+ // Logger function would be called if available in context
227
+ })
228
+
229
+ it('should handle error logging', async () => {
230
+ const errorContext: ErrorContext = {
231
+ request: new Request('http://localhost:3000/test'),
232
+ path: '/test',
233
+ method: 'GET',
234
+ headers: {},
235
+ query: {},
236
+ params: {},
237
+ startTime: Date.now(),
238
+ error: new Error('Test error'),
239
+ duration: 100,
240
+ handled: false
241
+ }
242
+
243
+ await loggerPlugin.onError!(errorContext)
244
+ // Logger function would be called if available in context
245
+ })
246
+ })
247
+
248
+ describe('Swagger Plugin', () => {
249
+ it('should have correct metadata', () => {
250
+ expect(swaggerPlugin.name).toBe('swagger')
251
+ expect(swaggerPlugin.priority).toBe('normal')
252
+ expect(swaggerPlugin.category).toBe('documentation')
253
+ expect(swaggerPlugin.configSchema).toBeDefined()
254
+ expect(swaggerPlugin.defaultConfig).toBeDefined()
255
+ })
256
+
257
+ it('should setup successfully', async () => {
258
+ await swaggerPlugin.setup!(context)
259
+ expect(mockApp.use).toHaveBeenCalled()
260
+ expect(mockLogger.info).toHaveBeenCalledWith(
261
+ expect.stringContaining('Swagger documentation enabled'),
262
+ expect.any(Object)
263
+ )
264
+ })
265
+
266
+ it('should handle server start', async () => {
267
+ await swaggerPlugin.onServerStart!(context)
268
+ expect(mockLogger.info).toHaveBeenCalledWith(
269
+ expect.stringContaining('Swagger documentation available')
270
+ )
271
+ })
272
+ })
273
+
274
+ describe('Vite Plugin', () => {
275
+ it('should have correct metadata', () => {
276
+ expect(vitePlugin.name).toBe('vite')
277
+ expect(vitePlugin.priority).toBe('high')
278
+ expect(vitePlugin.category).toBe('development')
279
+ expect(vitePlugin.configSchema).toBeDefined()
280
+ expect(vitePlugin.defaultConfig).toBeDefined()
281
+ })
282
+
283
+ it('should setup successfully', async () => {
284
+ await vitePlugin.setup!(context)
285
+ expect(mockLogger.info).toHaveBeenCalledWith(
286
+ expect.stringContaining('Setting up Vite integration')
287
+ )
288
+ })
289
+
290
+ it('should handle server start', async () => {
291
+ // Setup first to initialize vite config
292
+ await vitePlugin.setup!(context)
293
+ await vitePlugin.onServerStart!(context)
294
+ expect(mockLogger.info).toHaveBeenCalledWith(
295
+ expect.stringContaining('Vite integration active')
296
+ )
297
+ })
298
+ })
299
+
300
+ describe('Static Plugin', () => {
301
+ it('should have correct metadata', () => {
302
+ expect(staticPlugin.name).toBe('static')
303
+ expect(staticPlugin.priority).toBe('low')
304
+ expect(staticPlugin.category).toBe('core')
305
+ expect(staticPlugin.configSchema).toBeDefined()
306
+ expect(staticPlugin.defaultConfig).toBeDefined()
307
+ })
308
+
309
+ it('should setup successfully', async () => {
310
+ await staticPlugin.setup!(context)
311
+ expect(mockApp.get).toHaveBeenCalledWith('/*', expect.any(Function))
312
+ expect(mockLogger.info).toHaveBeenCalledWith(
313
+ 'Enhanced static files plugin activated',
314
+ expect.any(Object)
315
+ )
316
+ })
317
+
318
+ it('should handle server start', async () => {
319
+ await staticPlugin.onServerStart!(context)
320
+ expect(mockLogger.info).toHaveBeenCalledWith(
321
+ expect.stringContaining('Static files plugin ready'),
322
+ expect.any(Object)
323
+ )
324
+ })
325
+ })
326
+
327
+ describe('Plugin Utilities', () => {
328
+ it('should get default plugins for development', () => {
329
+ const plugins = getDefaultPlugins('development')
330
+ expect(plugins).toHaveLength(5)
331
+ expect(plugins).toContain(loggerPlugin)
332
+ expect(plugins).toContain(staticPlugin)
333
+ expect(plugins).toContain(vitePlugin)
334
+ expect(plugins).toContain(swaggerPlugin)
335
+ expect(plugins).toContain(monitoringPlugin)
336
+ })
337
+
338
+ it('should get default plugins for production', () => {
339
+ const plugins = getDefaultPlugins('production')
340
+ expect(plugins).toHaveLength(3)
341
+ expect(plugins).toContain(loggerPlugin)
342
+ expect(plugins).toContain(staticPlugin)
343
+ expect(plugins).toContain(monitoringPlugin)
344
+ })
345
+
346
+ it('should get default plugins for test', () => {
347
+ const plugins = getDefaultPlugins('test')
348
+ expect(plugins).toHaveLength(1)
349
+ expect(plugins).toContain(loggerPlugin)
350
+ })
351
+
352
+ it('should get plugin by name', () => {
353
+ expect(getBuiltInPlugin('logger')).toBe(loggerPlugin)
354
+ expect(getBuiltInPlugin('swagger')).toBe(swaggerPlugin)
355
+ expect(getBuiltInPlugin('monitoring')).toBe(monitoringPlugin)
356
+ expect(getBuiltInPlugin('nonexistent')).toBeUndefined()
357
+ })
358
+
359
+ it('should check if plugin is built-in', () => {
360
+ expect(isBuiltInPlugin('logger')).toBe(true)
361
+ expect(isBuiltInPlugin('swagger')).toBe(true)
362
+ expect(isBuiltInPlugin('monitoring')).toBe(true)
363
+ expect(isBuiltInPlugin('custom-plugin')).toBe(false)
364
+ })
365
+ })
366
+ })