You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by lo...@apache.org on 2013/06/13 00:02:14 UTC

[4/8] webworks commit: [CB-3604] target script changed from project level to repo level script

[CB-3604] target script changed from project level to repo level 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/554bd506
Tree: http://git-wip-us.apache.org/repos/asf/cordova-blackberry/tree/554bd506
Diff: http://git-wip-us.apache.org/repos/asf/cordova-blackberry/diff/554bd506

Branch: refs/heads/master
Commit: 554bd506171eb69913a05974a26e74dd8a7ebc82
Parents: ad135dd
Author: lorinbeer <lo...@adobe.com>
Authored: Fri Jun 7 14:29:37 2013 -0700
Committer: lorinbeer <lo...@adobe.com>
Committed: Wed Jun 12 15:01:44 2013 -0700

----------------------------------------------------------------------
 blackberry10/bin/lib/target.js    | 209 +++++++++++++++++++++++++++++++++
 blackberry10/bin/lib/targets.json |   5 +
 blackberry10/bin/target           |   3 +
 blackberry10/bin/target.bat       |  21 ++++
 4 files changed, 238 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/554bd506/blackberry10/bin/lib/target.js
----------------------------------------------------------------------
diff --git a/blackberry10/bin/lib/target.js b/blackberry10/bin/lib/target.js
new file mode 100644
index 0000000..d66d5ec
--- /dev/null
+++ b/blackberry10/bin/lib/target.js
@@ -0,0 +1,209 @@
+#!/usr/bin/env node
+/*
+ *  Copyright 2013 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'),
+    propertiesFile = './targets.json',
+    properties = require(propertiesFile),
+    fs = require('fs'),
+    commander = require('commander'),
+    command,
+    name,
+    ip,
+    type,
+    password,
+    pin,
+    pinRegex = new RegExp("[0-9A-Fa-f]{8}");
+
+function writeProjectFile(contents, file) {
+    fs.writeFile(file, contents, 'utf-8', function (err) {
+        if (err) console.log("Error updating project.json :(\n" + err);
+        process.exit();
+    });
+}
+
+function isValidIp(ip) {
+    var num,
+        result = true,
+        ipArray;
+
+    if (typeof ip !== 'string') {
+        console.log("IP is required");
+        console.log(commander.helpInformation());
+        process.exit(2); 
+    } else {
+        ipArray = ip.split('.');
+        if (ipArray.length !== 4) {
+            result = false;
+        }
+        ipArray.forEach(function (quadrant) {
+            num = Number(quadrant);
+            if (isNaN(num) || (num < 0) || (num > 255)) {
+                result = false;
+            }
+        });
+    }
+    return result;
+}
+
+function isValidType(type) {
+    var result = true;
+
+    if (typeof type !== 'string') {
+        console.log("target type is required");
+        console.log(commander.helpInformation());
+        process.exit(2); 
+    }
+    else if (!(type === 'device' || type === 'simulator')) {
+        result = false;
+    }
+    return result;
+}
+
+function isValidPin(pin) {
+    var result = true;
+    if (typeof pin !== 'undefined' && !pinRegex.test(pin)) {
+        result = false;
+    }
+    return result;
+}
+
+commander
+    .usage('[command] [params]')
+    .option('-p, --password <password>', 'Specifies password for this target')
+    .option('--pin <devicepin>', 'Specifies PIN for this device')
+    .option('-t, --type <device | simulator>', 'Specifies the target type');
+
+commander
+    .on('--help', function () {
+        console.log('   Synopsis:');
+        console.log('   $ target');
+        console.log('   $ target add <name> <ip> [-t | --type <device | simulator>] [-p | --password <password>] [--pin <devicepin>]');
+        console.log('   $ target remove <name>');
+        console.log('   $ target default [name]');
+        console.log(' ');
+    });
+
+commander
+    .command('add')
+    .description("Add specified target")
+    .action(function () {
+        if (commander.args.length === 1) {
+            console.log("Target details not specified");
+            console.log(commander.helpInformation());
+            process.exit(2); 
+        }
+        name = commander.args[0];
+        ip = commander.args[1];
+        type = commander.type ? commander.type : "device";
+        if (commander.password && typeof commander.password === 'string') {
+            password = commander.password;
+        }
+        if (commander.pin && typeof commander.pin === 'string') {
+            pin = commander.pin;
+        }
+        if (!isValidIp(ip)) {
+            console.log("Invalid IP: " + ip);
+            console.log(commander.helpInformation());
+            process.exit(2); 
+        }
+        if (!isValidType(type)) {
+            console.log("Invalid target type: " + type);
+            console.log(commander.helpInformation());
+            process.exit(2); 
+        }
+        if (!isValidPin(pin)) {
+            console.log("Invalid PIN: " + pin);
+            console.log(commander.helpInformation());
+            process.exit(2); 
+        }
+        if (properties.targets.hasOwnProperty(name)) {
+            console.log("Overwriting target: " + name);
+        }
+        properties.targets[name] = {"ip": ip, "type": type, "password": password, "pin": pin};
+    });
+
+commander
+    .command('remove')
+    .description("Remove specified target")
+    .action(function () {
+        if (commander.args.length === 1) {
+            console.log('No target specified');
+            console.log(commander.helpInformation());
+            process.exit(2); 
+        }
+        name = commander.args[0];
+        if (!properties.targets.hasOwnProperty(name)) {
+            console.log("Target: '" + name + "' not found");
+            console.log(commander.helpInformation());
+            process.exit(2); 
+        }
+        if (name === properties.defaultTarget) {
+            console.log("Deleting default target, please set a new default target");
+            properties.defaultTarget = "";
+        }
+        delete properties.targets[name];
+    });
+
+commander
+    .command('default')
+    .description("Get or set default target")
+    .action(function () {
+        if (commander.args.length === 1) {
+            console.log(properties.defaultTarget);
+            process.exit();
+        }
+        name = commander.args[0];
+        if (properties.targets.hasOwnProperty(name)) {
+            properties.defaultTarget = name;
+        } else {
+            console.log("Target '" + name + "' not found");
+            console.log(commander.helpInformation());
+            process.exit(2); 
+        }
+    });
+
+commander
+    .command('*')
+    .action(function () {
+        console.log('Unrecognized command');
+        console.log(commander.helpInformation());
+        process.exit(2);
+    });
+
+
+try {
+    commander.parse(process.argv);
+
+    if (commander.args.length === 0) {
+        Object.keys(properties.targets).forEach(function (target) {
+            if (target === properties.defaultTarget) {
+                console.log('* ' + target);
+            } else {
+                console.log('  ' + target);
+            }
+        });
+        process.exit();
+    }
+    if (Object.keys(properties.targets).length === 1) {
+        properties.defaultTarget = Object.keys(properties.targets)[0];
+    }
+
+    writeProjectFile(JSON.stringify(properties, null, 4) + "\n", propertiesFile);
+} catch (e) {
+    console.log(e);
+    process.exit();
+}

http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/554bd506/blackberry10/bin/lib/targets.json
----------------------------------------------------------------------
diff --git a/blackberry10/bin/lib/targets.json b/blackberry10/bin/lib/targets.json
new file mode 100644
index 0000000..85d0113
--- /dev/null
+++ b/blackberry10/bin/lib/targets.json
@@ -0,0 +1,5 @@
+{
+    "defaultTarget": "bb10",
+    "targets": {
+    }
+}

http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/554bd506/blackberry10/bin/target
----------------------------------------------------------------------
diff --git a/blackberry10/bin/target b/blackberry10/bin/target
new file mode 100755
index 0000000..4e676d2
--- /dev/null
+++ b/blackberry10/bin/target
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+node "$( dirname "$0")/lib/target" "$@"

http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/554bd506/blackberry10/bin/target.bat
----------------------------------------------------------------------
diff --git a/blackberry10/bin/target.bat b/blackberry10/bin/target.bat
new file mode 100755
index 0000000..3c05c97
--- /dev/null
+++ b/blackberry10/bin/target.bat
@@ -0,0 +1,21 @@
+@ECHO OFF
+goto comment
+       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
+       regarding copyright ownership.  The ASF licenses this file
+       to you 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.
+:comment
+
+@node.exe %~dps0\lib\target %*