Skip to content

Commit 85bd764

Browse files
committed
Added support for the outDir compiler option
1 parent a12ad13 commit 85bd764

2 files changed

Lines changed: 20 additions & 7 deletions

File tree

dist/Compiler.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ exports.__esModule = true;
33
var ts = require("typescript");
44
var Transpiler_1 = require("./Transpiler");
55
var TSHelper_1 = require("./TSHelper");
6-
function compile(fileNames, options) {
6+
function compile(fileNames, options, projectRoot) {
77
// Verify target
88
if (options.target != "lua") {
99
console.error("Wrong compilation target! Add \"target\": \"lua\" to your tsconfig.json!");
@@ -36,7 +36,13 @@ function compile(fileNames, options) {
3636
// Transpile AST
3737
var lua = Transpiler_1.LuaTranspiler.transpileSourceFile(sourceFile, checker);
3838
var outPath = sourceFile.fileName.substring(0, sourceFile.fileName.lastIndexOf(".")) + ".lua";
39-
//console.log(outPath);
39+
if (options.outDir) {
40+
var extension = options.outDir;
41+
if (extension[extension.length - 1] != "/")
42+
extension = extension + "/";
43+
outPath = outPath.replace(projectRoot + "/", projectRoot + "/" + extension);
44+
console.log(outPath);
45+
}
4046
// Write output
4147
ts.sys.writeFile(outPath, lua);
4248
}
@@ -79,7 +85,7 @@ if (configPath) {
7985
console.error(configFile.error);
8086
}
8187
else {
82-
compile(files, configFile.config.compilerOptions);
88+
compile(files, configFile.config.compilerOptions, projectRoot);
8389
}
8490
}
8591
else {

src/Compiler.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {readFileSync,writeFileSync} from "fs";
44
import {LuaTranspiler, TranspileError} from "./Transpiler";
55
import {TSHelper as tsEx} from "./TSHelper";
66

7-
function compile(fileNames: string[], options: ts.CompilerOptions): void {
7+
function compile(fileNames: string[], options: ts.CompilerOptions, projectRoot: string): void {
88
// Verify target
99
if ((<string><any>options.target) != "lua") {
1010
console.error("Wrong compilation target! Add \"target\": \"lua\" to your tsconfig.json!");
@@ -41,8 +41,15 @@ function compile(fileNames: string[], options: ts.CompilerOptions): void {
4141
try {
4242
// Transpile AST
4343
let lua = LuaTranspiler.transpileSourceFile(sourceFile, checker);
44-
const outPath = sourceFile.fileName.substring(0, sourceFile.fileName.lastIndexOf(".")) + ".lua";
45-
//console.log(outPath);
44+
let outPath = sourceFile.fileName.substring(0, sourceFile.fileName.lastIndexOf(".")) + ".lua";
45+
46+
if (options.outDir) {
47+
var extension = options.outDir;
48+
if (extension[extension.length - 1] != "/") extension = extension + "/";
49+
outPath = outPath.replace(projectRoot + "/", projectRoot + "/" + extension);
50+
console.log(outPath);
51+
}
52+
4653
// Write output
4754
ts.sys.writeFile(outPath, lua);
4855
} catch (exception) {
@@ -88,7 +95,7 @@ if (configPath) {
8895
console.error("Error occured:");
8996
console.error(configFile.error);
9097
} else {
91-
compile(files, configFile.config.compilerOptions);
98+
compile(files, configFile.config.compilerOptions, projectRoot);
9299
}
93100
} else {
94101
console.error("Could not find tsconfig.json, place one in your project root!");

0 commit comments

Comments
 (0)