@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
@@ -1,279 +0,0 @@
1
- // import * as path from 'path'
2
- // import { assert } from 'chai'
3
- // import * as sinon from 'sinon'
4
-
5
- // import { action } from './pikku-nextjs.js'
6
-
7
- // // Mocking external dependencies
8
- // import * as fsPromises from 'fs/promises'
9
- // import * as extractPikkuInformation from '../src/extract-pikku-information.js'
10
- // import * as getFileImportRelativePath from '../src/utils.js'
11
- // import * as nextjsWrapperGenerator from '../src/nextjs-wrapper-generator.js'
12
-
13
- // import * as getPikkuConfig from '@pikku/core/pikku-config'
14
-
15
- // describe('action function - generateNextJsWrapper arguments', () => {
16
- // let sandbox: sinon.SinonSandbox
17
- // let getPikkuConfigStub: sinon.SinonStub
18
- // let extractPikkuInformationStub: sinon.SinonStub
19
- // let getFileImportRelativePathStub: sinon.SinonStub
20
- // let generateNextJsWrapperStub: sinon.SinonStub
21
- // let processExitStub: sinon.SinonStub
22
- // let consoleErrorStub: sinon.SinonStub
23
-
24
- // beforeEach(() => {
25
- // sandbox = sinon.createSandbox()
26
-
27
- // // Stub external dependencies
28
- // getPikkuConfigStub = sandbox.stub(
29
- // getPikkuConfig,
30
- // 'getPikkuConfig'
31
- // )
32
- // extractPikkuInformationStub = sandbox.stub(
33
- // extractPikkuInformation,
34
- // 'extractPikkuInformation'
35
- // )
36
- // getFileImportRelativePathStub = sandbox.stub(
37
- // getFileImportRelativePath,
38
- // 'getFileImportRelativePath'
39
- // )
40
- // generateNextJsWrapperStub = sandbox.stub(
41
- // nextjsWrapperGenerator,
42
- // 'generateNextJsWrapper'
43
- // )
44
-
45
- // // Stub fs.promises methods to prevent actual file system operations
46
- // sandbox.stub(fsPromises, 'mkdir').resolves()
47
- // sandbox.stub(fsPromises, 'writeFile').resolves()
48
-
49
- // // Stub process.exit and console.error to prevent test from exiting and to capture errors
50
- // processExitStub = sandbox.stub(process, 'exit')
51
- // sandbox.stub(console, 'log')
52
- // consoleErrorStub = sandbox.stub(console, 'error')
53
-
54
- // // Default stubs for external functions
55
- // getPikkuConfigStub.resolves({
56
- // pikkuNextFile: 'nextFile.ts',
57
- // rootDir: 'rootDir',
58
- // routesFile: 'routes.ts',
59
- // configDir: 'configDir',
60
- // packageMappings: {},
61
- // schemaDirectory: 'schemas',
62
- // })
63
-
64
- // extractPikkuInformationStub.resolves({
65
- // pikkuConfigs: { 'configFile.ts': ['pikkuConfigVariable'] },
66
- // sessionServicesFactories: {
67
- // 'sessionFactoryFile.ts': ['sessionFactoryVariable'],
68
- // },
69
- // singletonServicesFactories: {
70
- // 'singletonFactoryFile.ts': ['singletonFactoryVariable'],
71
- // },
72
- // })
73
-
74
- // // Mock getFileImportRelativePath to return predictable paths
75
- // getFileImportRelativePathStub.callsFake(
76
- // (from: string, to: string, packageMappings: any) => {
77
- // return `./${to}`
78
- // }
79
- // )
80
- // })
81
-
82
- // afterEach(() => {
83
- // sandbox.restore()
84
- // })
85
-
86
- // it('should pass correct imports to generateNextJsWrapper', async () => {
87
- // await action({})
88
-
89
- // // Capture the arguments passed to generateNextJsWrapper
90
- // assert(
91
- // generateNextJsWrapperStub.calledOnce,
92
- // 'generateNextJsWrapper should be called once'
93
- // )
94
-
95
- // const [
96
- // ,
97
- // ,
98
- // pikkuConfigImport,
99
- // singletonServicesImport,
100
- // sessionServicesImport,
101
- // ] = generateNextJsWrapperStub.firstCall.args
102
-
103
- // const expectedPikkuConfigImport = `import { pikkuConfigVariable } from './configFile.ts'`
104
- // const expectedSingletonServicesImport = `import { singletonFactoryVariable } from './singletonFactoryFile.ts'`
105
- // const expectedSessionServicesImport = `import { sessionFactoryVariable } from './sessionFactoryFile.ts'`
106
-
107
- // assert.strictEqual(
108
- // pikkuConfigImport,
109
- // expectedPikkuConfigImport,
110
- // 'pikkuConfigImport should match expected import'
111
- // )
112
- // assert.strictEqual(
113
- // singletonServicesImport,
114
- // expectedSingletonServicesImport,
115
- // 'singletonServicesImport should match expected import'
116
- // )
117
- // assert.strictEqual(
118
- // sessionServicesImport,
119
- // expectedSessionServicesImport,
120
- // 'sessionServicesImport should match expected import'
121
- // )
122
- // })
123
-
124
- // it('should use provided pikkuConfigFile and pikkuConfigVariable', async () => {
125
- // const options = {
126
- // pikkuConfigFile: 'customConfigFile.ts',
127
- // pikkuConfigVariable: 'customPikkuConfigVariable',
128
- // }
129
-
130
- // await action(options)
131
-
132
- // assert(
133
- // generateNextJsWrapperStub.calledOnce,
134
- // 'generateNextJsWrapper should be called once'
135
- // )
136
-
137
- // const [, , pikkuConfigImport] = generateNextJsWrapperStub.firstCall.args
138
-
139
- // const expectedImport = `import { customPikkuConfigVariable } from './customConfigFile.ts'`
140
- // assert.strictEqual(
141
- // pikkuConfigImport,
142
- // expectedImport,
143
- // 'pikkuConfigImport should use provided file and variable'
144
- // )
145
- // })
146
-
147
- // it('should handle missing pikkuConfigs and exit', async () => {
148
- // // Modify the stub to simulate missing pikkuConfigs
149
- // extractPikkuInformationStub.resolves({
150
- // pikkuConfigs: {},
151
- // sessionServicesFactories: {
152
- // 'sessionFactoryFile.ts': ['sessionFactoryVariable'],
153
- // },
154
- // singletonServicesFactories: {
155
- // 'singletonFactoryFile.ts': ['singletonFactoryVariable'],
156
- // },
157
- // })
158
-
159
- // await action({})
160
-
161
- // assert(consoleErrorStub.calledWithMatch('Found errors:'))
162
- // assert(consoleErrorStub.calledWithMatch('No PikkuConfig object found'))
163
- // assert(
164
- // processExitStub.calledWith(1),
165
- // 'process.exit should be called with 1'
166
- // )
167
- // assert.isFalse(
168
- // generateNextJsWrapperStub.called,
169
- // 'generateNextJsWrapper should not be called when there is an error'
170
- // )
171
- // })
172
-
173
- // it('should generate correct import paths with packageMappings', async () => {
174
- // // Provide packageMappings in the pikkuConfig
175
- // getPikkuConfigStub.resolves({
176
- // pikkuNextFile: 'nextFile.ts',
177
- // rootDir: 'rootDir',
178
- // routesFile: 'routes.ts',
179
- // configDir: 'configDir',
180
- // packageMappings: {
181
- // 'configFile.ts': '@configs/configFile',
182
- // 'singletonFactoryFile.ts': '@factories/singletonFactory',
183
- // 'sessionFactoryFile.ts': '@factories/sessionFactory',
184
- // },
185
- // schemaDirectory: 'schemas',
186
- // })
187
-
188
- // // Modify getFileImportRelativePath to consider packageMappings
189
- // getFileImportRelativePathStub.callsFake(
190
- // (from: string, to: string, packageMappings: any) => {
191
- // const mappedPackage = packageMappings[to]
192
- // return mappedPackage || `./${path.relative(path.dirname(from), to)}`
193
- // }
194
- // )
195
-
196
- // await action({})
197
-
198
- // assert(
199
- // generateNextJsWrapperStub.calledOnce,
200
- // 'generateNextJsWrapper should be called once'
201
- // )
202
-
203
- // const [
204
- // ,
205
- // ,
206
- // pikkuConfigImport,
207
- // singletonServicesImport,
208
- // sessionServicesImport,
209
- // ] = generateNextJsWrapperStub.firstCall.args
210
-
211
- // const expectedPikkuConfigImport = `import { pikkuConfigVariable } from '@configs/configFile'`
212
- // const expectedSingletonServicesImport = `import { singletonFactoryVariable } from '@factories/singletonFactory'`
213
- // const expectedSessionServicesImport = `import { sessionFactoryVariable } from '@factories/sessionFactory'`
214
-
215
- // assert.strictEqual(
216
- // pikkuConfigImport,
217
- // expectedPikkuConfigImport,
218
- // 'pikkuConfigImport should use package mapping'
219
- // )
220
- // assert.strictEqual(
221
- // singletonServicesImport,
222
- // expectedSingletonServicesImport,
223
- // 'singletonServicesImport should use package mapping'
224
- // )
225
- // assert.strictEqual(
226
- // sessionServicesImport,
227
- // expectedSessionServicesImport,
228
- // 'sessionServicesImport should use package mapping'
229
- // )
230
- // })
231
-
232
- // it('should use provided singletonServicesFactoryFile and singletonServicesFactoryVariable', async () => {
233
- // const options = {
234
- // singletonServicesFactoryFile: 'customSingletonFactoryFile.ts',
235
- // singletonServicesFactoryVariable: 'customSingletonFactoryVariable',
236
- // }
237
-
238
- // await action(options)
239
-
240
- // assert(
241
- // generateNextJsWrapperStub.calledOnce,
242
- // 'generateNextJsWrapper should be called once'
243
- // )
244
-
245
- // const [, , , singletonServicesImport] =
246
- // generateNextJsWrapperStub.firstCall.args
247
-
248
- // const expectedImport = `import { customSingletonFactoryVariable } from './customSingletonFactoryFile.ts'`
249
- // assert.strictEqual(
250
- // singletonServicesImport,
251
- // expectedImport,
252
- // 'singletonServicesImport should use provided file and variable'
253
- // )
254
- // })
255
-
256
- // it('should use provided sessionServicesFactoryFile and sessionServicesFactoryVariable', async () => {
257
- // const options = {
258
- // sessionServicesFactoryFile: 'customSessionFactoryFile.ts',
259
- // sessionServicesFactoryVariable: 'customSessionFactoryVariable',
260
- // }
261
-
262
- // await action(options)
263
-
264
- // assert(
265
- // generateNextJsWrapperStub.calledOnce,
266
- // 'generateNextJsWrapper should be called once'
267
- // )
268
-
269
- // const [, , , , sessionServicesImport] =
270
- // generateNextJsWrapperStub.firstCall.args
271
-
272
- // const expectedImport = `import { customSessionFactoryVariable } from './customSessionFactoryFile.ts'`
273
- // assert.strictEqual(
274
- // sessionServicesImport,
275
- // expectedImport,
276
- // 'sessionServicesImport should use provided file and variable'
277
- // )
278
- // })
279
- // })
@@ -1,152 +0,0 @@
1
- import { Command } from 'commander'
2
- import { serializeNextJsBackendWrapper as serializeNextBackendWrapper } from '../src/nextjs/serialize-nextjs-backend-wrapper.js'
3
- import { serializeNextJsHTTPWrapper as serializeNextHTTPWrapper } from '../src/nextjs/serialize-nextjs-http-wrapper.js'
4
- import {
5
- getFileImportRelativePath,
6
- getPikkuFilesAndMethods,
7
- logCommandInfoAndTime,
8
- logPikkuLogo,
9
- PikkuCLIOptions,
10
- writeFileInDir,
11
- } from '../src/utils.js'
12
- import { getPikkuCLIConfig, PikkuCLIConfig } from '../src/pikku-cli-config.js'
13
- import { InspectorState } from '@pikku/inspector'
14
- import { inspectorGlob } from '../src/inspector-glob.js'
15
-
16
- export const pikkuNext = async (
17
- {
18
- nextBackendFile,
19
- nextHTTPFile,
20
- routesFile,
21
- routesMapDeclarationFile,
22
- schemaDirectory,
23
- packageMappings,
24
- fetchFile,
25
- }: PikkuCLIConfig,
26
- visitState: InspectorState,
27
- options: PikkuCLIOptions
28
- ) => {
29
- return await logCommandInfoAndTime(
30
- 'Generating nextjs wrapper',
31
- 'Generated nextjs wrapper',
32
- [
33
- nextBackendFile === undefined && nextHTTPFile === undefined,
34
- 'nextjs outfile is not defined',
35
- ],
36
- async () => {
37
- if (!nextBackendFile && !nextHTTPFile) {
38
- throw new Error(
39
- 'nextBackendFile or nextHTTPFile is required in pikku config for nextJS'
40
- )
41
- }
42
-
43
- if (nextHTTPFile && !fetchFile) {
44
- throw new Error(
45
- 'fetchFile is required in pikku config in order for nextJS http wrapper to work'
46
- )
47
- }
48
-
49
- if (nextBackendFile) {
50
- const {
51
- pikkuConfigFactory,
52
- singletonServicesFactory,
53
- sessionServicesFactory,
54
- } = await getPikkuFilesAndMethods(
55
- visitState,
56
- packageMappings,
57
- nextBackendFile,
58
- options,
59
- {
60
- config: true,
61
- singletonServicesFactory: true,
62
- sessionServicesFactory: true,
63
- }
64
- )
65
-
66
- const pikkuConfigImport = `import { ${pikkuConfigFactory.variable} as createConfig } from '${getFileImportRelativePath(nextBackendFile, pikkuConfigFactory.file, packageMappings)}'`
67
- const singletonServicesImport = `import { ${singletonServicesFactory.variable} as createSingletonServices } from '${getFileImportRelativePath(nextBackendFile, singletonServicesFactory.file, packageMappings)}'`
68
- const sessionServicesImport = `import { ${sessionServicesFactory.variable} as createSessionServices } from '${getFileImportRelativePath(nextBackendFile, sessionServicesFactory.file, packageMappings)}'`
69
-
70
- const routesPath = getFileImportRelativePath(
71
- nextBackendFile,
72
- routesFile,
73
- packageMappings
74
- )
75
-
76
- const routesMapDeclarationPath = getFileImportRelativePath(
77
- nextBackendFile,
78
- routesMapDeclarationFile,
79
- packageMappings
80
- )
81
- const schemasPath = getFileImportRelativePath(
82
- nextBackendFile,
83
- `${schemaDirectory}/register.gen.ts`,
84
- packageMappings
85
- )
86
-
87
- const content = serializeNextBackendWrapper(
88
- routesPath,
89
- routesMapDeclarationPath,
90
- schemasPath,
91
- pikkuConfigImport,
92
- singletonServicesImport,
93
- sessionServicesImport
94
- )
95
- await writeFileInDir(nextBackendFile, content)
96
- }
97
-
98
- if (nextHTTPFile) {
99
- const routesPath = getFileImportRelativePath(
100
- nextHTTPFile,
101
- routesFile,
102
- packageMappings
103
- )
104
-
105
- const routesMapDeclarationPath = getFileImportRelativePath(
106
- nextHTTPFile,
107
- routesMapDeclarationFile,
108
- packageMappings
109
- )
110
-
111
- const content = serializeNextHTTPWrapper(
112
- routesPath,
113
- routesMapDeclarationPath
114
- )
115
- await writeFileInDir(nextHTTPFile, content)
116
- }
117
- }
118
- )
119
- }
120
-
121
- export const action = async (options: PikkuCLIOptions): Promise<void> => {
122
- logPikkuLogo()
123
- const cliConfig = await getPikkuCLIConfig(
124
- options.config,
125
- ['rootDir', 'schemaDirectory', 'configDir'],
126
- options.tags,
127
- true
128
- )
129
- const visitState = await inspectorGlob(
130
- cliConfig.rootDir,
131
- cliConfig.routeDirectories,
132
- cliConfig.filters
133
- )
134
- await pikkuNext(cliConfig, visitState, options)
135
- }
136
-
137
- export const nextjs = (program: Command): void => {
138
- program
139
- .command('nextjs')
140
- .description('generate nextjs wrapper')
141
- .option('-ct | --pikku-config-type', 'The type of your pikku config object')
142
- .option(
143
- '-ss | --singleton-services-factory-type',
144
- 'The type of your singleton services factory'
145
- )
146
- .option(
147
- '-se | --session-services-factory-type',
148
- 'The type of your session services factory'
149
- )
150
- .option('-c | --config <string>', 'The path to pikku cli config file')
151
- .action(action)
152
- }
@@ -1,70 +0,0 @@
1
- import { Command } from 'commander'
2
- import {
3
- logCommandInfoAndTime,
4
- logPikkuLogo,
5
- PikkuCLIOptions,
6
- writeFileInDir,
7
- } from '../src/utils.js'
8
- import { generateSchemas } from '../src/schema/schema-generator.js'
9
- import { generateOpenAPISpec } from '../src/openapi/openapi-spec-generator.js'
10
- import { getPikkuCLIConfig, PikkuCLIConfig } from '../src/pikku-cli-config.js'
11
- import { InspectorState } from '@pikku/inspector'
12
- import { stringify } from 'yaml'
13
- import { inspectorGlob } from '../src/inspector-glob.js'
14
-
15
- export const pikkuOpenAPI = async (
16
- { tsconfig, openAPI }: PikkuCLIConfig,
17
- { http }: InspectorState
18
- ) => {
19
- await logCommandInfoAndTime(
20
- 'Creating OpenAPI spec',
21
- 'Created OpenAPI spec',
22
- [openAPI?.outputFile === undefined, 'openAPI outfile is not defined'],
23
- async () => {
24
- if (!openAPI?.outputFile) {
25
- throw new Error('openAPI is required')
26
- }
27
- const schemas = await generateSchemas(tsconfig, http.typesMap, http.meta)
28
- const openAPISpec = await generateOpenAPISpec(
29
- http.meta,
30
- schemas,
31
- openAPI.additionalInfo
32
- )
33
- if (openAPI.outputFile.endsWith('.json')) {
34
- await writeFileInDir(
35
- openAPI.outputFile,
36
- JSON.stringify(openAPISpec, null, 2),
37
- true
38
- )
39
- } else if (
40
- openAPI.outputFile.endsWith('.yaml') ||
41
- openAPI.outputFile.endsWith('.yml')
42
- ) {
43
- await writeFileInDir(openAPI.outputFile, stringify(openAPISpec), true)
44
- }
45
- }
46
- )
47
- }
48
-
49
- async function action({ config, tags }: PikkuCLIOptions): Promise<void> {
50
- logPikkuLogo()
51
- const cliConfig = await getPikkuCLIConfig(
52
- config,
53
- ['rootDir', 'routesFile', 'openAPI', 'schemaDirectory', 'tsconfig'],
54
- tags
55
- )
56
- const visitState = await inspectorGlob(
57
- cliConfig.rootDir,
58
- cliConfig.routeDirectories,
59
- cliConfig.filters
60
- )
61
- await pikkuOpenAPI(cliConfig, visitState)
62
- }
63
-
64
- export const openapi = (program: Command): void => {
65
- program
66
- .command('openapi')
67
- .description('Generate an openapi spec')
68
- .option('-c | --config <string>', 'The path to pikku cli config file')
69
- .action(action)
70
- }
@@ -1,55 +0,0 @@
1
- import { Command } from 'commander'
2
- import { getPikkuCLIConfig, PikkuCLIConfig } from '../src/pikku-cli-config.js'
3
- import { InspectorState } from '@pikku/inspector'
4
- import {
5
- logCommandInfoAndTime,
6
- logPikkuLogo,
7
- PikkuCLIOptions,
8
- writeFileInDir,
9
- } from '../src/utils.js'
10
- import { serializeTypedRoutesMap } from '../src/http/serialize-typed-route-map.js'
11
- import { inspectorGlob } from '../src/inspector-glob.js'
12
-
13
- export const pikkuHTTPMap = async (
14
- { routesMapDeclarationFile, packageMappings }: PikkuCLIConfig,
15
- { http }: InspectorState
16
- ) => {
17
- return await logCommandInfoAndTime(
18
- 'Creating routes map',
19
- 'Created routes map',
20
- [http.files.size === 0],
21
- async () => {
22
- const content = serializeTypedRoutesMap(
23
- routesMapDeclarationFile,
24
- packageMappings,
25
- http.typesMap,
26
- http.meta,
27
- http.metaInputTypes
28
- )
29
- await writeFileInDir(routesMapDeclarationFile, content)
30
- }
31
- )
32
- }
33
-
34
- async function action(cliOptions: PikkuCLIOptions): Promise<void> {
35
- logPikkuLogo()
36
- const cliConfig = await getPikkuCLIConfig(
37
- cliOptions.config,
38
- ['rootDir', 'routeDirectories', 'routesFile'],
39
- cliOptions.tags
40
- )
41
- const visitState = await inspectorGlob(
42
- cliConfig.rootDir,
43
- cliConfig.routeDirectories,
44
- cliConfig.filters
45
- )
46
- await pikkuHTTPMap(cliConfig, visitState)
47
- }
48
-
49
- export const routesMap = (program: Command): void => {
50
- program
51
- .command('map')
52
- .description('Generate a map of all routes to aid in type checking')
53
- .option('-c | --config <string>', 'The path to pikku cli config file')
54
- .action(action)
55
- }
@@ -1,62 +0,0 @@
1
- import { Command } from 'commander'
2
- import { getPikkuCLIConfig, PikkuCLIConfig } from '../src/pikku-cli-config.js'
3
- import { InspectorState } from '@pikku/inspector'
4
- import {
5
- logCommandInfoAndTime,
6
- logPikkuLogo,
7
- PikkuCLIOptions,
8
- writeFileInDir,
9
- } from '../src/utils.js'
10
- import {
11
- serializeSchedulerMeta,
12
- serializeSchedulers,
13
- } from '../src/scheduler/serialize-schedulers.js'
14
- import { inspectorGlob } from '../src/inspector-glob.js'
15
-
16
- export const pikkuScheduler = async (
17
- cliConfig: PikkuCLIConfig,
18
- visitState: InspectorState
19
- ) => {
20
- return await logCommandInfoAndTime(
21
- 'Finding scheduled tasks',
22
- 'Found scheduled tasks',
23
- [visitState.scheduledTasks.files.size === 0],
24
- async () => {
25
- const { schedulersFile, packageMappings } = cliConfig
26
- const { scheduledTasks } = visitState
27
- const content = [
28
- serializeSchedulers(
29
- schedulersFile,
30
- scheduledTasks.files,
31
- packageMappings
32
- ),
33
- serializeSchedulerMeta(scheduledTasks.meta),
34
- ]
35
- await writeFileInDir(schedulersFile, content.join('\n\n'))
36
- }
37
- )
38
- }
39
-
40
- async function action(options: PikkuCLIOptions): Promise<void> {
41
- logPikkuLogo()
42
-
43
- const cliConfig = await getPikkuCLIConfig(
44
- options.config,
45
- ['rootDir', 'routeDirectories', 'routesFile'],
46
- options.tags
47
- )
48
- const visitState = await inspectorGlob(
49
- cliConfig.rootDir,
50
- cliConfig.routeDirectories,
51
- cliConfig.filters
52
- )
53
- await pikkuScheduler(cliConfig, visitState)
54
- }
55
-
56
- export const schedules = (program: Command): void => {
57
- program
58
- .command('scheduler')
59
- .description('Find all scheduled tasks to import')
60
- .option('-c | --config <string>', 'The path to pikku cli config file')
61
- .action(action)
62
- }
@@ -1,52 +0,0 @@
1
- import { Command } from 'commander'
2
- import { saveSchemas, generateSchemas } from '../src/schema/schema-generator.js'
3
-
4
- import { getPikkuCLIConfig, PikkuCLIConfig } from '../src/pikku-cli-config.js'
5
- import { InspectorState } from '@pikku/inspector'
6
- import { logCommandInfoAndTime, logPikkuLogo } from '../src/utils.js'
7
- import { inspectorGlob } from '../src/inspector-glob.js'
8
-
9
- export const pikkuSchemas = async (
10
- { tsconfig, schemaDirectory, supportsImportAttributes }: PikkuCLIConfig,
11
- { http }: InspectorState
12
- ) => {
13
- return await logCommandInfoAndTime(
14
- 'Creating schemas',
15
- 'Created schemas',
16
- [false],
17
- async () => {
18
- const schemas = await generateSchemas(tsconfig, http.typesMap, http.meta)
19
- await saveSchemas(
20
- schemaDirectory,
21
- schemas,
22
- http.typesMap,
23
- http.meta,
24
- supportsImportAttributes
25
- )
26
- }
27
- )
28
- }
29
-
30
- async function action({ config }: { config?: string }): Promise<void> {
31
- logPikkuLogo()
32
-
33
- const cliConfig = await getPikkuCLIConfig(config, [
34
- 'routeDirectories',
35
- 'schemaDirectory',
36
- 'tsconfig',
37
- ])
38
- const visitState = await inspectorGlob(
39
- cliConfig.rootDir,
40
- cliConfig.routeDirectories,
41
- cliConfig.filters
42
- )
43
- await pikkuSchemas(cliConfig, visitState)
44
- }
45
-
46
- export const schemas = (program: Command): void => {
47
- program
48
- .command('schemas')
49
- .description('Generate schemas for all the expected function input types')
50
- .option('-c | --config <string>', 'The path to pikku cli config file')
51
- .action(action)
52
- }