Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/Compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,18 @@ export function compile(fileNames: string[], options: CompilerOptions): void {
outPath = path.join(options.outDir, relativeSourcePath);
}

// change extension
const fileNameLua = path.basename(outPath, path.extname(outPath)) + ".lua";
outPath = path.join(path.dirname(outPath), fileNameLua);
// change extension or rename to outFile
if (options.outFile) {
if (path.isAbsolute(options.outFile)) {
outPath = options.outFile;
} else {
// append to workingDir or outDir
outPath = path.resolve(options.outDir, options.outFile);
}
} else {
const fileNameLua = path.basename(outPath, path.extname(outPath)) + ".lua";
outPath = path.join(path.dirname(outPath), fileNameLua);
}

// Write output
ts.sys.writeFile(outPath, lua);
Expand Down
33 changes: 33 additions & 0 deletions test/compiler/outfile.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { Expect, SetupFixture, Teardown, Test, TestCase } from "alsatian";
import * as fs from "fs";
import * as path from "path";
import { execCommandLine } from "../../src/Compiler";

export class CompilerOutFileTests {

private outFileRelPath: string;
private outFileAbsPath: string;

@SetupFixture
public setupFixture() {
this.outFileRelPath = "./testfiles/out_file.script";
this.outFileAbsPath = path.join(__dirname, this.outFileRelPath);
}

@Test("Compile project")
public outFileTest() {
// Compile project
execCommandLine(["--outFile", this.outFileAbsPath, path.join(__dirname, "./testfiles/out_file.ts")]);

Expect(fs.existsSync(this.outFileAbsPath)).toBe(true);
}

@Teardown
public teardown() {
fs.unlink(this.outFileAbsPath, (err) => {
if (err) {
throw err;
}
});
}
}
3 changes: 3 additions & 0 deletions test/compiler/testfiles/out_file.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class Test {

}