Skip to content

Instantly share code, notes, and snippets.

@leaysgur
Created May 18, 2026 06:31
Show Gist options
  • Select an option

  • Save leaysgur/1b982b4602b775eed4f49bd3a37b8845 to your computer and use it in GitHub Desktop.

Select an option

Save leaysgur/1b982b4602b775eed4f49bd3a37b8845 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# Simulate `npm i oxfmt` from local sources.
#
# Builds the dev artifacts, assembles a package layout matching `npm/oxfmt/`
# plus the freshly built `dist/`, packs it with `npm pack`, then installs the
# tarball into a clean directory under /tmp to mimic a real user install.
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
OXFMT_APP_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
REPO_ROOT="$(cd "$OXFMT_APP_DIR/../.." && pwd)"
NPM_TEMPLATE_DIR="$REPO_ROOT/npm/oxfmt"
STAGE_DIR="/tmp/oxfmt-pack"
INSTALL_DIR="/tmp/oxfmt-install"
echo "==> Building oxfmt (pnpm build-dev)"
(cd "$OXFMT_APP_DIR" && pnpm build-dev)
echo "==> Staging package at $STAGE_DIR"
rm -rf "$STAGE_DIR"
mkdir -p "$STAGE_DIR"
# Copy published files from the npm template (package.json, bin/, README, schema)
cp "$NPM_TEMPLATE_DIR/package.json" "$STAGE_DIR/package.json"
cp "$NPM_TEMPLATE_DIR/README.md" "$STAGE_DIR/README.md"
cp "$NPM_TEMPLATE_DIR/configuration_schema.json" "$STAGE_DIR/configuration_schema.json"
mkdir -p "$STAGE_DIR/bin"
cp "$NPM_TEMPLATE_DIR/bin/oxfmt" "$STAGE_DIR/bin/oxfmt"
# Copy freshly built dist (includes the local .node binary from build-dev)
cp -R "$OXFMT_APP_DIR/dist" "$STAGE_DIR/dist"
echo "==> Running npm pack"
TARBALL_NAME="$(cd "$STAGE_DIR" && npm pack --silent)"
TARBALL_PATH="$STAGE_DIR/$TARBALL_NAME"
echo " -> $TARBALL_PATH"
echo "==> Installing into $INSTALL_DIR"
rm -rf "$INSTALL_DIR"
mkdir -p "$INSTALL_DIR"
(
cd "$INSTALL_DIR"
npm init -y >/dev/null
npm install "$TARBALL_PATH"
)
echo "==> Smoke test: oxfmt --version"
"$INSTALL_DIR/node_modules/.bin/oxfmt" --version
echo ""
echo "Done!"
echo " Tarball : $TARBALL_PATH"
echo " Install : $INSTALL_DIR"
echo " CLI : $INSTALL_DIR/node_modules/.bin/oxfmt"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment