diff --git a/app/srv/ws/sync/editor/code/build.ts b/app/srv/ws/sync/editor/code/build.ts index 14475458..54b1d0f4 100644 --- a/app/srv/ws/sync/editor/code/build.ts +++ b/app/srv/ws/sync/editor/code/build.ts @@ -14,11 +14,15 @@ export const codeBuild = async (code: DBCode) => { const id_code = code.id; if (!Code.build.ctx[id_code]) { Code.build.ctx[id_code] = await context({ - absWorkingDir: dir.path(`${g.datadir}/site/code/${id_code}`), + absWorkingDir: dir.path( + `${g.datadir}/site/code/${code.id_site}/${id_code}` + ), entryPoints: ["index.tsx"], bundle: true, format: "cjs", - outfile: dir.path(`${g.datadir}/build/code/${id_code}/index.js`), + outfile: dir.path( + `${g.datadir}/site/build/${id_code}/index.js` + ), minify: true, treeShaking: true, sourcemap: true, diff --git a/app/srv/ws/sync/editor/code/prep-code.ts b/app/srv/ws/sync/editor/code/prep-code.ts index 7adf0282..98c88ee9 100644 --- a/app/srv/ws/sync/editor/code/prep-code.ts +++ b/app/srv/ws/sync/editor/code/prep-code.ts @@ -6,9 +6,11 @@ export type DBCode = Exclude>, null>; export const prepCode = async (site_id: string, name: string) => { let code = await getCode(site_id, name); - const pkgfile = Bun.file(dir.path(`${g.datadir}/site/code/package.json`)); + const pkgfile = Bun.file( + dir.path(`${g.datadir}/site/code/${site_id}/package.json`) + ); if (!(await pkgfile.exists())) { - await dirAsync(dir.path(`${g.datadir}/site/code`)); + await dirAsync(dir.path(`${g.datadir}/site/code/${site_id}`)); await Bun.write( pkgfile, JSON.stringify( @@ -23,7 +25,7 @@ export const prepCode = async (site_id: string, name: string) => { } if (code) { - await dirAsync(dir.path(`${g.datadir}/site/code/${code.id}`)); + await dirAsync(dir.path(`${g.datadir}/site/code/${site_id}/${code.id}`)); return code; } let new_code = await db.code.create({ diff --git a/app/srv/ws/sync/editor/code/watcher.ts b/app/srv/ws/sync/editor/code/watcher.ts index 5e3942fa..ecf9d28d 100644 --- a/app/srv/ws/sync/editor/code/watcher.ts +++ b/app/srv/ws/sync/editor/code/watcher.ts @@ -20,8 +20,10 @@ export const Code = { timeout: {} as Record>, }, timeout: {} as Record>, - path: (id: string, p?: string) => { - return dir.path(`${g.datadir}/site/code/${id}${p ? "/" + p : ""}`); + path: (id_site: string, id_code: string, p?: string) => { + return dir.path( + `${g.datadir}/site/code/${id_site}/${id_code}${p ? "/" + p : ""}` + ); }, }; @@ -45,6 +47,41 @@ export const startCodeWatcher = async (code: DBCode) => { ); } + if (!code.code_file.find((e) => e.path === "tsconfig.json")) { + code.code_file.push( + await db.code_file.create({ + data: { + id_code: code.id, + path: "tsconfig.json", + content: JSON.stringify( + { + include: ["./", "../global.d.ts"], + compilerOptions: { + lib: ["ESNext", "DOM"], + module: "esnext", + target: "esnext", + moduleResolution: "bundler", + moduleDetection: "force", + allowImportingTsExtensions: true, + noEmit: true, + composite: true, + strict: true, + downlevelIteration: true, + skipLibCheck: true, + jsx: "react-jsx", + allowSyntheticDefaultImports: true, + forceConsistentCasingInFileNames: true, + allowJs: true, + }, + }, + null, + 2 + ), + }, + }) + ); + } + if (!code.code_file.find((e) => e.path === "index.tsx")) { let content = `export const hello = 'world';`; @@ -60,7 +97,7 @@ export const startCodeWatcher = async (code: DBCode) => { } for (const c of code.code_file) { - const path = Code.path(c.id_code, c.path); + const path = Code.path(code.id_site, c.id_code, c.path); indexes[c.path] = c; const file = Bun.file(path); @@ -77,17 +114,17 @@ export const startCodeWatcher = async (code: DBCode) => { await spawn({ cmd: ["bun", "i"], - cwd: Code.path(code.id), + cwd: Code.path(code.id_site, code.id), stderr: "ignore", stdout: "ignore", }).exited; - + await codeBuild(code); Code.watchers[code.id] = { id: code.id, watcher: watch( - Code.path(code.id), + Code.path(code.id_site, code.id), { recursive: true }, async (event, path) => { if (path !== "package.json") { @@ -98,7 +135,7 @@ export const startCodeWatcher = async (code: DBCode) => { } if (path) { - const file = Bun.file(Code.path(code.id, path)); + const file = Bun.file(Code.path(code.id_site, code.id, path)); const item = indexes[path]; if (event === "change") { if (item) { diff --git a/app/web/src/render/ed/panel/popup/code/code.tsx b/app/web/src/render/ed/panel/popup/code/code.tsx index ed11f02c..c5cb2c1d 100644 --- a/app/web/src/render/ed/panel/popup/code/code.tsx +++ b/app/web/src/render/ed/panel/popup/code/code.tsx @@ -110,7 +110,7 @@ export const EdPopCode = () => { <> { if ( @@ -156,7 +156,7 @@ export const EdPopCode = () => { id_code={p.ui.popup.code.id} /> } - className="flex items-center border-l relative border-l hover:bg-blue-50 cursor-pointer px-2 transition-all" + className="flex items-center border-l relative hover:bg-blue-50 cursor-pointer px-2 transition-all" >
{ <>
Loading VS Code... diff --git a/app/web/tsconfig.json b/app/web/tsconfig.json index 283fd92c..194b8c52 100644 --- a/app/web/tsconfig.json +++ b/app/web/tsconfig.json @@ -2,12 +2,7 @@ "compilerOptions": { "target": "ESNext", "useDefineForClassFields": true, - "lib": [ - "WebWorker", - "DOM", - "DOM.Iterable", - "ESNext" - ], + "lib": ["WebWorker", "DOM", "DOM.Iterable", "ESNext"], "allowJs": false, "skipLibCheck": false, "esModuleInterop": false, @@ -21,9 +16,7 @@ // "noEmit": true, "jsx": "react-jsx", "paths": { - "dbgen": [ - "../../node_modules/.prisma/client/index.d.ts" - ], + "dbgen": ["../../node_modules/.prisma/client/index.d.ts"], } - }, -} \ No newline at end of file + } +} diff --git a/app/web/y.d.ts b/app/web/y.d.ts index 82307d97..62eb68c7 100644 --- a/app/web/y.d.ts +++ b/app/web/y.d.ts @@ -1,14 +1,8 @@ -import type * as Y from "yjs"; -import { syncronize } from "y-pojo"; +import * as ImportYJS from "yjs"; +import * as YPojo from "y-pojo"; +type Yjs = typeof ImportYJS; -export import Doc = Y.Doc; -export import UndoManager = Y.UndoManager; -export import applyUpdate = Y.applyUpdate; -export import encodeStateVector = Y.encodeStateVector; -export import encodeStateAsUpdate = Y.encodeStateAsUpdate; -export import Text = Y.Text; -export import Map = Y.Map; -export import Array = Y.Array; -export import syncronize = syncronize; - -export as namespace Y; +declare global { + const Y: Yjs; + const syncronize: typeof YPojo.syncronize; +}