From 9fb195819eb925d0286e8201b402c6dec5f1238d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tristan=20Dani=C3=ABl=20Maat?= Date: Sun, 18 Sep 2022 19:27:54 +0100 Subject: [PATCH] templates: Handle package.json conversion in direnv By splitting out the check for package.yaml into a separate check, we can avoid the constant massive shell reloads for the nix shell. --- flake.nix | 11 ----------- templates/.envrc | 10 ++++++++++ templates/.gitignore | 1 + 3 files changed, 11 insertions(+), 11 deletions(-) create mode 100644 templates/.envrc diff --git a/flake.nix b/flake.nix index 31efafc..eb41e49 100644 --- a/flake.nix +++ b/flake.nix @@ -34,17 +34,6 @@ yj ] ++ old.buildInputs; - - shellHook = - '' - # Update package.json - if [ -e ./package.json ]; then - unlink ./package.json - fi - - cat ./package.yaml | yj > ./package.json - '' - + old.shellHook; }); server = nixpkgs.legacyPackages.${system}.mkShell { diff --git a/templates/.envrc b/templates/.envrc new file mode 100644 index 0000000..6dc0224 --- /dev/null +++ b/templates/.envrc @@ -0,0 +1,10 @@ +nix_direnv_watch_file package-lock.json +use flake ..#templates + +# Update package.json +if ! cmp --silent .checksum-package.yaml <(sha256sum package.yaml); then + echo "Updating package.json" + unlink ./package.json + yj < ./package.yaml > ./package.json + sha256sum package.yaml > .checksum-package.yaml +fi diff --git a/templates/.gitignore b/templates/.gitignore index e349813..d6989d1 100644 --- a/templates/.gitignore +++ b/templates/.gitignore @@ -3,3 +3,4 @@ dist/ node_modules/ package.json result +.checksum-package.yaml