mirror of
https://github.com/wu736139669/hapi.git
synced 2026-08-05 06:24:37 +00:00
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
49 lines
1.5 KiB
JavaScript
49 lines
1.5 KiB
JavaScript
#!/usr/bin/env node
|
|
|
|
const { execFileSync } = require('child_process');
|
|
const path = require('path');
|
|
|
|
const platform = process.platform;
|
|
const arch = process.arch;
|
|
const pkgName = `@twsxtd/hapi-${platform}-${arch}`;
|
|
|
|
function getBinaryPath() {
|
|
try {
|
|
// Try to find the platform-specific package
|
|
const pkgPath = require.resolve(`${pkgName}/package.json`);
|
|
const binName = platform === 'win32' ? 'hapi.exe' : 'hapi';
|
|
return path.join(path.dirname(pkgPath), 'bin', binName);
|
|
} catch (e) {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
const binPath = getBinaryPath();
|
|
|
|
if (!binPath) {
|
|
console.error(`Unsupported platform: ${platform}-${arch}`);
|
|
console.error('');
|
|
console.error('Supported platforms:');
|
|
console.error(' - darwin-arm64 (macOS Apple Silicon)');
|
|
console.error(' - darwin-x64 (macOS Intel)');
|
|
console.error(' - linux-arm64');
|
|
console.error(' - linux-x64');
|
|
console.error(' - win32-x64');
|
|
console.error('');
|
|
console.error('You can download the binary manually from:');
|
|
console.error(' https://github.com/anthropics/hapi/releases');
|
|
process.exit(1);
|
|
}
|
|
|
|
try {
|
|
execFileSync(binPath, process.argv.slice(2), { stdio: 'inherit' });
|
|
} catch (e) {
|
|
// If the binary execution fails, exit with the same code
|
|
if (e.status !== undefined) {
|
|
process.exit(e.status);
|
|
}
|
|
// For other errors (e.g., binary not found), print and exit
|
|
console.error(`Failed to execute ${binPath}:`, e.message);
|
|
process.exit(1);
|
|
}
|