Skip to content

Commit 8dfcc37

Browse files
committed
Add ${firmwareLocation} substitution
1 parent f6e5b9a commit 8dfcc37

2 files changed

Lines changed: 32 additions & 1 deletion

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "its-typescript-to-lua",
3-
"version": "1.33.2-3",
3+
"version": "1.33.2-6",
44
"description": "A generic TypeScript to Lua transpiler. Write your code in TypeScript and publish Lua!",
55
"repository": "https://github.com/TypeScriptToLua/TypeScriptToLua",
66
"homepage": "https://typescripttolua.github.io/",

src/cli/parse.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import * as ts from "typescript";
22
import { BuildMode, CompilerOptions, LuaLibImportKind, LuaTarget } from "../CompilerOptions";
33
import * as cliDiagnostics from "./diagnostics";
4+
import * as fs from "fs";
5+
import * as path from "path";
46

57
export interface ParsedCommandLine extends ts.ParsedCommandLine {
68
options: CompilerOptions;
@@ -111,6 +113,31 @@ export const optionDeclarations: CommandLineOption[] = [
111113
},
112114
];
113115

116+
function substituteFirmwareLocation(config: ts.ParsedCommandLine) {
117+
if (config.options.outDir?.includes("${firmwareLocation}")) {
118+
let substitution = "";
119+
const baseDir = process.cwd();
120+
const paths = fs.readdirSync(baseDir, { recursive: true });
121+
const filtered = paths.filter(dir => dir.toString().endsWith("sharedscripts_default"));
122+
if (filtered.length === 1) {
123+
substitution = path.dirname(filtered[0].toString());
124+
}
125+
if (substitution && substitution !== "") {
126+
config.options.outDir = path.normalize(config.options.outDir?.replace("${firmwareLocation}", substitution));
127+
} else {
128+
config.errors.push({
129+
file: undefined,
130+
start: undefined,
131+
length: undefined,
132+
category: ts.DiagnosticCategory.Error,
133+
code: 42,
134+
source: "typescript-to-lua",
135+
messageText: "Cannot find firmware location (sharedscripts_default)"
136+
});
137+
}
138+
}
139+
}
140+
114141
export function updateParsedConfigFile(parsedConfigFile: ts.ParsedCommandLine): ParsedCommandLine {
115142
let hasRootLevelOptions = false;
116143
for (const [name, rawValue] of Object.entries(parsedConfigFile.raw)) {
@@ -140,6 +167,8 @@ export function updateParsedConfigFile(parsedConfigFile: ts.ParsedCommandLine):
140167
}
141168
}
142169

170+
substituteFirmwareLocation(parsedConfigFile);
171+
143172
return parsedConfigFile;
144173
}
145174

@@ -181,6 +210,8 @@ function updateParsedCommandLine(parsedCommandLine: ts.ParsedCommandLine, args:
181210
}
182211
}
183212

213+
substituteFirmwareLocation(parsedCommandLine);
214+
184215
return parsedCommandLine;
185216
}
186217

0 commit comments

Comments
 (0)