You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by bh...@apache.org on 2013/07/17 19:15:24 UTC
[1/2] webworks commit: [CB-4268] Rework util functions to support
getting list of connected devices / emulators
Updated Branches:
refs/heads/3.0.x b017b8032 -> d273506c8
[CB-4268] Rework util functions to support getting list of connected devices / emulators
This will be used by the run script to determine if a connected device or emulator is available.
Project: http://git-wip-us.apache.org/repos/asf/cordova-blackberry/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-blackberry/commit/698d188b
Tree: http://git-wip-us.apache.org/repos/asf/cordova-blackberry/tree/698d188b
Diff: http://git-wip-us.apache.org/repos/asf/cordova-blackberry/diff/698d188b
Branch: refs/heads/3.0.x
Commit: 698d188b99d3a7f3a2c09368bc124dd6114091d3
Parents: b017b80
Author: Bryan Higgins <bh...@blackberry.com>
Authored: Tue Jul 16 18:12:35 2013 -0400
Committer: Bryan Higgins <bh...@blackberry.com>
Committed: Wed Jul 17 13:15:44 2013 -0400
----------------------------------------------------------------------
.../templates/project/cordova/lib/cordova.js | 64 ----------------
.../project/cordova/lib/list-devices.js | 6 +-
.../project/cordova/lib/list-emulator-images.js | 5 +-
.../cordova/lib/list-started-emulators.js | 6 +-
.../bin/templates/project/cordova/lib/run | 3 +-
.../project/cordova/lib/target-utils.js | 80 ++++++++++++++++++++
6 files changed, 89 insertions(+), 75 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/698d188b/blackberry10/bin/templates/project/cordova/lib/cordova.js
----------------------------------------------------------------------
diff --git a/blackberry10/bin/templates/project/cordova/lib/cordova.js b/blackberry10/bin/templates/project/cordova/lib/cordova.js
deleted file mode 100644
index 8d7119c..0000000
--- a/blackberry10/bin/templates/project/cordova/lib/cordova.js
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * 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 _self,
- path = require('path'),
- exec = require('child_process').exec,
- tool_dir = path.join(__dirname),
- build_dir = path.join(tool_dir,'..','..','build');
- bb10_utils = require('./utils'),
- blackberryProperties = require(path.join(bb10_utils.getCordovaDir(), '/', bb10_utils.getPropertiesFileName()));
-
-_self = {
- getTargetList : function (type) {
- var targList = [],
- targets = blackberryProperties['targets'];
- if (targets) {
- for (t in targets) {
- if (targets[t]['type'] == type) {
- targets[t]['name'] = t;
- targList.push(targets[t]);
- }
- }
- }
- return targList;
- },
-
- listTargets : function(type, pruneDisconnected) {
- var targets = _self.getTargetList(type),
- outstr = null;
- if (targets) {
- for (i in targets) {
- var t = targets[i];
- outstr = t.name + " ip: " + t.ip;
- if (pruneDisconnected) {
- exec('blackberry-deploy -test ' + t.ip, function(error, stdout, stderr) {
- // error code 3 corresponds to a connected device, null corresponds to connected sim
- if (error == null) {
- console.log(outstr, "status: connected");
- } else if (error.code == 3) {
- console.log(outstr, "status: connected");
- }
- });
- } else {
- console.log(outstr);
- }
- }
- }
- }
-};
-
-module.exports = _self;
http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/698d188b/blackberry10/bin/templates/project/cordova/lib/list-devices.js
----------------------------------------------------------------------
diff --git a/blackberry10/bin/templates/project/cordova/lib/list-devices.js b/blackberry10/bin/templates/project/cordova/lib/list-devices.js
index 394f29d..b27a7fb 100644
--- a/blackberry10/bin/templates/project/cordova/lib/list-devices.js
+++ b/blackberry10/bin/templates/project/cordova/lib/list-devices.js
@@ -1,3 +1,5 @@
+#!/usr/bin/env node
+
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
@@ -15,6 +17,4 @@
// specific language governing permissions and limitations
// under the License.
-var cordova = require('./cordova');
-
-cordova.listTargets('device', true);
+require('./target-utils').listTargets('device', true);
http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/698d188b/blackberry10/bin/templates/project/cordova/lib/list-emulator-images.js
----------------------------------------------------------------------
diff --git a/blackberry10/bin/templates/project/cordova/lib/list-emulator-images.js b/blackberry10/bin/templates/project/cordova/lib/list-emulator-images.js
index 551378a..2459694 100644
--- a/blackberry10/bin/templates/project/cordova/lib/list-emulator-images.js
+++ b/blackberry10/bin/templates/project/cordova/lib/list-emulator-images.js
@@ -1,3 +1,4 @@
+#!/usr/bin/env node
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
@@ -15,6 +16,4 @@
// specific language governing permissions and limitations
// under the License.
-var cordova = require('./cordova');
-
-cordova.listTargets('simulator', false);
+require('./target-utils').listTargets('simulator', false);
http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/698d188b/blackberry10/bin/templates/project/cordova/lib/list-started-emulators.js
----------------------------------------------------------------------
diff --git a/blackberry10/bin/templates/project/cordova/lib/list-started-emulators.js b/blackberry10/bin/templates/project/cordova/lib/list-started-emulators.js
index aba3f5e..5297c10 100644
--- a/blackberry10/bin/templates/project/cordova/lib/list-started-emulators.js
+++ b/blackberry10/bin/templates/project/cordova/lib/list-started-emulators.js
@@ -1,3 +1,4 @@
+#!/usr/bin/env node
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
@@ -14,7 +15,4 @@
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
-
-var cordova = require('./cordova');
-
-cordova.listTargets('simulator', true);
+require('./target-utils').listTargets('simulator', true);
http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/698d188b/blackberry10/bin/templates/project/cordova/lib/run
----------------------------------------------------------------------
diff --git a/blackberry10/bin/templates/project/cordova/lib/run b/blackberry10/bin/templates/project/cordova/lib/run
index 9111a4a..097a73a 100755
--- a/blackberry10/bin/templates/project/cordova/lib/run
+++ b/blackberry10/bin/templates/project/cordova/lib/run
@@ -256,9 +256,10 @@ function postBuild() {
function exec() {
program
- .usage('[--target=<id>] [-k | --keystorepass] [--no-launch] [--no-uninstall] [--no-build]')
+ .usage('[--device] [--emulator] [--target=<id>] [-k | --keystorepass] [--no-launch] [--no-uninstall] [--no-build]')
.option('-k, --keystorepass <password>', 'the password of signing key; needed for creating debug token')
.option('--device', 'run on connected device')
+ .option('--emulator', 'run on BB10 simulator')
.option('--target', 'specifies the target to run the application')
.option('--no-uninstall', 'does not uninstall application from device')
.option('--no-launch', 'do not launch the application on device')
http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/698d188b/blackberry10/bin/templates/project/cordova/lib/target-utils.js
----------------------------------------------------------------------
diff --git a/blackberry10/bin/templates/project/cordova/lib/target-utils.js b/blackberry10/bin/templates/project/cordova/lib/target-utils.js
new file mode 100644
index 0000000..50091a4
--- /dev/null
+++ b/blackberry10/bin/templates/project/cordova/lib/target-utils.js
@@ -0,0 +1,80 @@
+/*
+ * 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 _self,
+ exec = require('child_process').exec,
+ bb10_utils = require('./utils'),
+ blackberryProperties = bb10_utils.getProperties();
+
+_self = {
+ getTargetList : function (type, pruneDisconnected, callback) {
+ var targList = [],
+ count = 0,
+ targets = blackberryProperties.targets,
+ addItem = function (t) {
+ targets[t].name = t;
+ targList.push(targets[t]);
+ },
+ checkConnection = function (name) {
+ _self.checkConnection(targets[name].ip, type, function (connected) {
+ count++;
+ if (connected) {
+ addItem(name);
+ }
+ complete();
+ });
+ },
+ complete = function () {
+ if (count === Object.keys(targets).length) {
+ callback(targList);
+ }
+ };
+ if (targets) {
+ for (t in targets) {
+ if (targets.hasOwnProperty(t) && targets[t].type === type) {
+ if (pruneDisconnected) {
+ checkConnection(t);
+ }
+ else {
+ addItem(t);
+ count++;
+ }
+ } else {
+ count++;
+ }
+ }
+ }
+ complete();
+ },
+
+ checkConnection: function(ip, type, callback) {
+ exec('blackberry-deploy -test ' + ip, function(error, stdout, stderr) {
+ // error code 3 corresponds to a connected device, null corresponds to connected sim
+ callback((type === 'simulator' && error === null) || (type == 'device' && error.code === 3));
+ });
+ },
+
+ listTargets : function(type, pruneDisconnected) {
+ _self.getTargetList(type, pruneDisconnected, function (targets) {
+ for (t in targets) {
+ console.log(targets[t].name + ' ip: ' + targets[t].ip + (pruneDisconnected ? ' status: connected' : ''));
+ }
+ });
+ }
+
+};
+
+module.exports = _self;
[2/2] webworks commit: [CB-4268] Add support for --device and
--emulator to run script
Posted by bh...@apache.org.
[CB-4268] Add support for --device and --emulator to run script
Project: http://git-wip-us.apache.org/repos/asf/cordova-blackberry/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-blackberry/commit/d273506c
Tree: http://git-wip-us.apache.org/repos/asf/cordova-blackberry/tree/d273506c
Diff: http://git-wip-us.apache.org/repos/asf/cordova-blackberry/diff/d273506c
Branch: refs/heads/3.0.x
Commit: d273506c8a0a6079617eb4e0d50e0f9507adf414
Parents: 698d188
Author: Bryan Higgins <bh...@blackberry.com>
Authored: Wed Jul 17 08:47:28 2013 -0400
Committer: Bryan Higgins <bh...@blackberry.com>
Committed: Wed Jul 17 13:15:58 2013 -0400
----------------------------------------------------------------------
.../bin/templates/project/cordova/lib/run | 57 +++++++++++++++-----
1 file changed, 44 insertions(+), 13 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/d273506c/blackberry10/bin/templates/project/cordova/lib/run
----------------------------------------------------------------------
diff --git a/blackberry10/bin/templates/project/cordova/lib/run b/blackberry10/bin/templates/project/cordova/lib/run
index 097a73a..0d57afd 100755
--- a/blackberry10/bin/templates/project/cordova/lib/run
+++ b/blackberry10/bin/templates/project/cordova/lib/run
@@ -23,6 +23,7 @@ var childProcess = require("child_process"),
wrench = require("wrench"),
conf = require("./conf"),
utils = require("./utils"),
+ targetUtils = require("./target-utils.js"),
localize = require("./localize"),
pkgrUtils = require("./packager-utils"),
debugTokenHelper = require("./debugtoken-helper"),
@@ -95,6 +96,35 @@ function execNativeDeploy(optionsArray, callback) {
});
}
+function setTarget(callback) {
+ target = program.args[0] ? program.args[0] : targets.defaultTarget;
+ if (program["device"]) {
+ targetUtils.getTargetList("device", true, function (targets) {
+ if (targets && targets.length > 0) {
+ target = targets[0].name;
+ callback();
+ } else {
+ console.error("No connected device found");
+ console.error("Devices must first be configured using platforms/blackberry/cordova/target");
+ process.exit(1);
+ }
+ });
+ } else if (program["emulator"]) {
+ targetUtils.getTargetList("simulator", true, function (targets) {
+ if (targets && targets.length > 0) {
+ target = targets[0].name;
+ callback();
+ } else {
+ console.error("No connected BB10 simulator found");
+ console.error("Simulators must first be configured using platforms/blackberry/cordova/target");
+ process.exit(1);
+ }
+ });
+ } else {
+ callback();
+ }
+}
+
function checkTarget() {
if (!target) {
console.log("No target exists, to add that target please run target add <name> <ip> [-t | --type <device | simulator>] [-p <password>] [--pin <devicepin>]");
@@ -273,22 +303,23 @@ function exec() {
}
program.parse(process.argv);
- target = program.args[0] ? program.args[0] : targets.defaultTarget;
- if (checkTarget()) {
- if (program.build) {
- jWorkflow.order(checkDebugtoken)
- .andThen(createDebugToken)
- .andThen(deployDebugToken)
- .andThen(build)
- .andThen(postBuild)
- .start();
+ setTarget(function () {
+ if (checkTarget()) {
+ if (program.build) {
+ jWorkflow.order(checkDebugtoken)
+ .andThen(createDebugToken)
+ .andThen(deployDebugToken)
+ .andThen(build)
+ .andThen(postBuild)
+ .start();
+ } else {
+ postBuild();
+ }
} else {
- postBuild();
+ process.exit(1);
}
- } else {
- process.exit(1);
- }
+ });
}
exec();