Improve desktop app !
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
import { copy } from "@std/fs";
|
||||
import { copy, walk } from "@std/fs";
|
||||
import { relative } from "@std/path";
|
||||
import { PROTOCOL_VERSION } from "./common/protocol.ts";
|
||||
import { CLIENT_MANIFEST, client_manifest, sha256 } from "./desktop/client_updates.ts";
|
||||
import { createCanvas, loadImage } from "@gfx/canvas-wasm";
|
||||
import { ENGINE_TEXTURE_DIR, load_and_check, load_order, LoadedMod } from "./tools/check_mods.ts";
|
||||
import { pack_mod } from "./tools/pack_mod.ts";
|
||||
@@ -127,6 +130,21 @@ async function build_client() {
|
||||
await copy("./client/index.html", `${BUILD_FOLDER}/client/index.html`);
|
||||
}
|
||||
|
||||
// every file the client needs with its hash, and the protocol it speaks. the desktop app compares it with the site's
|
||||
// to update its client, see desktop/client_updates.ts
|
||||
async function write_client_manifest(build_dir: string) {
|
||||
const files: Record<string, string> = {};
|
||||
for (const top of ["client", "assets"]) {
|
||||
for await (const entry of walk(`${build_dir}/${top}`, { includeDirs: false })) {
|
||||
const path = relative(build_dir, entry.path).replaceAll("\\", "/");
|
||||
if (path === CLIENT_MANIFEST) continue;
|
||||
files[path] = await sha256(Deno.readFileSync(entry.path));
|
||||
}
|
||||
}
|
||||
const manifest = await client_manifest(files, PROTOCOL_VERSION);
|
||||
Deno.writeTextFileSync(`${build_dir}/${CLIENT_MANIFEST}`, JSON.stringify(manifest, null, "\t"));
|
||||
}
|
||||
|
||||
async function build() {
|
||||
try {
|
||||
const now = performance.now();
|
||||
@@ -135,6 +153,7 @@ async function build() {
|
||||
const mods = load_mods();
|
||||
await build_assets();
|
||||
await build_client();
|
||||
await write_client_manifest(BUILD_FOLDER);
|
||||
await build_mods(mods);
|
||||
console.log(`Built in ${(performance.now() - now).toFixed(2)}ms`);
|
||||
} catch (e) {
|
||||
|
||||
Reference in New Issue
Block a user