aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--flake.nix21
-rwxr-xr-xsrc/frontend/build.sh5
-rw-r--r--src/frontend/deno.lock (renamed from src/frontend/lock.json)0
-rw-r--r--src/frontend/deps.ts10
-rw-r--r--src/frontend/wasiterm.tsx50
-rw-r--r--static/js/.gitignore1
6 files changed, 74 insertions, 13 deletions
diff --git a/flake.nix b/flake.nix
index c271984..9e78148 100644
--- a/flake.nix
+++ b/flake.nix
@@ -88,23 +88,28 @@
};
frontend = let
- share-button = pkgs.deno2nix.mkBundled {
- pname = "xesite-frontend-mastodon-share-button";
+ build = { entrypoint, name ? entrypoint, minify ? true }: pkgs.deno2nix.mkBundled {
+ pname = "xesite-frontend-${name}";
inherit (bin) version;
src = ./src/frontend;
- lockfile = ./src/frontend/lock.json;
+ lockfile = ./src/frontend/deno.lock;
- output = "mastodon_share_button.js";
+ output = "${entrypoint}.js";
outPath = "static/js";
- entrypoint = "./mastodon_share_button.tsx";
+ entrypoint = "./${entrypoint}.tsx";
importMap = "./import_map.json";
- minify = true;
+ inherit minify;
+ };
+ share-button = build {
+ entrypoint = "mastodon_share_button";
+ };
+ wasiterm = build {
+ entrypoint = "wasiterm";
};
-
in pkgs.symlinkJoin {
name = "xesite-frontend-${bin.version}";
- paths = [ share-button ];
+ paths = [ share-button wasiterm ];
};
static = pkgs.stdenv.mkDerivation {
diff --git a/src/frontend/build.sh b/src/frontend/build.sh
index 0f5859a..33577ae 100755
--- a/src/frontend/build.sh
+++ b/src/frontend/build.sh
@@ -1,11 +1,12 @@
#!/usr/bin/env bash
denobuild() {
- deno cache --import-map=./import_map.json --lock lock.json --lock-write *.tsx deps.ts
- deno bundle --import-map=./import_map.json --lock lock.json $1 $2
+ deno cache --import-map=./import_map.json --lock deno.lock --lock-write *.tsx deps.ts
+ deno bundle --import-map=./import_map.json --lock deno.lock $1 $2
}
set -e
export RUST_LOG=info
denobuild ./mastodon_share_button.tsx ../../static/js/mastodon_share_button.js
+denobuild ./wasiterm.tsx ../../static/js/wasiterm.js
diff --git a/src/frontend/lock.json b/src/frontend/deno.lock
index 01f35a5..01f35a5 100644
--- a/src/frontend/lock.json
+++ b/src/frontend/deno.lock
diff --git a/src/frontend/deps.ts b/src/frontend/deps.ts
index db03865..d885509 100644
--- a/src/frontend/deps.ts
+++ b/src/frontend/deps.ts
@@ -1,6 +1,10 @@
import * as wasi from "https://deno.land/x/wasm@v1.2.2/wasi.ts";
-import * as xeact from "xeact";
+//import * as xterm from "https://esm.sh/xterm@5.0.0";
-await wasi.init();
+import * as xeact from "xeact";
-export { wasi, xeact };
+export {
+ wasi,
+ xeact,
+ //xterm
+};
diff --git a/src/frontend/wasiterm.tsx b/src/frontend/wasiterm.tsx
new file mode 100644
index 0000000..352d03c
--- /dev/null
+++ b/src/frontend/wasiterm.tsx
@@ -0,0 +1,50 @@
+import { wasi as wasiMod, xeact } from "./deps.ts";
+
+const { x, t } = xeact;
+//const { Terminal } = xterm;
+const { WASI } = wasiMod;
+
+const init = async (rootElem: Element, wasmURL: string) => {
+ const termElem = <code></code>;
+
+ //const term = new Terminal();
+ //term.open(termElem);
+
+ const runProgram = async () => {
+ await wasiMod.init(new URL("https://cdn.xeiaso.net/file/christine-static/wasm/5410143de81b20061e9750d1cf80aceef56d2938ab949e30dd7b13fa699307ad.wasm"));
+
+ termElem.appendChild(t(`loading ${wasmURL}`));
+
+ const wasi = new WASI({
+ env: {
+ "HOSTNAME": "pyra",
+ },
+ })
+
+ const moduleBytes = fetch(wasmURL);
+ const module = await WebAssembly.compileStreaming(moduleBytes);
+ await wasi.instantiate(module, {});
+ //term.writeln("executing");
+ termElem.appendChild(t("executing"));
+ let exitCode = wasi.start();
+ let stdout = wasi.getStdoutString();
+ console.log(`${stdout}\n\n(exit code: ${exitCode})`);
+ termElem.appendChild(t(`${stdout}\n\n(exit code: ${exitCode})`));
+ };
+
+ const runButton = <button onclick={runProgram}>Run</button>;
+
+ const root = <div>
+ <link rel="stylesheet" href="https://cdn.xeiaso.net/file/christine-static/wasm/xterm/xterm-a36f07105014cc9220cae423d97c30d1a59fdb0230da8e53bb74bb0faade4310.css" type="text/css" />
+ {runButton}
+ <pre>{termElem}</pre>
+ </div>;
+
+ x(rootElem);
+ rootElem.appendChild(root);
+
+ //term.writeln(`loading ${wasmURL}`);
+ //term.writeln(`${stdout}\n\n(exit code: ${exitCode})`);
+}
+
+export { init };
diff --git a/static/js/.gitignore b/static/js/.gitignore
index 4bf7e61..bc93d0d 100644
--- a/static/js/.gitignore
+++ b/static/js/.gitignore
@@ -1 +1,2 @@
mastodon_share_button.js
+wasiterm.js