@pikku/cli 0.7.0 → 0.7.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.
- package/CHANGELOG.md +9 -0
- package/bin/pikku-all.ts +203 -0
- package/bin/pikku-channels-map.ts +55 -0
- package/bin/pikku-channels.ts +63 -0
- package/bin/pikku-fetch.ts +55 -0
- package/bin/pikku-function-types.ts +84 -0
- package/bin/pikku-functions.ts +35 -0
- package/bin/pikku-http-map.ts +55 -0
- package/bin/pikku-http-routes.ts +63 -0
- package/bin/pikku-nextjs.test.ts +279 -0
- package/bin/pikku-nextjs.ts +152 -0
- package/bin/pikku-openapi.ts +74 -0
- package/bin/pikku-rpc.ts +22 -0
- package/bin/pikku-scheduler.ts +64 -0
- package/bin/pikku-schemas.ts +56 -0
- package/bin/pikku-websocket.ts +58 -0
- package/bin/pikku.ts +26 -0
- package/dist/bin/pikku-all.js +3 -0
- package/dist/bin/pikku-functions.d.ts +0 -2
- package/dist/bin/pikku-functions.js +2 -17
- package/dist/bin/pikku-rpc.d.ts +3 -0
- package/dist/bin/pikku-rpc.js +8 -0
- package/dist/bin/pikku.js +0 -0
- package/dist/src/pikku-cli-config.d.ts +1 -0
- package/dist/src/pikku-cli-config.js +3 -0
- package/dist/src/schema-generator.js +1 -2
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +3 -3
- package/src/inspector-glob.ts +28 -0
- package/src/openapi-spec-generator.ts +227 -0
- package/src/pikku-cli-config.ts +240 -0
- package/src/schema-generator.ts +136 -0
- package/{dist/src/events/http/serialize-fetch-wrapper.js → src/serialize-fetch-wrapper.ts} +4 -4
- package/src/serialize-import-map.ts +34 -0
- package/{dist/src/nextjs/serialize-nextjs-backend-wrapper.js → src/serialize-nextjs-backend-wrapper.ts} +11 -4
- package/{dist/src/nextjs/serialize-nextjs-http-wrapper.js → src/serialize-nextjs-http-wrapper.ts} +7 -4
- package/{dist/src/core/serialize-pikku-types.js → src/serialize-pikku-types.ts} +46 -35
- package/src/serialize-scheduler-meta.ts +18 -0
- package/src/serialize-typed-channel-map.ts +138 -0
- package/src/serialize-typed-function-map.ts +151 -0
- package/src/serialize-typed-http-map.ts +151 -0
- package/{dist/src/channels/serialize-websocket-wrapper.js → src/serialize-websocket-wrapper.ts} +4 -4
- package/src/utils.ts +284 -0
- package/tsconfig.json +21 -0
- package/dist/bin/pikku-http.d.ts +0 -5
- package/dist/bin/pikku-http.js +0 -27
- package/dist/bin/pikku-routes-map.d.ts +0 -5
- package/dist/bin/pikku-routes-map.js +0 -23
- package/dist/src/channels/serialize-channels.d.ts +0 -3
- package/dist/src/channels/serialize-channels.js +0 -19
- package/dist/src/channels/serialize-typed-channel-map.d.ts +0 -3
- package/dist/src/channels/serialize-typed-channel-map.js +0 -93
- package/dist/src/channels/serialize-websocket-wrapper.d.ts +0 -1
- package/dist/src/core/serialize-import-map.d.ts +0 -2
- package/dist/src/core/serialize-import-map.js +0 -24
- package/dist/src/core/serialize-pikku-types.d.ts +0 -4
- package/dist/src/events/channels/serialize-channels.d.ts +0 -3
- package/dist/src/events/channels/serialize-channels.js +0 -19
- package/dist/src/events/channels/serialize-typed-channel-map.d.ts +0 -3
- package/dist/src/events/channels/serialize-typed-channel-map.js +0 -90
- package/dist/src/events/channels/serialize-websocket-wrapper.d.ts +0 -1
- package/dist/src/events/channels/serialize-websocket-wrapper.js +0 -61
- package/dist/src/events/http/serialize-fetch-wrapper.d.ts +0 -1
- package/dist/src/events/http/serialize-route-imports.d.ts +0 -1
- package/dist/src/events/http/serialize-route-imports.js +0 -13
- package/dist/src/events/http/serialize-route-meta.d.ts +0 -2
- package/dist/src/events/http/serialize-route-meta.js +0 -6
- package/dist/src/events/http/serialize-typed-route-map.d.ts +0 -4
- package/dist/src/events/http/serialize-typed-route-map.js +0 -107
- package/dist/src/events/scheduler/serialize-schedulers.d.ts +0 -3
- package/dist/src/events/scheduler/serialize-schedulers.js +0 -23
- package/dist/src/http/serialize-fetch-wrapper.d.ts +0 -1
- package/dist/src/http/serialize-fetch-wrapper.js +0 -67
- package/dist/src/http/serialize-route-imports.d.ts +0 -1
- package/dist/src/http/serialize-route-imports.js +0 -13
- package/dist/src/http/serialize-route-meta.d.ts +0 -2
- package/dist/src/http/serialize-route-meta.js +0 -6
- package/dist/src/http/serialize-typed-route-map.d.ts +0 -4
- package/dist/src/http/serialize-typed-route-map.js +0 -107
- package/dist/src/nextjs/serialize-nextjs-backend-wrapper.d.ts +0 -1
- package/dist/src/nextjs/serialize-nextjs-http-wrapper.d.ts +0 -1
- package/dist/src/openapi/openapi-spec-generator.d.ts +0 -79
- package/dist/src/openapi/openapi-spec-generator.js +0 -136
- package/dist/src/scheduler/serialize-schedulers.d.ts +0 -3
- package/dist/src/scheduler/serialize-schedulers.js +0 -23
- package/dist/src/schema/schema-generator.d.ts +0 -5
- package/dist/src/schema/schema-generator.js +0 -89
- package/dist/src/serialize-typed-route-map.d.ts +0 -4
- package/dist/src/serialize-typed-route-map.js +0 -107
|
@@ -0,0 +1,279 @@
|
|
|
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
|
+
// })
|
|
@@ -0,0 +1,152 @@
|
|
|
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.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
|
+
httpRoutesFile,
|
|
21
|
+
httpRoutesMapDeclarationFile,
|
|
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
|
+
httpRoutesFile,
|
|
73
|
+
packageMappings
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
const routesMapDeclarationPath = getFileImportRelativePath(
|
|
77
|
+
nextBackendFile,
|
|
78
|
+
httpRoutesMapDeclarationFile,
|
|
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
|
+
httpRoutesFile,
|
|
102
|
+
packageMappings
|
|
103
|
+
)
|
|
104
|
+
|
|
105
|
+
const routesMapDeclarationPath = getFileImportRelativePath(
|
|
106
|
+
nextHTTPFile,
|
|
107
|
+
httpRoutesMapDeclarationFile,
|
|
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.srcDirectories,
|
|
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
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
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-generator.js'
|
|
9
|
+
import { generateOpenAPISpec } from '../src/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, functions }: 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(
|
|
28
|
+
tsconfig,
|
|
29
|
+
[http.typesMap, functions.typesMap],
|
|
30
|
+
http.meta
|
|
31
|
+
)
|
|
32
|
+
const openAPISpec = await generateOpenAPISpec(
|
|
33
|
+
http.meta,
|
|
34
|
+
schemas,
|
|
35
|
+
openAPI.additionalInfo
|
|
36
|
+
)
|
|
37
|
+
if (openAPI.outputFile.endsWith('.json')) {
|
|
38
|
+
await writeFileInDir(
|
|
39
|
+
openAPI.outputFile,
|
|
40
|
+
JSON.stringify(openAPISpec, null, 2),
|
|
41
|
+
true
|
|
42
|
+
)
|
|
43
|
+
} else if (
|
|
44
|
+
openAPI.outputFile.endsWith('.yaml') ||
|
|
45
|
+
openAPI.outputFile.endsWith('.yml')
|
|
46
|
+
) {
|
|
47
|
+
await writeFileInDir(openAPI.outputFile, stringify(openAPISpec), true)
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
async function action({ config, tags }: PikkuCLIOptions): Promise<void> {
|
|
54
|
+
logPikkuLogo()
|
|
55
|
+
const cliConfig = await getPikkuCLIConfig(
|
|
56
|
+
config,
|
|
57
|
+
['rootDir', 'httpRoutesFile', 'openAPI', 'schemaDirectory', 'tsconfig'],
|
|
58
|
+
tags
|
|
59
|
+
)
|
|
60
|
+
const visitState = await inspectorGlob(
|
|
61
|
+
cliConfig.rootDir,
|
|
62
|
+
cliConfig.srcDirectories,
|
|
63
|
+
cliConfig.filters
|
|
64
|
+
)
|
|
65
|
+
await pikkuOpenAPI(cliConfig, visitState)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export const openapi = (program: Command): void => {
|
|
69
|
+
program
|
|
70
|
+
.command('openapi')
|
|
71
|
+
.description('Generate an openapi spec')
|
|
72
|
+
.option('-c | --config <string>', 'The path to pikku cli config file')
|
|
73
|
+
.action(action)
|
|
74
|
+
}
|
package/bin/pikku-rpc.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { PikkuCLIConfig } from '../src/pikku-cli-config.js'
|
|
2
|
+
import { InspectorState } from '@pikku/inspector'
|
|
3
|
+
import { logCommandInfoAndTime, writeFileInDir } from '../src/utils.js'
|
|
4
|
+
|
|
5
|
+
export const pikkuRPC = async (
|
|
6
|
+
cliConfig: PikkuCLIConfig,
|
|
7
|
+
visitState: InspectorState
|
|
8
|
+
) => {
|
|
9
|
+
return await logCommandInfoAndTime(
|
|
10
|
+
'Finding RPCs tasks',
|
|
11
|
+
'Found rpcs',
|
|
12
|
+
[visitState.functions.files.size === 0],
|
|
13
|
+
async () => {
|
|
14
|
+
const { rpcFile } = cliConfig
|
|
15
|
+
const { rpc } = visitState
|
|
16
|
+
await writeFileInDir(
|
|
17
|
+
rpcFile,
|
|
18
|
+
`import { pikkuState } from '@pikku/core'\npikkuState('rpc', 'meta', ${JSON.stringify(rpc.meta, null, 2)})`
|
|
19
|
+
)
|
|
20
|
+
}
|
|
21
|
+
)
|
|
22
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
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
|
+
serializeFileImports,
|
|
9
|
+
writeFileInDir,
|
|
10
|
+
} from '../src/utils.js'
|
|
11
|
+
import { serializeSchedulerMeta } from '../src/serialize-scheduler-meta.js'
|
|
12
|
+
import { inspectorGlob } from '../src/inspector-glob.js'
|
|
13
|
+
|
|
14
|
+
export const pikkuScheduler = async (
|
|
15
|
+
cliConfig: PikkuCLIConfig,
|
|
16
|
+
visitState: InspectorState
|
|
17
|
+
) => {
|
|
18
|
+
return await logCommandInfoAndTime(
|
|
19
|
+
'Finding scheduled tasks',
|
|
20
|
+
'Found scheduled tasks',
|
|
21
|
+
[visitState.scheduledTasks.files.size === 0],
|
|
22
|
+
async () => {
|
|
23
|
+
const { schedulersFile, schedulersMetaFile, packageMappings } = cliConfig
|
|
24
|
+
const { scheduledTasks } = visitState
|
|
25
|
+
await writeFileInDir(
|
|
26
|
+
schedulersMetaFile,
|
|
27
|
+
serializeSchedulerMeta(scheduledTasks.meta)
|
|
28
|
+
)
|
|
29
|
+
await writeFileInDir(
|
|
30
|
+
schedulersFile,
|
|
31
|
+
serializeFileImports(
|
|
32
|
+
'addSerializedTasks',
|
|
33
|
+
schedulersFile,
|
|
34
|
+
scheduledTasks.files,
|
|
35
|
+
packageMappings
|
|
36
|
+
)
|
|
37
|
+
)
|
|
38
|
+
}
|
|
39
|
+
)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
async function action(options: PikkuCLIOptions): Promise<void> {
|
|
43
|
+
logPikkuLogo()
|
|
44
|
+
|
|
45
|
+
const cliConfig = await getPikkuCLIConfig(
|
|
46
|
+
options.config,
|
|
47
|
+
['rootDir', 'srcDirectories', 'httpRoutesFile'],
|
|
48
|
+
options.tags
|
|
49
|
+
)
|
|
50
|
+
const visitState = await inspectorGlob(
|
|
51
|
+
cliConfig.rootDir,
|
|
52
|
+
cliConfig.srcDirectories,
|
|
53
|
+
cliConfig.filters
|
|
54
|
+
)
|
|
55
|
+
await pikkuScheduler(cliConfig, visitState)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export const schedules = (program: Command): void => {
|
|
59
|
+
program
|
|
60
|
+
.command('scheduler')
|
|
61
|
+
.description('Find all scheduled tasks to import')
|
|
62
|
+
.option('-c | --config <string>', 'The path to pikku cli config file')
|
|
63
|
+
.action(action)
|
|
64
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { Command } from 'commander'
|
|
2
|
+
import { saveSchemas, generateSchemas } from '../src/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
|
+
{ functions, http, channels }: InspectorState
|
|
12
|
+
) => {
|
|
13
|
+
return await logCommandInfoAndTime(
|
|
14
|
+
'Creating schemas',
|
|
15
|
+
'Created schemas',
|
|
16
|
+
[false],
|
|
17
|
+
async () => {
|
|
18
|
+
const schemas = await generateSchemas(
|
|
19
|
+
tsconfig,
|
|
20
|
+
[functions.typesMap, http.typesMap, channels.typesMap],
|
|
21
|
+
http.meta
|
|
22
|
+
)
|
|
23
|
+
await saveSchemas(
|
|
24
|
+
schemaDirectory,
|
|
25
|
+
schemas,
|
|
26
|
+
functions.typesMap,
|
|
27
|
+
http.meta,
|
|
28
|
+
supportsImportAttributes
|
|
29
|
+
)
|
|
30
|
+
}
|
|
31
|
+
)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async function action({ config }: { config?: string }): Promise<void> {
|
|
35
|
+
logPikkuLogo()
|
|
36
|
+
|
|
37
|
+
const cliConfig = await getPikkuCLIConfig(config, [
|
|
38
|
+
'srcDirectories',
|
|
39
|
+
'schemaDirectory',
|
|
40
|
+
'tsconfig',
|
|
41
|
+
])
|
|
42
|
+
const visitState = await inspectorGlob(
|
|
43
|
+
cliConfig.rootDir,
|
|
44
|
+
cliConfig.srcDirectories,
|
|
45
|
+
cliConfig.filters
|
|
46
|
+
)
|
|
47
|
+
await pikkuSchemas(cliConfig, visitState)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export const schemas = (program: Command): void => {
|
|
51
|
+
program
|
|
52
|
+
.command('schemas')
|
|
53
|
+
.description('Generate schemas for all the expected function input types')
|
|
54
|
+
.option('-c | --config <string>', 'The path to pikku cli config file')
|
|
55
|
+
.action(action)
|
|
56
|
+
}
|