|
| 1 | +#!/usr/bin/env bash |
| 2 | +# Stage the production tree for nfpm under staging/opt/etherpad. |
| 3 | +# Run from the repo root after `pnpm install` and `pnpm run build:etherpad`. |
| 4 | +# Used by .github/workflows/deb-package.yml and packaging/test-local.sh. |
| 5 | +set -euxo pipefail |
| 6 | + |
| 7 | +cd "$(dirname "$0")/.." |
| 8 | + |
| 9 | +STAGE=staging/opt/etherpad |
| 10 | +rm -rf staging |
| 11 | +mkdir -p "${STAGE}" |
| 12 | + |
| 13 | +# Production footprint = src/ + bin/ + metadata, plus a fresh |
| 14 | +# production-only node_modules installed below. src/ already holds the |
| 15 | +# admin + oidc builds from `build:etherpad`. Copying the workspace |
| 16 | +# node_modules used to ship every devDependency (typescript, playwright, |
| 17 | +# vitest, eslint, vite, ...) and the admin/ui/doc dependency trees, which |
| 18 | +# pushed the .deb past GitHub's 100 MiB per-file limit for the apt repo. |
| 19 | +cp -a src bin package.json pnpm-lock.yaml README.md LICENSE "${STAGE}/" |
| 20 | +rm -rf "${STAGE}/src/node_modules" "${STAGE}/bin/node_modules" \ |
| 21 | + "${STAGE}/src/tests" "${STAGE}/src/playwright.config.ts" \ |
| 22 | + "${STAGE}/src/vitest.config.ts" |
| 23 | + |
| 24 | +# Install production deps for the runtime workspace (root, src, bin) from |
| 25 | +# the lockfile. pnpm installs the dependencies of every importer listed in |
| 26 | +# the lockfile, even if its directory is missing, so drop the build-only |
| 27 | +# importers from the staged lockfile and workspace file. Everything else |
| 28 | +# (overrides, build policy) stays as-is so --frozen-lockfile still matches. |
| 29 | +BUILD_ONLY='admin|doc|ui|admin/tools/openapi-codegen' |
| 30 | +awk -v re="^ (${BUILD_ONLY}):\$" ' |
| 31 | + /^importers:/ { imp = 1; print; next } |
| 32 | + imp && /^[^ ]/ { imp = 0; skip = 0 } |
| 33 | + imp && /^ [^ ]/ { skip = ($0 ~ re) } |
| 34 | + !skip { print } |
| 35 | +' pnpm-lock.yaml > "${STAGE}/pnpm-lock.yaml" |
| 36 | +grep -Ev "^ - (${BUILD_ONLY})\$" pnpm-workspace.yaml > "${STAGE}/pnpm-workspace.yaml" |
| 37 | +( cd "${STAGE}" && CI=1 pnpm install --prod --frozen-lockfile ) |
| 38 | + |
| 39 | +# Ship the same minimal workspace file as before (same trick the |
| 40 | +# Dockerfile uses) and no lockfile. |
| 41 | +printf 'packages:\n - src\n - bin\n' > "${STAGE}/pnpm-workspace.yaml" |
| 42 | +rm -f "${STAGE}/pnpm-lock.yaml" |
| 43 | + |
| 44 | +mkdir -p packaging/etc |
| 45 | +cp settings.json.template packaging/etc/settings.json.dist |
| 46 | + |
| 47 | +# Purge test fixtures and docs from node_modules to shrink size. |
| 48 | +find "${STAGE}/node_modules" -type d \ |
| 49 | + \( -name test -o -name tests -o -name '__tests__' \ |
| 50 | + -o -name example -o -name examples -o -name docs \) \ |
| 51 | + -prune -exec rm -rf {} + 2>/dev/null || true |
| 52 | +find "${STAGE}/node_modules" -type f \ |
| 53 | + \( -name '*.md' -o -name '*.ts.map' -o -name '*.map' \ |
| 54 | + -o -name 'CHANGELOG*' -o -name 'HISTORY*' \) \ |
| 55 | + -delete 2>/dev/null || true |
0 commit comments