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;
|
const id_code = code.id;
|
||||||
if (!Code.build.ctx[id_code]) {
|
if (!Code.build.ctx[id_code]) {
|
||||||
Code.build.ctx[id_code] = await context({
|
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"],
|
entryPoints: ["index.tsx"],
|
||||||
bundle: true,
|
bundle: true,
|
||||||
format: "cjs",
|
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,
|
minify: true,
|
||||||
treeShaking: true,
|
treeShaking: true,
|
||||||
sourcemap: 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) => {
|
export const prepCode = async (site_id: string, name: string) => {
|
||||||
let code = await getCode(site_id, name);
|
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())) {
|
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(
|
await Bun.write(
|
||||||
pkgfile,
|
pkgfile,
|
||||||
JSON.stringify(
|
JSON.stringify(
|
||||||
|
|
@ -23,7 +25,7 @@ export const prepCode = async (site_id: string, name: string) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (code) {
|
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;
|
return code;
|
||||||
}
|
}
|
||||||
let new_code = await db.code.create({
|
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>>,
|
||||||
},
|
},
|
||||||
timeout: {} as Record<string, ReturnType<typeof setTimeout>>,
|
timeout: {} as Record<string, ReturnType<typeof setTimeout>>,
|
||||||
path: (id: string, p?: string) => {
|
path: (id_site: string, id_code: string, p?: string) => {
|
||||||
return dir.path(`${g.datadir}/site/code/${id}${p ? "/" + p : ""}`);
|
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")) {
|
if (!code.code_file.find((e) => e.path === "index.tsx")) {
|
||||||
let content = `export const hello = 'world';`;
|
let content = `export const hello = 'world';`;
|
||||||
|
|
||||||
|
|
@ -60,7 +97,7 @@ export const startCodeWatcher = async (code: DBCode) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const c of code.code_file) {
|
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;
|
indexes[c.path] = c;
|
||||||
const file = Bun.file(path);
|
const file = Bun.file(path);
|
||||||
|
|
@ -77,7 +114,7 @@ export const startCodeWatcher = async (code: DBCode) => {
|
||||||
|
|
||||||
await spawn({
|
await spawn({
|
||||||
cmd: ["bun", "i"],
|
cmd: ["bun", "i"],
|
||||||
cwd: Code.path(code.id),
|
cwd: Code.path(code.id_site, code.id),
|
||||||
stderr: "ignore",
|
stderr: "ignore",
|
||||||
stdout: "ignore",
|
stdout: "ignore",
|
||||||
}).exited;
|
}).exited;
|
||||||
|
|
@ -87,7 +124,7 @@ export const startCodeWatcher = async (code: DBCode) => {
|
||||||
Code.watchers[code.id] = {
|
Code.watchers[code.id] = {
|
||||||
id: code.id,
|
id: code.id,
|
||||||
watcher: watch(
|
watcher: watch(
|
||||||
Code.path(code.id),
|
Code.path(code.id_site, code.id),
|
||||||
{ recursive: true },
|
{ recursive: true },
|
||||||
async (event, path) => {
|
async (event, path) => {
|
||||||
if (path !== "package.json") {
|
if (path !== "package.json") {
|
||||||
|
|
@ -98,7 +135,7 @@ export const startCodeWatcher = async (code: DBCode) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (path) {
|
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];
|
const item = indexes[path];
|
||||||
if (event === "change") {
|
if (event === "change") {
|
||||||
if (item) {
|
if (item) {
|
||||||
|
|
|
||||||
|
|
@ -110,7 +110,7 @@ export const EdPopCode = () => {
|
||||||
<>
|
<>
|
||||||
<Tooltip
|
<Tooltip
|
||||||
content={"Delete Code Module"}
|
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"
|
placement="bottom"
|
||||||
onClick={async () => {
|
onClick={async () => {
|
||||||
if (
|
if (
|
||||||
|
|
@ -156,7 +156,7 @@ export const EdPopCode = () => {
|
||||||
id_code={p.ui.popup.code.id}
|
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
|
<div
|
||||||
dangerouslySetInnerHTML={{
|
dangerouslySetInnerHTML={{
|
||||||
|
|
@ -208,7 +208,7 @@ export const EdPopCode = () => {
|
||||||
<>
|
<>
|
||||||
<iframe
|
<iframe
|
||||||
className="flex flex-1 absolute inset-0 w-full h-full z-10"
|
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>
|
></iframe>
|
||||||
<div className="flex flex-1 absolute inset-0 z-0 items-center justify-center">
|
<div className="flex flex-1 absolute inset-0 z-0 items-center justify-center">
|
||||||
Loading VS Code...
|
Loading VS Code...
|
||||||
|
|
|
||||||
|
|
@ -2,12 +2,7 @@
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"target": "ESNext",
|
"target": "ESNext",
|
||||||
"useDefineForClassFields": true,
|
"useDefineForClassFields": true,
|
||||||
"lib": [
|
"lib": ["WebWorker", "DOM", "DOM.Iterable", "ESNext"],
|
||||||
"WebWorker",
|
|
||||||
"DOM",
|
|
||||||
"DOM.Iterable",
|
|
||||||
"ESNext"
|
|
||||||
],
|
|
||||||
"allowJs": false,
|
"allowJs": false,
|
||||||
"skipLibCheck": false,
|
"skipLibCheck": false,
|
||||||
"esModuleInterop": false,
|
"esModuleInterop": false,
|
||||||
|
|
@ -21,9 +16,7 @@
|
||||||
// "noEmit": true,
|
// "noEmit": true,
|
||||||
"jsx": "react-jsx",
|
"jsx": "react-jsx",
|
||||||
"paths": {
|
"paths": {
|
||||||
"dbgen": [
|
"dbgen": ["../../node_modules/.prisma/client/index.d.ts"],
|
||||||
"../../node_modules/.prisma/client/index.d.ts"
|
|
||||||
],
|
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,14 +1,8 @@
|
||||||
import type * as Y from "yjs";
|
import * as ImportYJS from "yjs";
|
||||||
import { syncronize } from "y-pojo";
|
import * as YPojo from "y-pojo";
|
||||||
|
type Yjs = typeof ImportYJS;
|
||||||
|
|
||||||
export import Doc = Y.Doc;
|
declare global {
|
||||||
export import UndoManager = Y.UndoManager;
|
const Y: Yjs;
|
||||||
export import applyUpdate = Y.applyUpdate;
|
const syncronize: typeof YPojo.syncronize;
|
||||||
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;
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue