This repository has been archived by the owner on Apr 18, 2019. It is now read-only.
/
build.js
executable file
·126 lines (110 loc) · 4.86 KB
/
build.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/usr/bin/env node
/*
* Copyright 2012 Research In Motion Limited.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var path = require("path"),
exit = require("exit"),
command = require("commander"),
os = require("os"),
utils = require("./utils"),
signingUtils = require("./signing-utils"),
bbProperties = utils.getProperties(),
bbwpArgv = [
process.argv[0],
path.resolve(path.join(__dirname, process.argv[1])),
path.resolve(path.join(__dirname, "..", "..", "www")),
"-o",
path.resolve(path.join(__dirname, "..", "..", "build"))
],
async = require("async"),
childProcess = require("child_process"),
pkgrUtils = require("./packager-utils"),
session = require("./session"),
ERROR_VALUE = 2,
commandStr;
function copyArgIfExists(arg) {
if (command[arg]) {
bbwpArgv.push("--" + arg);
bbwpArgv.push(command[arg]);
}
}
command
.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.).')
.option('-p, --params <params JSON file>', 'specifies additional parameters to pass to downstream tools.')
.option('-ll, --loglevel <loglevel>', 'set the logging level (error, warn, verbose)');
try {
command.parse(process.argv);
if (command.debug && command.release) {
console.error("Invalid build command: cannot specify both debug and release parameters.");
console.log(command.helpInformation());
exit(ERROR_VALUE);
}
signingUtils.warn();
utils.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 = [],
keystorepass = session.getKeyStorePass(command),
err;
if (command.release) {
copyArgIfExists("buildId");
//Note: Packager refers to signing password as "password" not "keystorepass"
bbwpArgv.push("--password");
if (keystorepass) {
bbwpArgv.push(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 "+pkgrUtils.homedir()+"/.cordova/blackberry10.json or use --keystorepass via command-line";
}
}
async.waterfall(childTasks, function (error) { allDone(error || err);});
},
function build (done) {
//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(done);
}
]
);
} catch (e) {
console.error(os.EOL + e);
exit(ERROR_VALUE);
}