@pikku/cli 0.6.20 → 0.7.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 (111) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/cli.schema.json +2 -2
  3. package/dist/bin/pikku-all.js +34 -16
  4. package/dist/bin/pikku-channels-map.js +4 -4
  5. package/dist/bin/pikku-channels.js +6 -10
  6. package/dist/bin/pikku-fetch.d.ts +1 -1
  7. package/dist/bin/pikku-fetch.js +3 -3
  8. package/dist/bin/pikku-function-types.js +4 -4
  9. package/dist/bin/pikku-functions.d.ts +5 -0
  10. package/dist/bin/pikku-functions.js +24 -0
  11. package/dist/bin/pikku-http-map.d.ts +5 -0
  12. package/dist/bin/pikku-http-map.js +23 -0
  13. package/dist/bin/pikku-http-routes.d.ts +5 -0
  14. package/dist/bin/pikku-http-routes.js +24 -0
  15. package/dist/bin/pikku-http.js +3 -5
  16. package/dist/bin/pikku-nextjs.d.ts +1 -1
  17. package/dist/bin/pikku-nextjs.js +8 -8
  18. package/dist/bin/pikku-openapi.d.ts +1 -1
  19. package/dist/bin/pikku-openapi.js +6 -6
  20. package/dist/bin/pikku-routes-map.d.ts +1 -1
  21. package/dist/bin/pikku-routes-map.js +3 -3
  22. package/dist/bin/pikku-scheduler.js +7 -10
  23. package/dist/bin/pikku-schemas.d.ts +1 -1
  24. package/dist/bin/pikku-schemas.js +6 -6
  25. package/dist/bin/pikku-websocket.js +1 -1
  26. package/dist/bin/pikku.js +2 -2
  27. package/dist/src/channels/serialize-typed-channel-map.js +5 -2
  28. package/dist/src/core/serialize-import-map.js +1 -0
  29. package/dist/src/core/serialize-pikku-types.js +90 -6
  30. package/dist/src/events/channels/serialize-channels.d.ts +3 -0
  31. package/dist/src/events/channels/serialize-channels.js +19 -0
  32. package/dist/src/events/channels/serialize-typed-channel-map.d.ts +3 -0
  33. package/dist/src/events/channels/serialize-typed-channel-map.js +90 -0
  34. package/dist/src/events/channels/serialize-websocket-wrapper.d.ts +1 -0
  35. package/{src/channels/serialize-websocket-wrapper.ts → dist/src/events/channels/serialize-websocket-wrapper.js} +4 -4
  36. package/dist/src/events/http/serialize-fetch-wrapper.d.ts +1 -0
  37. package/{src/http/serialize-fetch-wrapper.ts → dist/src/events/http/serialize-fetch-wrapper.js} +4 -4
  38. package/dist/src/events/http/serialize-route-imports.d.ts +1 -0
  39. package/dist/src/events/http/serialize-route-imports.js +13 -0
  40. package/dist/src/events/http/serialize-route-meta.d.ts +2 -0
  41. package/dist/src/events/http/serialize-route-meta.js +6 -0
  42. package/dist/src/events/http/serialize-typed-route-map.d.ts +4 -0
  43. package/dist/src/events/http/serialize-typed-route-map.js +107 -0
  44. package/dist/src/events/scheduler/serialize-schedulers.d.ts +3 -0
  45. package/dist/src/events/scheduler/serialize-schedulers.js +23 -0
  46. package/dist/src/http/serialize-typed-route-map.js +1 -1
  47. package/dist/src/inspector-glob.d.ts +1 -1
  48. package/dist/src/inspector-glob.js +2 -2
  49. package/dist/src/openapi-spec-generator.d.ts +79 -0
  50. package/dist/src/openapi-spec-generator.js +136 -0
  51. package/dist/src/pikku-cli-config.d.ts +9 -4
  52. package/dist/src/pikku-cli-config.js +19 -4
  53. package/dist/src/scheduler/serialize-schedulers.js +3 -2
  54. package/dist/src/schema/schema-generator.d.ts +1 -1
  55. package/dist/src/schema/schema-generator.js +20 -7
  56. package/dist/src/schema-generator.d.ts +5 -0
  57. package/dist/src/schema-generator.js +98 -0
  58. package/dist/src/serialize-fetch-wrapper.d.ts +1 -0
  59. package/dist/src/serialize-fetch-wrapper.js +67 -0
  60. package/dist/src/serialize-import-map.d.ts +2 -0
  61. package/dist/src/serialize-import-map.js +24 -0
  62. package/dist/src/serialize-nextjs-backend-wrapper.d.ts +1 -0
  63. package/{src/nextjs/serialize-nextjs-backend-wrapper.ts → dist/src/serialize-nextjs-backend-wrapper.js} +4 -11
  64. package/dist/src/serialize-nextjs-http-wrapper.d.ts +1 -0
  65. package/{src/nextjs/serialize-nextjs-http-wrapper.ts → dist/src/serialize-nextjs-http-wrapper.js} +4 -7
  66. package/dist/src/serialize-pikku-types.d.ts +4 -0
  67. package/dist/src/serialize-pikku-types.js +136 -0
  68. package/dist/src/serialize-scheduler-meta.d.ts +2 -0
  69. package/dist/src/serialize-scheduler-meta.js +10 -0
  70. package/dist/src/serialize-typed-channel-map.d.ts +3 -0
  71. package/dist/src/serialize-typed-channel-map.js +93 -0
  72. package/dist/src/serialize-typed-function-map.d.ts +4 -0
  73. package/dist/src/serialize-typed-function-map.js +107 -0
  74. package/dist/src/serialize-typed-http-map.d.ts +4 -0
  75. package/dist/src/serialize-typed-http-map.js +107 -0
  76. package/dist/src/serialize-typed-route-map.d.ts +4 -0
  77. package/dist/src/serialize-typed-route-map.js +107 -0
  78. package/dist/src/serialize-websocket-wrapper.d.ts +1 -0
  79. package/dist/src/serialize-websocket-wrapper.js +61 -0
  80. package/dist/src/utils.d.ts +1 -0
  81. package/dist/src/utils.js +17 -5
  82. package/package.json +3 -3
  83. package/bin/pikku-all.ts +0 -180
  84. package/bin/pikku-channels-map.ts +0 -55
  85. package/bin/pikku-channels.ts +0 -58
  86. package/bin/pikku-fetch.ts +0 -55
  87. package/bin/pikku-function-types.ts +0 -84
  88. package/bin/pikku-http.ts +0 -56
  89. package/bin/pikku-nextjs.test.ts +0 -279
  90. package/bin/pikku-nextjs.ts +0 -152
  91. package/bin/pikku-openapi.ts +0 -70
  92. package/bin/pikku-routes-map.ts +0 -55
  93. package/bin/pikku-scheduler.ts +0 -62
  94. package/bin/pikku-schemas.ts +0 -52
  95. package/bin/pikku-websocket.ts +0 -58
  96. package/bin/pikku.ts +0 -26
  97. package/dist/tsconfig.tsbuildinfo +0 -1
  98. package/src/channels/serialize-channels.ts +0 -34
  99. package/src/channels/serialize-typed-channel-map.ts +0 -136
  100. package/src/core/serialize-import-map.ts +0 -33
  101. package/src/core/serialize-pikku-types.ts +0 -55
  102. package/src/http/serialize-route-imports.ts +0 -24
  103. package/src/http/serialize-route-meta.ts +0 -10
  104. package/src/http/serialize-typed-route-map.ts +0 -150
  105. package/src/inspector-glob.ts +0 -28
  106. package/src/openapi/openapi-spec-generator.ts +0 -227
  107. package/src/pikku-cli-config.ts +0 -204
  108. package/src/scheduler/serialize-schedulers.ts +0 -41
  109. package/src/schema/schema-generator.ts +0 -114
  110. package/src/utils.ts +0 -260
  111. package/tsconfig.json +0 -21
package/src/utils.ts DELETED
@@ -1,260 +0,0 @@
1
- import { relative, dirname } from 'path'
2
- import { PathToNameAndType, InspectorState } from '@pikku/inspector'
3
- import { mkdir, writeFile } from 'fs/promises'
4
- import chalk from 'chalk'
5
- import { fileURLToPath } from 'url'
6
- import { readFileSync } from 'fs'
7
-
8
- const __filename = fileURLToPath(import.meta.url)
9
-
10
- export const logPrimary = (message: string) => {
11
- console.log(chalk.green(message))
12
- }
13
-
14
- export const logSuccess = (message: string) => {
15
- console.log(chalk.green(message))
16
- }
17
-
18
- export const logInfo = (message: string) => {
19
- console.log(chalk.blue(message))
20
- }
21
-
22
- export const getFileImportRelativePath = (
23
- from: string,
24
- to: string,
25
- packageMappings: Record<string, string>
26
- ): string => {
27
- let filePath = relative(dirname(from), to)
28
- if (!/^\.+\//.test(filePath)) {
29
- filePath = `./${filePath}`
30
- }
31
- let usesPackageName = false
32
- for (const [path, packageName] of Object.entries(packageMappings)) {
33
- if (filePath.includes(path)) {
34
- usesPackageName = true
35
- filePath = filePath.replace(new RegExp(`.*${path}`), packageName)
36
- break
37
- }
38
- }
39
- if (usesPackageName) {
40
- return filePath.replace('.ts', '')
41
- }
42
- return filePath.replace('.ts', '.js')
43
- }
44
-
45
- interface Meta {
46
- file: string
47
- variable: string
48
- type: string
49
- typePath: string
50
- }
51
-
52
- export type FilesAndMethods = {
53
- userSessionType: Meta
54
- sessionServicesType: Meta
55
- singletonServicesType: Meta
56
- pikkuConfigFactory: Meta
57
- singletonServicesFactory: Meta
58
- sessionServicesFactory: Meta
59
- }
60
-
61
- export interface PikkuCLIOptions {
62
- watch?: boolean
63
- config?: string
64
- configFileType?: string
65
- userSessionType?: string
66
- singletonServicesFactoryType?: string
67
- sessionServicesFactoryType?: string
68
- tags?: string[]
69
- }
70
-
71
- const getMetaTypes = (
72
- type: string,
73
- errors: Map<string, PathToNameAndType>,
74
- map: PathToNameAndType,
75
- desiredType?: string
76
- ) => {
77
- if (desiredType) {
78
- const entries = Object.entries(map)
79
- for (const [file, meta] of entries) {
80
- for (const { type, variable, typePath } of meta) {
81
- if (type === desiredType) {
82
- return { file, variable, type, typePath }
83
- }
84
- }
85
- }
86
- errors.set(`No ${desiredType} found that extends ${type}`, map)
87
- return undefined
88
- }
89
-
90
- const totalValues = Object.values(map).flat()
91
- if (totalValues.length === 0) {
92
- errors.set(`No ${type} found`, map)
93
- } else if (totalValues.length > 1) {
94
- errors.set(`More than one ${type} found`, map)
95
- } else {
96
- const entry = Object.entries(map)[0]
97
- if (entry) {
98
- const [file, [{ type, variable, typePath }]] = entry
99
- return { file, type, variable, typePath }
100
- }
101
- }
102
-
103
- return undefined
104
- }
105
-
106
- export const getPikkuFilesAndMethods = async (
107
- {
108
- singletonServicesTypeImportMap,
109
- sessionServicesTypeImportMap,
110
- userSessionTypeImportMap,
111
- sessionServicesFactories,
112
- singletonServicesFactories,
113
- configFactories,
114
- }: InspectorState,
115
- packageMappings: Record<string, string>,
116
- outputFile: string,
117
- {
118
- configFileType,
119
- singletonServicesFactoryType,
120
- sessionServicesFactoryType,
121
- }: PikkuCLIOptions,
122
- requires: Partial<{
123
- config: boolean
124
- sessionServiceType: boolean
125
- singletonServicesType: boolean
126
- userSessionType: boolean
127
- singletonServicesFactory: boolean
128
- sessionServicesFactory: boolean
129
- }> = {
130
- config: false,
131
- singletonServicesType: false,
132
- sessionServiceType: false,
133
- userSessionType: false,
134
- singletonServicesFactory: false,
135
- sessionServicesFactory: false,
136
- }
137
- ): Promise<FilesAndMethods> => {
138
- let errors = new Map<string, PathToNameAndType>()
139
-
140
- const result: Partial<FilesAndMethods> = {
141
- userSessionType: getMetaTypes(
142
- 'CoreUserSession',
143
- requires.userSessionType ? errors : new Map(),
144
- userSessionTypeImportMap,
145
- configFileType
146
- ),
147
- singletonServicesType: getMetaTypes(
148
- 'CoreSingletonServices',
149
- requires.singletonServicesType ? errors : new Map(),
150
- singletonServicesTypeImportMap
151
- ),
152
- sessionServicesType: getMetaTypes(
153
- 'CoreServices',
154
- requires.sessionServiceType ? errors : new Map(),
155
- sessionServicesTypeImportMap
156
- ),
157
- pikkuConfigFactory: getMetaTypes(
158
- 'CoreConfig',
159
- requires.config ? errors : new Map(),
160
- configFactories,
161
- configFileType
162
- ),
163
- singletonServicesFactory: getMetaTypes(
164
- 'CreateSingletonServices',
165
- requires.singletonServicesFactory ? errors : new Map(),
166
- singletonServicesFactories,
167
- singletonServicesFactoryType
168
- ),
169
- sessionServicesFactory: getMetaTypes(
170
- 'CreateSessionServices',
171
- requires.sessionServicesFactory ? errors : new Map(),
172
- sessionServicesFactories,
173
- sessionServicesFactoryType
174
- ),
175
- }
176
-
177
- if (errors.size > 0) {
178
- const result: string[] = ['Found errors:']
179
- errors.forEach((filesAndMethods, message) => {
180
- result.push(`- ${message}`)
181
- for (const [file, methods] of Object.entries(filesAndMethods)) {
182
- result.push(
183
- `\t* file: ${getFileImportRelativePath(outputFile, file, packageMappings)}`
184
- )
185
- result.push(
186
- `\t* methods: ${methods.map(({ variable, type }) => `${variable}: ${type}`).join(', ')}`
187
- )
188
- }
189
- })
190
-
191
- console.error(result.join('\n'))
192
- process.exit(1)
193
- }
194
-
195
- return result as FilesAndMethods
196
- }
197
-
198
- export const writeFileInDir = async (
199
- path: string,
200
- content: string,
201
- ignoreModifyComment: boolean = false
202
- ) => {
203
- if (content.includes('server-only')) {
204
- content = content.replace(
205
- "'server-only'",
206
- `'server-only'\n\n${ignoreModifyComment ? '' : DO_NOT_MODIFY_COMMENT}`
207
- )
208
- } else {
209
- content = `${ignoreModifyComment ? '' : DO_NOT_MODIFY_COMMENT}${content}`
210
- }
211
-
212
- await mkdir(dirname(path), { recursive: true })
213
- await writeFile(path, content, 'utf-8')
214
- logSuccess(`✓ File written to ${path}`)
215
- }
216
-
217
- export const logCommandInfoAndTime = async (
218
- commandStart: string,
219
- commandEnd: string,
220
- [skipCondition, skipMessage = 'none found']: [boolean] | [boolean, string],
221
- callback: (...args: any[]) => Promise<unknown>
222
- ): Promise<boolean> => {
223
- if (skipCondition === true) {
224
- logInfo(
225
- `• Skipping ${commandStart.charAt(0).toLocaleLowerCase()}${commandStart.slice(1)} since ${skipMessage}.`
226
- )
227
- return false
228
- }
229
-
230
- const start = Date.now()
231
- chalk.blue(`• ${commandStart}...`)
232
- await callback()
233
-
234
- logSuccess(`✓ ${commandEnd} in ${Date.now() - start}ms.`)
235
- return true
236
- }
237
-
238
- const logo = `
239
- ______ _ _ _
240
- (_____ (_) | | |
241
- _____) )| | _| | _ _ _
242
- | ____/ | |_/ ) |_/ ) | | |
243
- | | | | _ (| _ (| |_| |
244
- |_| |_|_| \_)_| \_)____/
245
- `
246
-
247
- export const logPikkuLogo = () => {
248
- logPrimary(logo)
249
-
250
- const packageJson = JSON.parse(
251
- readFileSync(`${dirname(__filename)}/../../package.json`, 'utf-8')
252
- )
253
- logPrimary(`⚙️ Welcome to the Pikku CLI (v${packageJson.version})\n`)
254
- }
255
-
256
- // TODO: add version back in once the ESM dust settles
257
- export const DO_NOT_MODIFY_COMMENT = `/**
258
- * This file was generated by the @pikku/cli
259
- */
260
- `
package/tsconfig.json DELETED
@@ -1,21 +0,0 @@
1
- {
2
- "extends": "../tsconfig.json",
3
- "compilerOptions": {
4
- "rootDir": ".",
5
- "module": "Node16",
6
- "outDir": "dist",
7
- "target": "esnext",
8
- "declaration": true,
9
- "resolveJsonModule": true
10
- },
11
- "include": ["bin/**/*.ts", "src/**/*.ts"],
12
- "exclude": ["**/*.test.ts", "node_modules", "bin/dist"],
13
- "references": [
14
- {
15
- "path": "../core/tsconfig.json"
16
- },
17
- {
18
- "path": "../inspector/tsconfig.json"
19
- }
20
- ]
21
- }