diff --git a/.vscode/launch.json b/.vscode/launch.json --- 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 --- a/dev/openapi-ts.config.ts +++ b/dev/openapi-ts.config.ts @@ -103,7 +103,7 @@ // 'tsconfig.nodenext.json', // ), // }, - path.resolve(__dirname, '.gen'), + '.gen', ], parser: { filters: { @@ -478,7 +478,7 @@ // // level: 'debug', // path: './logs', // }, - // output: path.resolve(__dirname, '.gen'), + // output: '.gen', // }, ]; }); diff --git a/scripts/examples-generate.sh b/scripts/examples-generate.sh --- a/scripts/examples-generate.sh +++ b/scripts/examples-generate.sh @@ -11,30 +11,6 @@ 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} diff --git a/packages/openapi-ts/package.json b/packages/openapi-ts/package.json --- 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/packages/openapi-ts/bin/run.cmd b/packages/openapi-ts/bin/run.cmd new file mode 100644 --- /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 100644 --- /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);