feat: add npx/bunx binary distribution support

Adds infrastructure for distributing Hapi via npm as a scoped package
(@twsxtd/hapi) with platform-specific optional dependencies. This enables
installation via `npx @twsxtd/hapi` or `bunx @twsxtd/hapi`.

- Add bin/hapi.js wrapper script for platform detection and binary selection
- Create npm/ directory structure for platform-specific packages (darwin-{arm64,x64},
  linux-{arm64,x64}, win32-x64)
- Add scripts/prepare-npm-packages.ts to generate platform-specific package.json files
  and copy binaries to npm packages
- Add scripts/publish-npm.ts for automated publishing of platform packages
- Update package.json with new scoped name, bin entry, optionalDependencies, and
  prepack/publish scripts
- Update .gitignore to ignore generated npm packages and build outputs
- Update .npmignore to only include bin/hapi.js wrapper, excluding source and build files
This commit is contained in:
weishu
2025-12-24 14:39:05 +08:00
parent bb9c5b66d3
commit 85c2dc10ea
12 changed files with 429 additions and 11 deletions
+11 -4
View File
@@ -11,10 +11,10 @@
},
},
"cli": {
"name": "hapi",
"name": "@twsxtd/hapi",
"version": "0.12.0-1",
"bin": {
"hapi": "./src/index.ts",
"hapi": "bin/hapi.js",
},
"dependencies": {
"@modelcontextprotocol/sdk": "^1.22.0",
@@ -49,6 +49,13 @@
"typescript": "^5",
"vitest": "^3.2.4",
},
"optionalDependencies": {
"@twsxtd/hapi-darwin-arm64": "0.0.0-placeholder",
"@twsxtd/hapi-darwin-x64": "0.0.0-placeholder",
"@twsxtd/hapi-linux-arm64": "0.0.0-placeholder",
"@twsxtd/hapi-linux-x64": "0.0.0-placeholder",
"@twsxtd/hapi-win32-x64": "0.0.0-placeholder",
},
},
"server": {
"name": "hapi-server",
@@ -588,6 +595,8 @@
"@tsconfig/node16": ["@tsconfig/node16@1.0.4", "", {}, "sha512-vxhUy4J8lyeyinH7Azl1pdd43GJhZH/tP2weN8TntQblOY+A0XbT8DJk1/oCPuOOyg/Ja757rG0CgHcWC8OfMA=="],
"@twsxtd/hapi": ["@twsxtd/hapi@workspace:cli"],
"@types/babel__core": ["@types/babel__core@7.20.5", "", { "dependencies": { "@babel/parser": "^7.20.7", "@babel/types": "^7.20.7", "@types/babel__generator": "*", "@types/babel__template": "*", "@types/babel__traverse": "*" } }, "sha512-qoQprZvz5wQFJwMDqeseRXWv3rqMvhgpbXFfVyWhbx9X47POIA6i/+dXefEmZKoAgOaTdaIgNSMqMIU61yRyzA=="],
"@types/babel__generator": ["@types/babel__generator@7.27.0", "", { "dependencies": { "@babel/types": "^7.0.0" } }, "sha512-ufFd2Xi92OAVPYsy+P4n7/U7e68fex0+Ee8gSG9KX7eo084CWiQ4sdxktvdl0bOPupXtVJPY19zk6EwWqUQ8lg=="],
@@ -1062,8 +1071,6 @@
"grammy": ["grammy@1.38.4", "", { "dependencies": { "@grammyjs/types": "3.22.2", "abort-controller": "^3.0.0", "debug": "^4.4.3", "node-fetch": "^2.7.0" } }, "sha512-z07Kin3HgRwMdy40KUs+c9fmNBvGlSxGwcqY8NAH0a8KULGFYEMQaFAo3ge0V5tvmgr02Jgubkf54KjHLAMCbw=="],
"hapi": ["hapi@workspace:cli"],
"hapi-server": ["hapi-server@workspace:server"],
"hapi-web": ["hapi-web@workspace:web"],