Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
[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>
  • Loading branch information
Jeffrey Heifetz authored and bryanhiggins committed Sep 13, 2013
1 parent 4baa515 commit 42ed4bf892b306131417dc8e425b37a8cc9ef8ca
Showing 1 changed file with 74 additions and 77 deletions.
@@ -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);
}

0 comments on commit 42ed4bf

Please sign in to comment.