Skip to content

Commit aac5e0c

Browse files
committed
Implements #1556
Massive code restructure
1 parent 735170e commit aac5e0c

File tree

256 files changed

+317
-493
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

256 files changed

+317
-493
lines changed

.air.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ tmp_dir = "tmp"
66
bin = "silverbullet"
77
cmd = "deno task build && go build"
88
# delay = 10000
9-
exclude_dir = ["node_modules", "website", "scripts", "dist_client_bundle", "dist_plug_bundle", "dist"]
9+
exclude_dir = ["node_modules", "website", "scripts", "dist_client_bundle", "dist_base_fs_bundle", "dist"]
1010
exclude_file = ["public_version.ts"]
1111
exclude_regex = ["_test.go", ".test.ts"]
1212
exclude_unchanged = false

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.env
22
.DS_Store
33
dist_client_bundle
4-
dist_plug_bundle
4+
dist_base_fs_bundle
55
dist
66
*.js.map
77
website_build

Makefile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
build:
22
# Build frontend
33
deno task build
4+
# Build plug-compile
5+
deno task build-plug-compile
46
# Build backend
57
go build
68

9+
clean:
10+
deno task clean
11+
rm -f silverbullet
12+
713
check:
814
# Frontend type check
915
deno task check
@@ -23,3 +29,7 @@ test:
2329
deno task test
2430
# Run backend tests
2531
go test ./pkg/...
32+
33+
generate:
34+
# Regenerate the Lua parser from the the grammar
35+
deno run -A npm:@lezer/generator@1.5.1 lib/space_lua/lua.grammar -o lib/space_lua/parse-lua.js

plug-compile.ts renamed to bin/plug-compile.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import.meta.main = false;
22
import { Command } from "@cliffy/command";
33

4-
import { version } from "./version.ts";
4+
import { version } from "../version.ts";
55

6-
import { plugCompileCommand } from "./cmd/plug_compile.ts";
6+
import { plugCompileCommand } from "../lib/plugos/plug_compile.ts";
77

88
await new Command()
99
.name("plug-compile")

build_web.ts renamed to build_client.ts

Lines changed: 18 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -3,68 +3,41 @@ import { fileURLToPath } from "node:url";
33

44
import sass from "denosass";
55

6-
import { parseArgs } from "@std/cli/parse-args";
7-
import { patchDenoLibJS } from "./cmd/compile.ts";
6+
import { patchDenoLibJS } from "./lib/plugos/plug_compile.ts";
87
import { denoPlugins } from "@luca/esbuild-deno-loader";
98
import * as esbuild from "esbuild";
10-
import { updateVersionFile } from "./cmd/update_version.ts";
119

12-
export async function bundleAll(
13-
watch: boolean,
14-
): Promise<void> {
15-
let building = false;
10+
// This builds the client and puts it into dist_client_bundle/
11+
12+
export async function bundleAll(): Promise<void> {
1613
await buildCopyBundleAssets();
17-
let timer;
18-
if (watch) {
19-
const watcher = Deno.watchFs([
20-
"web",
21-
"dist_plug_bundle/_plug",
22-
"lib",
23-
"Library",
24-
]);
25-
for await (const _event of watcher) {
26-
if (timer) {
27-
clearTimeout(timer);
28-
}
29-
timer = setTimeout(() => {
30-
console.log("Change detected, rebuilding...");
31-
if (building) {
32-
return;
33-
}
34-
building = true;
35-
buildCopyBundleAssets().finally(() => {
36-
building = false;
37-
});
38-
}, 1000);
39-
}
40-
}
4114
}
4215

4316
export async function copyAssets(dist: string) {
4417
await Deno.mkdir(dist, { recursive: true });
45-
await copy("web/fonts", `${dist}`, { overwrite: true });
46-
await copy("web/index.html", `${dist}/index.html`, {
18+
await copy("client/fonts", `${dist}`, { overwrite: true });
19+
await copy("client/index.html", `${dist}/index.html`, {
4720
overwrite: true,
4821
});
49-
await copy("web/auth.html", `${dist}/auth.html`, {
22+
await copy("client/auth.html", `${dist}/auth.html`, {
5023
overwrite: true,
5124
});
52-
await copy("web/images/favicon.png", `${dist}/favicon.png`, {
25+
await copy("client/images/favicon.png", `${dist}/favicon.png`, {
5326
overwrite: true,
5427
});
55-
await copy("web/images/logo.png", `${dist}/logo.png`, {
28+
await copy("client/images/logo.png", `${dist}/logo.png`, {
5629
overwrite: true,
5730
});
58-
await copy("web/images/logo-dock.png", `${dist}/logo-dock.png`, {
31+
await copy("client/images/logo-dock.png", `${dist}/logo-dock.png`, {
5932
overwrite: true,
6033
});
61-
await copy("web/manifest.json", `${dist}/manifest.json`, {
34+
await copy("client/manifest.json", `${dist}/manifest.json`, {
6235
overwrite: true,
6336
});
6437
const compiler = sass(
65-
Deno.readTextFileSync("web/styles/main.scss"),
38+
Deno.readTextFileSync("client/styles/main.scss"),
6639
{
67-
load_paths: ["web/styles"],
40+
load_paths: ["client/styles"],
6841
},
6942
);
7043
await Deno.writeTextFile(
@@ -80,23 +53,18 @@ export async function copyAssets(dist: string) {
8053

8154
async function buildCopyBundleAssets() {
8255
await Deno.mkdir("dist_client_bundle", { recursive: true });
83-
await Deno.mkdir("dist_plug_bundle", { recursive: true });
84-
85-
// Copy Library files
86-
await copy("Library", "dist_plug_bundle/Library", {
87-
overwrite: true,
88-
});
56+
await Deno.mkdir("dist_base_fs_bundle", { recursive: true });
8957

9058
console.log("Now ESBuilding the client and service workers...");
9159

9260
const result = await esbuild.build({
9361
entryPoints: [
9462
{
95-
in: "web/boot.ts",
63+
in: "client/boot.ts",
9664
out: ".client/client",
9765
},
9866
{
99-
in: "web/service_worker.ts",
67+
in: "client/service_worker.ts",
10068
out: "service_worker",
10169
},
10270
],
@@ -133,16 +101,6 @@ async function buildCopyBundleAssets() {
133101
}
134102

135103
if (import.meta.main) {
136-
const args = parseArgs(Deno.args, {
137-
boolean: ["watch"],
138-
alias: { w: "watch" },
139-
default: {
140-
watch: false,
141-
},
142-
});
143-
await updateVersionFile();
144-
await bundleAll(args.watch);
145-
if (!args.watch) {
146-
esbuild.stop();
147-
}
104+
await bundleAll();
105+
esbuild.stop();
148106
}

build_plug_compile.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as esbuild from "esbuild";
44
await Deno.mkdir("dist", { recursive: true });
55
const result = await esbuild.build({
66
entryPoints: {
7-
"plug-compile": "plug-compile.ts",
7+
"plug-compile": "./bin/plug-compile.ts",
88
},
99
outdir: "dist",
1010
format: "esm",

build_plugs.ts

Lines changed: 0 additions & 39 deletions
This file was deleted.

build_plugs_libraries.ts

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import * as path from "@std/path";
2+
import * as esbuild from "esbuild";
3+
import { compileManifests } from "./lib/plugos/plug_compile.ts";
4+
import { builtinPlugNames } from "./plugs/builtin_plugs.ts";
5+
import { parseArgs } from "@std/cli/parse-args";
6+
import { fileURLToPath } from "node:url";
7+
import { copy } from "@std/fs";
8+
import { version } from "./version.ts";
9+
10+
// This builds all built-in plugs and libraries and puts them into dist_base_fs_bundle/
11+
12+
if (import.meta.main) {
13+
await updateVersionFile();
14+
const args = parseArgs(Deno.args, {
15+
boolean: ["debug", "reload", "info"],
16+
alias: { w: "watch" },
17+
});
18+
19+
const manifests = builtinPlugNames.map((name) =>
20+
`./plugs/${name}/${name}.plug.yaml`
21+
);
22+
23+
const plugBundlePath = "dist_base_fs_bundle";
24+
const targetDir = path.join(plugBundlePath, "_plug");
25+
Deno.mkdirSync(targetDir, { recursive: true });
26+
Deno.mkdirSync("dist", { recursive: true });
27+
28+
// Copy Library files
29+
await copy("libraries/Library", "dist_base_fs_bundle/Library", {
30+
overwrite: true,
31+
});
32+
33+
// Build the plugs
34+
await compileManifests(
35+
manifests,
36+
targetDir,
37+
{
38+
debug: args.debug,
39+
info: args.info,
40+
configPath: fileURLToPath(new URL("deno.json", import.meta.url)),
41+
},
42+
);
43+
esbuild.stop();
44+
}
45+
46+
export async function updateVersionFile() {
47+
const command = new Deno.Command("git", {
48+
args: ["describe", "--tags", "--long"],
49+
stdout: "piped",
50+
stderr: "piped",
51+
});
52+
53+
const { stdout } = await command.output();
54+
let commitVersion = new TextDecoder().decode(stdout).trim();
55+
56+
if (!commitVersion) {
57+
// Probably no valid .git repo, fallback to GITHUB_SHA env var (used in CI)
58+
commitVersion = `${version}-${Deno.env.get("GITHUB_SHA") || "unknown"}`;
59+
}
60+
61+
const versionFilePath = "./public_version.ts";
62+
const versionContent = `export const publicVersion = "${commitVersion}";`;
63+
64+
await Deno.writeTextFile(versionFilePath, versionContent);
65+
console.log(
66+
`Updated public_version.ts with version information: ${commitVersion}`,
67+
);
68+
}

0 commit comments

Comments
 (0)