Skip to content

Commit

Permalink
add run.js
Browse files Browse the repository at this point in the history
  • Loading branch information
Joshix-1 committed Jan 3, 2024
1 parent 5f13b13 commit 6d1cfc2
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 5 deletions.
9 changes: 5 additions & 4 deletions .github/workflows/website.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: Deploy
on: [ push ]

on:
push:
branches: [ main ]
jobs:
github-pages:
name: GitHub Pages
Expand Down Expand Up @@ -29,8 +30,8 @@ jobs:
run: wasm-pack build --target web --no-default-features --features=wasm-bindgen
- name: Optimize wasm
run: ./binaryen/bin/wasm-opt -Oz pkg/hangman_solver_lib_bg.wasm -o pkg/hangman_solver_lib_bg.wasm
- name: Move HTML
run: mv web/index.html pkg/
- name: Copy HTML
run: cp web/* pkg/
- name: Upload GitHub Pages artifact
uses: actions/upload-pages-artifact@v1
with:
Expand Down
9 changes: 8 additions & 1 deletion web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,14 @@
}

init().then(() => {
updateCurrentState()
const query = new URLSearchParams(window.location.search);
const state = getState();
for (const key in Object.keys(state)) {
if (query.has(key)) {
state[key] = query.get(key);
}
}
loadFromState(state);
addEventListeners();
})
</script>
44 changes: 44 additions & 0 deletions web/run.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/bin/env -S deno run --allow-net=github.asozial.org,asozial.org,deno.land
import { parse } from "https://deno.land/[email protected]/flags/mod.ts";
import { exit } from "https://deno.land/x/exit/mod.ts";
import init, { solve_hangman } from "https://github.asozial.org/hangman_solver/hangman_solver_lib.js";


const flags = parse(Deno.args, {
boolean: ["crossword"],
string: ["input", "invalid", "language"],
number: ["maxwords"],
default: { crossword: false, maxwords: 10, language: "de_umlauts" },
});

const response = await fetch(
`https://asozial.org/hangman-loeser/worte/${flags.language}/${flags.input?.length}.txt`,
);
if (!response.ok) {
console.error(`${response.url} returned ${response.status} ${response.statusText}`);
exit(1);
}
const words = (await response.text()).split("\n");

await init();

const result = solve_hangman(
words,
flags.input,
flags.invalid,
flags.maxwords,
flags.crossword,
);

console.log({
input: result.input,
invalid: result.invalid,
matchingWords: result.matching_words_count,
});

if (result.matching_words_count) {
console.log(`Letter frequency: ${result.letter_frequency}`);
console.log(`Words (${result.possible_words.length}/${result.matching_words_count}): ${result.possible_words.join(", ")}`);
} else {
console.log("Nothing found");
}

0 comments on commit 6d1cfc2

Please sign in to comment.