From d2b5106da2c3e843cad41b8272997d33a5b51d4e Mon Sep 17 00:00:00 2001 From: vroad Date: Wed, 22 Oct 2014 17:16:47 +0900 Subject: [PATCH] Add nodejs target --- tools/CommandLineTools.hx | 5 +++++ tools/platforms/Target.hx | 8 +++++++ tools/platforms/WindowsPlatform.hx | 35 ++++++++++++++++++++++-------- tools/project/ProjectXMLParser.hx | 6 +++++ 4 files changed, 45 insertions(+), 9 deletions(-) create mode 100644 tools/platforms/Target.hx diff --git a/tools/CommandLineTools.hx b/tools/CommandLineTools.hx index 2ace7fad9..e36c15183 100644 --- a/tools/CommandLineTools.hx +++ b/tools/CommandLineTools.hx @@ -1105,6 +1105,11 @@ class CommandLineTools { target = Platform.FIREFOX; overrides.haxedefs.set ("firefoxos", ""); + + case "nodejs": + + target = PlatformHelper.hostPlatform; + targetFlags.set ("nodejs", ""); default: diff --git a/tools/platforms/Target.hx b/tools/platforms/Target.hx new file mode 100644 index 000000000..4dc8f184c --- /dev/null +++ b/tools/platforms/Target.hx @@ -0,0 +1,8 @@ +package platforms; + +enum Target +{ + Cpp; + Neko; + NodeJs; +} \ No newline at end of file diff --git a/tools/platforms/WindowsPlatform.hx b/tools/platforms/WindowsPlatform.hx index 25a576cc7..349c72755 100644 --- a/tools/platforms/WindowsPlatform.hx +++ b/tools/platforms/WindowsPlatform.hx @@ -17,7 +17,7 @@ import project.HXProject; import project.PlatformTarget; import sys.io.File; import sys.FileSystem; - +import platforms.Target; class WindowsPlatform extends PlatformTarget { @@ -25,7 +25,7 @@ class WindowsPlatform extends PlatformTarget { private var applicationDirectory:String; private var executablePath:String; private var targetDirectory:String; - private var useNeko:Bool; + private var target:Target; public function new (command:String, _project:HXProject, targetFlags:Map ) { @@ -34,12 +34,21 @@ class WindowsPlatform extends PlatformTarget { targetDirectory = project.app.path + "/windows/cpp"; - if (project.targetFlags.exists ("neko") || project.target != PlatformHelper.hostPlatform) { + if (project.targetFlags.exists ("neko")) { targetDirectory = project.app.path + "/windows/neko"; - useNeko = true; + target = Target.Neko; - } + } else if (project.targetFlags.exists ("nodejs")) { + + targetDirectory = project.app.path + "/windows/nodejs"; + target = Target.NodeJs; + + } else { + + target = Target.Cpp; + + } applicationDirectory = targetDirectory + "/bin/"; executablePath = applicationDirectory + "/" + project.app.file + ".exe"; @@ -86,13 +95,20 @@ class WindowsPlatform extends PlatformTarget { } - if (useNeko) { + if (target == Target.Neko) { ProcessHelper.runCommand ("", "haxe", [ hxml ]); NekoHelper.createExecutable (project.templatePaths, "windows", targetDirectory + "/obj/ApplicationMain.n", executablePath); NekoHelper.copyLibraries (project.templatePaths, "windows", applicationDirectory); - } else { + } else if (target == Target.NodeJs) { + + ProcessHelper.runCommand ("", "haxe", [ hxml ]); + //NekoHelper.createExecutable (project.templatePaths, "windows", targetDirectory + "/obj/ApplicationMain.n", executablePath); + NekoHelper.copyLibraries (project.templatePaths, "windows", applicationDirectory); + + } + else { var haxeArgs = [ hxml ]; var flags = []; @@ -161,7 +177,7 @@ class WindowsPlatform extends PlatformTarget { } - var hxml = PathHelper.findTemplate (project.templatePaths, (useNeko ? "neko" : "cpp") + "/hxml/" + type + ".hxml"); + var hxml = PathHelper.findTemplate (project.templatePaths, (target == Target.Neko ? "neko" : target == Target.NodeJs ? "nodejs" : "cpp") + "/hxml/" + type + ".hxml"); var template = new Template (File.getContent (hxml)); Sys.println (template.execute (generateContext ())); @@ -173,6 +189,7 @@ class WindowsPlatform extends PlatformTarget { var context = project.templateContext; context.NEKO_FILE = targetDirectory + "/obj/ApplicationMain.n"; + context.NODE_FILE = targetDirectory + "/bin/ApplicationMain.js"; context.CPP_DIR = targetDirectory + "/obj"; context.BUILD_DIR = project.app.path + "/windows"; @@ -245,7 +262,7 @@ class WindowsPlatform extends PlatformTarget { //SWFHelper.generateSWFClasses (project, targetDirectory + "/haxe"); FileHelper.recursiveCopyTemplate (project.templatePaths, "haxe", targetDirectory + "/haxe", context); - FileHelper.recursiveCopyTemplate (project.templatePaths, (useNeko ? "neko" : "cpp") + "/hxml", targetDirectory + "/haxe", context); + FileHelper.recursiveCopyTemplate (project.templatePaths, (target == Target.Neko ? "neko" : target == Target.NodeJs ? "nodejs" : "cpp") + "/hxml", targetDirectory + "/haxe", context); if (project.targetFlags.exists ("static")) { diff --git a/tools/project/ProjectXMLParser.hx b/tools/project/ProjectXMLParser.hx index a9f870662..7c6c26ae3 100644 --- a/tools/project/ProjectXMLParser.hx +++ b/tools/project/ProjectXMLParser.hx @@ -79,6 +79,12 @@ class ProjectXMLParser extends HXProject { defines.set ("native", "1"); defines.set ("neko", "1"); + } else if (targetFlags.exists ("nodejs")) { + + defines.set ("native", "1"); + defines.set ("nodejs", "1"); + defines.set ("openfl_next", "1"); + } else if (target == Platform.FIREFOX) { defines.set ("html5", "1");