aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoris2022-09-04 21:51:40 +0200
committerJoris2022-09-04 21:51:40 +0200
commit57a1076a18ac82e603ffa9fc78f960ee373895d5 (patch)
tree800e66f532ccf823277fee5a894a68077b397d83
parent5df9270538bfcc08c9726887c7b8f54eec894dce (diff)
Improve build tooling
-rw-r--r--Makefile9
-rw-r--r--README.md10
-rwxr-xr-xbin/dev-server7
-rwxr-xr-xbin/watch16
-rw-r--r--flake.lock42
-rw-r--r--flake.nix21
-rw-r--r--shell.nix16
-rw-r--r--tsconfig.json2
8 files changed, 96 insertions, 27 deletions
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..593752d
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,9 @@
+build:
+ @esbuild \
+ --bundle src/main.ts \
+ --minify \
+ --target=es2017 \
+ --outdir=public
+
+clean:
+ @rm -f public/main.js
diff --git a/README.md b/README.md
index 9f5b91f..c23312d 100644
--- a/README.md
+++ b/README.md
@@ -1,9 +1,9 @@
# Getting started
-Run:
+With nix installed:
-```sh
-nix-shell --run bin/watch.sh
-```
+ bin/dev-server
-Then, open your browser at `http://localhost:8000`.
+# Build
+
+ make
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..61aca1b
--- /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": 1662320704,
+ "narHash": "sha256-y5vVFelV8ptJPBp84pgtAG61+S1xcRkLK7OTL6SeELA=",
+ "owner": "nixos",
+ "repo": "nixpkgs",
+ "rev": "0973090c9b7d1b4db88628a7987471d8e398eb94",
+ "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..325ed60
--- /dev/null
+++ b/flake.nix
@@ -0,0 +1,21 @@
+{
+ 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
+ psmisc # fuser
+ esbuild
+ watchexec
+ ];
+ }; }
+ );
+}
diff --git a/shell.nix b/shell.nix
deleted file mode 100644
index ad4a34d..0000000
--- a/shell.nix
+++ /dev/null
@@ -1,16 +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
- 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,