From 6e1ad373dd43a14567986a240a62481ecda4150b Mon Sep 17 00:00:00 2001 From: Rizky Date: Sat, 18 Nov 2023 16:06:29 +0700 Subject: [PATCH] fix --- app/srv/ws/sync/editor/code/build.ts | 1 + app/srv/ws/sync/editor/code/watcher.ts | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/app/srv/ws/sync/editor/code/build.ts b/app/srv/ws/sync/editor/code/build.ts index a4235070..14475458 100644 --- a/app/srv/ws/sync/editor/code/build.ts +++ b/app/srv/ws/sync/editor/code/build.ts @@ -76,6 +76,7 @@ export const codeBuild = async (code: DBCode) => { }); }); } catch (e: any) { + console.error(e); activity.site .room(code.id_site) .findAll({ site_js: code.name }) diff --git a/app/srv/ws/sync/editor/code/watcher.ts b/app/srv/ws/sync/editor/code/watcher.ts index 27b5e7e3..5e3942fa 100644 --- a/app/srv/ws/sync/editor/code/watcher.ts +++ b/app/srv/ws/sync/editor/code/watcher.ts @@ -33,7 +33,7 @@ export const startCodeWatcher = async (code: DBCode) => { let delay = false; const indexes = {} as Record; - if (code.code_file.length === 0) { + if (!code.code_file.find((e) => e.path === "package.json")) { code.code_file.push( await db.code_file.create({ data: { @@ -45,6 +45,20 @@ export const startCodeWatcher = async (code: DBCode) => { ); } + if (!code.code_file.find((e) => e.path === "index.tsx")) { + let content = `export const hello = 'world';`; + + code.code_file.push( + await db.code_file.create({ + data: { + id_code: code.id, + path: "index.tsx", + content, + }, + }) + ); + } + for (const c of code.code_file) { const path = Code.path(c.id_code, c.path); @@ -67,6 +81,8 @@ export const startCodeWatcher = async (code: DBCode) => { stderr: "ignore", stdout: "ignore", }).exited; + + await codeBuild(code); Code.watchers[code.id] = { id: code.id,