From 0d32e7b0d1eb1e4bcbdac3ca6e2af711f580afa5 Mon Sep 17 00:00:00 2001 From: Lubos Date: Mon, 27 Oct 2025 03:34:26 +0800 Subject: [PATCH] chore: put bin back --- .vscode/launch.json | 4 ++-- dev/openapi-ts.config.ts | 4 ++-- packages/openapi-ts/bin/run.cmd | 3 +++ packages/openapi-ts/bin/run.js | 18 ++++++++++++++++++ packages/openapi-ts/package.json | 3 ++- scripts/examples-generate.sh | 24 ------------------------ 6 files changed, 27 insertions(+), 29 deletions(-) create mode 100644 packages/openapi-ts/bin/run.cmd create mode 100755 packages/openapi-ts/bin/run.js diff --git a/.vscode/launch.json b/.vscode/launch.json index ae460a9a2..550fe0f2e 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -13,10 +13,10 @@ "request": "launch", "name": "openapi-ts", "skipFiles": ["/**"], + "cwd": "${workspaceFolder}/dev", "runtimeExecutable": "node", "runtimeArgs": ["-r", "ts-node/register/transpile-only"], - "program": "${workspaceFolder}/packages/openapi-ts/src/cli.ts", - "args": ["-f", "${workspaceFolder}/dev/openapi-ts.config.ts"] + "program": "${workspaceFolder}/packages/openapi-ts/src/cli.ts" } ] } diff --git a/dev/openapi-ts.config.ts b/dev/openapi-ts.config.ts index f1dbcdc11..40387011d 100644 --- a/dev/openapi-ts.config.ts +++ b/dev/openapi-ts.config.ts @@ -103,7 +103,7 @@ export default defineConfig(() => { // 'tsconfig.nodenext.json', // ), // }, - path.resolve(__dirname, '.gen'), + '.gen', ], parser: { filters: { @@ -478,7 +478,7 @@ export default defineConfig(() => { // // level: 'debug', // path: './logs', // }, - // output: path.resolve(__dirname, '.gen'), + // output: '.gen', // }, ]; }); diff --git a/packages/openapi-ts/bin/run.cmd b/packages/openapi-ts/bin/run.cmd new file mode 100644 index 000000000..d6abd96c4 --- /dev/null +++ b/packages/openapi-ts/bin/run.cmd @@ -0,0 +1,3 @@ +@echo off +node "%~dp0\run.js" %* + diff --git a/packages/openapi-ts/bin/run.js b/packages/openapi-ts/bin/run.js new file mode 100755 index 000000000..0e00c6225 --- /dev/null +++ b/packages/openapi-ts/bin/run.js @@ -0,0 +1,18 @@ +#!/usr/bin/env node +import { spawnSync } from 'node:child_process'; +import fs from 'node:fs'; +import path from 'node:path'; +import { fileURLToPath } from 'node:url'; + +const __dirname = path.dirname(fileURLToPath(import.meta.url)); +const target = path.join(__dirname, '..', 'dist', 'run.js'); + +if (!fs.existsSync(target)) { + console.error('openapi-ts not built (expect dist/run.js)'); + process.exit(1); +} + +const res = spawnSync(process.execPath, [target, ...process.argv.slice(2)], { + stdio: 'inherit', +}); +process.exit(res.status ?? 0); diff --git a/packages/openapi-ts/package.json b/packages/openapi-ts/package.json index 45597f9ca..b3ba3c61e 100644 --- a/packages/openapi-ts/package.json +++ b/packages/openapi-ts/package.json @@ -66,9 +66,10 @@ "./package.json": "./package.json" }, "bin": { - "openapi-ts": "./dist/run.js" + "openapi-ts": "./bin/run.js" }, "files": [ + "bin", "dist", "LICENSE.md", "README.md" diff --git a/scripts/examples-generate.sh b/scripts/examples-generate.sh index 00a275ab4..fb7032737 100755 --- a/scripts/examples-generate.sh +++ b/scripts/examples-generate.sh @@ -11,30 +11,6 @@ ROOT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)" echo "⏳ Generating client code for all examples..." -# Build the CLI package and show diagnostics so CI can report why the bin may be missing -echo "Building @hey-api/openapi-ts (required for example generation)..." -if command -v pnpm >/dev/null 2>&1; then - if pnpm -w -s --version >/dev/null 2>&1; then - pnpm -w -s --filter "@hey-api/openapi-ts" build || pnpm -s --filter "@hey-api/openapi-ts" build || true - else - pnpm -s --filter "@hey-api/openapi-ts" build || true - fi -fi - -CLI_PKG_DIR="$ROOT_DIR/packages/openapi-ts" -echo "-> Debug: showing $CLI_PKG_DIR/package.json" -if [ -f "$CLI_PKG_DIR/package.json" ]; then - cat "$CLI_PKG_DIR/package.json" -else - echo "-> Debug: package.json missing at $CLI_PKG_DIR" -fi - -echo "-> Debug: listing $CLI_PKG_DIR top-level files" -ls -la "$CLI_PKG_DIR" || true -echo "-> Debug: listing $CLI_PKG_DIR/dist" -ls -la "$CLI_PKG_DIR/dist" 2>/dev/null || echo "-> Debug: dist missing" - - # Find all examples with openapi-ts script and generate code in parallel # Concurrency control: adjust this number depending on CI machine resources CONCURRENCY=${CONCURRENCY:-4} -- 2.51.2