From 0b32b9110dd406ca052cfd7348f0ddd7e35b048e Mon Sep 17 00:00:00 2001 From: Joris Date: Sun, 4 Sep 2022 16:21:18 +0200 Subject: Use esbuild to produce JS --- README.md | 6 ++---- bin/dev-server | 7 ++----- bin/watch | 16 ++++++++++++++++ flake.lock | 42 ++++++++++++++++++++++++++++++++++++++++++ flake.nix | 22 ++++++++++++++++++++++ public/index.html | 20 ++------------------ shell.nix | 17 ----------------- tsconfig.json | 2 +- 8 files changed, 87 insertions(+), 45 deletions(-) create mode 100755 bin/watch create mode 100644 flake.lock create mode 100644 flake.nix delete mode 100644 shell.nix diff --git a/README.md b/README.md index 9f5b91f..4060ec1 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,7 @@ # Getting started -Run: +With nix installed: -```sh -nix-shell --run bin/watch.sh -``` + bin/dev-server Then, open your browser at `http://localhost:8000`. diff --git a/bin/dev-server b/bin/dev-server index 86eeab7..e1faf14 100755 --- a/bin/dev-server +++ b/bin/dev-server @@ -1,8 +1,5 @@ #!/usr/bin/env bash set -euo pipefail +cd `dirname "$0"`/.. -python -m http.server --directory public 8000 & - -trap "fuser -k 8000/tcp" EXIT - -tsc --target ES2017 --watch +nix develop --command bin/watch diff --git a/bin/watch b/bin/watch new file mode 100755 index 0000000..82686ae --- /dev/null +++ b/bin/watch @@ -0,0 +1,16 @@ +#!/usr/bin/env bash +set -euo pipefail + +# Run server + +python -m http.server --directory public 8000 & +trap "fuser -k 8000/tcp" EXIT + +# Watch TypeScript + +CHECK="echo Checking TypeScript… && tsc --checkJs" +BUILD="esbuild --bundle src/main.ts --target=es2017 --outdir=public" +watchexec \ + --clear \ + --watch src \ + -- "$CHECK && $BUILD" diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..01f7b38 --- /dev/null +++ b/flake.lock @@ -0,0 +1,42 @@ +{ + "nodes": { + "flake-utils": { + "locked": { + "lastModified": 1659877975, + "narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1662299586, + "narHash": "sha256-0zcDRe9eCcHfU7OQiuOZhu5LQR9C9u3XQR/dCJATGu8=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "5518e6aba11f50f0953fa21c7ad6a283c4741b95", + "type": "github" + }, + "original": { + "owner": "nixos", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..9ba146e --- /dev/null +++ b/flake.nix @@ -0,0 +1,22 @@ +{ + inputs = { + nixpkgs.url = "github:nixos/nixpkgs"; + flake-utils.url = "github:numtide/flake-utils"; + }; + + outputs = { self, nixpkgs, flake-utils }: + flake-utils.lib.eachDefaultSystem + (system: + let pkgs = nixpkgs.legacyPackages.${system}; + in { devShell = pkgs.mkShell { + buildInputs = with pkgs; [ + nodePackages.typescript + python3 + python3Packages.beautifulsoup4 + psmisc # fuser + esbuild + watchexec + ]; + }; } + ); +} diff --git a/public/index.html b/public/index.html index 27b8470..8fd4ddc 100644 --- a/public/index.html +++ b/public/index.html @@ -6,22 +6,6 @@ - - + - - + diff --git a/shell.nix b/shell.nix deleted file mode 100644 index 3bffe92..0000000 --- a/shell.nix +++ /dev/null @@ -1,17 +0,0 @@ -with (import (builtins.fetchGit { - name = "nixpkgs-20.09"; - url = "git@github.com:nixos/nixpkgs.git"; - rev = "cd63096d6d887d689543a0b97743d28995bc9bc3"; - ref = "refs/tags/20.09"; -}){}); - -mkShell { - - buildInputs = [ - nodePackages.typescript - python3 - python3Packages.beautifulsoup4 - psmisc # fuser - ]; - -} diff --git a/tsconfig.json b/tsconfig.json index 3e7f32b..380eab3 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,7 +1,7 @@ { "compilerOptions": { "module": "amd", - "target": "es5", + "target": "es2017", "baseUrl": "src", "outFile": "public/main.js", "noImplicitAny": true, -- cgit v1.2.3