@genxapi/cli
v0.2.0
Published
GenX API CLI - Orchestration for API client generation workflows.
Readme
@genxapi/cli
CLI to scaffold, regenerate, synchronise, and publish multiple API clients using the GenX API templates.
Requirements
- Node.js v20+ (required by Orval's Commander dependency; older runtimes will emit engine warnings).
- Access tokens if you plan to push to GitHub (
GITHUB_TOKEN) or publish to npm (NPM_TOKEN).
Commands
genxapi generate– Generate clients defined in configuration, optionally override the output directory (--target), initialise/synchronise a GitHub repository, and publish to npm.genxapi publish– Create GitHub releases using Octokit.
Running the CLI
- One-off (no install):
npx @genxapi/cli --help - Local install: add
"cli": "genxapi"topackage.jsonscripts, then runnpm run cli -- --help
Environment Variables
GITHUB_TOKEN(configurable viaproject.repository.tokenEnv) – required to push commits or open pull requests.NPM_TOKEN(configurable viaproject.publish.npm.tokenEnv) – required to publish the generated package to npm.
Ensure
project.repository.ownermatches your GitHub login (case-insensitive). Leading@characters are stripped automatically before syncing.
Use project.readme in your configuration to customise the generated package README (introduction, usage text, extra sections).
- Navigate to Settings ▸ Developer settings ▸ Personal access tokens in GitHub.
- Create either:
- a Fine-grained token scoped to the repos you will update and enable:
- Repository permissions → Contents → Read and write (allows pushing commits and editing files)
- Repository permissions → Pull requests → Read and write
- or a Classic token and tick the single checkbox repo (minimal scope for commit + PR access).
- a Fine-grained token scoped to the repos you will update and enable:
- Copy the token and export it as GITHUB_TOKEN before running the generator.
- Sign in to npmjs.com.
- Go to Access Tokens and click Generate new token.
- Choose an Automation or Publish token (Automation is recommended for CI).
- Copy the token and export it as NPM_TOKEN before running the generator.
Sample Usage
GITHUB_TOKEN=ghp_xxx NPM_TOKEN=xxx \
genxapi generate \
--config samples/orval-multi-client.config.json \
--target ./examples/multi-client-demo \
--log-level debugThis command will:
- Load the config (including repository/publish settings) from the provided path or cosmiconfig search.
- Call
@genxapi/template-orvalto scaffold the template, apply replacements, copy swagger files, run Orval, and execute hooks. - Commit and push the generated changes to GitHub and open a pull request if
project.repositoryexists. - Publish the package if
project.publish.npm.enabledistrue(generated clients default to public access, matching the publish scripts in this monorepo).
Semantic-release examples
After running the generator, you can compare swagger revisions and generate a commit message for semantic-release:
# Compare swagger files and classify the change
node --input-type=module -e "import base from './packages/cli/src/utils/swaggerDiff/fixtures/base.json' assert { type: 'json' };
import { analyzeSwaggerDiff } from './packages/cli/src/utils/swaggerDiff/index.js';
const next = structuredClone(base);
next.paths['/pets/{id}'] = { get: { operationId: 'getPet', responses: { '200': { description: 'single pet' } } } };
console.log(analyzeSwaggerDiff(base, next));"This prints the commit suggestion (feat, fix, or chore) that feeds semantic-release version bumps.
Type safety
Run npm run typecheck at the repository root to validate both packages before raising a PR or publishing.
Publishing the CLI
# Build + publish to npmjs.org (public)
npm run build --workspace @genxapi/cli
npm publish --workspace @genxapi/cli --access publicPublishing to GitHub Packages is optional; include --registry https://npm.pkg.github.com and use a PAT with read:packages and write:packages scopes.
Installing from GitHub Packages
- Authenticate (requires
GITHUB_TOKENwithread:packages+write:packages):npm config set @genxapi:registry https://npm.pkg.github.com/ npm config set //npm.pkg.github.com/:_authToken ${GITHUB_TOKEN} - Run the bundled sample:
npx genxapi generate \ --config samples/orval-multi-client.config.json \ --target ./examples/multi-client-demo \ --log-level info
