Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions scripts/build-kb-manifest.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { allKbApis } from '../src/kb/apis.ts'
import * as fs from 'fs'
import * as path from 'path'

const apisDir = './src/kb/apis'
const files = fs.readdirSync(apisDir).filter(f => f.endsWith('.ts'))

const nsToFile = new Map<string, string>()
for (const def of allKbApis) {
if (!nsToFile.has(def.namespace)) {
for (const file of files) {
const content = fs.readFileSync(path.join(apisDir, file), 'utf8')
if (content.includes(`namespace: "${def.namespace}"`)) {
nsToFile.set(def.namespace, file.replace('.ts', ''))
break
}
}
}
}

const manifest = allKbApis.map(d => ({
name: d.name,
namespace: d.namespace,
description: d.description,
method: d.method,
path: d.path,
namespaceFile: nsToFile.get(d.namespace) ?? 'unknown',
}))

const lines = [
'/*',
' * Copyright Elasticsearch B.V. and contributors',
' * SPDX-License-Identifier: Apache-2.0',
' */',
'',
'/*',
' * AUTO-GENERATED from src/kb/apis/*.ts.',
' * DO NOT EDIT BY HAND. Regenerate after running the code generator.',
' */',
'',
"import type { HttpMethod } from './types.ts'",
'',
'/** Cheap metadata for every Kibana API command. No Zod schemas built. */',
'export interface KbApiMeta {',
' readonly name: string',
' readonly namespace: string',
' readonly description: string',
' readonly method: HttpMethod',
' readonly path: string',
' /** File stem under src/kb/apis/ that holds the full KbApiDefinition. */',
' readonly namespaceFile: string',
'}',
'',
'export const kbApiManifest: readonly KbApiMeta[] = ' + JSON.stringify(manifest, null, 2),
'',
]

fs.writeFileSync('./src/kb/api-manifest.ts', lines.join('\n'))
console.log(`Wrote manifest with ${manifest.length} entries`)
4 changes: 2 additions & 2 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ if (firstArg === 'stack') {
}

if (secondArg == null || kbArgs.has(secondArg)) {
const { registerKbCommands } = await import('./kb/register.ts')
const kbGroup = registerKbCommands()
const { registerKbCommandsLazy } = await import('./kb/register.ts')
const kbGroup = await registerKbCommandsLazy()
kbGroup.alias('kibana')
stackChildren.push(kbGroup)
} else {
Expand Down
Loading