aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoris2022-09-04 16:21:18 +0200
committerJoris2022-09-04 16:21:18 +0200
commit0b32b9110dd406ca052cfd7348f0ddd7e35b048e (patch)
tree11e0da7d61be8d7602c53b95d1738a87b2179dd2
parenta5f8943c7eecd2048007b53610d7bc1edaa5ac05 (diff)
downloadglycemie-0b32b9110dd406ca052cfd7348f0ddd7e35b048e.tar.gz
glycemie-0b32b9110dd406ca052cfd7348f0ddd7e35b048e.tar.bz2
glycemie-0b32b9110dd406ca052cfd7348f0ddd7e35b048e.zip
Use esbuild to produce JS
-rw-r--r--README.md6
-rwxr-xr-xbin/dev-server7
-rwxr-xr-xbin/watch16
-rw-r--r--flake.lock42
-rw-r--r--flake.nix22
-rw-r--r--public/index.html20
-rw-r--r--shell.nix17
-rw-r--r--tsconfig.json2
8 files changed, 87 insertions, 45 deletions
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 @@
<link rel="stylesheet" href="/main.css">
<link rel="icon" href="/icon.png">
-<body>
- <script>
- // https://github.com/al6x/stupid&#45;simple&#45;typescript&#45;web&#45;starter
- window.define = function(name, required, moduleFn) {
- var require = function() { throw new Error("AMD require not supported!")}
- var exports = window.define.modules[name] = {}
- var resolved = [require, exports]
- for (var i = 2; i < required.length; i++) {
- var m = window.define.modules[required[i]]
- if (!m) throw new Error("AMD module `" + required[i] + "` not found!")
- resolved.push(m)
- }
- moduleFn.apply(null, resolved)
- }
- window.define.modules = {}
- </script>
+<body></body>
- <script src="main.js"></script>
-</body>
+<script src="main.js"></script>
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,