fix
This commit is contained in:
parent
0359d7ae9b
commit
b370df7af6
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -6,9 +6,11 @@ export type DBCode = Exclude<Awaited<ReturnType<typeof getCode>>, 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({
|
||||
|
|
|
|||
|
|
@ -20,8 +20,10 @@ export const Code = {
|
|||
timeout: {} as Record<string, ReturnType<typeof setTimeout>>,
|
||||
},
|
||||
timeout: {} as Record<string, ReturnType<typeof setTimeout>>,
|
||||
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,7 +114,7 @@ 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;
|
||||
|
|
@ -87,7 +124,7 @@ export const startCodeWatcher = async (code: DBCode) => {
|
|||
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) {
|
||||
|
|
|
|||
|
|
@ -110,7 +110,7 @@ export const EdPopCode = () => {
|
|||
<>
|
||||
<Tooltip
|
||||
content={"Delete Code Module"}
|
||||
className="flex items-center border-l relative border-l hover:bg-red-50 cursor-pointer px-2 transition-all text-red-500"
|
||||
className="flex items-center border-l relative hover:bg-red-50 cursor-pointer px-2 transition-all text-red-500"
|
||||
placement="bottom"
|
||||
onClick={async () => {
|
||||
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"
|
||||
>
|
||||
<div
|
||||
dangerouslySetInnerHTML={{
|
||||
|
|
@ -208,7 +208,7 @@ export const EdPopCode = () => {
|
|||
<>
|
||||
<iframe
|
||||
className="flex flex-1 absolute inset-0 w-full h-full z-10"
|
||||
src={`${vscode_url}folder=/site/code/${p.ui.popup.code.id}`}
|
||||
src={`${vscode_url}folder=/site/code/${p.site.id}/${p.ui.popup.code.id}`}
|
||||
></iframe>
|
||||
<div className="flex flex-1 absolute inset-0 z-0 items-center justify-center">
|
||||
Loading VS Code...
|
||||
|
|
|
|||
|
|
@ -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"],
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue