Skip to content

Commit feafe18

Browse files
committed
add supabase
1 parent 98bcaf9 commit feafe18

36 files changed

+534
-466
lines changed

build/plugins/build-plugins.ts

+64-47
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
1-
import sanitizeFilename from "sanitize-filename";
2-
import * as npm from "./npm";
3-
import pacote from "pacote";
41
import path from "node:path";
52

63
import esbuild from "esbuild";
74
import { fileExists } from "../files";
85

96
import { copyFileSync, writeFileSync } from "fs";
10-
import { getLocalRepositoryManifests } from "./local-repository";
117
import { ExtractedPluginManifest } from "./plugin-manifest";
128

139
const cwd = process.cwd();
1410
const outDir = path.join(cwd, "dist", "plugins");
15-
// rmSync(outDir, { recursive: true, force: true });
16-
console.log("outDir", outDir);
1711

1812
const external = [
1913
"@titan-reactor-runtime/ui",
@@ -48,66 +42,89 @@ export const build = async (repository: Repository) => {
4842
if (manifest.deprecated) {
4943
continue;
5044
}
51-
const hostFilePath = path.join(sourceFolderPath, "host", "index.ts");
52-
const uiFilePath = path.join(sourceFolderPath, "ui", "index");
53-
const readmeFilePath = path.join(sourceFolderPath, "readme.md");
45+
const hostFilePath = path.join(sourceFolderPath, "src", "index.ts");
46+
const uiFilePath = path.join(sourceFolderPath, "src", "components", "index");
5447

55-
const files = [
48+
const searchFiles = [
5649
{ path: hostFilePath, type: "host.js" },
5750
{ path: uiFilePath + ".tsx", type: "ui.js" },
5851
{ path: uiFilePath + ".jsx", type: "ui.js" },
59-
{ path: readmeFilePath, type: "readme.md" },
6052
];
6153

62-
for (const file of files) {
54+
const files: { path: string; type: string }[] = [];
55+
56+
for (const file of searchFiles) {
6357
if (await fileExists(file.path)) {
58+
files.push(file);
59+
}
60+
}
61+
62+
if (files.length === 0) {
63+
console.warn("no files found for", manifest.name);
64+
continue;
65+
}
66+
67+
const idx = {
68+
name: manifest.name,
69+
version: manifest.version,
70+
description: manifest.description,
71+
rootUrl: folderName,
72+
files: [],
73+
}
74+
75+
for (const file of files) {
6476
console.log(file.type + " file found", file);
6577

6678
try {
67-
const outfile = path.join(outDir, folderName, file.type);
68-
69-
if (file.type === "readme.md") {
70-
copyFileSync(file.path, outfile);
71-
} else {
72-
await esbuild.build({
73-
entryPoints: [file.path],
74-
bundle: true,
75-
format: "esm",
76-
outfile,
77-
external,
78-
banner: {
79-
js:
80-
file.type === "ui.js"
81-
? `import { _rc } from "@titan-reactor-runtime/ui"; const registerComponent = (...args) => _rc("${manifest.name}", ...args);`
82-
: "",
83-
},
84-
});
85-
}
79+
const outfile = path.join(outDir, folderName, "dist", file.type);
80+
81+
await esbuild.build({
82+
entryPoints: [file.path],
83+
bundle: true,
84+
format: "esm",
85+
outfile,
86+
external,
87+
banner: {
88+
js:
89+
file.type === "ui.js"
90+
? `import { _rc } from "@titan-reactor-runtime/ui"; const registerComponent = (...args) => _rc("${manifest.name}", ...args);`
91+
: "",
92+
},
93+
});
8694

87-
copyFileSync(
88-
path.join(sourceFolderPath, "package.json"),
89-
path.join(outDir, folderName, "package.json")
90-
);
91-
92-
const idx = index.get(manifest.name) ?? {
93-
name: manifest.name,
94-
version: manifest.version,
95-
description: manifest.description,
96-
rootUrl: folderName,
97-
files: [],
98-
};
9995
idx.files.push(file.type);
100-
index.set(manifest.name, idx);
10196
} catch (error) {
102-
console.log("error building", file.path, error);
97+
console.error("error building", file.path, error);
10398
}
10499
}
100+
101+
try {
102+
copyFileSync(
103+
path.join(sourceFolderPath, "package.json"),
104+
path.join(outDir, folderName, "package.json")
105+
);
106+
107+
if (await fileExists(path.join(sourceFolderPath, "readme.md"))) {
108+
copyFileSync(
109+
path.join(sourceFolderPath, "readme.md"),
110+
path.join(outDir, folderName, "readme.md")
111+
);
112+
}
113+
index.set(manifest.name, idx);
114+
} catch (error) {
115+
console.error("error building manifest", error);
116+
}
105117
}
106-
}
107118

108119
if (cleanup) {
109120
cleanup();
110121
}
111122

112-
writeFileSync(path.join(outDir, "index.json"), JSON.stringify([...index.values()]));
123+
const indexJson = {
124+
indexVersion: 1,
125+
buildVersion: 0,
126+
packages: [...index.values()],
127+
}
128+
129+
writeFileSync(path.join(outDir, "index.json"), JSON.stringify(indexJson));
113130
};

esbuild.runtime.ts

+9-7
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,32 @@ const { rmSync, readFileSync, writeFileSync, createReadStream } = require("fs");
44
const path = require("path");
55
const { createHash } = require("crypto");
66

7-
rmSync("dist/plugins", { recursive: true, force: true });
7+
const OUTDIR = "dist/runtime";
8+
9+
rmSync(OUTDIR, { recursive: true, force: true });
810

911
(async () => {
1012
await esbuild.build({
1113
entryPoints: ["src/runtime.tsx"],
12-
outdir: "dist/plugins",
14+
outdir: OUTDIR,
1315
keepNames: true,
1416
minify: false,
1517
format: "esm",
1618
});
1719

1820
// copy assets
19-
await copy("bundled/assets", "dist/plugins/assets");
20-
await copy("src/runtime.html", "dist/plugins/runtime.html");
21+
await copy("bundled/assets", `${OUTDIR}/assets`);
22+
await copy("src/runtime.html", `${OUTDIR}/runtime.html`);
2123

2224
// make file hash for cache busting
2325
const fileHash = (
24-
(await generateFileHash("dist/plugins/runtime.js")) as string
26+
(await generateFileHash(`${OUTDIR}/runtime.js`)) as string
2527
).substring(0, 8);
2628

2729
const newFileName = `runtime.${fileHash}.js`;
28-
await move("dist/plugins/runtime.js", `dist/plugins/${newFileName}`);
30+
await move(`${OUTDIR}/runtime.js`, `${OUTDIR}/${newFileName}`);
2931

30-
const htmlPath = path.join(__dirname, "dist", "plugins", "runtime.html");
32+
const htmlPath = path.join(__dirname, "dist", "runtime", "runtime.html");
3133
const content = readFileSync(htmlPath, "utf8").replace(/runtime.js/g, newFileName);
3234
writeFileSync(htmlPath, content, "utf8");
3335
})();

package.json

+5-2
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,14 @@
1616
"postinstall": "git apply -v --stat --directory=node_modules/scm-extractor build/patches/scm-extractor.patch",
1717
"generate:api-types": "ts-node -T .\\build\\api-types\\index.ts",
1818
"generate:plugin-api-docs": "typedoc --out docs/host --tsconfig tsconfig.host-api.json build/api-types/host/index.d.ts && typedoc --out docs/ui --tsconfig tsconfig.ui-api.json build/api-types/ui/index.d.ts",
19-
"build:plugins": "ts-node -T ./esbuild.runtime.ts && ts-node -T .\\build\\plugins\\index.ts",
20-
"serve:plugins": "http-server .\\dist\\plugins -p 8090 --cors",
19+
"build:plugins": "ts-node -T .\\build\\plugins\\index.ts",
20+
"serve:plugins": "http-server .\\dist\\plugins -p 8091 --cors",
21+
"build:runtime": "ts-node -T ./esbuild.runtime.ts",
22+
"serve:runtime": "http-server .\\dist\\runtime -p 8090 --cors",
2123
"web": "vite -c vite.config.web.ts",
2224
"build:web": "vite build -c vite.config.web.ts",
2325
"plugins": "yarn build:plugins && yarn serve:plugins",
26+
"runtime": "yarn build:runtime && yarn serve:runtime",
2427
"build": "yarn build:web && yarn build:plugins"
2528
},
2629
"repository": {

src/common/get-app-settings-leva-config.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
} from "common/types";
77
import lSet from "lodash.set";
88

9-
const isProd = process.env.NODE_ENV !== "development";
9+
const isProd = import.meta.env.PROD;
1010

1111
export const generateAppSettingsFromLevaFormat = (
1212
settings: Record<string, { value: any }>

src/common/supabase.ts

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { createClient } from "@supabase/supabase-js";
2+
3+
export const SUPABASE_URL = "https://dypueayfjieyijupqhei.supabase.co";
4+
export const SUPABASE_PUBLIC_ANON_KEY =
5+
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImR5cHVlYXlmamlleWlqdXBxaGVpIiwicm9sZSI6ImFub24iLCJpYXQiOjE2OTc3NTA0OTQsImV4cCI6MjAxMzMyNjQ5NH0.mn3PKMcsP4yqPpb-BQmEJn4mBIHLAZ0re7g3n9Ni8cQ";
6+
7+
export const supabase = createClient( SUPABASE_URL, SUPABASE_PUBLIC_ANON_KEY );
8+
9+
export const SUPABASE_REPLAY_BUCKET = `${SUPABASE_URL}/storage/v1/object/public/replays/`;
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/// <reference types="vite/client" />
2+
3+
interface ImportMetaEnv {
4+
readonly VITE_PLUGINS_RUNTIME_ENTRY: string
5+
readonly VITE_OFFICIAL_PLUGINS_SERVER_URL: string
6+
// more env variables...
7+
}
8+
9+
interface ImportMeta {
10+
readonly env: ImportMetaEnv
11+
}

src/common/types/plugin.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,17 @@ export interface PluginPackage {
3232
* A plugin's metadata based off it's package.json file and surrounding plugin files.
3333
*/
3434
export interface PluginMetaData extends PluginPackage {
35-
nativeSource?: string | null;
3635
path: string;
3736
date?: Date;
3837
readme?: string;
39-
indexFile: string;
4038
isSceneController: boolean;
4139
apiVersion: string;
4240
url: string;
4341
config: PluginConfig;
42+
urls: {
43+
host: string | null,
44+
ui: string | null,
45+
}
4446
}
4547

4648
/**

src/renderer/audio/main-mixer.ts

-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,6 @@ export class Mixer {
139139
return await this.context.decodeAudioData( buffer.slice( 0 ) );
140140
}
141141

142-
143142
async loadAudioBuffer( url: string ): Promise<AudioBuffer> {
144143
return await this.context.decodeAudioData( await fetch( url ).then( ( r ) => r.arrayBuffer() ) );
145144
}

src/renderer/configuration-ui/index.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,11 @@ const container = document.getElementById("app");
6363
const root = createRoot(container!);
6464

6565
window.opener.postMessage({
66-
type: "connect",
66+
type: "control-panel:connect",
6767
});
6868

6969
window.addEventListener("message", (event) => {
70-
if (event.data.type === "connected") {
70+
if (event.data.type === "control-panel:connected") {
7171
console.log("connected", window.deps.useSettingsStore.getState());
7272
window.deps.useSettingsStore.subscribe((state) => {
7373
console.log("state", state);

src/renderer/core/global-events.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { TypeEmitter } from "@utils/type-emitter";
22
import type Chk from "bw-chk";
3-
import type { LogLevel } from "common/logging";
43
import type { MacroAction, PluginConfig, PluginMetaData } from "common/types";
54
import type { ValidatedReplay } from "../scenes/replay-scene-loader";
65

@@ -13,7 +12,6 @@ export interface GlobalEvents {
1312
"unsafe-open-url": string;
1413
"load-iscriptah": string;
1514
"queue-files": { files: File[] };
16-
"log-message": { message: string; level: LogLevel; server?: boolean };
1715
"reload-all-plugins": undefined;
1816
"exec-macro": string;
1917
"reset-macro-actions": string;
@@ -26,6 +24,7 @@ export interface GlobalEvents {
2624
"map-ready": { map: Chk };
2725
"xr-session-start": void;
2826
"xr-session-end": void;
27+
"metaverse-presence": { presence: any };
2928
}
3029

3130
export const globalEventKeys: ( keyof GlobalEvents )[] = [
@@ -37,7 +36,6 @@ export const globalEventKeys: ( keyof GlobalEvents )[] = [
3736
"unsafe-open-url",
3837
"load-iscriptah",
3938
"queue-files",
40-
"log-message",
4139
"reload-all-plugins",
4240
"exec-macro",
4341
"reset-macro-actions",

src/renderer/core/image-hd.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,8 @@ export class ImageHD
204204
setFrame( frame: number, flip: boolean ) {
205205
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
206206
if ( this.atlas!.frames[frame] === undefined ) {
207-
if ( process.env.NODE_ENV !== "production" ) {
207+
208+
if ( import.meta.env.DEV ) {
208209
// debugger;
209210
// throw new Error(
210211
// `Invalid frame ${frame}/${this.atlas!.frames.length} for atlas ${

0 commit comments

Comments
 (0)