wip fix code
This commit is contained in:
parent
8a28aaf1ca
commit
0f4cfc87f7
|
|
@ -111,7 +111,7 @@ export const _ = {
|
|||
},
|
||||
};
|
||||
|
||||
function readDirectoryRecursively(
|
||||
export function readDirectoryRecursively(
|
||||
dirPath: string,
|
||||
baseDir?: string[]
|
||||
): Record<string, string> {
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import { prepCode } from "../editor/code/prep-code";
|
|||
import { startCodeWatcher, stopCodeWatcher } from "../editor/code/watcher";
|
||||
import { activity as a } from "../entity/activity";
|
||||
import { SyncConnection } from "../type";
|
||||
|
||||
export const activity: SAction["activity"] = async function (
|
||||
this: SyncConnection,
|
||||
name,
|
||||
|
|
|
|||
|
|
@ -1,19 +1,41 @@
|
|||
import { dir } from "dir";
|
||||
import { g } from "utils/global";
|
||||
import { DCode } from "../../../../web/src/utils/types/root";
|
||||
import { readDirectoryRecursively } from "../../../api/site-export";
|
||||
import { SAction } from "../actions";
|
||||
import { docs } from "../entity/docs";
|
||||
import { SyncConnection } from "../type";
|
||||
import { getCode } from "../editor/code/prep-code";
|
||||
export const code_load: SAction["code"]["load"] = async function (
|
||||
this: SyncConnection,
|
||||
id,
|
||||
site_id,
|
||||
type
|
||||
) {
|
||||
let result = null as unknown as Awaited<ReturnType<SAction["code"]["load"]>>;
|
||||
|
||||
if (!docs.code[id]) {
|
||||
const src_doc = new Y.Doc() as DCode;
|
||||
const built_doc = new Y.Doc() as DCode;
|
||||
docs.code[id] = { id, src: src_doc, built: built_doc };
|
||||
const code = await getCode(site_id, "site");
|
||||
|
||||
if (code) {
|
||||
if (!docs.code[site_id]) {
|
||||
docs.code[site_id] = {
|
||||
id: site_id,
|
||||
src: loadFolderAsDCode(dir.path(`${g.datadir}/site/code/${code.id}`)),
|
||||
build: loadFolderAsDCode(
|
||||
dir.path(`${g.datadir}/site/build/${code.id}`)
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
return result;
|
||||
return { id: site_id, snapshot: null };
|
||||
};
|
||||
|
||||
const loadFolderAsDCode = (path: string) => {
|
||||
const doc = new Y.Doc() as DCode;
|
||||
|
||||
const dirs = readDirectoryRecursively(path);
|
||||
|
||||
return doc;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import { dir } from "dir";
|
||||
import { g } from "utils/global";
|
||||
import { dirAsync } from "fs-jetpack";
|
||||
import { docs } from "../../entity/docs";
|
||||
export type DBCode = Exclude<Awaited<ReturnType<typeof getCode>>, null>;
|
||||
|
||||
export const prepCode = async (site_id: string, name: string) => {
|
||||
|
|
@ -61,10 +62,11 @@ export const hello_world = () => {
|
|||
});
|
||||
|
||||
code = await getCode(site_id);
|
||||
|
||||
return code as DBCode;
|
||||
};
|
||||
|
||||
const getCode = async (site_id: string, name?: string) => {
|
||||
export const getCode = async (site_id: string, name?: string) => {
|
||||
return await db.code.findFirst({
|
||||
where: name
|
||||
? { id_site: site_id, name }
|
||||
|
|
|
|||
|
|
@ -27,5 +27,5 @@ export const docs = {
|
|||
um: Y.UndoManager;
|
||||
}
|
||||
>,
|
||||
code: {} as Record<string, { id: string; src: DCode; built: DCode }>,
|
||||
code: {} as Record<string, { id: string; src: DCode; build: DCode }>,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ export const EdMain = () => {
|
|||
const meta = active.comp_id
|
||||
? p.comp.list[active.comp_id].meta[active.item_id]
|
||||
: p.page.meta[active.item_id];
|
||||
|
||||
return (
|
||||
<div
|
||||
className={cx(
|
||||
|
|
|
|||
|
|
@ -54,6 +54,7 @@ export const viLoadLegacy = async (vi: {
|
|||
await importModule(path);
|
||||
if (!vi.site.db.get()) {
|
||||
}
|
||||
|
||||
if (!vi.site.api.get()) {
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue