Skip to content

Commit 89a6481

Browse files
committed
Added outFile option
1 parent e3f5d46 commit 89a6481

3 files changed

Lines changed: 49 additions & 3 deletions

File tree

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+
// appedn to workinDir 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: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { Expect, SetupFixture, Teardown, Test, TestCase, FocusTest } 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+
@FocusTest
19+
public outFileTest() {
20+
// Compile project
21+
execCommandLine(["--outFile", this.outFileAbsPath, path.join(__dirname, "./testfiles/out_file.ts")]);
22+
23+
Expect(fs.existsSync(this.outFileAbsPath)).toBe(true);
24+
}
25+
26+
@Teardown
27+
public teardown() {
28+
fs.unlink(this.outFileAbsPath, (err) => {
29+
if (err) {
30+
throw err;
31+
}
32+
});
33+
}
34+
}
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)