You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by za...@apache.org on 2014/12/15 14:33:12 UTC
[23/37] cordova-ubuntu git commit: Added a new logging system as well
as more meaningful debugging messages.
Added a new logging system as well as more meaningful debugging messages.
* Debug Mode: use --debug to show additional command output
* Normal Mode: clearly messages show the developer what is happening
* Configuration of shelljs verbosity from the new config.js module.
Project: http://git-wip-us.apache.org/repos/asf/cordova-ubuntu/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-ubuntu/commit/a9fe227a
Tree: http://git-wip-us.apache.org/repos/asf/cordova-ubuntu/tree/a9fe227a
Diff: http://git-wip-us.apache.org/repos/asf/cordova-ubuntu/diff/a9fe227a
Branch: refs/heads/master
Commit: a9fe227aedd9e7d8622315b164c4aaf5d67e64c3
Parents: cb3692c
Author: Jean-Francois Moy <je...@gmail.com>
Authored: Thu Nov 6 16:00:23 2014 +0000
Committer: Jean-Francois Moy <je...@gmail.com>
Committed: Thu Nov 6 16:00:23 2014 +0000
----------------------------------------------------------------------
bin/templates/project/cordova/build | 5 ++-
bin/templates/project/cordova/lib/build.js | 39 ++++++++--------
bin/templates/project/cordova/lib/config.js | 44 ++++++++++++++++++
bin/templates/project/cordova/lib/device.js | 13 ++++--
bin/templates/project/cordova/lib/logger.js | 57 ++++++++++++++++++++++++
bin/templates/project/cordova/lib/run.js | 35 ++++++++++-----
bin/templates/project/cordova/lib/utils.js | 34 ++++++++------
bin/templates/project/cordova/run | 3 ++
8 files changed, 180 insertions(+), 50 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-ubuntu/blob/a9fe227a/bin/templates/project/cordova/build
----------------------------------------------------------------------
diff --git a/bin/templates/project/cordova/build b/bin/templates/project/cordova/build
index ed571ff..91c3847 100755
--- a/bin/templates/project/cordova/build
+++ b/bin/templates/project/cordova/build
@@ -28,6 +28,9 @@ var root = path.resolve();
var www = path.join(root, 'www');
check_reqs(function () {
- var argv = require('optimist').string(['framework']).argv;
+ var argv = require('optimist').boolean(['debug']).string(['framework']).argv;
+ if (argv.debug) {
+ require('./lib/config').debugMode();
+ }
return build(root, PLATFORMS.ALL, false, undefined, argv.framework, false);
});
http://git-wip-us.apache.org/repos/asf/cordova-ubuntu/blob/a9fe227a/bin/templates/project/cordova/lib/build.js
----------------------------------------------------------------------
diff --git a/bin/templates/project/cordova/lib/build.js b/bin/templates/project/cordova/lib/build.js
index b970ef7..e840e64 100644
--- a/bin/templates/project/cordova/lib/build.js
+++ b/bin/templates/project/cordova/lib/build.js
@@ -28,6 +28,7 @@ var shell = require('shelljs');
var Constants = require('./constants');
var Utils = require('./utils');
+var logger = require('./logger');
var PLATFORMS = Constants.PLATFORM_TYPES;
@@ -54,6 +55,8 @@ module.exports.build = function(rootDir, target, nobuild, architecture, framewor
};
function buildClickPackage(campoDir, ubuntuDir, nobuild, architecture, framework, debug) {
+ logger.info('Building Phone Application...');
+
assert.ok(architecture && architecture.match(/^[a-z0-9_]+$/));
var archDir = path.join(ubuntuDir, framework, architecture);
@@ -126,6 +129,8 @@ function buildClickPackage(campoDir, ubuntuDir, nobuild, architecture, framework
}
function buildNative(campoDir, ubuntuDir, nobuild, debug) {
+ logger.info('Building Desktop Application...');
+
var nativeDir = path.join(ubuntuDir, 'native');
var prefixDir = path.join(nativeDir, 'prefix');
@@ -206,8 +211,8 @@ function buildNative(campoDir, ubuntuDir, nobuild, debug) {
for (var i = 0; i < templates.length; i++) {
fillTemplate(templates[i].source, templates[i].dest, props);
}
- console.error('In order to build debian package, execute'.yellow);
- console.error(('cd ' + debDir + '; ' + 'debuild').yellow);
+ logger.info('In order to build debian package, execute: ');
+ logger.info('cd ' + debDir + '; ' + 'debuild');
});
};
@@ -218,7 +223,7 @@ function buildNative(campoDir, ubuntuDir, nobuild, debug) {
function fillTemplate(source, dest, obj) {
var content = fs.readFileSync(source, {encoding: "utf8"});
for (var prop in obj) {
- content = content.replace(new RegExp('{' + prop + '}', 'g'), obj[prop])
+ content = content.replace(new RegExp('{' + prop + '}', 'g'), obj[prop]);
}
fs.writeFileSync(dest, content);
@@ -249,7 +254,7 @@ function checkClickPackage(prefixDir) {
// FIXME: remove this check after EOL
if (fs.existsSync('/usr/bin/click-run-checks')) {
var cmd = '/usr/bin/click-run-checks *.click';
- console.log(cmd.green);
+ logger.debug(cmd);
var output = shell.exec(cmd, { silent: true }).output;
var json = '[', b = 0;
for (var i = 0; i < output.length; i++) {
@@ -272,9 +277,9 @@ function checkClickPackage(prefixDir) {
if (out[i].warn) {
for (var m in out[i].warn) {
if (out[i].warn[m].text) {
- console.warn(out[i].warn[m].text.yellow);
+ logger.warn(out[i].warn[m].text);
if (out[i].warn[m].link)
- console.warn(out[i].warn[m].link);
+ logger.warn(out[i].warn[m].link);
}
}
}
@@ -283,9 +288,9 @@ function checkClickPackage(prefixDir) {
if (out[i].error) {
for (var m in out[i].error) {
if (out[i].error[m].text) {
- console.warn(out[i].error[m].text.yellow);
+ logger.warn(out[i].error[m].text);
if (out[i].error[m].link)
- console.warn(out[i].error[m].link);
+ logger.warn(out[i].error[m].link);
}
}
}
@@ -307,11 +312,9 @@ function checkEnv(ubuntuDir) {
return;
var cmd = "dpkg-query -Wf'${db:Status-abbrev}' " + deps;
- console.log(cmd.green);
- res = shell.exec(cmd);
-
+ var res = Utils.execSync(cmd);
if (res.code !== 0 || res.output.indexOf('un') !== -1) {
- console.error(("Error: missing packages" + deps).red);
+ logger.error("Error: missing packages" + deps);
process.exit(1);
}
}
@@ -322,13 +325,11 @@ function checkChrootEnv(ubuntuDir, architecture, framework) {
deps = deps.replace(/ARCH/g, architecture);
var cmd = "click chroot -a " + architecture + " -f " + framework + " run dpkg-query -Wf'${db:Status-abbrev}' " + deps;
- console.log(cmd.green);
- res = shell.exec(cmd);
-
+ var res = Utils.execSync(cmd);
if (res.code !== 0 || res.output.indexOf('un') !== -1) {
- console.error(("Error: missing " + architecture + " chroot").red);
- console.error(("run:\nsudo click chroot -a " + architecture + " -f " + framework + " create").red);
- console.error(("sudo click chroot -a " + architecture + " -f " + framework + " install " + deps).red);
+ logger.error("Error: missing " + architecture + " chroot");
+ logger.error("run:\nsudo click chroot -a " + architecture + " -f " + framework + " create");
+ logger.error("sudo click chroot -a " + architecture + " -f " + framework + " install " + deps);
process.exit(1);
}
}
@@ -348,5 +349,3 @@ function additionalDependencies(ubuntuDir) {
}
return deb;
}
-
-
http://git-wip-us.apache.org/repos/asf/cordova-ubuntu/blob/a9fe227a/bin/templates/project/cordova/lib/config.js
----------------------------------------------------------------------
diff --git a/bin/templates/project/cordova/lib/config.js b/bin/templates/project/cordova/lib/config.js
new file mode 100644
index 0000000..fe65a6f
--- /dev/null
+++ b/bin/templates/project/cordova/lib/config.js
@@ -0,0 +1,44 @@
+#!/usr/bin/env node
+
+/*
+ *
+ * Copyright 2014 Canonical Ltd.
+ *
+ * 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 shellCfg = require('shelljs').config;
+
+/**
+ * The configuration is used by other tasks to access shared properties, such as if the tasks are
+ * running in debug mode (verbose).
+ */
+function Config() {
+ this._debug = false;
+ shellCfg.silent = true;
+}
+
+Config.prototype = {
+ debugMode: function () {
+ this._debug = true;
+ shellCfg.silent = false;
+ },
+
+ inDebugMode: function () {
+ return this._debug;
+ }
+};
+
+module.exports = new Config();
http://git-wip-us.apache.org/repos/asf/cordova-ubuntu/blob/a9fe227a/bin/templates/project/cordova/lib/device.js
----------------------------------------------------------------------
diff --git a/bin/templates/project/cordova/lib/device.js b/bin/templates/project/cordova/lib/device.js
index f5c6213..5ba2f9a 100644
--- a/bin/templates/project/cordova/lib/device.js
+++ b/bin/templates/project/cordova/lib/device.js
@@ -22,9 +22,12 @@
var assert = require('assert');
var Utils = require('./utils');
+var logger = require('./logger');
+
module.exports.list = function () {
- var res = Utils.execSync('adb devices');
+ logger.info('Searching for connected devices');
+ var res = Utils.execSync('adb devices', false);
var response = res.output.split('\n');
var deviceList = [];
@@ -60,12 +63,14 @@ module.exports.arch = function (target) {
function adbExec(target, command, options) {
assert.ok(target && command);
- return Utils.execSync('adb -s ' + target + ' ' + command);
+ options = options || {};
+ return Utils.execSync('adb -s ' + target + ' ' + command, options.silent);
}
-function adbExecAsync(target, command) {
+function adbExecAsync(target, command, options) {
assert.ok(target && command);
- return Utils.execAsync('adb -s ' + target + ' ' + command);
+ options = options || {};
+ return Utils.execAsync('adb -s ' + target + ' ' + command, options.silent);
}
module.exports.adbExec = adbExec;
http://git-wip-us.apache.org/repos/asf/cordova-ubuntu/blob/a9fe227a/bin/templates/project/cordova/lib/logger.js
----------------------------------------------------------------------
diff --git a/bin/templates/project/cordova/lib/logger.js b/bin/templates/project/cordova/lib/logger.js
new file mode 100644
index 0000000..9f263ef
--- /dev/null
+++ b/bin/templates/project/cordova/lib/logger.js
@@ -0,0 +1,57 @@
+#!/usr/bin/env node
+
+/*
+ *
+ * Copyright 2014 Canonical Ltd.
+ *
+ * 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 colors = require('colors');
+var config = require('./config');
+
+/**
+ * Output debug messages in white. If not in verbose mode, nothing is output.
+ */
+module.exports.debug = function (msg) {
+ if (config.inDebugMode()) {
+ console.log(msg);
+ }
+};
+
+/**
+ * Output info messages in green to the console.
+ */
+module.exports.info = function (msg) {
+ console.log(msg.green);
+};
+
+/**
+ * Output warning messages in yellow to the console.
+ */
+module.exports.warn = function (msg) {
+ console.warn(msg.yellow);
+};
+
+/**
+ * Output error messages in red to the console.
+ */
+module.exports.error = function (msg) {
+ console.error(msg.red);
+};
+
+module.exports.rainbow = function (msg) {
+ console.log(msg.rainbow);
+};
http://git-wip-us.apache.org/repos/asf/cordova-ubuntu/blob/a9fe227a/bin/templates/project/cordova/lib/run.js
----------------------------------------------------------------------
diff --git a/bin/templates/project/cordova/lib/run.js b/bin/templates/project/cordova/lib/run.js
index dfe0274..cd7a6a9 100644
--- a/bin/templates/project/cordova/lib/run.js
+++ b/bin/templates/project/cordova/lib/run.js
@@ -25,6 +25,7 @@ var path = require('path');
var shell = require('shelljs');
var build = require('./build').build;
+var logger = require('./logger');
var Devices = require('./device');
var Constants = require('./constants');
@@ -35,19 +36,23 @@ var MSG = Constants.MSG;
module.exports.run = function(rootDir, desktop, debug, target, nobuild, emulator, framework) {
if (desktop && !emulator) {
+ logger.info('Building Desktop Application...');
return build(rootDir, PLATFORMS.DESKTOP, nobuild, null, null, debug).then(function () {
+ logger.info('Build Successful. Running the application.');
return runNative(rootDir, debug);
});
}
- if (!framework)
+ if (!framework) {
+ logger.warn('No framework specified. Using default framework: ' + Constants.DEFAULT_FRAMEWORK);
framework = Constants.DEFAULT_FRAMEWORK;
+ }
if (!target) {
var devices = Devices.list();
if (!devices.length) {
- console.error(MSG.UBUNTU_TOUCH_DEVICE_NOT_AVALAIBLE.red)
+ logger.error(MSG.UBUNTU_TOUCH_DEVICE_NOT_AVALAIBLE);
process.exit(1);
}
@@ -56,7 +61,7 @@ module.exports.run = function(rootDir, desktop, debug, target, nobuild, emulator
return name.match(/^emulator-/);
});
if (!devices.length) {
- console.error(MSG.EMULATOR_IS_NOT_RUNNING.red)
+ logger.error(MSG.EMULATOR_IS_NOT_RUNNING);
process.exit(1);
}
}
@@ -64,19 +69,21 @@ module.exports.run = function(rootDir, desktop, debug, target, nobuild, emulator
target = devices[0];
if (devices.length > 1) {
- console.warn('you can specify target with --target <device id>'.yellow);
- console.warn(('running on ' + target).yellow);
+ logger.warn('Multiple targets found, you can specify target with --target <device id>');
}
+
+ logger.info('Target Device: ' + target);
}
var arch = Devices.arch(target);
return build(rootDir, PLATFORMS.PHONE, nobuild, arch, framework, debug).then(function () {
+ logger.info('Build Successful. Running the application.');
return runOnDevice(rootDir, debug, target, arch, framework);
});
};
function runNative(rootDir, debug) {
- console.log('Running Cordova'.green);
+ logger.info('Running Cordova');
var ubuntuDir = path.join(rootDir, 'platforms', 'ubuntu');
var nativeDir = path.join(ubuntuDir, 'native');
@@ -85,9 +92,10 @@ function runNative(rootDir, debug) {
var cmd = 'QTWEBKIT_INSPECTOR_SERVER=9222 ./cordova-ubuntu www/';
if (debug) {
cmd = "DEBUG=1 " + cmd;
- console.error('Debug enabled. Try pointing a WebKit browser to http://127.0.0.1:9222'.yellow);
+ logger.info('Debug enabled. Try pointing a WebKit browser to http://127.0.0.1:9222');
}
+ logger.info('Launching the application.');
return Utils.execAsync(cmd).then(function () {
Utils.popd();
});
@@ -97,7 +105,7 @@ function runOnDevice(rootDir, debug, target, architecture, framework) {
var ubuntuDir = path.join(rootDir, 'platforms', 'ubuntu');
if (!Devices.isAttached(target)) {
- console.error(MSG.UBUNTU_TOUCH_DEVICE_NOT_AVALAIBLE.red);
+ logger.error(MSG.UBUNTU_TOUCH_DEVICE_NOT_AVALAIBLE);
process.exit(1);
}
@@ -110,27 +118,30 @@ function runOnDevice(rootDir, debug, target, architecture, framework) {
var appId = manifest.name;
var names = shell.ls().filter(function (name) {
- return name.indexOf(appId) == 0 && name.indexOf('.click');
+ return name.indexOf(appId) === 0 && name.indexOf('.click');
});
assert.ok(names.length == 1);
+ logger.info('Killing application if already running on your device.');
Devices.adbExec(target, 'shell "ps -A -eo pid,cmd | grep cordova-ubuntu | awk \'{ print \\$1 }\' | xargs kill -9"');
if (debug)
Devices.adbExec(target, 'forward --remove-all');
+ logger.info('Installing the application on your device.');
Devices.adbExec(target, 'push ' + names[0] + ' /home/phablet');
- Devices.adbExec(target, 'shell "cd /home/phablet/; pkcon install-local ' + names[0] + ' -p --allow-untrusted -y"');
+ Devices.adbExec(target, 'shell "cd /home/phablet/; pkcon install-local ' + names[0] + ' -p --allow-untrusted -y"', {silent: false});
if (debug) {
- console.error('Debug enabled. Try pointing a WebKit browser to http://127.0.0.1:9222');
+ logger.info('Debug enabled. Try pointing a WebKit browser to http://127.0.0.1:9222');
Devices.adbExec(target, 'forward tcp:9222 tcp:9222');
}
- console.log('have fun!'.rainbow);
+ logger.info('Launching the application on your device.');
return Devices.adbExecAsync(target, 'shell bash -c "ubuntu-app-launch \\`ubuntu-app-triplet ' + appId + '\\`"').then(function () {
+ logger.rainbow('have fun!');
Utils.popd();
});
}
http://git-wip-us.apache.org/repos/asf/cordova-ubuntu/blob/a9fe227a/bin/templates/project/cordova/lib/utils.js
----------------------------------------------------------------------
diff --git a/bin/templates/project/cordova/lib/utils.js b/bin/templates/project/cordova/lib/utils.js
index 60e99c4..403da44 100644
--- a/bin/templates/project/cordova/lib/utils.js
+++ b/bin/templates/project/cordova/lib/utils.js
@@ -22,46 +22,55 @@ var Q = require('q');
var colors = require('colors');
var shell = require('shelljs');
+var config = require('./config');
+var logger = require('./logger');
+
module.exports.cp = function(source, dest) {
- console.log(('cp -Rf ' + source + ' ' + dest).green);
+ var cmd = 'cp -Rf ' + source + ' ' + dest;
+ logger.debug(cmd);
if (shell.cp('-r', source, dest) === null) {
- console.error("FAILED".underline.red);
+ logger.error(cmd + " FAILED".underline);
process.exit(1);
}
};
module.exports.pushd = function(dir) {
- console.log(('pushd ' + dir).green);
+ logger.debug('pushd ' + dir);
shell.pushd(dir);
};
module.exports.popd = function(dir) {
- console.log(('popd').green);
+ logger.debug('popd');
shell.popd();
};
module.exports.execSync = function(cmd, silent) {
- console.log(cmd.green);
+ logger.debug(cmd);
+ silent = (typeof silent === 'boolean') ? silent : !config.inDebugMode();
var res = shell.exec(cmd, { silent: silent });
if (res.code !== 0) {
- console.error(cmd.green + " " + "FAILED".underline.red);
+ logger.error(cmd.green + " " + "FAILED".underline);
+ logger.error(res.output);
+ logger.error('You can run with --debug to debug more easily.');
process.exit(1);
}
return res;
};
-module.exports.execAsync = function (cmd) {
- var deferred = Q.defer();
-
- console.log(cmd.green);
+module.exports.execAsync = function (cmd, silent) {
+ logger.debug(cmd);
- shell.exec(cmd, { async: true }, function (code, output) {
+ var deferred = Q.defer();
+ silent = (typeof silent === 'boolean') ? silent : !config.inDebugMode();
+ shell.exec(cmd, { async: true, silent: silent }, function (code, output) {
var res = { code: code, output: output };
if (res.code !== 0) {
- console.error(cmd.green + " " + "FAILED".underline.red);
+ logger.error(cmd.green + " " + "FAILED".underline);
+ logger.error(res.output);
+ logger.error('You can run with --debug to debug more easily.')
process.exit(1);
}
deferred.resolve(res);
@@ -69,4 +78,3 @@ module.exports.execAsync = function (cmd) {
return deferred.promise;
};
-
http://git-wip-us.apache.org/repos/asf/cordova-ubuntu/blob/a9fe227a/bin/templates/project/cordova/run
----------------------------------------------------------------------
diff --git a/bin/templates/project/cordova/run b/bin/templates/project/cordova/run
index 2668dda..fc36457 100755
--- a/bin/templates/project/cordova/run
+++ b/bin/templates/project/cordova/run
@@ -29,5 +29,8 @@ var www = path.join(root, 'www');
check_reqs(function () {
var argv = require('optimist').boolean(['device', 'emulator', 'debug', 'nobuild']).string(['target', 'framework']).argv;
+ if (argv.debug) {
+ require('./lib/config').debugMode();
+ }
return run(root, !argv.device, argv.debug, argv.target, argv.nobuild, argv.emulator, argv.framework);
});
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org