47 lines
2.0 KiB
Bash
Executable File
47 lines
2.0 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Publish all @logger/* packages to the private Verdaccio WITH a `readme` field
|
|
# injected into each manifest.
|
|
#
|
|
# Why this script (and not `pnpm publish -r`): Verdaccio v6 does NOT extract the
|
|
# README from the tarball — it only reads the manifest `readme` field, which
|
|
# modern `npm`/`pnpm publish` no longer populate. Without injection the registry
|
|
# UI shows "No README data found!" for every package. This script injects
|
|
# `readme` (from each package's README.md), rewrites `workspace:*` to the real
|
|
# version for the publish, then restores the source package.json.
|
|
#
|
|
# Usage:
|
|
# ./scripts/publish.sh # version = packages/shared-schema's version
|
|
# ./scripts/publish.sh 0.2.2 # explicit version
|
|
# REGISTRY=http://192.168.0.15:4873 ./scripts/publish.sh
|
|
set -euo pipefail
|
|
cd "$(dirname "$0")/.."
|
|
REGISTRY="${REGISTRY:-http://localhost:4873}"
|
|
VER="${1:-$(node -p "require('./packages/shared-schema/package.json').version")}"
|
|
PKGS=(shared-schema sdk collector cli)
|
|
|
|
echo "Publishing @logger/*@${VER} to ${REGISTRY} (readme injected)"
|
|
|
|
restore_all() { for f in packages/*/package.json.bak; do [ -f "$f" ] && mv "$f" "${f%.bak}"; done; }
|
|
trap restore_all EXIT
|
|
|
|
for pkg in "${PKGS[@]}"; do
|
|
f="packages/$pkg/package.json"
|
|
cp "$f" "$f.bak"
|
|
node -e "
|
|
const fs=require('fs');
|
|
const f='$f', pkgName='$pkg', ver='$VER';
|
|
const pkg=JSON.parse(fs.readFileSync(f,'utf8'));
|
|
pkg.readme = fs.readFileSync('packages/'+pkgName+'/README.md','utf8');
|
|
const deps = pkg.dependencies || {};
|
|
for (const d of Object.keys(deps)) if (deps[d] === 'workspace:*') deps[d] = '^'+ver;
|
|
fs.writeFileSync(f, JSON.stringify(pkg,null,2)+'\n');
|
|
"
|
|
echo "--- @logger/$pkg@$VER ---"
|
|
( cd "packages/$pkg" && npm publish --registry="$REGISTRY" --access public 2>&1 | tail -2 )
|
|
mv "$f.bak" "$f"
|
|
done
|
|
trap - EXIT
|
|
|
|
echo "done; source package.json files restored."
|
|
echo "verify: curl -s ${REGISTRY}/@logger/cli | node -e \"let s='';process.stdin.on('data',d=>s+=d).on('end',()=>console.log('readme len:',(JSON.parse(s).readme||'').length))\""
|