cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bhigg...@apache.org
Subject [1/2] webworks commit: [CB-4732] Re-writing build script to use async
Date Fri, 13 Sep 2013 12:53:18 GMT
Updated Branches:
  refs/heads/master 4baa51563 -> 1f955e96e


[CB-4732] Re-writing build script to use async

Added --query flag to request keystorepass

Reviewed by Bryan Higgins <bhiggins@blackberry.com>
Tested by Tracy Li <tli@blackberry.com>


Project: http://git-wip-us.apache.org/repos/asf/cordova-blackberry/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-blackberry/commit/42ed4bf8
Tree: http://git-wip-us.apache.org/repos/asf/cordova-blackberry/tree/42ed4bf8
Diff: http://git-wip-us.apache.org/repos/asf/cordova-blackberry/diff/42ed4bf8

Branch: refs/heads/master
Commit: 42ed4bf892b306131417dc8e425b37a8cc9ef8ca
Parents: 4baa515
Author: Jeffrey Heifetz <jheifetz@blackberry.com>
Authored: Mon Sep 9 16:11:03 2013 -0400
Committer: Bryan Higgins <bhiggins@blackberry.com>
Committed: Fri Sep 13 08:56:00 2013 -0400

----------------------------------------------------------------------
 .../bin/templates/project/cordova/lib/build     | 151 +++++++++----------
 1 file changed, 74 insertions(+), 77 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/42ed4bf8/blackberry10/bin/templates/project/cordova/lib/build
----------------------------------------------------------------------
diff --git a/blackberry10/bin/templates/project/cordova/lib/build b/blackberry10/bin/templates/project/cordova/lib/build
index 8b54709..d1d4af5 100755
--- a/blackberry10/bin/templates/project/cordova/lib/build
+++ b/blackberry10/bin/templates/project/cordova/lib/build
@@ -27,8 +27,9 @@ var path = require("path"),
         "-o",
         path.resolve(path.join(__dirname, "..", "..", "build"))
     ],
-    jWorkflow = require("jWorkflow"),
+    async = require("async"),
     childProcess = require("child_process"),
+    logger = require("./logger"),
     pkgrUtils = require("./packager-utils"),
     commandStr;
 
@@ -39,79 +40,11 @@ function copyArgIfExists(arg) {
     }
 }
 
-function doReleaseBuild() {
-    //Note: Packager refers to signing password as "password" not "keystorepass"
-    if (command["keystorepass"]) {
-        bbwpArgv.push("--password");
-        bbwpArgv.push(command["keystorepass"]);
-    } else if (bbProperties.keystorepass) {
-        bbwpArgv.push("--password");
-        bbwpArgv.push(bbProperties.keystorepass);
-    } else {
-        console.log("No signing password provided. Please enter a value for 'keystorepass'
in %HOME%/.cordova/blackberry10.json or use --keystorepass via command-line directly from
the project cordova scripts (WILL NOT WORK FROM CLI).");
-        console.log(command.helpInformation());
-        process.exit(2);
-    }
-
-    copyArgIfExists("buildId");
-
-    build();
-}
-
-function build() {
-    //enable webinspector in debug mode or if --webinspector was provided
-    if (!command.release || command.webInspector) {
-        bbwpArgv.push("-d");
-    }
-
-    copyArgIfExists("params");
-    copyArgIfExists("loglevel");
-
-    //Overwrite process.argv, before calling packager
-    process.argv = bbwpArgv;
-
-    //Delete cached commander object. It will conflict with the packagers commander
-    delete require.cache[require.resolve("commander")];
-    delete require.cache[require.resolve("commander/lib/commander")];
-
-    require("./packager").start(function() {});
-}
-
-function postClean() {
-    if (command.release) {
-        doReleaseBuild();
-    } else {
-        build();
-    }
-}
-
-function clean(previous, baton) {
-    var cleanScript,
-        execName = "./clean";
-
-    if (pkgrUtils.isWindows()) {
-        execName = "clean";
-    }
-
-    baton.take();
-
-    cleanScript = childProcess.exec(execName, {
-        "cwd": path.normalize(__dirname + "/.."),
-        "env": process.env
-    });
-
-    cleanScript.stdout.on("data", pkgrUtils.handleProcessOutput);
-    cleanScript.stderr.on("data", pkgrUtils.handleProcessOutput);
-
-    cleanScript.on("exit", function (code) {
-        baton.pass();
-    });
-}
-
 command
-    .usage('[--debug] [--release] [-k | --keystorepass] [-b | --buildId <number>] [-p
| --params <json>] [-ll | --loglevel <level>]')
+    .usage('[--debug] [--release] [--query] [-k | --keystorepass] [-b | --buildId <number>]
[-p | --params <json>] [-ll | --loglevel <level>]')
     .option('--debug', 'build in debug mode.')
     .option('--release', 'build in release mode. This will sign the resulting bar.')
+    .option('--query', 'query on the commandline when a password is needed')
     .option('-k, --keystorepass <password>', 'signing key password')
     .option('-b, --buildId <num>', 'specifies the build number for signing (typically
incremented from previous signing).')
     .option('-d, --web-inspector', 'enables webinspector. Enabled by default in debug mode.).')
@@ -122,17 +55,81 @@ try {
     command.parse(process.argv);
 
     if (command.debug && command.release) {
-        console.log("Invalid build command: cannot specify both debug and release parameters.");
+        logger.warn("Invalid build command: cannot specify both debug and release parameters.");
         console.log(command.helpInformation());
         process.exit(2);
     }
 
-    // Implicitly call clean first
-    jWorkflow.order(clean)
-             .andThen(postClean)
-             .start();
+    async.series(
+        [
+            function clean (done) {
+                var cmd = utils.isWindows() ? "clean" : "./clean",
+                    args = [],
+                    opts = { "cwd": path.normalize(__dirname + "/..") };
+
+                utils.exec(cmd, args, opts, done);
+            },
+            function releaseBuild (allDone) {
+                var childTasks = [],
+                    err;
+
+                if (command.release) {
+                    copyArgIfExists("buildId");
+                    //Note: Packager refers to signing password as "password" not "keystorepass"
+                    bbwpArgv.push("--password");
+                    if (command.keystorepass) {
+                        bbwpArgv.push(command.keystorepass);
+                    } else if (bbProperties.keystorepass) {
+                        bbwpArgv.push(bbProperties.keystorepass);
+                    } else if (command.query) {
+                        childTasks.push(utils.prompt.bind(this, {description: "Please enter
your keystore password: ", hidden: true}));
+                        childTasks.push(function (password, done) {
+                            bbwpArgv.push(password);
+                            done();
+                        });
+                    } else {
+                        err = "No signing password provided. Please enter a value for 'keystorepass'
in %HOME%/.cordova/blackberry10.json or use --keystorepass via command-line";
+                    }
+                }
+
+                async.waterfall(childTasks, function (error) { allDone(error || err);});
+            },
+            function build (done) {
+                //enable weybinspector in debug mode or if --webinspector was provided
+                if (!command.release || command.webInspector) {
+                    bbwpArgv.push("-d");
+                }
+
+                copyArgIfExists("params");
+                copyArgIfExists("loglevel");
+
+                //Overwrite process.argv, before calling packager
+                process.argv = bbwpArgv;
+
+                //Delete cached commander object. It will conflict with the packagers commander
+                delete require.cache[require.resolve("commander")];
+                delete require.cache[require.resolve("commander/lib/commander")];
+
+                require("./packager").start(done);
+            }
+        ],
+        function (err, results) {
+            if (err) {
+                if (typeof err === "string") {
+                    logger.error(err);
+                    process.exit(1);
+                } else if (typeof err === "number") {
+                    process.exit(err);
+                } else {
+                    process.exit(2);
+                }
+            } else {
+                process.exit(0);
+            }
+        }
+    );
 } catch (e) {
-    console.log(e);
+    logger.error(e);
     process.exit(2);
 }
 


Mime
View raw message