diff --git a/src/Compiler.ts b/src/Compiler.ts index 104473274..457b40647 100644 --- a/src/Compiler.ts +++ b/src/Compiler.ts @@ -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); diff --git a/test/compiler/outfile.spec.ts b/test/compiler/outfile.spec.ts new file mode 100644 index 000000000..8604fa36c --- /dev/null +++ b/test/compiler/outfile.spec.ts @@ -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; + } + }); + } +} diff --git a/test/compiler/testfiles/out_file.ts b/test/compiler/testfiles/out_file.ts new file mode 100644 index 000000000..45842c5e2 --- /dev/null +++ b/test/compiler/testfiles/out_file.ts @@ -0,0 +1,3 @@ +class Test { + +}