#!/usr/bin/env bash # Packs @colineapp/onset for a released version: the package names that # release's builds and checksums (from its download channel), so `on` from # npm fetches exactly what the release published. # Usage: npm/pack.sh [channel: latest|stable] [out folder] # Then: npm publish --access public set -euo pipefail VERSION=$1 CHANNEL=${2:-latest} OUT=${3:-$PWD} BASE=${ONSET_DOWNLOADS:-https://downloads.coline.dev/onset} HERE=$(cd "$(dirname "$0")" && pwd) DIR=$(mktemp -d) trap 'rm -rf "$DIR"' EXIT cp -R "$HERE/bin" "$HERE/package.json" "$HERE/README.md" "$DIR/" cp "$HERE/../LICENSE-APACHE" "$DIR/LICENSE" curl -fsSL "$BASE/$CHANNEL.json" -o "$DIR/manifest.json" node -e ' const fs = require("fs"); const [dir, version] = process.argv.slice(1); const m = JSON.parse(fs.readFileSync(dir + "/manifest.json", "utf8")); if (m.version !== version) { console.error(`the channel has ${m.version}, not ${version}`); process.exit(1); } for (const p of ["darwin-arm64", "darwin-x64", "linux-arm64", "linux-x64", "windows-x64", "windows-arm64"]) { if (!m.platforms[p]) { console.error(`the release has no ${p} build`); process.exit(1); } } const pkg = JSON.parse(fs.readFileSync(dir + "/package.json", "utf8")); pkg.version = version; fs.writeFileSync(dir + "/package.json", JSON.stringify(pkg, null, 2) + "\n"); ' "$DIR" "$VERSION" mkdir -p "$OUT" (cd "$DIR" && npm pack --silent --pack-destination "$OUT" >/dev/null 2>&1) echo "$OUT/colineapp-onset-$VERSION.tgz"