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
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,10 @@ tmp/
# the skill). Canonical source is the workspace-root skills/.
packages/cli/skills/

# Generated by the cli's `prebuild` step (scripts/sync-version.mjs) so
# the CLI's --version output stays in lockstep with package.json. Only
# writer is the generator script; do not commit.
packages/cli/src/version.ts

# npm pack artifacts (regenerated each publish via cli's prepack script)
*.tgz
4 changes: 4 additions & 0 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,15 @@
"skills"
],
"scripts": {
"sync:version": "node scripts/sync-version.mjs",
"prestart": "npm run sync:version",
"start": "tsx src/index.ts",
"pretypecheck": "npm run sync:version",
"typecheck": "tsc --noEmit",
"lint": "eslint .",
"test": "vitest run",
"test:cli-contract": "vitest run __tests__/contract.test.ts",
"prebuild": "npm run sync:version",
"build": "tsc --noEmit && esbuild src/index.ts --bundle --platform=node --format=esm --external:commander --external:yaml --external:zod --external:@openhop/server --external:@openhop/web --external:fastify --external:@fastify/static --external:@fastify/http-proxy --outfile=dist/index.js --banner:js='#!/usr/bin/env node'",
"prepack": "npm run build && rm -rf skills && cp -r ../../skills ./skills"
},
Expand Down
18 changes: 18 additions & 0 deletions packages/cli/scripts/sync-version.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env node
// Regenerates src/version.ts from package.json so the CLI's --version
// output can never drift from the published package version. Run as
// prebuild — see packages/cli/package.json scripts.build.
//
// src/version.ts is gitignored; this script is the only writer.

import { readFileSync, writeFileSync } from 'node:fs'
import { fileURLToPath } from 'node:url'
import { dirname, resolve } from 'node:path'

const here = dirname(fileURLToPath(import.meta.url))
const pkgPath = resolve(here, '..', 'package.json')
const outPath = resolve(here, '..', 'src', 'version.ts')

const pkg = JSON.parse(readFileSync(pkgPath, 'utf-8'))
const banner = '// Auto-generated by scripts/sync-version.mjs from package.json. Do not edit.\n'
writeFileSync(outPath, `${banner}export const VERSION = ${JSON.stringify(pkg.version)}\n`)
3 changes: 2 additions & 1 deletion packages/cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
logStderr,
} from './utils.js'
import { ExitCode } from './exit-codes.js'
import { VERSION } from './version.js'
import { registerGet } from './get.js'
import { registerValidate } from './validate.js'
import { registerHelpJson } from './help-json.js'
Expand Down Expand Up @@ -50,7 +51,7 @@ if (process.argv.includes('--api-version')) {

const program = new Command()

program.name('openhop').description('OpenHop — Data Flow Visualization CLI').version('0.2.0')
program.name('openhop').description('OpenHop — Data Flow Visualization CLI').version(VERSION)

// --- serve ---
//
Expand Down
Loading