Browse Source

run command for mac and web

Josh Engebretson 10 years ago
parent
commit
5248e84836
2 changed files with 55 additions and 0 deletions
  1. 19 0
      CLI/cli.js
  2. 36 0
      CLI/index.js

+ 19 - 0
CLI/cli.js

@@ -68,6 +68,25 @@ cmd.setDefaults({action: function (args) {
     });
 }});
 
+var addCommonArguments = function (parser) {
+    parser.addArgument(["--debug"], {action: "storeTrue", help: "Build in debug mode."});
+};
+
+var cmd = commands.addParser("run", {help: "Build and run on a given platform.",
+    description: "Builds and runs the game on a single given platform."});
+cmd.addArgument(["platform"], {metavar: "platform", nargs: "?",
+    help: "A platform to target. Choose from " + cli.PLATFORMS.join(", ") + ". If omitted, 'default_platform' will be used."});
+addCommonArguments(cmd);
+cmd.addArgument(["--no-build"], {action: "storeTrue", help: "Don't rebuild before running."});
+
+cmd.setDefaults({action: function (args) {
+  cli.run(args.platform, {
+      debug: args.debug,
+      noBuild: args.no_build,
+  });
+}});
+
+
 var cmd = commands.addParser("platform-add", {help: "Adds a platform to the project",
     description: "Adds a platform to the project"});
 cmd.addArgument(["platform"], {help: "The platform to add (windows|mac|ios|android|ios)"});

+ 36 - 0
CLI/index.js

@@ -15,6 +15,8 @@ var ATOMIC_TOOL_BIN = __dirname + "/data/bin/Mac/AtomicTool";
 var HTTP_PORT = 4000;
 var SOCKET_PORT = HTTP_PORT+1;
 
+exports.PLATFORMS = ["windows", "mac", "android", "ios", "web"];
+
 exports.VERSION = JSON.parse(fs.readFileSync(__dirname + "/package.json")).version;
 
 var exec = function (command, flags, opts) {
@@ -67,6 +69,40 @@ exports.addPlatform = function (platform) {
   return atomictool(["platform-add", platform], {output:true});
 };
 
+exports.run = function (platform, opts) {
+    opts = opts || {};
+    var debug = opts.debug;
+
+    if (platform == null) {
+        // platform = get(config, "default_platform", "flash");
+    }
+
+    //checkPlatforms([platform]);
+
+    var run = function () {
+        switch (platform) {
+        case "web":
+            var url = "http://localhost:" + HTTP_PORT + "/AtomicPlayer.html";
+            console.log("Launching: " + url);
+
+            var open = require("open");
+            open(url);
+            break;
+
+          case "mac":
+              var open = require("open");
+              open("Build/Mac-Build/AtomicPlayer.app");
+              break;
+
+        }
+    };
+
+    return opts.noBuild ? run() : exports.build([platform], opts).then(function () {
+        console.log();
+        return run();
+    });
+};
+
 // Web Server (from flambe: https://raw.githubusercontent.com/aduros/flambe/master/command/index.js)
 var Server = function () {
 };