Skip to content

Commit

Permalink
add tstl compiling messages [skip CI].
Browse files Browse the repository at this point in the history
  • Loading branch information
pigpigyyy committed Jan 9, 2024
1 parent 4b85930 commit 2ba8a0b
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 59 deletions.
115 changes: 58 additions & 57 deletions Tools/dora-dora/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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": {
Expand Down
13 changes: 11 additions & 2 deletions Tools/dora-dora/src/TranspileTS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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) === "";
}));
Expand Down

0 comments on commit 2ba8a0b

Please sign in to comment.