compileToScript() find meta files relative to the haxelib that called it
This commit is contained in:
@@ -66,11 +66,33 @@ class CompilerTools {
|
|||||||
// create it again
|
// create it again
|
||||||
FileSystem.createDirectory(args.outputFolder);
|
FileSystem.createDirectory(args.outputFolder);
|
||||||
|
|
||||||
// Copy all files in that don't need to be processed in some way
|
// Find the haxelib folder of the class compiling a script (trickier than it should be):
|
||||||
function copyToFolder(file) {
|
var module = Context.getLocalModule();
|
||||||
File.copy(file, Path.join([args.outputFolder, file.withoutDirectory()]));
|
var moduleFile = module.replace(".", "/") + ".hx";
|
||||||
|
var fullFile = Context.getPosInfos(Context.currentPos()).file.replace("\\", "/");
|
||||||
|
var classPath = fullFile.replace(moduleFile, "");
|
||||||
|
var classPathFolders = classPath.split("/");
|
||||||
|
while (classPathFolders.length > 0) {
|
||||||
|
try {
|
||||||
|
Helpers.libPath(classPathFolders[classPathFolders.length - 1]);
|
||||||
|
break;
|
||||||
|
} catch (e) {
|
||||||
|
classPathFolders.pop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (classPathFolders.length == 0) {
|
||||||
|
throw 'compileToScript called by file $moduleFile which is not in a haxelib folder';
|
||||||
|
}
|
||||||
|
var haxelibPath = classPathFolders.join("/");
|
||||||
|
|
||||||
|
function copyToFolder(file, ?libPath) {
|
||||||
|
if (libPath == null)
|
||||||
|
libPath = haxelibPath;
|
||||||
|
|
||||||
|
File.copy(Path.join([libPath, file]), Path.join([args.outputFolder, file.withoutDirectory()]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Copy all files in that don't need to be processed in some way
|
||||||
if (args.extraFiles == null) {
|
if (args.extraFiles == null) {
|
||||||
args.extraFiles = [];
|
args.extraFiles = [];
|
||||||
}
|
}
|
||||||
@@ -80,15 +102,15 @@ class CompilerTools {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If a main haxe file was given, use it
|
// If a main haxe file was given, use it.
|
||||||
var mainHxFile = if (args.mainHxFile != null) {
|
|
||||||
args.mainHxFile;
|
|
||||||
}
|
|
||||||
// Otherwise use the default
|
// Otherwise use the default
|
||||||
else {
|
var mainHxFile = "ScriptMain.hx";
|
||||||
Path.join([Helpers.libPath("kiss"), "src", "kiss", "ScriptMain.hx"]);
|
if (args.mainHxFile != null) {
|
||||||
|
mainHxFile = args.mainHxFile;
|
||||||
|
copyToFolder(mainHxFile);
|
||||||
|
} else {
|
||||||
|
copyToFolder(mainHxFile, Path.join([Helpers.libPath("kiss"), "src", "kiss"]));
|
||||||
}
|
}
|
||||||
copyToFolder(mainHxFile);
|
|
||||||
|
|
||||||
var mainClassName = mainHxFile.withoutDirectory().withoutExtension();
|
var mainClassName = mainHxFile.withoutDirectory().withoutExtension();
|
||||||
|
|
||||||
@@ -120,7 +142,7 @@ class CompilerTools {
|
|||||||
Prelude.assertProcess("haxelib", ["install", "--always", buildHxmlFile]);
|
Prelude.assertProcess("haxelib", ["install", "--always", buildHxmlFile]);
|
||||||
if (args.hxmlFile != null) {
|
if (args.hxmlFile != null) {
|
||||||
hxmlFiles.push(args.hxmlFile);
|
hxmlFiles.push(args.hxmlFile);
|
||||||
Prelude.assertProcess("haxelib", ["install", "--always", args.hxmlFile]);
|
Prelude.assertProcess("haxelib", ["install", "--always", Path.join([haxelibPath, args.hxmlFile])]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compile the script
|
// Compile the script
|
||||||
@@ -147,7 +169,7 @@ class CompilerTools {
|
|||||||
move("package-lock.json", "package-lock.json.temp");
|
move("package-lock.json", "package-lock.json.temp");
|
||||||
move("node_modules", "node_modules.temp");
|
move("node_modules", "node_modules.temp");
|
||||||
|
|
||||||
File.copy(args.langProjectFile, "package.json");
|
File.copy(Path.join([haxelibPath, args.langProjectFile]), "package.json");
|
||||||
|
|
||||||
if (Sys.systemName() == "Windows") {
|
if (Sys.systemName() == "Windows") {
|
||||||
Prelude.assertProcess("cmd.exe", ["/c", 'npm', 'install']);
|
Prelude.assertProcess("cmd.exe", ["/c", 'npm', 'install']);
|
||||||
@@ -181,7 +203,7 @@ class CompilerTools {
|
|||||||
switch (args.langProjectFile.extension()) {
|
switch (args.langProjectFile.extension()) {
|
||||||
case "txt":
|
case "txt":
|
||||||
// the requirements file's original path is fine for this case
|
// the requirements file's original path is fine for this case
|
||||||
Prelude.assertProcess(envPython, ["-m", "pip", "install", "-r", args.langProjectFile]);
|
Prelude.assertProcess(envPython, ["-m", "pip", "install", "-r", Path.join([haxelibPath, args.langProjectFile])]);
|
||||||
case "py":
|
case "py":
|
||||||
// python setup.py install
|
// python setup.py install
|
||||||
Prelude.assertProcess(envPython, [Path.join([args.outputFolder, args.langProjectFile.withoutDirectory()]), "install"]);
|
Prelude.assertProcess(envPython, [Path.join([args.outputFolder, args.langProjectFile.withoutDirectory()]), "install"]);
|
||||||
|
Reference in New Issue
Block a user