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