Context.enter();
Context ctx = Context.getCurrentContext();
nodeScript.exec(ctx, globalScope);
NativeObject proc = (NativeObject) globalScope.get("process");
NativeArray argv = (NativeArray) proc.get("argv");
argv.defineProperty("length", 0, ScriptableObject.EMPTY);
int i = 0;
argv.put(i++, argv, "node");
argv.put(i++, argv, "tsc.js");
if (noStandardLib) {
argv.put(i++, argv, "--nolib");
}
if (libDTS != null && libDTS.exists()) {
if (!watching) {
getLog().info("Adding standard library file " + libDTS);
}
argv.put(i++, argv, libDTS.getAbsolutePath());
}
if (libraryDirectory != null && libraryDirectory.exists()) {
File[] libFiles = libraryDirectory.listFiles();
if (libFiles != null) {
for (File libFile : libFiles) {
if (libFile.getName().endsWith(".d.ts") && libFile.exists()) {
if (!watching) {
getLog().info("Adding library file " + libFile);
}
argv.put(i++, argv, libFile.getAbsolutePath());
}
}
}
}
if (targetVersion != null) {
getLog().info("Setting target version to " + targetVersion);
argv.put(i++, argv, "--target");
argv.put(i++, argv, targetVersion);
}
for (String s : args) {
argv.put(i++, argv, s);
}
proc.defineProperty("encoding", encoding, ScriptableObject.READONLY);
NativeObject mainModule = (NativeObject) proc.get("mainModule");
mainModule.defineProperty("filename", new File("tsc.js").getAbsolutePath(), ScriptableObject.READONLY);
tscScript.exec(ctx, globalScope);
} catch (JavaScriptException e) {
if (e.getValue() instanceof NativeJavaObject) {
NativeJavaObject njo = (NativeJavaObject) e.getValue();