@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/bin/pikku-all.ts DELETED
@@ -1,180 +0,0 @@
1
- import { Command } from 'commander'
2
- import {
3
- getFileImportRelativePath,
4
- logInfo,
5
- logPikkuLogo,
6
- PikkuCLIOptions,
7
- writeFileInDir,
8
- } from '../src/utils.js'
9
- import { getPikkuCLIConfig, PikkuCLIConfig } from '../src/pikku-cli-config.js'
10
- import { pikkuHTTP } from './pikku-http.js'
11
- import { pikkuFunctionTypes } from './pikku-function-types.js'
12
- import { pikkuHTTPMap } from './pikku-routes-map.js'
13
- import { existsSync } from 'fs'
14
- import { pikkuFetch } from './pikku-fetch.js'
15
- import { pikkuChannelsMap } from './pikku-channels-map.js'
16
- import { pikkuChannels } from './pikku-channels.js'
17
- import { pikkuNext } from './pikku-nextjs.js'
18
- import { pikkuOpenAPI } from './pikku-openapi.js'
19
- import { pikkuScheduler } from './pikku-scheduler.js'
20
- import { pikkuSchemas } from './pikku-schemas.js'
21
- import { pikkuWebSocket } from './pikku-websocket.js'
22
- import { inspectorGlob } from '../src/inspector-glob.js'
23
- import chokidar from 'chokidar'
24
-
25
- const runAll = async (cliConfig: PikkuCLIConfig, options: PikkuCLIOptions) => {
26
- const imports: string[] = []
27
- const addImport = (from: string) => {
28
- imports.push(
29
- `import '${getFileImportRelativePath(cliConfig.bootstrapFile, from, cliConfig.packageMappings)}'`
30
- )
31
- }
32
-
33
- let typesDeclarationFileExists = true
34
- let visitState = await inspectorGlob(
35
- cliConfig.rootDir,
36
- cliConfig.routeDirectories,
37
- cliConfig.filters
38
- )
39
-
40
- if (!existsSync(cliConfig.typesDeclarationFile)) {
41
- typesDeclarationFileExists = false
42
- }
43
- await pikkuFunctionTypes(cliConfig, options, visitState)
44
-
45
- // This is needed since the addRoutes function will add the routes to the visitState
46
- if (!typesDeclarationFileExists) {
47
- logInfo(`• Type file first created, inspecting again...\x1b[0m`)
48
- visitState = await inspectorGlob(
49
- cliConfig.rootDir,
50
- cliConfig.routeDirectories,
51
- cliConfig.filters
52
- )
53
- }
54
-
55
- const routes = await pikkuHTTP(cliConfig, visitState)
56
- if (routes) {
57
- await pikkuHTTPMap(cliConfig, visitState)
58
- await pikkuFetch(cliConfig)
59
- addImport(cliConfig.routesFile)
60
- }
61
-
62
- const scheduled = await pikkuScheduler(cliConfig, visitState)
63
- if (scheduled) {
64
- addImport(cliConfig.schedulersFile)
65
- }
66
-
67
- const channels = await pikkuChannels(cliConfig, visitState)
68
- if (channels) {
69
- await pikkuChannelsMap(cliConfig, visitState)
70
- await pikkuWebSocket(cliConfig)
71
- addImport(cliConfig.channelsFile)
72
- }
73
-
74
- const schemas = await pikkuSchemas(cliConfig, visitState)
75
- if (schemas) {
76
- addImport(`${cliConfig.schemaDirectory}/register.gen.ts`)
77
- }
78
-
79
- if (cliConfig.nextBackendFile || cliConfig.nextHTTPFile) {
80
- await pikkuNext(cliConfig, visitState, options)
81
- }
82
-
83
- if (cliConfig.openAPI) {
84
- logInfo(`• OpenAPI requires a reinspection to pickup new generated types..`)
85
- visitState = await inspectorGlob(
86
- cliConfig.rootDir,
87
- cliConfig.routeDirectories,
88
- cliConfig.filters
89
- )
90
- await pikkuOpenAPI(cliConfig, visitState)
91
- }
92
-
93
- await writeFileInDir(cliConfig.bootstrapFile, imports.join('\n'))
94
- }
95
-
96
- const watch = (cliConfig: PikkuCLIConfig, options: PikkuCLIOptions) => {
97
- const configWatcher = chokidar.watch(cliConfig.routeDirectories, {
98
- ignoreInitial: true,
99
- ignored: /.*\.gen\.tsx?/,
100
- })
101
-
102
- let watcher = new chokidar.FSWatcher({})
103
-
104
- const generatorWatcher = () => {
105
- watcher.close()
106
-
107
- logInfo(
108
- `• Watching directories: \n - ${cliConfig.routeDirectories.join('\n - ')}`
109
- )
110
- watcher = chokidar.watch(cliConfig.routeDirectories, {
111
- ignoreInitial: true,
112
- ignored: /.*\.gen\.ts/,
113
- })
114
-
115
- watcher.on('ready', async () => {
116
- const handle = async () => {
117
- try {
118
- await runAll(cliConfig, options)
119
- } catch (err) {
120
- console.error(err)
121
- console.info()
122
- }
123
- }
124
-
125
- await handle()
126
-
127
- let timeout: ReturnType<typeof setTimeout> | undefined
128
-
129
- const deduped = (_file: string) => {
130
- if (timeout) {
131
- clearTimeout(timeout)
132
- }
133
- timeout = setTimeout(handle, 10)
134
- }
135
-
136
- watcher.on('change', deduped)
137
- watcher.on('add', deduped)
138
- watcher.on('unlink', deduped)
139
- })
140
- }
141
-
142
- configWatcher.on('ready', generatorWatcher)
143
- configWatcher.on('change', generatorWatcher)
144
- }
145
-
146
- export const action = async (options: PikkuCLIOptions): Promise<void> => {
147
- logPikkuLogo()
148
-
149
- const cliConfig = await getPikkuCLIConfig(
150
- options.config,
151
- [],
152
- options.tags,
153
- true
154
- )
155
-
156
- if (options.watch) {
157
- watch(cliConfig, options)
158
- } else {
159
- await runAll(cliConfig, options)
160
- }
161
- }
162
-
163
- export const all = (program: Command): void => {
164
- program
165
- .command('all', { isDefault: true })
166
- .description('Generate all the files used by pikku')
167
- .option('-ct | --pikku-config-type', 'The type of your pikku config object')
168
- .option(
169
- '-ss | --singleton-services-factory-type',
170
- 'The type of your singleton services factory'
171
- )
172
- .option(
173
- '-se | --session-services-factory-type',
174
- 'The type of your session services factory'
175
- )
176
- .option('-c | --config <string>', 'The path to pikku cli config file')
177
- .option('-t | --tags <tags...>', 'Which tags to filter by')
178
- .option('-w | --watch', 'Whether to watch file changes')
179
- .action(action)
180
- }
@@ -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 { serializeTypedChannelsMap } from '../src/channels/serialize-typed-channel-map.js'
11
- import { inspectorGlob } from '../src/inspector-glob.js'
12
-
13
- export const pikkuChannelsMap = async (
14
- { channelsMapDeclarationFile, packageMappings }: PikkuCLIConfig,
15
- state: InspectorState
16
- ) => {
17
- return await logCommandInfoAndTime(
18
- 'Creating channels map',
19
- 'Created channels map',
20
- [state.channels.files.size === 0],
21
- async () => {
22
- const content = serializeTypedChannelsMap(
23
- channelsMapDeclarationFile,
24
- packageMappings,
25
- state.channels.typesMap,
26
- state.channels.meta
27
- )
28
- await writeFileInDir(channelsMapDeclarationFile, content)
29
- }
30
- )
31
- }
32
-
33
- async function action(cliOptions: PikkuCLIOptions): Promise<void> {
34
- logPikkuLogo()
35
- const cliConfig = await getPikkuCLIConfig(
36
- cliOptions.config,
37
- ['rootDir', 'routeDirectories', 'routesFile'],
38
- cliOptions.tags,
39
- false
40
- )
41
- const visitState = await inspectorGlob(
42
- cliConfig.rootDir,
43
- cliConfig.routeDirectories,
44
- cliConfig.filters
45
- )
46
- await pikkuChannelsMap(cliConfig, visitState)
47
- }
48
-
49
- export const channelsMap = (program: Command): void => {
50
- program
51
- .command('channels-map')
52
- .description('Generate a map of all channels to aid in type checking')
53
- .option('-c | --config <string>', 'The path to pikku cli config file')
54
- .action(action)
55
- }
@@ -1,58 +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
- serializeChannels,
12
- serializeChannelMeta,
13
- } from '../src/channels/serialize-channels.js'
14
- import { inspectorGlob } from '../src/inspector-glob.js'
15
-
16
- export const pikkuChannels = async (
17
- cliConfig: PikkuCLIConfig,
18
- visitState: InspectorState
19
- ) => {
20
- return await logCommandInfoAndTime(
21
- 'Finding Channels',
22
- 'Found channels',
23
- [visitState.channels.files.size === 0],
24
- async () => {
25
- const { channelsFile, packageMappings } = cliConfig
26
- const { channels } = visitState
27
- const content = [
28
- serializeChannels(channelsFile, channels.files, packageMappings),
29
- serializeChannelMeta(channels.meta),
30
- ]
31
- await writeFileInDir(channelsFile, content.join('\n\n'))
32
- }
33
- )
34
- }
35
-
36
- async function action(cliOptions: PikkuCLIOptions): Promise<void> {
37
- logPikkuLogo()
38
-
39
- const cliConfig = await getPikkuCLIConfig(
40
- cliOptions.config,
41
- ['rootDir', 'routeDirectories', 'routesFile'],
42
- cliOptions.tags
43
- )
44
- const visitState = await inspectorGlob(
45
- cliConfig.rootDir,
46
- cliConfig.routeDirectories,
47
- cliConfig.filters
48
- )
49
- await pikkuChannels(cliConfig, visitState)
50
- }
51
-
52
- export const channels = (program: Command): void => {
53
- program
54
- .command('channels')
55
- .description('Find all channels to import')
56
- .option('-c | --config <string>', 'The path to pikku cli config file')
57
- .action(action)
58
- }
@@ -1,55 +0,0 @@
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 { serializeFetchWrapper } from '../src/http/serialize-fetch-wrapper.js'
11
-
12
- export const pikkuFetch = async ({
13
- fetchFile,
14
- routesMapDeclarationFile,
15
- packageMappings,
16
- }: PikkuCLIConfig) => {
17
- await logCommandInfoAndTime(
18
- 'Generating fetch wrapper',
19
- 'Generated fetch wrapper',
20
- [fetchFile === undefined, "fetchFile isn't set in the pikku config"],
21
- async () => {
22
- if (!fetchFile) {
23
- throw new Error("fetchFile is isn't set in the pikku config")
24
- }
25
-
26
- const routesMapDeclarationPath = getFileImportRelativePath(
27
- fetchFile,
28
- routesMapDeclarationFile,
29
- packageMappings
30
- )
31
-
32
- const content = [serializeFetchWrapper(routesMapDeclarationPath)]
33
- await writeFileInDir(fetchFile, 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
- options.tags,
44
- true
45
- )
46
- await pikkuFetch(cliConfig)
47
- }
48
-
49
- export const fetch = (program: Command): void => {
50
- program
51
- .command('fetch')
52
- .description('generate fetch wrapper')
53
- .option('-c | --config <string>', 'The path to pikku cli config file')
54
- .action(action)
55
- }
@@ -1,84 +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
- getFileImportRelativePath,
6
- getPikkuFilesAndMethods,
7
- logCommandInfoAndTime,
8
- logPikkuLogo,
9
- PikkuCLIOptions,
10
- writeFileInDir,
11
- } from '../src/utils.js'
12
- import { pikkuHTTP } from './pikku-http.js'
13
- import { inspectorGlob } from '../src/inspector-glob.js'
14
- import { serializePikkuTypes } from '../src/core/serialize-pikku-types.js'
15
-
16
- export const pikkuFunctionTypes = async (
17
- { typesDeclarationFile: typesFile, packageMappings }: PikkuCLIConfig,
18
- options: PikkuCLIOptions,
19
- visitState: InspectorState
20
- ) => {
21
- await logCommandInfoAndTime(
22
- 'Creating api types',
23
- 'Created api types',
24
- [false],
25
- async () => {
26
- const { userSessionType, sessionServicesType, singletonServicesType } =
27
- await getPikkuFilesAndMethods(
28
- visitState,
29
- packageMappings,
30
- typesFile,
31
- options,
32
- {
33
- userSessionType: true,
34
- sessionServiceType: true,
35
- singletonServicesType: true,
36
- }
37
- )
38
-
39
- const content = serializePikkuTypes(
40
- `import type { ${userSessionType.type} } from '${getFileImportRelativePath(typesFile, userSessionType.typePath, packageMappings)}'`,
41
- userSessionType.type,
42
- `import type { ${singletonServicesType.type} } from '${getFileImportRelativePath(typesFile, singletonServicesType.typePath, packageMappings)}'`,
43
- singletonServicesType.type,
44
- `import type { ${sessionServicesType.type} } from '${getFileImportRelativePath(typesFile, sessionServicesType.typePath, packageMappings)}'`,
45
- sessionServicesType.type
46
- )
47
- await writeFileInDir(typesFile, content)
48
- }
49
- )
50
- }
51
-
52
- async function action(cliOptions: PikkuCLIOptions): Promise<void> {
53
- logPikkuLogo()
54
-
55
- const cliConfig = await getPikkuCLIConfig(
56
- cliOptions.config,
57
- ['rootDir', 'routeDirectories', 'typesDeclarationFile'],
58
- cliOptions.tags
59
- )
60
-
61
- const visitState = await inspectorGlob(
62
- cliConfig.rootDir,
63
- cliConfig.routeDirectories,
64
- cliConfig.filters
65
- )
66
- await pikkuHTTP(cliConfig, visitState)
67
- }
68
-
69
- export const functionTypes = (program: Command): void => {
70
- program
71
- .command('types')
72
- .description('Generate the core API')
73
- .option('-ct | --pikku-config-type', 'The type of your pikku config object')
74
- .option(
75
- '-ss | --singleton-services-factory-type',
76
- 'The type of your singleton services factory'
77
- )
78
- .option(
79
- '-se | --session-services-factory-type',
80
- 'The type of your session services factory'
81
- )
82
- .option('-c | --config <string>', 'The path to pikku cli config file')
83
- .action(action)
84
- }
package/bin/pikku-http.ts DELETED
@@ -1,56 +0,0 @@
1
- import { Command } from 'commander'
2
- import { getPikkuCLIConfig, PikkuCLIConfig } from '../src/pikku-cli-config.js'
3
- import { serializeHTTPRoutesMeta } from '../src/http/serialize-route-meta.js'
4
- import { InspectorState } from '@pikku/inspector'
5
- import {
6
- logCommandInfoAndTime,
7
- logPikkuLogo,
8
- PikkuCLIOptions,
9
- writeFileInDir,
10
- } from '../src/utils.js'
11
- import { serializeRoutes } from '../src/http/serialize-route-imports.js'
12
- import { inspectorGlob } from '../src/inspector-glob.js'
13
-
14
- export const pikkuHTTP = async (
15
- cliConfig: PikkuCLIConfig,
16
- visitState: InspectorState
17
- ) => {
18
- return await logCommandInfoAndTime(
19
- 'Finding HTTP routes',
20
- 'Found HTTP routes',
21
- [visitState.http.files.size === 0],
22
- async () => {
23
- const { routesFile, packageMappings } = cliConfig
24
- const { http } = visitState
25
- const content = [
26
- serializeRoutes(routesFile, http.files, packageMappings),
27
- serializeHTTPRoutesMeta(http.meta),
28
- ]
29
- await writeFileInDir(routesFile, content.join('\n\n'))
30
- }
31
- )
32
- }
33
-
34
- async function action(cliOptions: PikkuCLIOptions): Promise<void> {
35
- logPikkuLogo()
36
-
37
- const cliConfig = await getPikkuCLIConfig(
38
- cliOptions.config,
39
- ['rootDir', 'routeDirectories', 'routesFile'],
40
- cliOptions.tags
41
- )
42
- const visitState = await inspectorGlob(
43
- cliConfig.rootDir,
44
- cliConfig.routeDirectories,
45
- cliConfig.filters
46
- )
47
- await pikkuHTTP(cliConfig, visitState)
48
- }
49
-
50
- export const routes = (program: Command): void => {
51
- program
52
- .command('routes')
53
- .description('Find all routes to import')
54
- .option('-c | --config <string>', 'The path to pikku cli config file')
55
- .action(action)
56
- }