diff --git a/bin/openapi-mcp-generator.js b/bin/openapi-mcp-generator.js new file mode 100755 index 0000000..3f1bb95 --- /dev/null +++ b/bin/openapi-mcp-generator.js @@ -0,0 +1,6 @@ +#!/usr/bin/env node + +import { program } from '../dist/index.js'; + +// Parse CLI arguments and run the program +program.parse(process.argv); \ No newline at end of file diff --git a/package.json b/package.json index 0837bd8..77840db 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "openapi-mcp-generator", - "version": "3.1.0", + "version": "3.1.1", "description": "Generates MCP server code from OpenAPI specifications", "license": "MIT", "author": "Harsha", @@ -9,10 +9,11 @@ "node": ">=20.0.0" }, "bin": { - "openapi-mcp-generator": "./dist/index.js" + "openapi-mcp-generator": "./bin/openapi-mcp-generator.js" }, "files": [ "dist", + "bin", "README.md", "LICENSE" ], @@ -20,7 +21,7 @@ "start": "node dist/index.js", "clean": "rimraf dist", "typecheck": "tsc --noEmit", - "build": "tsc && chmod 755 dist/index.js", + "build": "tsc && chmod 755 dist/index.js && chmod 755 bin/openapi-mcp-generator.js", "version:patch": "npm version patch", "version:minor": "npm version minor", "version:major": "npm version major" diff --git a/src/index.ts b/src/index.ts index 7b97d78..54629d5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -72,22 +72,17 @@ program (val) => parseInt(val, 10) ) .option('--force', 'Overwrite existing files without prompting') - .version('3.1.0'); // Match package.json version + .version('3.1.1') // Match package.json version + .action(options => { + runGenerator(options) + .catch((error) => { + console.error('Unhandled error:', error); + process.exit(1); + }); + }); -// Check if module is being run directly (not imported) -const isMainModule = process.argv[1] === new URL(import.meta.url).pathname; - -if (isMainModule) { - // Parse arguments explicitly from process.argv - program.parse(process.argv); - - // Run with the parsed options - runGenerator(program.opts()) - .catch((error) => { - console.error('Unhandled error:', error); - process.exit(1); - }); -} +// Export the program object for use in bin stub +export { program }; /** * Main function to run the generator