skillhub/cli/scripts/generate-pkg-info.ts
dongmucat e249db35a3 test(cli): add comprehensive integration tests and fix update command bugs
- Add integration tests for doctor, install, list, publish, remove, whoami commands
- Expand fake-registry with resolve/delete state capture for real assertions
- Fix update command: use correct package name @astron-team/skillhub from constants
- Refactor runUpdateCommand to accept string[] instead of fragile string splitting
- Add dependency injection to updateCommand for testable unit tests without global mocks
- Replace package.json import with codegen (scripts/generate-pkg-info.ts) to avoid
  leaking devDependencies into the build artifact
- Fix startNetworkFailureServer TOCTOU race by keeping listener alive
- Add TODO markers for known help command bugs (--json not forwarded, unknown topic crash)
- Extend update integration test timeout for real npm registry checks
2026-05-07 14:46:40 +08:00

29 lines
990 B
TypeScript

import { mkdir, readFile, writeFile } from 'node:fs/promises'
import { dirname, resolve } from 'node:path'
import { fileURLToPath } from 'node:url'
interface PackageJson {
name: string
version: string
}
const scriptDir = dirname(fileURLToPath(import.meta.url))
const cliRoot = resolve(scriptDir, '..')
const pkgPath = resolve(cliRoot, 'package.json')
const outPath = resolve(cliRoot, 'src/generated/pkg-info.ts')
const pkg = JSON.parse(await readFile(pkgPath, 'utf8')) as PackageJson
if (typeof pkg.name !== 'string' || typeof pkg.version !== 'string') {
throw new Error(`package.json at ${pkgPath} is missing name or version`)
}
const contents =
'// Generated by scripts/generate-pkg-info.ts - do not edit by hand.\n' +
`export const PKG_NAME = ${JSON.stringify(pkg.name)}\n` +
`export const PKG_VERSION = ${JSON.stringify(pkg.version)}\n`
await mkdir(dirname(outPath), { recursive: true })
await writeFile(outPath, contents, 'utf8')
console.log(`generated ${outPath}`)