Dist cleanup

pull/87/head
Zef Hemel 2022-10-08 16:47:55 +02:00
parent f472cce2fe
commit 33f77cb1ce
6 changed files with 18 additions and 32 deletions

View File

@ -1,6 +1,6 @@
.PHONY: plugs
plugs:
deno run -A --unstable plugos/bin/plugos-bundle.ts --dist dist plugs/global.plug.yaml
deno run -A --unstable plugos/bin/plugos-bundle.ts --dist dist/web plugs/global.plug.yaml
deno run -A --unstable plugos/bin/plugos-bundle.ts --dist plugs/dist --exclude=https://esm.sh/handlebars,https://deno.land/std/encoding/yaml.ts,https://esm.sh/@lezer/lr plugs/*/*.plug.yaml
test:

View File

@ -6,7 +6,7 @@ import { denoPlugin } from "./esbuild_deno_loader/mod.ts";
import { copy } from "https://deno.land/std@0.158.0/fs/copy.ts";
import sass from "https://deno.land/x/denosass@1.0.4/mod.ts";
import { bundleFolder } from "./json_bundle.ts";
import { bundleFolder } from "./common/json_bundle.ts";
import { patchDenoLibJS } from "./common/hack.ts";
// @ts-ignore trust me
@ -14,9 +14,9 @@ const esbuild: typeof esbuildWasm = Deno.run === undefined
? esbuildWasm
: esbuildNative;
async function prepareAssets(dest: string) {
await copy("web/fonts", dest, { overwrite: true });
await copy("web/index.html", `${dest}/index.html`, {
async function prepareAssets(dist: string) {
await copy("web/fonts", `${dist}/web`, { overwrite: true });
await copy("web/index.html", `${dist}/web/index.html`, {
overwrite: true,
});
const compiler = sass(
@ -26,7 +26,7 @@ async function prepareAssets(dest: string) {
},
);
await Deno.writeTextFile(
"dist/main.css",
`${dist}/web/main.css`,
compiler.to_string("expanded") as string,
);
// await bundleRun({
@ -36,11 +36,12 @@ async function prepareAssets(dest: string) {
// exclude: [],
// });
let bundleJs = await Deno.readTextFile("dist/client.js");
// HACK: Patch the JS by removing an invalid regex
let bundleJs = await Deno.readTextFile(`${dist}/web/client.js`);
bundleJs = patchDenoLibJS(bundleJs);
await Deno.writeTextFile("dist/client.js", bundleJs);
await Deno.writeTextFile(`${dist}/web/client.js`, bundleJs);
await bundleFolder("dist", "dist_bundle.json");
await bundleFolder(`dist/web`, "dist/web_bundle.json");
}
async function bundle(): Promise<void> {
@ -50,7 +51,7 @@ async function bundle(): Promise<void> {
"client": "web/boot.ts",
"worker": "plugos/environments/sandbox_worker.ts",
},
outdir: "./dist",
outdir: "./dist/web",
absWorkingDir: Deno.cwd(),
bundle: true,
treeShaking: true,

View File

@ -1,12 +1,12 @@
import { walk } from "https://deno.land/std@0.159.0/fs/mod.ts";
import { base64Encode } from "./common/base64.ts";
import { base64Encode } from "./base64.ts";
export async function bundleFolder(path: string, bundlePath: string) {
const bundle: Record<string, string> = {};
for await (const { path: filePath } of walk(path, { includeDirs: false })) {
console.log("Bundling", filePath);
const b64content = base64Encode(await Deno.readFile(filePath));
bundle[filePath] = b64content;
bundle[filePath.substring(path.length + 1)] = b64content;
}
await Deno.writeTextFile(bundlePath, JSON.stringify(bundle, null, 2));
}

File diff suppressed because one or more lines are too long

View File

@ -76,7 +76,7 @@ export class ExpressServer {
this.password = options.password;
this.globalModules = JSON.parse(
assetReadTextFileSync(this.assetBundle, `dist/global.plug.json`),
assetReadTextFileSync(this.assetBundle, `global.plug.json`),
);
// Set up the PlugOS System
@ -331,14 +331,14 @@ export class ExpressServer {
ctx.response.headers.set("Content-type", "text/html");
ctx.response.body = assetReadTextFileSync(
this.assetBundle,
"dist/index.html",
"index.html",
);
return;
}
try {
ctx.response.body = assetReadFileSync(
this.assetBundle,
`dist${ctx.request.url.pathname}`,
`${ctx.request.url.pathname.substring(1)}`,
);
ctx.response.headers.set(
"Content-type",
@ -364,7 +364,7 @@ export class ExpressServer {
ctx.response.headers.set("Content-type", "text/html");
ctx.response.body = assetReadTextFileSync(
this.assetBundle,
"dist/index.html",
"index.html",
);
});

View File

@ -23,7 +23,7 @@ const port = args.port ? +args.port : 3000;
// const webappDistDir = new URL("./../../dist", import.meta.url).pathname;
// console.log("Webapp dist dir", webappDistDir);
import assetBundle from "../dist_bundle.json" assert { type: "json" };
import assetBundle from "../dist/web_bundle.json" assert { type: "json" };
const plugDistDir = new URL("./../plugs/dist", import.meta.url).pathname;
console.log("Pages dir", pagesPath);