about summary refs log tree commit diff
path: root/pkgs/by-name/bl/blade-formatter/update.sh
blob: c7a0cdde38aa3b73f35b81fe798c4be7e70f4f8d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env nix-shell
#!nix-shell -i bash -p ripgrep common-updater-scripts prefetch-npm-deps jq sd

set -xeu -o pipefail

PACKAGE_DIR="$(realpath "$(dirname "$0")")"
cd "$PACKAGE_DIR/.."
while ! test -f default.nix; do cd .. ; done
NIXPKGS_DIR="$PWD"

new_version="$(
  list-git-tags --url=https://github.com/shufo/blade-formatter \
  | rg '^v([\d.]*)' -r '$1' \
  | sort --version-sort \
  | tail -n1
)"

cd "$NIXPKGS_DIR"
update-source-version blade-formatter "$new_version"

TMPDIR="$(mktemp -d)"
cd "$TMPDIR"

src="$(nix-build --no-link "$NIXPKGS_DIR" -A blade-formatter.src)"
cp $src/package.json .
npm update
cp ./package-lock.json "$PACKAGE_DIR"

prev_npm_hash="$(nix-instantiate "$NIXPKGS_DIR" \
  --eval --json \
  -A blade-formatter.npmDepsHash \
  | jq -r .
)"
new_npm_hash="$(prefetch-npm-deps ./package-lock.json)"

sd --fixed-strings "$prev_npm_hash" "$new_npm_hash" "$PACKAGE_DIR/package.nix"

rm -rf "$TMPDIR"