@pikku/cli 0.6.6

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 (95) hide show
  1. package/CHANGELOG.md +445 -0
  2. package/README.md +3 -0
  3. package/bin/pikku-all.ts +110 -0
  4. package/bin/pikku-channels-map.ts +53 -0
  5. package/bin/pikku-channels.ts +57 -0
  6. package/bin/pikku-fetch.ts +54 -0
  7. package/bin/pikku-function-types.ts +76 -0
  8. package/bin/pikku-nextjs.test.ts +279 -0
  9. package/bin/pikku-nextjs.ts +113 -0
  10. package/bin/pikku-openapi.ts +71 -0
  11. package/bin/pikku-routes-map.ts +54 -0
  12. package/bin/pikku-routes.ts +55 -0
  13. package/bin/pikku-scheduler.ts +61 -0
  14. package/bin/pikku-schemas.ts +51 -0
  15. package/bin/pikku-websocket.ts +54 -0
  16. package/bin/pikku.ts +26 -0
  17. package/cli.schema.json +212 -0
  18. package/dist/bin/pikku-all.d.ts +4 -0
  19. package/dist/bin/pikku-all.js +71 -0
  20. package/dist/bin/pikku-channels-map.d.ts +5 -0
  21. package/dist/bin/pikku-channels-map.js +27 -0
  22. package/dist/bin/pikku-channels.d.ts +5 -0
  23. package/dist/bin/pikku-channels.js +32 -0
  24. package/dist/bin/pikku-fetch.d.ts +6 -0
  25. package/dist/bin/pikku-fetch.js +25 -0
  26. package/dist/bin/pikku-function-types.d.ts +6 -0
  27. package/dist/bin/pikku-function-types.js +32 -0
  28. package/dist/bin/pikku-nextjs.d.ts +7 -0
  29. package/dist/bin/pikku-nextjs.js +40 -0
  30. package/dist/bin/pikku-openapi.d.ts +5 -0
  31. package/dist/bin/pikku-openapi.js +41 -0
  32. package/dist/bin/pikku-routes-map.d.ts +5 -0
  33. package/dist/bin/pikku-routes-map.js +27 -0
  34. package/dist/bin/pikku-routes.d.ts +5 -0
  35. package/dist/bin/pikku-routes.js +33 -0
  36. package/dist/bin/pikku-scheduler.d.ts +5 -0
  37. package/dist/bin/pikku-scheduler.js +32 -0
  38. package/dist/bin/pikku-schemas.d.ts +5 -0
  39. package/dist/bin/pikku-schemas.js +27 -0
  40. package/dist/bin/pikku-websocket.d.ts +6 -0
  41. package/dist/bin/pikku-websocket.js +25 -0
  42. package/dist/bin/pikku.d.ts +2 -0
  43. package/dist/bin/pikku.js +23 -0
  44. package/dist/src/channels/serialize-channels.d.ts +3 -0
  45. package/dist/src/channels/serialize-channels.js +19 -0
  46. package/dist/src/channels/serialize-typed-channel-map.d.ts +3 -0
  47. package/dist/src/channels/serialize-typed-channel-map.js +87 -0
  48. package/dist/src/channels/serialize-websocket-wrapper.d.ts +1 -0
  49. package/dist/src/channels/serialize-websocket-wrapper.js +61 -0
  50. package/dist/src/core/serialize-import-map.d.ts +2 -0
  51. package/dist/src/core/serialize-import-map.js +23 -0
  52. package/dist/src/core/serialize-pikku-types.d.ts +4 -0
  53. package/dist/src/core/serialize-pikku-types.js +48 -0
  54. package/dist/src/http/serialize-fetch-wrapper.d.ts +1 -0
  55. package/dist/src/http/serialize-fetch-wrapper.js +57 -0
  56. package/dist/src/http/serialize-route-imports.d.ts +1 -0
  57. package/dist/src/http/serialize-route-imports.js +13 -0
  58. package/dist/src/http/serialize-route-meta.d.ts +2 -0
  59. package/dist/src/http/serialize-route-meta.js +6 -0
  60. package/dist/src/http/serialize-typed-route-map.d.ts +3 -0
  61. package/dist/src/http/serialize-typed-route-map.js +107 -0
  62. package/dist/src/inspector-glob.d.ts +2 -0
  63. package/dist/src/inspector-glob.js +12 -0
  64. package/dist/src/nextjs/serialize-nextjs-wrapper.d.ts +1 -0
  65. package/dist/src/nextjs/serialize-nextjs-wrapper.js +149 -0
  66. package/dist/src/openapi/openapi-spec-generator.d.ts +79 -0
  67. package/dist/src/openapi/openapi-spec-generator.js +135 -0
  68. package/dist/src/pikku-cli-config.d.ts +31 -0
  69. package/dist/src/pikku-cli-config.js +113 -0
  70. package/dist/src/scheduler/serialize-schedulers.d.ts +3 -0
  71. package/dist/src/scheduler/serialize-schedulers.js +22 -0
  72. package/dist/src/schema/schema-generator.d.ts +5 -0
  73. package/dist/src/schema/schema-generator.js +79 -0
  74. package/dist/src/utils.d.ts +34 -0
  75. package/dist/src/utils.js +109 -0
  76. package/dist/tsconfig.tsbuildinfo +1 -0
  77. package/package.json +42 -0
  78. package/run-tests.sh +53 -0
  79. package/src/channels/serialize-channels.ts +34 -0
  80. package/src/channels/serialize-typed-channel-map.ts +133 -0
  81. package/src/channels/serialize-websocket-wrapper.ts +61 -0
  82. package/src/core/serialize-import-map.ts +33 -0
  83. package/src/core/serialize-pikku-types.ts +53 -0
  84. package/src/http/serialize-fetch-wrapper.ts +57 -0
  85. package/src/http/serialize-route-imports.ts +24 -0
  86. package/src/http/serialize-route-meta.ts +10 -0
  87. package/src/http/serialize-typed-route-map.ts +147 -0
  88. package/src/inspector-glob.ts +27 -0
  89. package/src/nextjs/serialize-nextjs-wrapper.ts +156 -0
  90. package/src/openapi/openapi-spec-generator.ts +229 -0
  91. package/src/pikku-cli-config.ts +189 -0
  92. package/src/scheduler/serialize-schedulers.ts +43 -0
  93. package/src/schema/schema-generator.ts +117 -0
  94. package/src/utils.ts +219 -0
  95. package/tsconfig.json +21 -0
@@ -0,0 +1,61 @@
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(cliOptions: PikkuCLIOptions): Promise<void> {
41
+ logPikkuLogo()
42
+
43
+ const cliConfig = await getPikkuCLIConfig(cliOptions.config, [
44
+ 'rootDir',
45
+ 'routeDirectories',
46
+ 'routesFile',
47
+ ])
48
+ const visitState = await inspectorGlob(
49
+ cliConfig.rootDir,
50
+ cliConfig.routeDirectories
51
+ )
52
+ await pikkuScheduler(cliConfig, visitState)
53
+ }
54
+
55
+ export const schedules = (program: Command): void => {
56
+ program
57
+ .command('scheduler')
58
+ .description('Find all scheduled tasks to import')
59
+ .option('-c | --config <string>', 'The path to pikku cli config file')
60
+ .action(action)
61
+ }
@@ -0,0 +1,51 @@
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
+ )
42
+ await pikkuSchemas(cliConfig, visitState)
43
+ }
44
+
45
+ export const schemas = (program: Command): void => {
46
+ program
47
+ .command('schemas')
48
+ .description('Generate schemas for all the expected function input types')
49
+ .option('-c | --config <string>', 'The path to pikku cli config file')
50
+ .action(action)
51
+ }
@@ -0,0 +1,54 @@
1
+ import { Command } from 'commander'
2
+ import {
3
+ getFileImportRelativePath,
4
+ logCommandInfoAndTime,
5
+ logPikkuLogo,
6
+ PikkuCLIOptions,
7
+ writeFileInDir,
8
+ } from '../src/utils.js'
9
+ import { getPikkuCLIConfig, PikkuCLIConfig } from '../src/pikku-cli-config.js'
10
+ import { serializeWebsocketWrapper } from '../src/channels/serialize-websocket-wrapper.js'
11
+
12
+ export const pikkuWebSocket = async ({
13
+ websocketFile,
14
+ channelsMapDeclarationFile,
15
+ packageMappings,
16
+ }: PikkuCLIConfig) => {
17
+ await logCommandInfoAndTime(
18
+ 'Generating websocket wrapper',
19
+ 'Generated websocket wrapper',
20
+ [websocketFile === undefined, 'websocketFile is required in pikku config'],
21
+ async () => {
22
+ if (!websocketFile) {
23
+ throw new Error('fetchFile is required in pikku config')
24
+ }
25
+
26
+ const channelsMapDeclarationPath = getFileImportRelativePath(
27
+ websocketFile,
28
+ channelsMapDeclarationFile,
29
+ packageMappings
30
+ )
31
+
32
+ const content = [serializeWebsocketWrapper(channelsMapDeclarationPath)]
33
+ await writeFileInDir(websocketFile, content.join('\n'))
34
+ }
35
+ )
36
+ }
37
+
38
+ export const action = async (options: PikkuCLIOptions): Promise<void> => {
39
+ logPikkuLogo()
40
+ const cliConfig = await getPikkuCLIConfig(
41
+ options.config,
42
+ ['rootDir', 'schemaDirectory', 'configDir', 'fetchFile'],
43
+ true
44
+ )
45
+ await pikkuWebSocket(cliConfig)
46
+ }
47
+
48
+ export const websocket = (program: Command): void => {
49
+ program
50
+ .command('websocket')
51
+ .description('generate websocket wrapper')
52
+ .option('-c | --config <string>', 'The path to pikku cli config file')
53
+ .action(action)
54
+ }
package/bin/pikku.ts ADDED
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/env node
2
+ import { Command } from 'commander'
3
+ import { schemas } from './pikku-schemas.js'
4
+ import { routes } from './pikku-routes.js'
5
+ import { nextjs } from './pikku-nextjs.js'
6
+ import { all } from './pikku-all.js'
7
+ import { functionTypes } from './pikku-function-types.js'
8
+ import { routesMap } from './pikku-routes-map.js'
9
+ import { fetch } from './pikku-fetch.js'
10
+ import { channels } from './pikku-channels.js'
11
+ import { schedules } from './pikku-scheduler.js'
12
+
13
+ const program = new Command('pikku')
14
+ program.usage('[command]')
15
+
16
+ all(program)
17
+ routes(program)
18
+ routesMap(program)
19
+ functionTypes(program)
20
+ schemas(program)
21
+ nextjs(program)
22
+ fetch(program)
23
+ channels(program)
24
+ schedules(program)
25
+
26
+ program.parse(process.argv)
@@ -0,0 +1,212 @@
1
+ {
2
+ "$ref": "#/definitions/PikkuCLIConfig",
3
+ "$schema": "http://json-schema.org/draft-07/schema#",
4
+ "definitions": {
5
+ "OpenAPISpecInfo": {
6
+ "additionalProperties": false,
7
+ "properties": {
8
+ "externalDocs": {
9
+ "additionalProperties": false,
10
+ "properties": {
11
+ "description": {
12
+ "type": "string"
13
+ },
14
+ "url": {
15
+ "type": "string"
16
+ }
17
+ },
18
+ "required": ["url"],
19
+ "type": "object"
20
+ },
21
+ "info": {
22
+ "additionalProperties": false,
23
+ "properties": {
24
+ "contact": {
25
+ "additionalProperties": false,
26
+ "properties": {
27
+ "email": {
28
+ "type": "string"
29
+ },
30
+ "name": {
31
+ "type": "string"
32
+ },
33
+ "url": {
34
+ "type": "string"
35
+ }
36
+ },
37
+ "type": "object"
38
+ },
39
+ "description": {
40
+ "type": "string"
41
+ },
42
+ "license": {
43
+ "additionalProperties": false,
44
+ "properties": {
45
+ "name": {
46
+ "type": "string"
47
+ },
48
+ "url": {
49
+ "type": "string"
50
+ }
51
+ },
52
+ "required": ["name"],
53
+ "type": "object"
54
+ },
55
+ "termsOfService": {
56
+ "type": "string"
57
+ },
58
+ "title": {
59
+ "type": "string"
60
+ },
61
+ "version": {
62
+ "type": "string"
63
+ }
64
+ },
65
+ "required": ["title", "version", "description"],
66
+ "type": "object"
67
+ },
68
+ "security": {
69
+ "items": {
70
+ "additionalProperties": {
71
+ "items": {},
72
+ "type": "array"
73
+ },
74
+ "type": "object"
75
+ },
76
+ "type": "array"
77
+ },
78
+ "securitySchemes": {
79
+ "type": "object"
80
+ },
81
+ "servers": {
82
+ "items": {
83
+ "additionalProperties": false,
84
+ "properties": {
85
+ "description": {
86
+ "type": "string"
87
+ },
88
+ "url": {
89
+ "type": "string"
90
+ }
91
+ },
92
+ "required": ["url"],
93
+ "type": "object"
94
+ },
95
+ "type": "array"
96
+ },
97
+ "tags": {
98
+ "items": {
99
+ "additionalProperties": false,
100
+ "properties": {
101
+ "description": {
102
+ "type": "string"
103
+ },
104
+ "name": {
105
+ "type": "string"
106
+ }
107
+ },
108
+ "required": ["name"],
109
+ "type": "object"
110
+ },
111
+ "type": "array"
112
+ }
113
+ },
114
+ "required": ["info", "servers"],
115
+ "type": "object"
116
+ },
117
+ "PikkuCLIConfig": {
118
+ "additionalProperties": false,
119
+ "properties": {
120
+ "$schema": {
121
+ "type": "string"
122
+ },
123
+ "bootstrapFile": {
124
+ "type": "string"
125
+ },
126
+ "channelsFile": {
127
+ "type": "string"
128
+ },
129
+ "channelsMapDeclarationFile": {
130
+ "type": "string"
131
+ },
132
+ "configDir": {
133
+ "type": "string"
134
+ },
135
+ "extends": {
136
+ "type": "string"
137
+ },
138
+ "fetchFile": {
139
+ "type": "string"
140
+ },
141
+ "nextJSfile": {
142
+ "type": "string"
143
+ },
144
+ "openAPI": {
145
+ "additionalProperties": false,
146
+ "properties": {
147
+ "additionalInfo": {
148
+ "$ref": "#/definitions/OpenAPISpecInfo"
149
+ },
150
+ "outputFile": {
151
+ "type": "string"
152
+ }
153
+ },
154
+ "required": ["outputFile", "additionalInfo"],
155
+ "type": "object"
156
+ },
157
+ "outDir": {
158
+ "type": "string"
159
+ },
160
+ "packageMappings": {
161
+ "additionalProperties": {
162
+ "type": "string"
163
+ },
164
+ "type": "object"
165
+ },
166
+ "rootDir": {
167
+ "type": "string"
168
+ },
169
+ "routeDirectories": {
170
+ "items": {
171
+ "type": "string"
172
+ },
173
+ "type": "array"
174
+ },
175
+ "routesFile": {
176
+ "type": "string"
177
+ },
178
+ "routesMapDeclarationFile": {
179
+ "type": "string"
180
+ },
181
+ "schedulersFile": {
182
+ "type": "string"
183
+ },
184
+ "schemaDirectory": {
185
+ "type": "string"
186
+ },
187
+ "tsconfig": {
188
+ "type": "string"
189
+ },
190
+ "typesDeclarationFile": {
191
+ "type": "string"
192
+ }
193
+ },
194
+ "required": [
195
+ "bootstrapFile",
196
+ "channelsFile",
197
+ "channelsMapDeclarationFile",
198
+ "configDir",
199
+ "packageMappings",
200
+ "rootDir",
201
+ "routeDirectories",
202
+ "routesFile",
203
+ "routesMapDeclarationFile",
204
+ "schedulersFile",
205
+ "schemaDirectory",
206
+ "tsconfig",
207
+ "typesDeclarationFile"
208
+ ],
209
+ "type": "object"
210
+ }
211
+ }
212
+ }
@@ -0,0 +1,4 @@
1
+ import { Command } from 'commander';
2
+ import { PikkuCLIOptions } from '../src/utils.js';
3
+ export declare const action: (options: PikkuCLIOptions) => Promise<void>;
4
+ export declare const all: (program: Command) => void;
@@ -0,0 +1,71 @@
1
+ import { getFileImportRelativePath, logPikkuLogo, writeFileInDir, } from '../src/utils.js';
2
+ import { getPikkuCLIConfig } from '../src/pikku-cli-config.js';
3
+ import { pikkuRoutes } from './pikku-routes.js';
4
+ import { pikkuFunctionTypes } from './pikku-function-types.js';
5
+ import { pikkuHTTPMap } from './pikku-routes-map.js';
6
+ import { existsSync } from 'fs';
7
+ import { pikkuFetch } from './pikku-fetch.js';
8
+ import { pikkuChannelsMap } from './pikku-channels-map.js';
9
+ import { pikkuChannels } from './pikku-channels.js';
10
+ import { pikkuNext } from './pikku-nextjs.js';
11
+ import { pikkuOpenAPI } from './pikku-openapi.js';
12
+ import { pikkuScheduler } from './pikku-scheduler.js';
13
+ import { pikkuSchemas } from './pikku-schemas.js';
14
+ import { pikkuWebSocket } from './pikku-websocket.js';
15
+ import { inspectorGlob } from '../src/inspector-glob.js';
16
+ export const action = async (options) => {
17
+ logPikkuLogo();
18
+ const imports = [];
19
+ const addImport = (from) => {
20
+ imports.push(`import '${getFileImportRelativePath(cliConfig.bootstrapFile, from, cliConfig.packageMappings)}'`);
21
+ };
22
+ const cliConfig = await getPikkuCLIConfig(options.config, [], true);
23
+ let typesDeclarationFileExists = true;
24
+ let visitState = await inspectorGlob(cliConfig.rootDir, cliConfig.routeDirectories);
25
+ if (!existsSync(cliConfig.typesDeclarationFile)) {
26
+ typesDeclarationFileExists = false;
27
+ }
28
+ await pikkuFunctionTypes(cliConfig, options, visitState);
29
+ // This is needed since the addRoutes function will add the routes to the visitState
30
+ if (!typesDeclarationFileExists) {
31
+ console.log(`\x1b[34m• Type file first created, inspecting again...\x1b[0m`);
32
+ visitState = await inspectorGlob(cliConfig.rootDir, cliConfig.routeDirectories);
33
+ }
34
+ const routes = await pikkuRoutes(cliConfig, visitState);
35
+ if (routes) {
36
+ await pikkuHTTPMap(cliConfig, visitState);
37
+ await pikkuFetch(cliConfig);
38
+ addImport(cliConfig.routesFile);
39
+ }
40
+ const scheduled = await pikkuScheduler(cliConfig, visitState);
41
+ if (scheduled) {
42
+ addImport(cliConfig.schedulersFile);
43
+ }
44
+ const channels = await pikkuChannels(cliConfig, visitState);
45
+ if (channels) {
46
+ await pikkuChannelsMap(cliConfig, visitState);
47
+ await pikkuWebSocket(cliConfig);
48
+ addImport(cliConfig.channelsFile);
49
+ }
50
+ const schemas = await pikkuSchemas(cliConfig, visitState);
51
+ if (schemas) {
52
+ addImport(`${cliConfig.schemaDirectory}/register.gen.ts`);
53
+ }
54
+ await pikkuNext(cliConfig, visitState, options);
55
+ if (cliConfig.openAPI) {
56
+ console.log(`\x1b[34m• OpenAPI requires a reinspection to pickup new generated types..\x1b[0m`);
57
+ visitState = await inspectorGlob(cliConfig.rootDir, cliConfig.routeDirectories);
58
+ await pikkuOpenAPI(cliConfig, visitState);
59
+ }
60
+ await writeFileInDir(cliConfig.bootstrapFile, imports.join('\n'));
61
+ };
62
+ export const all = (program) => {
63
+ program
64
+ .command('all', { isDefault: true })
65
+ .description('Generate all the files used by pikku')
66
+ .option('-ct | --pikku-config-type', 'The type of your pikku config object')
67
+ .option('-ss | --singleton-services-factory-type', 'The type of your singleton services factory')
68
+ .option('-se | --session-services-factory-type', 'The type of your session services factory')
69
+ .option('-c | --config <string>', 'The path to pikku cli config file')
70
+ .action(action);
71
+ };
@@ -0,0 +1,5 @@
1
+ import { Command } from 'commander';
2
+ import { PikkuCLIConfig } from '../src/pikku-cli-config.js';
3
+ import { InspectorState } from '@pikku/inspector';
4
+ export declare const pikkuChannelsMap: ({ channelsMapDeclarationFile, packageMappings }: PikkuCLIConfig, state: InspectorState) => Promise<boolean>;
5
+ export declare const channelsMap: (program: Command) => void;
@@ -0,0 +1,27 @@
1
+ import { getPikkuCLIConfig } from '../src/pikku-cli-config.js';
2
+ import { logCommandInfoAndTime, logPikkuLogo, writeFileInDir, } from '../src/utils.js';
3
+ import { serializeTypedChannelsMap } from '../src/channels/serialize-typed-channel-map.js';
4
+ import { inspectorGlob } from '../src/inspector-glob.js';
5
+ export const pikkuChannelsMap = async ({ channelsMapDeclarationFile, packageMappings }, state) => {
6
+ return await logCommandInfoAndTime('Creating channels map', 'Created channels map', [state.channels.files.size === 0], async () => {
7
+ const content = serializeTypedChannelsMap(channelsMapDeclarationFile, packageMappings, state.channels.typesMap, state.channels.meta);
8
+ await writeFileInDir(channelsMapDeclarationFile, content);
9
+ });
10
+ };
11
+ async function action(cliOptions) {
12
+ logPikkuLogo();
13
+ const cliConfig = await getPikkuCLIConfig(cliOptions.config, [
14
+ 'rootDir',
15
+ 'routeDirectories',
16
+ 'routesFile',
17
+ ]);
18
+ const visitState = await inspectorGlob(cliConfig.rootDir, cliConfig.routeDirectories);
19
+ await pikkuChannelsMap(cliConfig, visitState);
20
+ }
21
+ export const channelsMap = (program) => {
22
+ program
23
+ .command('channels-map')
24
+ .description('Generate a map of all channels to aid in type checking')
25
+ .option('-c | --config <string>', 'The path to pikku cli config file')
26
+ .action(action);
27
+ };
@@ -0,0 +1,5 @@
1
+ import { Command } from 'commander';
2
+ import { PikkuCLIConfig } from '../src/pikku-cli-config.js';
3
+ import { InspectorState } from '@pikku/inspector';
4
+ export declare const pikkuChannels: (cliConfig: PikkuCLIConfig, visitState: InspectorState) => Promise<boolean>;
5
+ export declare const channels: (program: Command) => void;
@@ -0,0 +1,32 @@
1
+ import { getPikkuCLIConfig } from '../src/pikku-cli-config.js';
2
+ import { logCommandInfoAndTime, logPikkuLogo, writeFileInDir, } from '../src/utils.js';
3
+ import { serializeChannels, serializeChannelMeta, } from '../src/channels/serialize-channels.js';
4
+ import { inspectorGlob } from '../src/inspector-glob.js';
5
+ export const pikkuChannels = async (cliConfig, visitState) => {
6
+ return await logCommandInfoAndTime('Finding Channels', 'Found channels', [visitState.channels.files.size === 0], async () => {
7
+ const { channelsFile, packageMappings } = cliConfig;
8
+ const { channels } = visitState;
9
+ const content = [
10
+ serializeChannels(channelsFile, channels.files, packageMappings),
11
+ serializeChannelMeta(channels.meta),
12
+ ];
13
+ await writeFileInDir(channelsFile, content.join('\n\n'));
14
+ });
15
+ };
16
+ async function action(cliOptions) {
17
+ logPikkuLogo();
18
+ const cliConfig = await getPikkuCLIConfig(cliOptions.config, [
19
+ 'rootDir',
20
+ 'routeDirectories',
21
+ 'routesFile',
22
+ ]);
23
+ const visitState = await inspectorGlob(cliConfig.rootDir, cliConfig.routeDirectories);
24
+ await pikkuChannels(cliConfig, visitState);
25
+ }
26
+ export const channels = (program) => {
27
+ program
28
+ .command('channels')
29
+ .description('Find all channels to import')
30
+ .option('-c | --config <string>', 'The path to pikku cli config file')
31
+ .action(action);
32
+ };
@@ -0,0 +1,6 @@
1
+ import { Command } from 'commander';
2
+ import { PikkuCLIOptions } from '../src/utils.js';
3
+ import { PikkuCLIConfig } from '../src/pikku-cli-config.js';
4
+ export declare const pikkuFetch: ({ fetchFile, routesMapDeclarationFile, packageMappings, }: PikkuCLIConfig) => Promise<void>;
5
+ export declare const action: (options: PikkuCLIOptions) => Promise<void>;
6
+ export declare const fetch: (program: Command) => void;
@@ -0,0 +1,25 @@
1
+ import { getFileImportRelativePath, logCommandInfoAndTime, logPikkuLogo, writeFileInDir, } from '../src/utils.js';
2
+ import { getPikkuCLIConfig } from '../src/pikku-cli-config.js';
3
+ import { serializeFetchWrapper } from '../src/http/serialize-fetch-wrapper.js';
4
+ export const pikkuFetch = async ({ fetchFile, routesMapDeclarationFile, packageMappings, }) => {
5
+ await logCommandInfoAndTime('Generating fetch wrapper', 'Generated fetch wrapper', [fetchFile === undefined, 'fetchFile is required in pikku config'], async () => {
6
+ if (!fetchFile) {
7
+ throw new Error('fetchFile is required in pikku config');
8
+ }
9
+ const routesMapDeclarationPath = getFileImportRelativePath(fetchFile, routesMapDeclarationFile, packageMappings);
10
+ const content = [serializeFetchWrapper(routesMapDeclarationPath)];
11
+ await writeFileInDir(fetchFile, content.join('\n'));
12
+ });
13
+ };
14
+ export const action = async (options) => {
15
+ logPikkuLogo();
16
+ const cliConfig = await getPikkuCLIConfig(options.config, ['rootDir', 'schemaDirectory', 'configDir', 'fetchFile'], true);
17
+ await pikkuFetch(cliConfig);
18
+ };
19
+ export const fetch = (program) => {
20
+ program
21
+ .command('fetch')
22
+ .description('generate fetch wrapper')
23
+ .option('-c | --config <string>', 'The path to pikku cli config file')
24
+ .action(action);
25
+ };
@@ -0,0 +1,6 @@
1
+ import { Command } from 'commander';
2
+ import { PikkuCLIConfig } from '../src/pikku-cli-config.js';
3
+ import { InspectorState } from '@pikku/inspector';
4
+ import { PikkuCLIOptions } from '../src/utils.js';
5
+ export declare const pikkuFunctionTypes: ({ typesDeclarationFile: typesFile, packageMappings }: PikkuCLIConfig, options: PikkuCLIOptions, visitState: InspectorState) => Promise<void>;
6
+ export declare const functionTypes: (program: Command) => void;
@@ -0,0 +1,32 @@
1
+ import { getPikkuCLIConfig } from '../src/pikku-cli-config.js';
2
+ import { getFileImportRelativePath, getPikkuFilesAndMethods, logCommandInfoAndTime, logPikkuLogo, writeFileInDir, } from '../src/utils.js';
3
+ import { pikkuRoutes } from './pikku-routes.js';
4
+ import { inspectorGlob } from '../src/inspector-glob.js';
5
+ import { serializePikkuTypes } from '../src/core/serialize-pikku-types.js';
6
+ export const pikkuFunctionTypes = async ({ typesDeclarationFile: typesFile, packageMappings }, options, visitState) => {
7
+ await logCommandInfoAndTime('Creating api types', 'Created api types', [false], async () => {
8
+ const { userSessionType, sessionServicesType } = await getPikkuFilesAndMethods(visitState, packageMappings, typesFile, options, { userSessionType: true, sessionServiceType: true });
9
+ const content = serializePikkuTypes(`import type { ${userSessionType.type} } from '${getFileImportRelativePath(typesFile, userSessionType.typePath, packageMappings)}'`, userSessionType.type, `import type { ${sessionServicesType.type} } from '${getFileImportRelativePath(typesFile, sessionServicesType.typePath, packageMappings)}'`, sessionServicesType.type);
10
+ await writeFileInDir(typesFile, content);
11
+ });
12
+ };
13
+ async function action(cliOptions) {
14
+ logPikkuLogo();
15
+ const cliConfig = await getPikkuCLIConfig(cliOptions.config, [
16
+ 'rootDir',
17
+ 'routeDirectories',
18
+ 'typesDeclarationFile',
19
+ ]);
20
+ const visitState = await inspectorGlob(cliConfig.rootDir, cliConfig.routeDirectories);
21
+ await pikkuRoutes(cliConfig, visitState);
22
+ }
23
+ export const functionTypes = (program) => {
24
+ program
25
+ .command('types')
26
+ .description('Generate the core API')
27
+ .option('-ct | --pikku-config-type', 'The type of your pikku config object')
28
+ .option('-ss | --singleton-services-factory-type', 'The type of your singleton services factory')
29
+ .option('-se | --session-services-factory-type', 'The type of your session services factory')
30
+ .option('-c | --config <string>', 'The path to pikku cli config file')
31
+ .action(action);
32
+ };
@@ -0,0 +1,7 @@
1
+ import { Command } from 'commander';
2
+ import { PikkuCLIOptions } from '../src/utils.js';
3
+ import { PikkuCLIConfig } from '../src/pikku-cli-config.js';
4
+ import { InspectorState } from '@pikku/inspector';
5
+ export declare const pikkuNext: ({ nextJSfile, routesFile, routesMapDeclarationFile, schemaDirectory, packageMappings, }: PikkuCLIConfig, visitState: InspectorState, options: PikkuCLIOptions) => Promise<boolean>;
6
+ export declare const action: (options: PikkuCLIOptions) => Promise<void>;
7
+ export declare const nextjs: (program: Command) => void;