#!/usr/bin/env bun
/**
* Prepares the editor's static assets in public/ (gitignored):
* - the Code - OSS web build from the MIT `vscode-web` package, minus Microsoft/GitHub auth extensions;
* - the gitfor-fs web extension, bundled for the extension host worker.
*/
import { cpSync, existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
import { join } from "node:path";
const root = join(import.meta.dir, "..");
const source = join(root, "node_modules/vscode-web/dist");
const version: string = JSON.parse(readFileSync(join(source, "package.json"), "utf8")).version;
const target = join(root, "public/vscode-web", version);
const EXCLUDED_EXTENSIONS = new Set(["github-authentication", "microsoft-authentication"]);
if (!existsSync(join(target, ".complete"))) {
rmSync(join(root, "public/vscode-web"), { recursive: true, force: true });
mkdirSync(target, { recursive: true });
cpSync(source, target, {
recursive: true,
filter: (path) => {
const relative = path.slice(source.length + 1);
const [top, name] = relative.split("/");
return !(top === "extensions" && name && EXCLUDED_EXTENSIONS.has(name));
},
});
writeFileSync(join(target, ".complete"), new Date().toISOString());
console.log(`vendored vscode-web ${version}`);
}
const extensionDir = join(root, "public/editor-ext/gitfor-fs");
mkdirSync(extensionDir, { recursive: true });
const result = await Bun.build({
entrypoints: [join(root, "src/editor-extension/extension.ts")],
target: "browser",
format: "cjs",
external: ["vscode"],
minify: true,
outdir: extensionDir,
naming: "extension.js",