1#!/usr/bin/env nix-shell
2#!nix-shell -i bash -p curl jq common-updater-scripts nodejs prefetch-npm-deps sd
3
4set -xeu -o pipefail
5
6PACKAGE_DIR="$(realpath "$(dirname "$0")")"
7cd "$PACKAGE_DIR/.."
8while ! test -f flake.nix; do cd .. ; done
9NIXPKGS_DIR="$PWD"
10
11latest_commit="$(
12 curl -L -s ${GITHUB_TOKEN:+-u ":${GITHUB_TOKEN}"} https://api.github.com/repos/less/less-plugin-clean-css/branches/master \
13 | jq -r .commit.sha
14)"
15
16# This repository does not report it's version in tags
17version="$(
18 curl https://raw.githubusercontent.com/less/less-plugin-clean-css/$latest_commit/package.json \
19 | jq -r .version
20)"
21update-source-version lessc.plugins.clean-css "$version" --rev=$latest_commit
22
23src="$(nix-build --no-link "$NIXPKGS_DIR" -A lessc.plugins.clean-css.src)"
24
25prev_npm_hash="$(
26 nix-instantiate "$NIXPKGS_DIR" \
27 --eval --json -A lessc.plugins.clean-css.npmDepsHash \
28 | jq -r .
29)"
30new_npm_hash="$(prefetch-npm-deps "$src/package-lock.json")"
31sd --fixed-strings "$prev_npm_hash" "$new_npm_hash" "$PACKAGE_DIR/default.nix"