galbe 0.15.0 โ 0.15.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/bin/commands/build.ts +8 -6
- package/bin/commands/generate/cli/index.ts +1 -1
- package/bin/commands/generate/cli/targets/cac.ts +1 -1
- package/bin/commands/generate/code.ts +11 -3
- package/bin/res/client.runtime.ts +2 -3
- package/package.json +2 -3
- package/src/index.ts +10 -10
- package/src/types.ts +3 -3
- package/scripts/hooks/prepare-commit-msg +0 -10
- package/scripts/postinstall.ts +0 -9
package/bin/commands/build.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { $ } from 'bun'
|
|
|
3
3
|
import { Command, Option } from 'commander'
|
|
4
4
|
import { resolve, relative, dirname } from 'path'
|
|
5
5
|
import { tmpdir } from 'os'
|
|
6
|
-
import { mkdir, rm
|
|
6
|
+
import { mkdir, rm } from 'fs/promises'
|
|
7
7
|
|
|
8
8
|
import { CWD, fmtVal, silentExec } from '../util'
|
|
9
9
|
import { Galbe } from '../../src'
|
|
@@ -20,7 +20,7 @@ const createBuildIndex = async (indexPath: string, g: Galbe, buildId: string, ou
|
|
|
20
20
|
if (existsSync(`${indexDir}/galbe.config.ts`)) configPath = `${indexDir}/galbe.config.ts`
|
|
21
21
|
else if (existsSync(`${indexDir}/galbe.config.js`)) configPath = `${indexDir}/galbe.config.js`
|
|
22
22
|
|
|
23
|
-
const routes = new Map<string, { filepath: string
|
|
23
|
+
const routes = new Map<string, { filepath: string; static?: { path: string; root: string } }>()
|
|
24
24
|
let errors: any[] = []
|
|
25
25
|
// Create GalbeProxy here
|
|
26
26
|
// use it to define routes
|
|
@@ -45,8 +45,10 @@ const createBuildIndex = async (indexPath: string, g: Galbe, buildId: string, ou
|
|
|
45
45
|
|
|
46
46
|
let buildIndex =
|
|
47
47
|
`import galbe from '${relative(buildPath, indexPath)}';\n` +
|
|
48
|
-
(configPath ? `import config from '${relative(buildPath, configPath)}';\n` : '') +
|
|
49
|
-
(configPath
|
|
48
|
+
(configPath ? `import config from '${relative(buildPath, configPath)}';\n` : '') +
|
|
49
|
+
(configPath
|
|
50
|
+
? `import {softMerge} from '${relative(buildPath, `${indexDir}/node_modules/galbe/src/util`)}';\n`
|
|
51
|
+
: '') +
|
|
50
52
|
(configPath ? `let conf = galbe.config;\ngalbe.config = softMerge(config, conf)\n` : '') +
|
|
51
53
|
`${[...routes.values()].map((r, idx) => `import _${idx} from '${relative(buildPath, r.filepath)}'`).join(';\n')}\n` +
|
|
52
54
|
`Bun.env.BUN_ENV = 'production';\n` +
|
|
@@ -86,7 +88,7 @@ export default (cmd: Command) => {
|
|
|
86
88
|
|
|
87
89
|
const bunfig = config ? (await import(resolve(CWD, config)))?.default || {} : {}
|
|
88
90
|
|
|
89
|
-
if
|
|
91
|
+
if (existsSync(outPath)) await rm(outPath, { recursive: true })
|
|
90
92
|
|
|
91
93
|
let error = null
|
|
92
94
|
Bun.write(Bun.stdout, '๐ฆ \x1b[1;30mBuilding \x1b[36mGalbe\x1b[0m\x1b[1;30m app\x1b[0m')
|
|
@@ -134,7 +136,7 @@ export default (cmd: Command) => {
|
|
|
134
136
|
console.log(...bo.logs)
|
|
135
137
|
}
|
|
136
138
|
if (compile) {
|
|
137
|
-
await $`bun build --compile ${resolve(CWD, out, 'index.js')} --outfile ${outPath}/bin`
|
|
139
|
+
await $`bun build --compile --minify --sourcemap --bytecode ${resolve(CWD, out, 'index.js')} --outfile ${outPath}/bin`
|
|
138
140
|
}
|
|
139
141
|
|
|
140
142
|
await rm(dirname(buildIndex), { recursive: true })
|
|
@@ -177,7 +177,7 @@ function generateSingleCommand(c: GalbeCLICommand, cliVar: string, includeTag: b
|
|
|
177
177
|
.map(o => {
|
|
178
178
|
const cleanName = sanitizeOptionName(o.name)
|
|
179
179
|
const short = o.short && !builtinShorts.has(o.short) ? `-${o.short}, ` : ''
|
|
180
|
-
const optType = o.type
|
|
180
|
+
const optType = o.type != null ? o.type : '[string]'
|
|
181
181
|
const defVal = o.default !== undefined ? `, { default: ${serializeValue(o.default)} }` : ''
|
|
182
182
|
return ` .option('${short}--${cleanName} ${optType}', ${JSON.stringify(o.description || o.name)}${defVal})`
|
|
183
183
|
})
|
|
@@ -2,7 +2,8 @@ import { $ } from 'bun'
|
|
|
2
2
|
import { devNull } from 'os'
|
|
3
3
|
import { Command, Option } from 'commander'
|
|
4
4
|
import { resolve, relative, extname } from 'path'
|
|
5
|
-
import {
|
|
5
|
+
import { readFile } from 'fs/promises'
|
|
6
|
+
import { existsSync } from 'fs'
|
|
6
7
|
|
|
7
8
|
import { CWD, fmtList, fmtVal } from '../../util'
|
|
8
9
|
import { applyPlan, planFromOapi, type GenerationPlan } from './code/openapi.parser'
|
|
@@ -114,10 +115,17 @@ export default (cmd: Command) => {
|
|
|
114
115
|
const outDir = resolve(CWD, out)
|
|
115
116
|
|
|
116
117
|
// Compute per-scope merge result.
|
|
117
|
-
const mergeResults: {
|
|
118
|
+
const mergeResults: {
|
|
119
|
+
scopeKey: string
|
|
120
|
+
content: string
|
|
121
|
+
added: RouteId[]
|
|
122
|
+
updated: RouteId[]
|
|
123
|
+
removed: RouteId[]
|
|
124
|
+
stale: RouteId[]
|
|
125
|
+
}[] = []
|
|
118
126
|
for (const scope of plan.scopes) {
|
|
119
127
|
const routePath = resolve(outDir, `${scope.routeFile}.${target}`)
|
|
120
|
-
const existing = (
|
|
128
|
+
const existing = existsSync(routePath) ? await readFile(routePath, 'utf-8') : null
|
|
121
129
|
const r = mergeRouteFile(existing, scope, mergeOpts)
|
|
122
130
|
mergeResults.push({ scopeKey: scope.scopeKey, ...r })
|
|
123
131
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// Inlined into the generated client โ no exports
|
|
2
|
+
import type { BodyInit } from 'bun'
|
|
2
3
|
|
|
3
4
|
type GalbeClientConfig = {
|
|
4
5
|
server?: { url?: string }
|
|
@@ -120,9 +121,7 @@ class GalbeRequest<T, E = any> {
|
|
|
120
121
|
return this.#getMain().then(onfulfilled, onrejected)
|
|
121
122
|
}
|
|
122
123
|
|
|
123
|
-
catch<R = never>(
|
|
124
|
-
onrejected?: ((reason: any) => R | PromiseLike<R>) | null
|
|
125
|
-
): Promise<T | R> {
|
|
124
|
+
catch<R = never>(onrejected?: ((reason: any) => R | PromiseLike<R>) | null): Promise<T | R> {
|
|
126
125
|
return this.#getMain().then(undefined, onrejected)
|
|
127
126
|
}
|
|
128
127
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "galbe",
|
|
3
|
-
"version": "0.15.
|
|
3
|
+
"version": "0.15.1",
|
|
4
4
|
"description": "Fast, lightweight and highly customizable JavaScript web framework based on Bun",
|
|
5
5
|
"author": "Pierre Caillaud M (https://github.com/pierre-cm)",
|
|
6
6
|
"type": "module",
|
|
@@ -35,11 +35,10 @@
|
|
|
35
35
|
"scripts": {
|
|
36
36
|
"test": "bun test",
|
|
37
37
|
"typecheck": "tsc --noEmit --emitDeclarationOnly false",
|
|
38
|
-
"postinstall": "bun run ./scripts/postinstall.ts",
|
|
39
38
|
"release": "release-it"
|
|
40
39
|
},
|
|
41
40
|
"devDependencies": {
|
|
42
|
-
"@types/bun": "
|
|
41
|
+
"@types/bun": "latest",
|
|
43
42
|
"openapi-types": "^12.1.3",
|
|
44
43
|
"release-it": "^17.1.1"
|
|
45
44
|
},
|
package/src/index.ts
CHANGED
|
@@ -35,7 +35,7 @@ const overloadDiscriminer = <
|
|
|
35
35
|
P extends Partial<STParams<Path>>,
|
|
36
36
|
Q extends STQuery,
|
|
37
37
|
B extends STBody,
|
|
38
|
-
R extends STResponse
|
|
38
|
+
R extends STResponse,
|
|
39
39
|
>(
|
|
40
40
|
galbe: Galbe,
|
|
41
41
|
method: M,
|
|
@@ -69,7 +69,7 @@ const galbeMethod = <
|
|
|
69
69
|
P extends Partial<STParams<Path>>,
|
|
70
70
|
Q extends STQuery,
|
|
71
71
|
B extends STBody,
|
|
72
|
-
R extends STResponse
|
|
72
|
+
R extends STResponse,
|
|
73
73
|
>(
|
|
74
74
|
_galbe: Galbe,
|
|
75
75
|
method: M,
|
|
@@ -130,7 +130,7 @@ export class Galbe {
|
|
|
130
130
|
stopCb: (() => void)[] = []
|
|
131
131
|
errorCb: ErrorHandler[] = []
|
|
132
132
|
listening: boolean = false
|
|
133
|
-
server?: Server
|
|
133
|
+
server?: Server<any>
|
|
134
134
|
plugins: GalbePlugin[] = []
|
|
135
135
|
constructor(config?: GalbeConfig) {
|
|
136
136
|
this.config = config ?? {}
|
|
@@ -186,7 +186,7 @@ export class Galbe {
|
|
|
186
186
|
H extends STHeaders,
|
|
187
187
|
Q extends STQuery,
|
|
188
188
|
B extends STBody,
|
|
189
|
-
R extends STResponse
|
|
189
|
+
R extends STResponse,
|
|
190
190
|
>(
|
|
191
191
|
path: Path,
|
|
192
192
|
arg2:
|
|
@@ -205,7 +205,7 @@ export class Galbe {
|
|
|
205
205
|
H extends STHeaders,
|
|
206
206
|
Q extends STQuery,
|
|
207
207
|
B extends STBody,
|
|
208
|
-
R extends STResponse
|
|
208
|
+
R extends STResponse,
|
|
209
209
|
>(
|
|
210
210
|
path: Path,
|
|
211
211
|
arg2:
|
|
@@ -223,7 +223,7 @@ export class Galbe {
|
|
|
223
223
|
H extends STHeaders,
|
|
224
224
|
Q extends STQuery,
|
|
225
225
|
B extends STBody,
|
|
226
|
-
R extends STResponse
|
|
226
|
+
R extends STResponse,
|
|
227
227
|
>(
|
|
228
228
|
path: Path,
|
|
229
229
|
arg2:
|
|
@@ -241,7 +241,7 @@ export class Galbe {
|
|
|
241
241
|
H extends STHeaders,
|
|
242
242
|
Q extends STQuery,
|
|
243
243
|
B extends STBody,
|
|
244
|
-
R extends STResponse
|
|
244
|
+
R extends STResponse,
|
|
245
245
|
>(
|
|
246
246
|
path: Path,
|
|
247
247
|
arg2:
|
|
@@ -259,7 +259,7 @@ export class Galbe {
|
|
|
259
259
|
H extends STHeaders,
|
|
260
260
|
Q extends STQuery,
|
|
261
261
|
B extends STBody,
|
|
262
|
-
R extends STResponse
|
|
262
|
+
R extends STResponse,
|
|
263
263
|
>(
|
|
264
264
|
path: Path,
|
|
265
265
|
arg2:
|
|
@@ -277,7 +277,7 @@ export class Galbe {
|
|
|
277
277
|
H extends STHeaders,
|
|
278
278
|
Q extends STQuery,
|
|
279
279
|
B extends STBody,
|
|
280
|
-
R extends STResponse
|
|
280
|
+
R extends STResponse,
|
|
281
281
|
>(
|
|
282
282
|
path: Path,
|
|
283
283
|
arg2:
|
|
@@ -295,7 +295,7 @@ export class Galbe {
|
|
|
295
295
|
H extends STHeaders,
|
|
296
296
|
Q extends STQuery,
|
|
297
297
|
B extends STBody,
|
|
298
|
-
R extends STResponse
|
|
298
|
+
R extends STResponse,
|
|
299
299
|
>(
|
|
300
300
|
path: Path,
|
|
301
301
|
arg2:
|
package/src/types.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Serve, SocketAddress, TLSOptions } from 'bun'
|
|
2
2
|
import type {
|
|
3
3
|
STAny,
|
|
4
4
|
STArray,
|
|
@@ -140,7 +140,7 @@ export type GalbeConfig = {
|
|
|
140
140
|
basePath?: string
|
|
141
141
|
/** Enable or disable TLS support. */
|
|
142
142
|
tls?: TLSOptions
|
|
143
|
-
server?: Exclude<
|
|
143
|
+
server?: Exclude<Serve.Options<any>, 'port'> | TLSOptions
|
|
144
144
|
/** A Glob Pattern or a list of Glob patterns defining the route files to be analyzed by the Automatic Route Analyzer. */
|
|
145
145
|
routes?: boolean | string | string[]
|
|
146
146
|
router?: { cacheEnabled: boolean }
|
|
@@ -343,7 +343,7 @@ export class RequestError extends Error {
|
|
|
343
343
|
const message =
|
|
344
344
|
typeof options.payload === 'string'
|
|
345
345
|
? options.payload
|
|
346
|
-
: HttpStatus[status as keyof typeof HttpStatus] ?? 'Request Error'
|
|
346
|
+
: (HttpStatus[status as keyof typeof HttpStatus] ?? 'Request Error')
|
|
347
347
|
super(message)
|
|
348
348
|
this.name = new.target?.name ?? 'RequestError'
|
|
349
349
|
this.status = status
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bun
|
|
2
|
-
|
|
3
|
-
const COMMIT_MSG = await Bun.file(Bun.argv[2]).text()
|
|
4
|
-
const COMMIT_EMOJI = { feat: 'โจ', fix: '๐ง', doc: '๐', chore: '๐งน' }
|
|
5
|
-
|
|
6
|
-
const newCommitMsg = COMMIT_MSG.replace(/^(feat|fix|doc|chore):(.*)/, (_, type, msg) => {
|
|
7
|
-
return `${COMMIT_EMOJI[type]} ${type}:${msg}`
|
|
8
|
-
})
|
|
9
|
-
|
|
10
|
-
await Bun.write(Bun.argv[2], newCommitMsg)
|
package/scripts/postinstall.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { $ } from 'bun'
|
|
2
|
-
import { existsSync } from 'fs'
|
|
3
|
-
|
|
4
|
-
if (existsSync('.git')) {
|
|
5
|
-
console.log('Setting up dev environment')
|
|
6
|
-
Bun.write('.git/hooks/prepare-commit-msg', Bun.file('scripts/hooks/prepare-commit-msg'))
|
|
7
|
-
await $`chmod +x .git/hooks/prepare-commit-msg`
|
|
8
|
-
console.log('done')
|
|
9
|
-
}
|