From 89a6481b5d132cbafcaee77eccbeb702f3429885 Mon Sep 17 00:00:00 2001 From: lolleko Date: Mon, 2 Apr 2018 10:57:13 +0200 Subject: [PATCH 1/3] Added outFile option --- src/Compiler.ts | 15 ++++++++++--- test/compiler/outfile.spec.ts | 34 +++++++++++++++++++++++++++++ test/compiler/testfiles/out_file.ts | 3 +++ 3 files changed, 49 insertions(+), 3 deletions(-) create mode 100644 test/compiler/outfile.spec.ts create mode 100644 test/compiler/testfiles/out_file.ts diff --git a/src/Compiler.ts b/src/Compiler.ts index 104473274..7db8b3282 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 { + // appedn to workinDir 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..0c835cad0 --- /dev/null +++ b/test/compiler/outfile.spec.ts @@ -0,0 +1,34 @@ +import { Expect, SetupFixture, Teardown, Test, TestCase, FocusTest } 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") + @FocusTest + 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 { + +} From d313006d7945e1f44a7cb4e10d8d798a481363f7 Mon Sep 17 00:00:00 2001 From: lolleko Date: Mon, 2 Apr 2018 10:58:45 +0200 Subject: [PATCH 2/3] Typo --- src/Compiler.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Compiler.ts b/src/Compiler.ts index 7db8b3282..bd1c41de7 100644 --- a/src/Compiler.ts +++ b/src/Compiler.ts @@ -55,7 +55,7 @@ export function compile(fileNames: string[], options: CompilerOptions): void { if (path.isAbsolute(options.outFile)) { outPath = options.outFile; } else { - // appedn to workinDir or outDir + // append to workinDir or outDir outPath = path.resolve(options.outDir, options.outFile); } } else { From 53d6e7120b345b3ad1534632841dc7d1c5b74535 Mon Sep 17 00:00:00 2001 From: lolleko Date: Mon, 2 Apr 2018 11:01:29 +0200 Subject: [PATCH 3/3] Removed FocusTest --- src/Compiler.ts | 2 +- test/compiler/outfile.spec.ts | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Compiler.ts b/src/Compiler.ts index bd1c41de7..457b40647 100644 --- a/src/Compiler.ts +++ b/src/Compiler.ts @@ -55,7 +55,7 @@ export function compile(fileNames: string[], options: CompilerOptions): void { if (path.isAbsolute(options.outFile)) { outPath = options.outFile; } else { - // append to workinDir or outDir + // append to workingDir or outDir outPath = path.resolve(options.outDir, options.outFile); } } else { diff --git a/test/compiler/outfile.spec.ts b/test/compiler/outfile.spec.ts index 0c835cad0..8604fa36c 100644 --- a/test/compiler/outfile.spec.ts +++ b/test/compiler/outfile.spec.ts @@ -1,4 +1,4 @@ -import { Expect, SetupFixture, Teardown, Test, TestCase, FocusTest } from "alsatian"; +import { Expect, SetupFixture, Teardown, Test, TestCase } from "alsatian"; import * as fs from "fs"; import * as path from "path"; import { execCommandLine } from "../../src/Compiler"; @@ -15,7 +15,6 @@ export class CompilerOutFileTests { } @Test("Compile project") - @FocusTest public outFileTest() { // Compile project execCommandLine(["--outFile", this.outFileAbsPath, path.join(__dirname, "./testfiles/out_file.ts")]);