diff --git a/Tools/dora-dora/src/App.tsx b/Tools/dora-dora/src/App.tsx index 075679037..56292b83a 100644 --- a/Tools/dora-dora/src/App.tsx +++ b/Tools/dora-dora/src/App.tsx @@ -1703,11 +1703,11 @@ export default function PersistentDrawerLeft() { } switch (mode) { case "Run": case "Run This": { - let key: string | null = null; - let title: string | null = null; - let dir = false; - if (tabIndex !== null) { - setFiles(files => { + setFiles(files => { + let key: string | null = null; + let title: string | null = null; + let dir = false; + if (tabIndex !== null) { const file = files.at(tabIndex); if (file !== undefined) { key = file.key; @@ -1718,61 +1718,62 @@ export default function PersistentDrawerLeft() { return [...files]; } } - return files; - }); - } - if (key === null || title === null) { - if (selectedNode === null) { - addAlert(t("alert.runNoTarget"), "info"); - return; } - key = selectedNode.key; - title = selectedNode.title; - dir = selectedNode.dir; - } - let asProj = mode === "Run"; - if (dir) { - key = path.join(key, "init"); - asProj = true; - } - const ext = path.extname(key).toLowerCase(); - switch (ext) { - case ".lua": - case ".yue": - case ".tl": - case ".ts": - case ".tsx": - case ".xml": - case ".wasm": - case ".yarn": - case ".vs": - case "": - if (ext === ".yarn" && !asProj) { - break; + if (key === null || title === null) { + if (selectedNode === null) { + addAlert(t("alert.runNoTarget"), "info"); + return files; } - Service.run({file: key, asProj}).then((res) => { - if (res.success) { - addAlert(t("alert.run", {title: res.target ?? title}), "success"); - setOpenLog({ - title: res.target ?? title ?? "Running", - stopOnClose: true - }); - } else { - addAlert(t("alert.runFailed", {title: res.target ?? title}), "error"); - } - if (res.err !== undefined) { - setPopupInfo({ - title: res.target ?? title ?? "", - msg: res.err, - raw: true - }); + key = selectedNode.key; + title = selectedNode.title; + dir = selectedNode.dir; + } + let asProj = mode === "Run"; + if (dir) { + key = path.join(key, "init"); + asProj = true; + } + const ext = path.extname(key).toLowerCase(); + switch (ext) { + case ".lua": + case ".yue": + case ".tl": + case ".ts": + case ".tsx": + case ".xml": + case ".wasm": + case ".yarn": + case ".vs": + case "": { + if (ext === ".yarn" && !asProj) { + break; } - }).catch(() => { - addAlert(t("alert.runFailed", {title}), "error"); - }) - return; - } - addAlert(t("alert.runFailed", {title}), "info"); + Service.run({file: key, asProj}).then((res) => { + if (res.success) { + addAlert(t("alert.run", {title: res.target ?? title}), "success"); + setOpenLog({ + title: res.target ?? title ?? "Running", + stopOnClose: true + }); + } else { + addAlert(t("alert.runFailed", {title: res.target ?? title}), "error"); + } + if (res.err !== undefined) { + setPopupInfo({ + title: res.target ?? title ?? "", + msg: res.err, + raw: true + }); + } + }).catch(() => { + addAlert(t("alert.runFailed", {title}), "error"); + }) + return files; + } + } + addAlert(t("alert.runFailed", {title}), "info"); + return files; + }); return; } case "Stop": { diff --git a/Tools/dora-dora/src/TranspileTS.ts b/Tools/dora-dora/src/TranspileTS.ts index d6a1c6b81..6252bc101 100644 --- a/Tools/dora-dora/src/TranspileTS.ts +++ b/Tools/dora-dora/src/TranspileTS.ts @@ -153,9 +153,9 @@ export async function transpileTypescript( content: string ) { const program = createTypescriptProgram(fileName, content); - console.log(ts.getPreEmitDiagnostics(program)); + let diagnostics = ts.getPreEmitDiagnostics(program); const collector = createEmitOutputCollector(); - new tstl.Transpiler({ + const res = new tstl.Transpiler({ emitHost: { directoryExists: () => false, fileExists: () => true, @@ -167,6 +167,15 @@ export async function transpileTypescript( program, writeFile: collector.writeFile }); + diagnostics = [...diagnostics, ...res.diagnostics]; + if (diagnostics.length > 0) { + Service.Log.text += (Service.Log.text !== "" ? "\n" : "") + `Compiling ${fileName}\n` + ts.formatDiagnostics(diagnostics, { + getCanonicalFileName: fileName => Info.path.normalize(fileName), + getCurrentDirectory: () => Info.path.dirname(fileName), + getNewLine: () => "\n" + }); + Service.webSocketEmitter.emit("Log"); + } const file = collector.files.find(({ sourceFiles }) => sourceFiles.some(f => { return Info.path.relative(f.fileName, fileName) === ""; }));