diff --git a/Makefile b/Makefile index f20a91b..0975d8e 100644 --- a/Makefile +++ b/Makefile @@ -161,12 +161,19 @@ load.utils: ############################## ..: COMMANDS pkg.*:.. ################################ +.PHONY: pkg.brew.sync +pkg.brew.sync: + @## npm run sync:brew + @echo -e "\n✨ Update Homebrew formula... ⏳\n" + @cd $(NPM_PKG_DIR) && npm run sync:brew + .PHONY: pkg.npm.bump.pptxdiff pkg.npm.bump.pptxdiff: @## npm version patch @echo -e "\n✨ Bumping NPM package version... ⏳\n" @cd $(NPM_PKG_DIR) && npm version minor --no-git-tag-version +.PHONY: pkg.npm.build pkg.npm.build: @## npm run build:npm @echo -e "\n✨ Building NPM package... ⏳\n" diff --git a/package.json b/package.json index 3c52d4e..b6bdf98 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ "pptxdiff": "bin/cli.js" }, "scripts": { + "sync:brew" : "cd ./src/packages/pptxdiff-brew/ && source ./sync-formula.sh --package pptxdiff --formula Formula/pptxdiff.rb", "build:npm": "mkdir -p dist && npm pack --pack-destination dist", "package:vscode": "cd src/packages/pptxdiff-vscode && mkdir -p dist && vsce package --out dist/pptxdiff-vscode-$(node -p \"require('./package.json').version\").vsix" }, diff --git a/src/packages/pptxdiff-brew/Formula/pptxdiff.rb b/src/packages/pptxdiff-brew/Formula/pptxdiff.rb index fb4db15..c8d3980 100644 --- a/src/packages/pptxdiff-brew/Formula/pptxdiff.rb +++ b/src/packages/pptxdiff-brew/Formula/pptxdiff.rb @@ -1,8 +1,8 @@ class Pptxdiff < Formula desc "Local-first PowerPoint (.pptx) deck diff tool with CLI and browser UI" homepage "https://github.com/sugatoray/pptxdiff" - url "https://registry.npmjs.org/pptxdiff/-/pptxdiff-0.7.0.tgz" - sha256 "b7bc10ffee012efa1d4914e53b264b338dfbb15dea0714f31c6f664023bff272" + url "https://registry.npmjs.org/pptxdiff/-/pptxdiff-0.8.0.tgz" + sha256 "6bfcb3535d7c9ea3baacbf7e0e506c52fe63c91f00b692f1928eeb5e21e5c35f" license "Apache-2.0" livecheck do diff --git a/src/packages/pptxdiff-brew/package.json b/src/packages/pptxdiff-brew/package.json index d523378..627c12b 100644 --- a/src/packages/pptxdiff-brew/package.json +++ b/src/packages/pptxdiff-brew/package.json @@ -1,6 +1,6 @@ { "name": "pptxdiff-brew", - "version": "0.7.0-20260809", + "version": "0.8.0", "description": "Homebrew formula packaging for pptxdiff (Formula/pptxdiff.rb) and its version-bump sync tooling (sync-tap.mjs) — not an npm package itself, just a place to run its Red/Green tests.", "license": "Apache-2.0", "private": true, diff --git a/src/packages/pptxdiff-brew/sync-formula.sh b/src/packages/pptxdiff-brew/sync-formula.sh new file mode 100755 index 0000000..20cbe50 --- /dev/null +++ b/src/packages/pptxdiff-brew/sync-formula.sh @@ -0,0 +1,138 @@ +#!/usr/bin/env bash +# Bumps a Homebrew formula's `url`/`sha256` pin to match a published npm +# package — the shell-script counterpart to sync-tap.mjs. The formula it +# updates lives at `Formula/.rb` relative to this script's +# directory. +# +# Usage: +# ./sync-formula.sh [PACKAGE_NAME] [--version x.y.z] [--formula Formula/name.rb] +# ./sync-formula.sh --package PACKAGE_NAME [--version x.y.z] +# +# PACKAGE_NAME npm package to resolve (default: pptxdiff). The formula +# file updated is `Formula/.rb` by default. +# --version pin an exact version; defaults to npm's dist-tags.latest. +# --formula formula path to update; defaults to Formula/.rb. +# +# Exits 0 whether or not a change was made; prints "already up to date" and +# leaves the file untouched when the pin already matches. + +set -euo pipefail + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" + +usage() { + cat >&2 <&2; usage; exit 2; } + PACKAGE_NAME="$2" + shift 2 + ;; + --version) + [[ $# -ge 2 ]] || { echo "error: --version requires a value" >&2; usage; exit 2; } + VERSION="$2" + shift 2 + ;; + --formula) + [[ $# -ge 2 ]] || { echo "error: --formula requires a value" >&2; usage; exit 2; } + FORMULA_FILE="$2" + shift 2 + ;; + -h|--help) + usage + exit 0 + ;; + --*) + echo "error: unknown argument: $1" >&2 + usage + exit 2 + ;; + *) + if [[ "$PACKAGE_NAME" != "pptxdiff" ]]; then + echo "error: package name was provided more than once" >&2 + usage + exit 2 + fi + PACKAGE_NAME="$1" + shift + ;; + esac +done + +if [[ -z "$FORMULA_FILE" ]]; then + FORMULA_FILE="$SCRIPT_DIR/Formula/$PACKAGE_NAME.rb" +elif [[ "$FORMULA_FILE" != /* ]]; then + FORMULA_FILE="$SCRIPT_DIR/$FORMULA_FILE" +fi + +if [[ ! -f "$FORMULA_FILE" ]]; then + echo "error: formula not found: $FORMULA_FILE" >&2 + exit 1 +fi + +command -v npm >/dev/null 2>&1 || { echo "error: npm is required" >&2; exit 1; } +command -v curl >/dev/null 2>&1 || { echo "error: curl is required" >&2; exit 1; } + +resolve_version() { + npm view "$PACKAGE_NAME@$VERSION" version 2>/dev/null +} + +resolve_tarball() { + npm view "$PACKAGE_NAME@$VERSION" dist.tarball 2>/dev/null +} + +sha256_of() { + if command -v shasum >/dev/null 2>&1; then + shasum -a 256 "$1" | awk '{print $1}' + else + sha256sum "$1" | awk '{print $1}' + fi +} + +VERSION="$(resolve_version)" +if [[ -z "$VERSION" ]]; then + echo "error: could not resolve a version for $PACKAGE_NAME" >&2 + exit 1 +fi + +TARBALL_URL="$(resolve_tarball)" +if [[ -z "$TARBALL_URL" ]]; then + echo "error: could not resolve a dist.tarball for $PACKAGE_NAME@$VERSION" >&2 + exit 1 +fi + +TMP_DIR="$(mktemp -d)" +trap 'rm -rf "$TMP_DIR"' EXIT + +TARBALL_FILE="$TMP_DIR/$PACKAGE_NAME-$VERSION.tgz" +echo "$PACKAGE_NAME@$VERSION: downloading $TARBALL_URL to compute its real sha256..." +curl -fsSL "$TARBALL_URL" -o "$TARBALL_FILE" +SHA256="$(sha256_of "$TARBALL_FILE")" + +CURRENT_URL="$(sed -nE 's/^[[:space:]]*url[[:space:]]+"([^"]+)"/\1/p' "$FORMULA_FILE" | head -n1)" +CURRENT_SHA256="$(sed -nE 's/^[[:space:]]*sha256[[:space:]]+"([^"]+)"/\1/p' "$FORMULA_FILE" | head -n1)" + +if [[ "$CURRENT_URL" == "$TARBALL_URL" && "$CURRENT_SHA256" == "$SHA256" ]]; then + echo "$FORMULA_FILE is already up to date with $PACKAGE_NAME@$VERSION." + exit 0 +fi + +sed -i.bak -E \ + -e "s|^([[:space:]]*url[[:space:]]+\")[^\"]+|\1$TARBALL_URL|" \ + -e "s|^([[:space:]]*sha256[[:space:]]+\")[^\"]+|\1$SHA256|" \ + "$FORMULA_FILE" +rm -f "$FORMULA_FILE.bak" + +echo "Updated $FORMULA_FILE:" +echo " url: $CURRENT_URL -> $TARBALL_URL" +echo " sha256: $CURRENT_SHA256 -> $SHA256" diff --git a/src/packages/pptxdiff-chocolatey/pptxdiff.nuspec b/src/packages/pptxdiff-chocolatey/pptxdiff.nuspec index 0682981..2bd0ed0 100644 --- a/src/packages/pptxdiff-chocolatey/pptxdiff.nuspec +++ b/src/packages/pptxdiff-chocolatey/pptxdiff.nuspec @@ -2,7 +2,7 @@ pptxdiff - 0.7.0 + 0.8.0 https://github.com/sugatoray/pptxdiff/tree/master/src/packages/pptxdiff-chocolatey sugatoray @@ -61,7 +61,7 @@ See the project README (https://github.com/sugatoray/pptxdiff) and documentation https://github.com/sugatoray/pptxdiff/blob/master/CHANGELOG.md - + diff --git a/src/packages/pptxdiff-chocolatey/tools/chocolateyinstall.ps1 b/src/packages/pptxdiff-chocolatey/tools/chocolateyinstall.ps1 index c64e1fc..fa053d6 100644 --- a/src/packages/pptxdiff-chocolatey/tools/chocolateyinstall.ps1 +++ b/src/packages/pptxdiff-chocolatey/tools/chocolateyinstall.ps1 @@ -5,7 +5,7 @@ $npmPackageVersion = $env:chocolateyPackageVersion if ([string]::IsNullOrWhiteSpace($npmPackageVersion)) { # Fallback for manual `choco pack`/`choco install -s .` runs where Chocolatey # doesn't set the package-version environment variable (e.g. local testing). - $npmPackageVersion = '0.7.0' + $npmPackageVersion = '0.8.0' } $npmCmd = Get-Command npm -ErrorAction SilentlyContinue