@pikku/cli 0.7.7 → 0.8.1

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 (197) hide show
  1. package/CHANGELOG.md +43 -0
  2. package/bin/pikku-all.ts +188 -91
  3. package/bin/pikku-fetch.ts +10 -38
  4. package/bin/pikku-nextjs.ts +12 -113
  5. package/bin/pikku-openapi.ts +9 -54
  6. package/bin/pikku-queue-service.ts +28 -0
  7. package/bin/pikku-schemas.ts +6 -32
  8. package/bin/pikku-websocket.ts +11 -41
  9. package/bin/pikku.ts +2 -0
  10. package/cli.schema.json +113 -10
  11. package/dist/bin/pikku-all.d.ts +1 -1
  12. package/dist/bin/pikku-all.js +105 -84
  13. package/dist/bin/pikku-fetch.d.ts +1 -3
  14. package/dist/bin/pikku-fetch.js +9 -15
  15. package/dist/bin/pikku-nextjs.d.ts +1 -4
  16. package/dist/bin/pikku-nextjs.js +10 -40
  17. package/dist/bin/pikku-openapi.d.ts +0 -3
  18. package/dist/bin/pikku-openapi.js +8 -24
  19. package/dist/bin/pikku-queue-service.d.ts +4 -0
  20. package/dist/bin/pikku-queue-service.js +19 -0
  21. package/dist/bin/pikku-schemas.d.ts +0 -3
  22. package/dist/bin/pikku-schemas.js +5 -11
  23. package/dist/bin/pikku-websocket.d.ts +1 -3
  24. package/dist/bin/pikku-websocket.js +9 -18
  25. package/dist/bin/pikku.js +2 -0
  26. package/dist/src/events/channels/pikku-channels.d.ts +2 -0
  27. package/dist/src/events/channels/pikku-channels.js +9 -0
  28. package/dist/src/events/channels/pikku-command-channels-map.d.ts +2 -0
  29. package/dist/src/events/channels/pikku-command-channels-map.js +8 -0
  30. package/dist/src/events/channels/pikku-command-channels.d.ts +2 -0
  31. package/dist/src/events/channels/pikku-command-channels.js +9 -0
  32. package/dist/src/events/channels/pikku-command-websocket-typed.d.ts +2 -0
  33. package/dist/src/events/channels/pikku-command-websocket-typed.js +15 -0
  34. package/dist/src/{serialize-typed-channel-map.js → events/channels/serialize-typed-channel-map.js} +2 -2
  35. package/dist/src/events/fetch/index.d.ts +2 -0
  36. package/dist/src/events/fetch/index.js +12 -0
  37. package/dist/src/events/functions/pikku-command-function-types.d.ts +2 -0
  38. package/dist/src/events/functions/pikku-command-function-types.js +13 -0
  39. package/dist/src/events/functions/pikku-command-functions.d.ts +6 -0
  40. package/dist/src/events/functions/pikku-command-functions.js +35 -0
  41. package/dist/src/events/functions/pikku-command-services.d.ts +3 -0
  42. package/dist/src/events/functions/pikku-command-services.js +73 -0
  43. package/dist/src/events/functions/pikku-function-types.d.ts +2 -0
  44. package/dist/{bin → src/events/functions}/pikku-function-types.js +6 -6
  45. package/dist/src/events/functions/pikku-functions.d.ts +6 -0
  46. package/dist/{bin → src/events/functions}/pikku-functions.js +5 -5
  47. package/dist/src/events/http/pikku-command-http-map.d.ts +2 -0
  48. package/dist/src/events/http/pikku-command-http-map.js +8 -0
  49. package/dist/src/events/http/pikku-command-http-routes.d.ts +2 -0
  50. package/dist/src/events/http/pikku-command-http-routes.js +9 -0
  51. package/dist/src/events/http/pikku-command-openapi.d.ts +2 -0
  52. package/dist/src/events/http/pikku-command-openapi.js +20 -0
  53. package/dist/src/events/http/pikku-http-routes.d.ts +2 -0
  54. package/dist/src/events/http/pikku-http-routes.js +9 -0
  55. package/dist/src/{serialize-typed-http-map.d.ts → events/http/serialize-typed-http-map.d.ts} +0 -1
  56. package/dist/src/{serialize-typed-http-map.js → events/http/serialize-typed-http-map.js} +2 -15
  57. package/dist/src/events/mcp/pikku-command-mcp-json.d.ts +2 -0
  58. package/dist/src/events/mcp/pikku-command-mcp-json.js +13 -0
  59. package/dist/src/events/mcp/pikku-command-mcp.d.ts +2 -0
  60. package/dist/src/events/mcp/pikku-command-mcp.js +54 -0
  61. package/dist/src/events/mcp/serialize-mcp-json.d.ts +5 -0
  62. package/dist/src/events/mcp/serialize-mcp-json.js +101 -0
  63. package/dist/src/events/queue/pikku-command-queue-map.d.ts +2 -0
  64. package/dist/src/events/queue/pikku-command-queue-map.js +8 -0
  65. package/dist/src/events/queue/pikku-command-queue-service.d.ts +2 -0
  66. package/dist/src/events/queue/pikku-command-queue-service.js +12 -0
  67. package/dist/src/events/queue/pikku-command-queue.d.ts +2 -0
  68. package/dist/src/events/queue/pikku-command-queue.js +10 -0
  69. package/dist/src/events/queue/pikku-queue-map.d.ts +2 -0
  70. package/dist/src/events/queue/pikku-queue-map.js +8 -0
  71. package/dist/src/events/queue/pikku-queue.d.ts +2 -0
  72. package/dist/src/events/queue/pikku-queue.js +10 -0
  73. package/dist/src/events/queue/serialize-queue-map.d.ts +4 -0
  74. package/dist/src/events/queue/serialize-queue-map.js +77 -0
  75. package/dist/src/events/queue/serialize-queue-meta.d.ts +2 -0
  76. package/dist/src/events/queue/serialize-queue-meta.js +6 -0
  77. package/dist/src/events/queue/serialize-queue-wrapper.d.ts +1 -0
  78. package/dist/src/events/queue/serialize-queue-wrapper.js +35 -0
  79. package/dist/src/events/rpc/pikku-command-rpc-client.d.ts +2 -0
  80. package/dist/src/events/rpc/pikku-command-rpc-client.js +12 -0
  81. package/dist/src/events/rpc/pikku-command-rpc-map.d.ts +2 -0
  82. package/dist/src/events/rpc/pikku-command-rpc-map.js +8 -0
  83. package/dist/src/events/rpc/pikku-command-rpc.d.ts +2 -0
  84. package/dist/src/events/rpc/pikku-command-rpc.js +6 -0
  85. package/dist/src/events/rpc/pikku-rpc.d.ts +2 -0
  86. package/dist/src/events/rpc/pikku-rpc.js +6 -0
  87. package/dist/src/events/rpc/serialize-rpc-wrapper.d.ts +1 -0
  88. package/dist/src/events/rpc/serialize-rpc-wrapper.js +29 -0
  89. package/dist/src/{serialize-typed-rpc-map.d.ts → events/rpc/serialize-typed-rpc-map.d.ts} +1 -1
  90. package/dist/src/{serialize-typed-rpc-map.js → events/rpc/serialize-typed-rpc-map.js} +3 -3
  91. package/dist/src/events/scheduler/pikku-command-scheduler.d.ts +2 -0
  92. package/dist/src/events/scheduler/pikku-command-scheduler.js +10 -0
  93. package/dist/src/inspector-glob.d.ts +1 -1
  94. package/dist/src/inspector-glob.js +4 -4
  95. package/dist/src/pikku-cli-config.d.ts +12 -2
  96. package/dist/src/pikku-cli-config.js +79 -30
  97. package/dist/src/pikku-command-schemas.d.ts +2 -0
  98. package/dist/src/pikku-command-schemas.js +8 -0
  99. package/dist/src/runtimes/nextjs/pikku-command-nextjs.d.ts +2 -0
  100. package/dist/src/runtimes/nextjs/pikku-command-nextjs.js +36 -0
  101. package/dist/src/schema-generator.d.ts +3 -2
  102. package/dist/src/schema-generator.js +9 -9
  103. package/dist/src/schemas.d.ts +2 -0
  104. package/dist/src/schemas.js +8 -0
  105. package/dist/src/{utils/serialize-import-map.js → serialize-import-map.js} +3 -0
  106. package/dist/src/serialize-pikku-types.js +378 -1
  107. package/dist/src/types.d.ts +5 -0
  108. package/dist/src/types.js +1 -0
  109. package/dist/src/{utils/utils.d.ts → utils.d.ts} +20 -7
  110. package/dist/src/{utils/utils.js → utils.js} +56 -32
  111. package/dist/tsconfig.tsbuildinfo +1 -1
  112. package/package.json +3 -3
  113. package/{bin → src/events/channels}/pikku-channels.ts +8 -3
  114. package/src/events/channels/pikku-command-channels-map.ts +26 -0
  115. package/src/events/channels/pikku-command-channels.ts +38 -0
  116. package/src/events/channels/pikku-command-websocket-typed.ts +36 -0
  117. package/src/{serialize-typed-channel-map.ts → events/channels/serialize-typed-channel-map.ts} +2 -2
  118. package/src/events/fetch/index.ts +33 -0
  119. package/src/events/functions/pikku-command-function-types.ts +48 -0
  120. package/src/events/functions/pikku-command-functions.ts +84 -0
  121. package/src/events/functions/pikku-command-services.ts +125 -0
  122. package/{bin → src/events/functions}/pikku-function-types.ts +12 -15
  123. package/{bin → src/events/functions}/pikku-functions.ts +9 -6
  124. package/src/events/http/pikku-command-http-map.ts +27 -0
  125. package/src/events/http/pikku-command-http-routes.ts +40 -0
  126. package/src/events/http/pikku-command-openapi.ts +54 -0
  127. package/{bin → src/events/http}/pikku-http-routes.ts +8 -3
  128. package/src/{serialize-typed-http-map.ts → events/http/serialize-typed-http-map.ts} +2 -19
  129. package/src/events/mcp/pikku-command-mcp-json.ts +33 -0
  130. package/src/events/mcp/pikku-command-mcp.ts +110 -0
  131. package/src/events/mcp/serialize-mcp-json.ts +159 -0
  132. package/src/events/queue/pikku-command-queue-map.ts +26 -0
  133. package/src/events/queue/pikku-command-queue-service.ts +33 -0
  134. package/src/events/queue/pikku-command-queue.ts +42 -0
  135. package/src/events/queue/pikku-queue-map.ts +26 -0
  136. package/src/events/queue/pikku-queue.ts +40 -0
  137. package/src/events/queue/serialize-queue-map.ts +119 -0
  138. package/src/events/queue/serialize-queue-meta.ts +10 -0
  139. package/src/events/queue/serialize-queue-wrapper.ts +35 -0
  140. package/src/events/rpc/pikku-command-rpc-client.ts +33 -0
  141. package/src/events/rpc/pikku-command-rpc-map.ts +26 -0
  142. package/src/events/rpc/pikku-command-rpc.ts +22 -0
  143. package/{bin → src/events/rpc}/pikku-rpc.ts +8 -6
  144. package/src/events/rpc/serialize-rpc-wrapper.ts +29 -0
  145. package/src/{serialize-typed-rpc-map.ts → events/rpc/serialize-typed-rpc-map.ts} +5 -4
  146. package/{bin/pikku-scheduler.ts → src/events/scheduler/pikku-command-scheduler.ts} +11 -8
  147. package/src/inspector-glob.ts +4 -2
  148. package/src/pikku-cli-config.ts +119 -42
  149. package/src/pikku-command-schemas.ts +33 -0
  150. package/src/runtimes/nextjs/pikku-command-nextjs.ts +110 -0
  151. package/src/schema-generator.ts +10 -5
  152. package/src/schemas.ts +33 -0
  153. package/src/{utils/serialize-import-map.ts → serialize-import-map.ts} +5 -0
  154. package/src/serialize-pikku-types.ts +378 -1
  155. package/src/types.ts +16 -0
  156. package/src/{utils/utils.ts → utils.ts} +68 -34
  157. package/tsconfig.json +1 -1
  158. package/bin/pikku-channels-map.ts +0 -25
  159. package/bin/pikku-http-map.ts +0 -26
  160. package/bin/pikku-nextjs.test.ts +0 -279
  161. package/bin/pikku-rpc-map.ts +0 -25
  162. package/dist/bin/pikku-channels-map.d.ts +0 -3
  163. package/dist/bin/pikku-channels-map.js +0 -8
  164. package/dist/bin/pikku-channels.d.ts +0 -3
  165. package/dist/bin/pikku-channels.js +0 -9
  166. package/dist/bin/pikku-function-types.d.ts +0 -4
  167. package/dist/bin/pikku-functions.d.ts +0 -7
  168. package/dist/bin/pikku-http-map.d.ts +0 -3
  169. package/dist/bin/pikku-http-map.js +0 -8
  170. package/dist/bin/pikku-http-routes.d.ts +0 -3
  171. package/dist/bin/pikku-http-routes.js +0 -9
  172. package/dist/bin/pikku-rpc-map.d.ts +0 -3
  173. package/dist/bin/pikku-rpc-map.js +0 -8
  174. package/dist/bin/pikku-rpc.d.ts +0 -3
  175. package/dist/bin/pikku-rpc.js +0 -6
  176. package/dist/bin/pikku-scheduler.d.ts +0 -3
  177. package/dist/bin/pikku-scheduler.js +0 -10
  178. /package/dist/src/{serialize-typed-channel-map.d.ts → events/channels/serialize-typed-channel-map.d.ts} +0 -0
  179. /package/dist/src/{serialize-websocket-wrapper.d.ts → events/channels/serialize-websocket-wrapper.d.ts} +0 -0
  180. /package/dist/src/{serialize-websocket-wrapper.js → events/channels/serialize-websocket-wrapper.js} +0 -0
  181. /package/dist/src/{openapi-spec-generator.d.ts → events/http/openapi-spec-generator.d.ts} +0 -0
  182. /package/dist/src/{openapi-spec-generator.js → events/http/openapi-spec-generator.js} +0 -0
  183. /package/dist/src/{serialize-fetch-wrapper.d.ts → events/http/serialize-fetch-wrapper.d.ts} +0 -0
  184. /package/dist/src/{serialize-fetch-wrapper.js → events/http/serialize-fetch-wrapper.js} +0 -0
  185. /package/dist/src/{serialize-scheduler-meta.d.ts → events/scheduler/serialize-scheduler-meta.d.ts} +0 -0
  186. /package/dist/src/{serialize-scheduler-meta.js → events/scheduler/serialize-scheduler-meta.js} +0 -0
  187. /package/dist/src/{serialize-nextjs-backend-wrapper.d.ts → runtimes/nextjs/serialize-nextjs-backend-wrapper.d.ts} +0 -0
  188. /package/dist/src/{serialize-nextjs-backend-wrapper.js → runtimes/nextjs/serialize-nextjs-backend-wrapper.js} +0 -0
  189. /package/dist/src/{serialize-nextjs-http-wrapper.d.ts → runtimes/nextjs/serialize-nextjs-http-wrapper.d.ts} +0 -0
  190. /package/dist/src/{serialize-nextjs-http-wrapper.js → runtimes/nextjs/serialize-nextjs-http-wrapper.js} +0 -0
  191. /package/dist/src/{utils/serialize-import-map.d.ts → serialize-import-map.d.ts} +0 -0
  192. /package/src/{serialize-websocket-wrapper.ts → events/channels/serialize-websocket-wrapper.ts} +0 -0
  193. /package/src/{openapi-spec-generator.ts → events/http/openapi-spec-generator.ts} +0 -0
  194. /package/src/{serialize-fetch-wrapper.ts → events/http/serialize-fetch-wrapper.ts} +0 -0
  195. /package/src/{serialize-scheduler-meta.ts → events/scheduler/serialize-scheduler-meta.ts} +0 -0
  196. /package/src/{serialize-nextjs-backend-wrapper.ts → runtimes/nextjs/serialize-nextjs-backend-wrapper.ts} +0 -0
  197. /package/src/{serialize-nextjs-http-wrapper.ts → runtimes/nextjs/serialize-nextjs-http-wrapper.ts} +0 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,48 @@
1
1
  # @pikku/cli
2
2
 
3
+ ## 0.8.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 44e3ff4: feat: enhance CLI filtering with type and directory filters
8
+
9
+ - Add --types filter to filter by PikkuEventTypes (http, channel, queue, scheduler, rpc, mcp)
10
+ - Add --directories filter to filter by file paths/directories
11
+ - All filters (tags, types, directories) now work together with AND logic
12
+ - Add comprehensive logging interface to inspector package
13
+ - Add comprehensive test suite for matchesFilters function
14
+ - Support cross-platform path handling
15
+
16
+ - 7c592b8: feat: support for required services and improved service configuration
17
+
18
+ This release includes several enhancements to service management and configuration:
19
+
20
+ - Added support for required services configuration
21
+ - Improved service discovery and registration
22
+ - Added typed RPC clients for service communication
23
+ - Updated middleware to run per function
24
+
25
+ - Updated dependencies [3261090]
26
+ - Updated dependencies [44e3ff4]
27
+ - Updated dependencies [7c592b8]
28
+ - Updated dependencies [30a082f]
29
+ - @pikku/core@0.8.1
30
+ - @pikku/inspector@0.8.1
31
+
32
+ ## 0.8.0
33
+
34
+ ### Major Features
35
+
36
+ - **Model Context Protocol (MCP) Support**: Complete MCP implementation with automatic generation of MCP JSON specifications, resources, tools, and prompts
37
+ - **Queue System**: Added queue support
38
+ - **RPC (Remote Procedure Calls)**: Added typed RPC call generation with local and remote procedure support
39
+ - **Multiple Bootstrap Files**: Added support for generating different transport-specific bootstrap files
40
+ - **Service Destructuring Analysis**: Added service destructuring analysis for better code generation
41
+ - **Bootstrap Files**: Added support for generating transport-specific bootstrap files
42
+ - **Service Destructuring**: Added service destructuring analysis for better code organization
43
+ - **Error Handling**: Improved error handling for complex type generation
44
+ - **Performance**: Optimized code generation for large projects with multiple event types
45
+
3
46
  ## 0.7.7
4
47
 
5
48
  ### Patch Changes
package/bin/pikku-all.ts CHANGED
@@ -1,67 +1,77 @@
1
1
  import { Command } from 'commander'
2
2
  import {
3
+ CLILogger,
3
4
  getFileImportRelativePath,
4
- logInfo,
5
- logPikkuLogo,
6
5
  PikkuCLIOptions,
7
6
  writeFileInDir,
8
- } from '../src/utils/utils.js'
7
+ } from '../src/utils.js'
9
8
  import { getPikkuCLIConfig, PikkuCLIConfig } from '../src/pikku-cli-config.js'
10
- import { pikkuHTTP } from './pikku-http-routes.js'
11
- import { pikkuFunctionTypes } from './pikku-function-types.js'
12
- import { pikkuHTTPMap } from './pikku-http-map.js'
9
+ import { pikkuHTTP } from '../src/events/http/pikku-command-http-routes.js'
10
+ import { pikkuFunctionTypes } from '../src/events/functions/pikku-command-function-types.js'
11
+ import { pikkuHTTPMap } from '../src/events/http/pikku-command-http-map.js'
13
12
  import { existsSync } from 'fs'
14
- import { pikkuFetch } from './pikku-fetch.js'
15
- import { pikkuChannelsMap } from './pikku-channels-map.js'
16
- import { pikkuChannels } from './pikku-channels.js'
17
- import { pikkuNext } from './pikku-nextjs.js'
18
- import { pikkuOpenAPI } from './pikku-openapi.js'
19
- import { pikkuScheduler } from './pikku-scheduler.js'
20
- import { pikkuSchemas } from './pikku-schemas.js'
21
- import { pikkuWebSocket } from './pikku-websocket.js'
13
+ import { pikkuChannelsMap } from '../src/events/channels/pikku-command-channels-map.js'
14
+ import { pikkuChannels } from '../src/events/channels/pikku-command-channels.js'
22
15
  import { inspectorGlob } from '../src/inspector-glob.js'
23
16
  import chokidar from 'chokidar'
24
- import { pikkuFunctions } from './pikku-functions.js'
25
- import { pikkuRPC } from './pikku-rpc.js'
26
- import { pikkuRPCMap } from './pikku-rpc-map.js'
27
- import { PikkuEventTypes } from '@pikku/core'
28
-
29
- const runAll = async (cliConfig: PikkuCLIConfig, options: PikkuCLIOptions) => {
30
- const boostrapImports: Partial<
31
- Record<PikkuEventTypes, { meta: string[]; events: string[] }>
32
- > & { all: { meta: string[]; events: string[] } } = {
33
- all: { meta: [], events: [] },
34
- }
17
+ import { pikkuFunctions } from '../src/events/functions/pikku-command-functions.js'
18
+ import { pikkuServices } from '../src/events/functions/pikku-command-services.js'
19
+ import { pikkuRPC } from '../src/events/rpc/pikku-command-rpc.js'
20
+ import { pikkuRPCMap } from '../src/events/rpc/pikku-command-rpc-map.js'
21
+ import { pikkuQueue } from '../src/events/queue/pikku-command-queue.js'
22
+ import { pikkuQueueMap } from '../src/events/queue/pikku-command-queue-map.js'
23
+ import { pikkuFetch } from '../src/events/fetch/index.js'
24
+ import { pikkuRPCClient } from '../src/events/rpc/pikku-command-rpc-client.js'
25
+ import { pikkuWebSocketTyped } from '../src/events/channels/pikku-command-websocket-typed.js'
26
+ import { pikkuOpenAPI } from '../src/events/http/pikku-command-openapi.js'
27
+ import { pikkuMCP } from '../src/events/mcp/pikku-command-mcp.js'
28
+ import { pikkuQueueService } from '../src/events/queue/pikku-command-queue-service.js'
29
+ import { pikkuScheduler } from '../src/events/scheduler/pikku-command-scheduler.js'
30
+ import { pikkuSchemas } from '../src/schemas.js'
31
+ import { pikkuMCPJSON } from '../src/events/mcp/pikku-command-mcp-json.js'
32
+ import { pikkuNext } from '../src/runtimes/nextjs/pikku-command-nextjs.js'
35
33
 
36
- const addImport = (
37
- from: string,
38
- type: 'meta' | 'events' | 'other',
39
- addTo?: PikkuEventTypes[]
40
- ) => {
41
- const statement = `import '${getFileImportRelativePath(cliConfig.bootstrapFile, from, cliConfig.packageMappings)}'`
42
- if (type === 'meta') {
43
- boostrapImports.all.meta.push(statement)
44
- } else {
45
- boostrapImports.all.events.push(statement)
46
- }
47
-
48
- for (const transport of Object.keys(PikkuEventTypes)) {
49
- if (!addTo || addTo?.includes(transport as PikkuEventTypes)) {
50
- boostrapImports[transport] = boostrapImports[transport] || {
51
- meta: [],
52
- events: [],
53
- }
54
- if (type === 'meta') {
55
- boostrapImports[transport].meta.push(statement)
56
- } else {
57
- boostrapImports[transport].events.push(statement)
58
- }
59
- }
60
- }
34
+ const generateBootstrapFile = async (
35
+ logger: CLILogger,
36
+ cliConfig: PikkuCLIConfig,
37
+ bootstrapFile: string,
38
+ specificImports: string[],
39
+ schemas?: boolean
40
+ ) => {
41
+ // Common imports that every bootstrap file needs
42
+ const commonImports = [cliConfig.functionsMetaFile, cliConfig.functionsFile]
43
+
44
+ // Add schema if it exists
45
+ if (schemas) {
46
+ commonImports.push(`${cliConfig.schemaDirectory}/register.gen.ts`)
61
47
  }
62
48
 
49
+ // Combine common imports with specific imports
50
+ const allImports = [...commonImports, ...specificImports]
51
+
52
+ await writeFileInDir(
53
+ logger,
54
+ bootstrapFile,
55
+ allImports
56
+ .map(
57
+ (to) =>
58
+ `import '${getFileImportRelativePath(bootstrapFile, to, cliConfig.packageMappings)}'`
59
+ )
60
+ .sort((to) => (to.includes('meta') ? -1 : 1)) // Ensure meta files are at the top
61
+ .join('\n')
62
+ )
63
+ }
64
+
65
+ const runAll = async (
66
+ logger: CLILogger,
67
+ cliConfig: PikkuCLIConfig,
68
+ options: PikkuCLIOptions
69
+ ) => {
70
+ const allImports: string[] = []
71
+
63
72
  let typesDeclarationFileExists = true
64
73
  let visitState = await inspectorGlob(
74
+ logger,
65
75
  cliConfig.rootDir,
66
76
  cliConfig.srcDirectories,
67
77
  cliConfig.filters
@@ -70,80 +80,158 @@ const runAll = async (cliConfig: PikkuCLIConfig, options: PikkuCLIOptions) => {
70
80
  if (!existsSync(cliConfig.typesDeclarationFile)) {
71
81
  typesDeclarationFileExists = false
72
82
  }
73
- await pikkuFunctionTypes(cliConfig, options, visitState)
83
+ await pikkuFunctionTypes(logger, cliConfig, visitState, options)
74
84
 
75
85
  // This is needed since the addHTTPRoute function will add the routes to the visitState
76
86
  if (!typesDeclarationFileExists) {
77
- logInfo(`• Type file first created, inspecting again...\x1b[0m`)
87
+ logger.info(`• Type file first created, inspecting again...\x1b[0m`)
78
88
  visitState = await inspectorGlob(
89
+ logger,
79
90
  cliConfig.rootDir,
80
91
  cliConfig.srcDirectories,
81
92
  cliConfig.filters
82
93
  )
83
94
  }
84
95
 
85
- const functions = pikkuFunctions(cliConfig, visitState)
96
+ const functions = pikkuFunctions(logger, cliConfig, visitState)
86
97
  if (!functions) {
87
- logInfo(`• No functions found, skipping remaining steps...\x1b[0m`)
98
+ logger.info(`• No functions found, skipping remaining steps...\x1b[0m`)
88
99
  process.exit(1)
89
100
  }
90
- addImport(cliConfig.functionsMetaFile, 'meta')
91
- addImport(cliConfig.functionsFile, 'events')
92
101
 
93
- await pikkuRPC(cliConfig, visitState)
94
- await pikkuRPCMap(cliConfig, visitState)
95
- addImport(cliConfig.rpcMetaFile, 'meta', [PikkuEventTypes.rpc])
102
+ // Base imports for all bootstrap files
103
+ allImports.push(cliConfig.functionsMetaFile, cliConfig.functionsFile)
104
+
105
+ // Generate services map
106
+ await pikkuServices(logger, cliConfig, visitState)
96
107
 
97
- const schemas = await pikkuSchemas(cliConfig, visitState)
108
+ await pikkuRPC(logger, cliConfig, visitState)
109
+ await pikkuRPCMap(logger, cliConfig, visitState)
110
+ await pikkuRPCClient(logger, cliConfig)
111
+ allImports.push(cliConfig.rpcMetaFile)
112
+
113
+ const schemas = await pikkuSchemas(logger, cliConfig, visitState)
98
114
  if (schemas) {
99
- addImport(`${cliConfig.schemaDirectory}/register.gen.ts`, 'other')
115
+ allImports.push(`${cliConfig.schemaDirectory}/register.gen.ts`)
100
116
  }
101
117
 
102
- const http = await pikkuHTTP(cliConfig, visitState)
118
+ // RPC bootstrap is always generated since RPC is always present
119
+ await generateBootstrapFile(
120
+ logger,
121
+ cliConfig,
122
+ cliConfig.bootstrapFiles.rpc,
123
+ [cliConfig.rpcMetaFile],
124
+ schemas
125
+ )
126
+
127
+ const http = await pikkuHTTP(logger, cliConfig, visitState)
103
128
  if (http) {
104
- await pikkuHTTPMap(cliConfig, visitState)
105
- await pikkuFetch(cliConfig)
106
- addImport(cliConfig.httpRoutesMetaFile, 'meta', [PikkuEventTypes.http])
107
- addImport(cliConfig.httpRoutesFile, 'events', [PikkuEventTypes.http])
129
+ await pikkuHTTPMap(logger, cliConfig, visitState)
130
+ await pikkuFetch(logger, cliConfig)
131
+ allImports.push(cliConfig.httpRoutesMetaFile, cliConfig.httpRoutesFile)
132
+
133
+ await generateBootstrapFile(
134
+ logger,
135
+ cliConfig,
136
+ cliConfig.bootstrapFiles.http,
137
+ [cliConfig.httpRoutesMetaFile, cliConfig.httpRoutesFile],
138
+ schemas
139
+ )
108
140
  }
109
141
 
110
- const scheduled = await pikkuScheduler(cliConfig, visitState)
111
- if (scheduled) {
112
- addImport(cliConfig.schedulersMetaFile, 'meta', [PikkuEventTypes.scheduled])
113
- addImport(cliConfig.schedulersFile, 'events', [PikkuEventTypes.scheduled])
142
+ const scheduler = await pikkuScheduler(logger, cliConfig, visitState)
143
+ if (scheduler) {
144
+ allImports.push(cliConfig.schedulersMetaFile, cliConfig.schedulersFile)
145
+
146
+ await generateBootstrapFile(
147
+ logger,
148
+ cliConfig,
149
+ cliConfig.bootstrapFiles.scheduler,
150
+ [cliConfig.schedulersMetaFile, cliConfig.schedulersFile],
151
+ schemas
152
+ )
153
+ }
154
+
155
+ const queues = await pikkuQueue(logger, cliConfig, visitState)
156
+ if (queues) {
157
+ await pikkuQueueMap(logger, cliConfig, visitState)
158
+ await pikkuQueueService(logger, cliConfig)
159
+ allImports.push(cliConfig.queueWorkersMetaFile, cliConfig.queueWorkersFile)
160
+
161
+ await generateBootstrapFile(
162
+ logger,
163
+ cliConfig,
164
+ cliConfig.bootstrapFiles.queue,
165
+ [cliConfig.queueWorkersMetaFile, cliConfig.queueWorkersFile],
166
+ schemas
167
+ )
114
168
  }
115
169
 
116
- const channels = await pikkuChannels(cliConfig, visitState)
170
+ const channels = await pikkuChannels(logger, cliConfig, visitState)
117
171
  if (channels) {
118
- await pikkuChannelsMap(cliConfig, visitState)
119
- await pikkuWebSocket(cliConfig)
120
- addImport(cliConfig.channelsMetaFile, 'meta', [PikkuEventTypes.channel])
121
- addImport(cliConfig.channelsFile, 'events', [PikkuEventTypes.channel])
172
+ await pikkuChannelsMap(logger, cliConfig, visitState)
173
+ await pikkuWebSocketTyped(logger, cliConfig)
174
+ allImports.push(cliConfig.channelsMetaFile, cliConfig.channelsFile)
175
+
176
+ await generateBootstrapFile(
177
+ logger,
178
+ cliConfig,
179
+ cliConfig.bootstrapFiles.channel,
180
+ [cliConfig.channelsMetaFile, cliConfig.channelsFile],
181
+ schemas
182
+ )
183
+ }
184
+
185
+ const mcp = await pikkuMCP(logger, cliConfig, visitState)
186
+ if (mcp) {
187
+ await pikkuMCPJSON(logger, cliConfig, visitState)
188
+ allImports.push(cliConfig.mcpEndpointsMetaFile, cliConfig.mcpEndpointsFile)
189
+
190
+ await generateBootstrapFile(
191
+ logger,
192
+ cliConfig,
193
+ cliConfig.bootstrapFiles.mcp,
194
+ [cliConfig.mcpEndpointsMetaFile, cliConfig.mcpEndpointsFile],
195
+ schemas
196
+ )
122
197
  }
123
198
 
124
199
  if (cliConfig.nextBackendFile || cliConfig.nextHTTPFile) {
125
- await pikkuNext(cliConfig, visitState, options)
200
+ await pikkuNext(logger, cliConfig, visitState, options)
126
201
  }
127
202
 
128
203
  if (cliConfig.openAPI) {
129
- logInfo(`• OpenAPI requires a reinspection to pickup new generated types..`)
204
+ logger.info(
205
+ `• OpenAPI requires a reinspection to pickup new generated types..`
206
+ )
130
207
  visitState = await inspectorGlob(
208
+ logger,
131
209
  cliConfig.rootDir,
132
210
  cliConfig.srcDirectories,
133
211
  cliConfig.filters
134
212
  )
135
- await pikkuOpenAPI(cliConfig, visitState)
213
+ await pikkuOpenAPI(logger, cliConfig, visitState)
136
214
  }
137
215
 
138
- for (const [type, { meta, events }] of Object.entries(boostrapImports)) {
139
- await writeFileInDir(
140
- type === 'all' ? cliConfig.bootstrapFile : cliConfig.bootstrapFiles[type],
141
- [...meta, ...events].join('\n')
142
- )
143
- }
216
+ // Generate main bootstrap file (pass all imports directly since this is the main file)
217
+ await writeFileInDir(
218
+ logger,
219
+ cliConfig.bootstrapFile,
220
+ allImports
221
+ .map(
222
+ (to) =>
223
+ `import '${getFileImportRelativePath(cliConfig.bootstrapFile, to, cliConfig.packageMappings)}'`
224
+ )
225
+ .sort((to) => (to.includes('meta') ? -1 : 1)) // Ensure meta files are at the top
226
+ .join('\n')
227
+ )
144
228
  }
145
229
 
146
- const watch = (cliConfig: PikkuCLIConfig, options: PikkuCLIOptions) => {
230
+ const watch = (
231
+ logger: CLILogger,
232
+ cliConfig: PikkuCLIConfig,
233
+ options: PikkuCLIOptions
234
+ ) => {
147
235
  const configWatcher = chokidar.watch(cliConfig.srcDirectories, {
148
236
  ignoreInitial: true,
149
237
  ignored: /.*\.gen\.tsx?/,
@@ -154,7 +242,7 @@ const watch = (cliConfig: PikkuCLIConfig, options: PikkuCLIOptions) => {
154
242
  const generatorWatcher = () => {
155
243
  watcher.close()
156
244
 
157
- logInfo(
245
+ logger.info(
158
246
  `• Watching directories: \n - ${cliConfig.srcDirectories.join('\n - ')}`
159
247
  )
160
248
  watcher = chokidar.watch(cliConfig.srcDirectories, {
@@ -165,7 +253,7 @@ const watch = (cliConfig: PikkuCLIConfig, options: PikkuCLIOptions) => {
165
253
  watcher.on('ready', async () => {
166
254
  const handle = async () => {
167
255
  try {
168
- await runAll(cliConfig, options)
256
+ await runAll(logger, cliConfig, options)
169
257
  } catch (err) {
170
258
  console.error(err)
171
259
  console.info()
@@ -194,19 +282,23 @@ const watch = (cliConfig: PikkuCLIConfig, options: PikkuCLIOptions) => {
194
282
  }
195
283
 
196
284
  export const action = async (options: PikkuCLIOptions): Promise<void> => {
197
- logPikkuLogo()
285
+ const logger = new CLILogger({ logLogo: true })
198
286
 
199
287
  const cliConfig = await getPikkuCLIConfig(
200
288
  options.config,
201
289
  [],
202
- options.tags,
290
+ {
291
+ tags: options.tags,
292
+ types: options.types,
293
+ directories: options.directories,
294
+ },
203
295
  true
204
296
  )
205
297
 
206
298
  if (options.watch) {
207
- watch(cliConfig, options)
299
+ watch(logger, cliConfig, options)
208
300
  } else {
209
- await runAll(cliConfig, options)
301
+ await runAll(logger, cliConfig, options)
210
302
  }
211
303
  }
212
304
 
@@ -225,6 +317,11 @@ export const all = (program: Command): void => {
225
317
  )
226
318
  .option('-c | --config <string>', 'The path to pikku cli config file')
227
319
  .option('-t | --tags <tags...>', 'Which tags to filter by')
320
+ .option(
321
+ '--types <types...>',
322
+ 'Which types to filter by (http, channel, queue, scheduler, rpc, mcp)'
323
+ )
324
+ .option('--directories <directories...>', 'Which directories to filter by')
228
325
  .option('-w | --watch', 'Whether to watch file changes')
229
326
  .action(action)
230
327
  }
@@ -1,49 +1,21 @@
1
1
  import { Command } from 'commander'
2
- import { getPikkuCLIConfig, PikkuCLIConfig } from '../src/pikku-cli-config.js'
3
- import { serializeFetchWrapper } from '../src/serialize-fetch-wrapper.js'
4
- import {
5
- getFileImportRelativePath,
6
- logCommandInfoAndTime,
7
- logPikkuLogo,
8
- PikkuCLIOptions,
9
- writeFileInDir,
10
- } from '../src/utils/utils.js'
11
-
12
- export const pikkuFetch = async ({
13
- fetchFile,
14
- httpRoutesMapDeclarationFile,
15
- packageMappings,
16
- }: PikkuCLIConfig) => {
17
- await logCommandInfoAndTime(
18
- 'Generating fetch wrapper',
19
- 'Generated fetch wrapper',
20
- [fetchFile === undefined, "fetchFile isn't set in the pikku config"],
21
- async () => {
22
- if (!fetchFile) {
23
- throw new Error("fetchFile is isn't set in the pikku config")
24
- }
25
-
26
- const routesMapDeclarationPath = getFileImportRelativePath(
27
- fetchFile,
28
- httpRoutesMapDeclarationFile,
29
- packageMappings
30
- )
31
-
32
- const content = [serializeFetchWrapper(routesMapDeclarationPath)]
33
- await writeFileInDir(fetchFile, content.join('\n'))
34
- }
35
- )
36
- }
2
+ import { getPikkuCLIConfig } from '../src/pikku-cli-config.js'
3
+ import { pikkuFetch } from '../src/events/fetch/index.js'
4
+ import { CLILogger, PikkuCLIOptions } from '../src/utils.js'
37
5
 
38
6
  export const action = async (options: PikkuCLIOptions): Promise<void> => {
39
- logPikkuLogo()
7
+ const logger = new CLILogger({ logLogo: true })
40
8
  const cliConfig = await getPikkuCLIConfig(
41
9
  options.config,
42
10
  ['rootDir', 'schemaDirectory', 'configDir', 'fetchFile'],
43
- options.tags,
11
+ {
12
+ tags: options.tags,
13
+ types: options.types,
14
+ directories: options.directories,
15
+ },
44
16
  true
45
17
  )
46
- await pikkuFetch(cliConfig)
18
+ await pikkuFetch(logger, cliConfig)
47
19
  }
48
20
 
49
21
  export const fetch = (program: Command): void => {
@@ -1,130 +1,29 @@
1
1
  import { Command } from 'commander'
2
- import { serializeNextJsBackendWrapper as serializeNextBackendWrapper } from '../src/serialize-nextjs-backend-wrapper.js'
3
- import { serializeNextJsHTTPWrapper as serializeNextHTTPWrapper } from '../src/serialize-nextjs-http-wrapper.js'
4
- import {
5
- getFileImportRelativePath,
6
- getPikkuFilesAndMethods,
7
- logCommandInfoAndTime,
8
- logPikkuLogo,
9
- PikkuCLIOptions,
10
- writeFileInDir,
11
- } from '../src/utils/utils.js'
12
- import { getPikkuCLIConfig, PikkuCLIConfig } from '../src/pikku-cli-config.js'
13
- import { InspectorState } from '@pikku/inspector'
2
+ import { CLILogger, PikkuCLIOptions } from '../src/utils.js'
3
+ import { getPikkuCLIConfig } from '../src/pikku-cli-config.js'
14
4
  import { inspectorGlob } from '../src/inspector-glob.js'
15
-
16
- export const pikkuNext = async (
17
- {
18
- nextBackendFile,
19
- nextHTTPFile,
20
- httpRoutesMapDeclarationFile,
21
- packageMappings,
22
- fetchFile,
23
- bootstrapFiles,
24
- }: PikkuCLIConfig,
25
- visitState: InspectorState,
26
- options: PikkuCLIOptions
27
- ) => {
28
- return await logCommandInfoAndTime(
29
- 'Generating nextjs wrapper',
30
- 'Generated nextjs wrapper',
31
- [
32
- nextBackendFile === undefined && nextHTTPFile === undefined,
33
- 'nextjs outfile is not defined',
34
- ],
35
- async () => {
36
- if (!nextBackendFile && !nextHTTPFile) {
37
- throw new Error(
38
- 'nextBackendFile or nextHTTPFile is required in pikku config for nextJS'
39
- )
40
- }
41
-
42
- if (nextHTTPFile && !fetchFile) {
43
- throw new Error(
44
- 'fetchFile is required in pikku config in order for nextJS http wrapper to work'
45
- )
46
- }
47
-
48
- if (nextBackendFile) {
49
- const {
50
- pikkuConfigFactory,
51
- singletonServicesFactory,
52
- sessionServicesFactory,
53
- } = await getPikkuFilesAndMethods(
54
- visitState,
55
- packageMappings,
56
- nextBackendFile,
57
- options,
58
- {
59
- config: true,
60
- singletonServicesFactory: true,
61
- sessionServicesFactory: true,
62
- }
63
- )
64
-
65
- const pikkuConfigImport = `import { ${pikkuConfigFactory.variable} as createConfig } from '${getFileImportRelativePath(nextBackendFile, pikkuConfigFactory.file, packageMappings)}'`
66
- const singletonServicesImport = `import { ${singletonServicesFactory.variable} as createSingletonServices } from '${getFileImportRelativePath(nextBackendFile, singletonServicesFactory.file, packageMappings)}'`
67
- const sessionServicesImport = `import { ${sessionServicesFactory.variable} as createSessionServices } from '${getFileImportRelativePath(nextBackendFile, sessionServicesFactory.file, packageMappings)}'`
68
-
69
- const httpBootstrapPath = getFileImportRelativePath(
70
- nextBackendFile,
71
- bootstrapFiles.http,
72
- packageMappings
73
- )
74
-
75
- const routesMapDeclarationPath = getFileImportRelativePath(
76
- nextBackendFile,
77
- httpRoutesMapDeclarationFile,
78
- packageMappings
79
- )
80
-
81
- const content = serializeNextBackendWrapper(
82
- httpBootstrapPath,
83
- routesMapDeclarationPath,
84
- pikkuConfigImport,
85
- singletonServicesImport,
86
- sessionServicesImport
87
- )
88
- await writeFileInDir(nextBackendFile, content)
89
- }
90
-
91
- if (nextHTTPFile && fetchFile) {
92
- const routesMapDeclarationPath = getFileImportRelativePath(
93
- nextHTTPFile,
94
- httpRoutesMapDeclarationFile,
95
- packageMappings
96
- )
97
-
98
- const fetchPath = getFileImportRelativePath(
99
- nextHTTPFile,
100
- fetchFile,
101
- packageMappings
102
- )
103
-
104
- const content = serializeNextHTTPWrapper(
105
- routesMapDeclarationPath,
106
- fetchPath
107
- )
108
- await writeFileInDir(nextHTTPFile, content)
109
- }
110
- }
111
- )
112
- }
5
+ import { pikkuNext } from '../src/runtimes/nextjs/pikku-command-nextjs.js'
113
6
 
114
7
  export const action = async (options: PikkuCLIOptions): Promise<void> => {
115
- logPikkuLogo()
8
+ const logger = new CLILogger({ logLogo: true })
9
+
116
10
  const cliConfig = await getPikkuCLIConfig(
117
11
  options.config,
118
12
  ['rootDir', 'schemaDirectory', 'configDir'],
119
- options.tags,
13
+ {
14
+ tags: options.tags,
15
+ types: options.types,
16
+ directories: options.directories,
17
+ },
120
18
  true
121
19
  )
122
20
  const visitState = await inspectorGlob(
21
+ logger,
123
22
  cliConfig.rootDir,
124
23
  cliConfig.srcDirectories,
125
24
  cliConfig.filters
126
25
  )
127
- await pikkuNext(cliConfig, visitState, options)
26
+ await pikkuNext(logger, cliConfig, visitState, options)
128
27
  }
129
28
 
130
29
  export const nextjs = (program: Command): void => {