Skip to content

Commit 4fe2266

Browse files
authored
Merge pull request #91 from Perryvw/outFile-option
Added outFile option
2 parents e3f5d46 + 53d6e71 commit 4fe2266

File tree

3 files changed

+48
-3
lines changed

3 files changed

+48
-3
lines changed

src/Compiler.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,18 @@ export function compile(fileNames: string[], options: CompilerOptions): void {
5050
outPath = path.join(options.outDir, relativeSourcePath);
5151
}
5252

53-
// change extension
54-
const fileNameLua = path.basename(outPath, path.extname(outPath)) + ".lua";
55-
outPath = path.join(path.dirname(outPath), fileNameLua);
53+
// change extension or rename to outFile
54+
if (options.outFile) {
55+
if (path.isAbsolute(options.outFile)) {
56+
outPath = options.outFile;
57+
} else {
58+
// append to workingDir or outDir
59+
outPath = path.resolve(options.outDir, options.outFile);
60+
}
61+
} else {
62+
const fileNameLua = path.basename(outPath, path.extname(outPath)) + ".lua";
63+
outPath = path.join(path.dirname(outPath), fileNameLua);
64+
}
5665

5766
// Write output
5867
ts.sys.writeFile(outPath, lua);

test/compiler/outfile.spec.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { Expect, SetupFixture, Teardown, Test, TestCase } from "alsatian";
2+
import * as fs from "fs";
3+
import * as path from "path";
4+
import { execCommandLine } from "../../src/Compiler";
5+
6+
export class CompilerOutFileTests {
7+
8+
private outFileRelPath: string;
9+
private outFileAbsPath: string;
10+
11+
@SetupFixture
12+
public setupFixture() {
13+
this.outFileRelPath = "./testfiles/out_file.script";
14+
this.outFileAbsPath = path.join(__dirname, this.outFileRelPath);
15+
}
16+
17+
@Test("Compile project")
18+
public outFileTest() {
19+
// Compile project
20+
execCommandLine(["--outFile", this.outFileAbsPath, path.join(__dirname, "./testfiles/out_file.ts")]);
21+
22+
Expect(fs.existsSync(this.outFileAbsPath)).toBe(true);
23+
}
24+
25+
@Teardown
26+
public teardown() {
27+
fs.unlink(this.outFileAbsPath, (err) => {
28+
if (err) {
29+
throw err;
30+
}
31+
});
32+
}
33+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class Test {
2+
3+
}

0 commit comments

Comments
 (0)