claude-code-best/scripts/pack-npm.sh
James Feng e806327608 feat: npm 离线打包脚本 — scripts/pack-npm.sh
一键构建 + 打包为 ccp-<version>.tgz:
  bash scripts/pack-npm.sh

目标机器安装(需要 Bun):
  npm install -g ./ccp-2.6.5.tgz
  ccp --version

产物 5.5MB,包含 dist-nosplit/cli.js + bin wrapper
2026-06-04 16:13:29 +08:00

60 lines
1.3 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env bash
# scripts/pack-npm.sh — 构建 + 打包为 npm .tgz 离线安装包
set -e
echo "=== 1. 构建 ==="
bun run build --no-splitting
echo "=== 2. 准备打包目录 ==="
VERSION=$(node -p "require('./package.json').version")
PACK_DIR="/tmp/ccp-pack"
rm -rf "$PACK_DIR"
mkdir -p "$PACK_DIR/bin"
echo "=== 3. 复制产物 ==="
cp dist-nosplit/cli.js "$PACK_DIR/cli.js"
chmod +x "$PACK_DIR/cli.js"
echo "=== 4. 创建 bin 入口 ==="
cat > "$PACK_DIR/bin/ccp" << 'BINEOF'
#!/usr/bin/env bash
# ccp — CC Pure CLI wrapper
# Requires: bun (https://bun.sh)
DIR="$(cd "$(dirname "$0")/.." && pwd)"
exec bun "$DIR/cli.js" "$@"
BINEOF
chmod +x "$PACK_DIR/bin/ccp"
echo "=== 5. 生成 package.json ==="
cat > "$PACK_DIR/package.json" << PKGEOF
{
"name": "ccp",
"version": "$VERSION",
"description": "CC Pure — 纯净版 Claude Code CLI",
"license": "UNLICENSED",
"private": true,
"bin": {
"ccp": "./bin/ccp"
},
"engines": {
"bun": ">=1.3.0"
},
"files": [
"cli.js",
"bin/"
]
}
PKGEOF
echo "=== 6. 打包 ==="
TARBALL="ccp-${VERSION}.tgz"
(cd "$PACK_DIR" && npm pack --pack-destination /tmp)
mv "/tmp/$TARBALL" "./$TARBALL"
echo ""
echo "✅ 完成: $(pwd)/$TARBALL ($(du -h ./$TARBALL | cut -f1))"
echo ""
echo "安装方式(目标机器需要 Bun:"
echo " npm install -g ./$TARBALL"
echo " ccp --version"