summaryrefslogtreecommitdiffstats
path: root/pkgs/by-name/da/dart_frog_cli/update.nix
blob: f41d0f2cab26b48b2523df301c86a64d467bdf56 (plain)
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
{
  writeShellApplication,
  common-updater-scripts,
  nix-update,
  yq-go,
  dart,
  nix,
}:
let
  name = "update-dart_frog_cli";
  packageName = "dart_frog_cli";
  packageDir = toString ./.;
in
writeShellApplication {
  inherit name;
  runtimeInputs = [
    common-updater-scripts
    nix-update
    yq-go
    dart
    nix
  ];
  text = ''
    pname="''${UPDATE_NIX_PNAME:-${packageName}}"

    main() {
      old_version="''${UPDATE_NIX_OLD_VERSION:-$(get_version)}"
      nix-update "$pname" --version stable --version-regex "$pname-v([0-9.]+(:?\\+[0-9]+)?)"
      new_version=$(get_version)
      if [[ "$new_version" == "$old_version" ]]; then
        exit 0
      fi
      generate_lockfile
    }

    get_version() {
      nix-instantiate --raw --eval --strict -A "$pname.version"
    }

    generate_lockfile() {
      tmp_dir=$(mktemp -d)
      trap 'rm -rf "$tmp_dir"' EXIT

      src=$(nix-build --no-link . -A "$pname.src")

      cp -r "$src/packages/$pname/." "$tmp_dir/"
      chmod -R +w "$tmp_dir"
      cd "$tmp_dir"

      # Remove pubspec overrides as in the nix preBuild
      rm pubspec_overrides.yaml

      # Generate lockfile because it's not included in the source
      if ! test -f pubspec.lock; then
        dart pub get
      fi

      # Convert to JSON
      yq -o=json . pubspec.lock > "${packageDir}/pubspec.lock.json"
    }

    main
  '';
}