You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by da...@apache.org on 2016/03/14 13:07:44 UTC

ios commit: CB-10840 Use cordova-common.CordovaLogger in cordova-ios

Repository: cordova-ios
Updated Branches:
  refs/heads/master 4c95f6441 -> 036765d32


CB-10840 Use cordova-common.CordovaLogger in cordova-ios

Removed unused events parameter from Plugman ctor


Project: http://git-wip-us.apache.org/repos/asf/cordova-ios/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-ios/commit/036765d3
Tree: http://git-wip-us.apache.org/repos/asf/cordova-ios/tree/036765d3
Diff: http://git-wip-us.apache.org/repos/asf/cordova-ios/diff/036765d3

Branch: refs/heads/master
Commit: 036765d326b24c14a3cae16a5c56646dae86d7c4
Parents: 4c95f64
Author: daserge <v-...@microsoft.com>
Authored: Fri Mar 11 16:07:43 2016 +0300
Committer: daserge <v-...@microsoft.com>
Committed: Mon Mar 14 14:57:10 2016 +0300

----------------------------------------------------------------------
 bin/create                                      |  4 +-
 bin/lib/create.js                               |  7 +-
 bin/templates/scripts/cordova/Api.js            | 31 +++++---
 bin/templates/scripts/cordova/build             |  4 +-
 bin/templates/scripts/cordova/clean             | 16 ++++-
 .../scripts/cordova/lib/ConsoleLogger.js        | 75 --------------------
 .../scripts/cordova/lib/plugman/Plugman.js      |  7 +-
 bin/templates/scripts/cordova/lib/prepare.js    |  2 +-
 bin/templates/scripts/cordova/loggingHelper.js  | 11 +++
 bin/templates/scripts/cordova/run               |  4 +-
 bin/update                                      |  4 +-
 11 files changed, 68 insertions(+), 97 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/036765d3/bin/create
----------------------------------------------------------------------
diff --git a/bin/create b/bin/create
index 95f12a7..af13d6b 100755
--- a/bin/create
+++ b/bin/create
@@ -38,7 +38,7 @@ var argv = require('nopt')({
     'cli' : Boolean,
     'shared' : Boolean, // alias for --link
     'link' : Boolean
-});
+}, { 'd' : '--verbose' });
 
 var projectPath = argv.argv.remain[0];
 
@@ -66,4 +66,6 @@ var options = {
     customTemplate: argv.argv.remain[3],
 };
 
+require('./templates/scripts/cordova/loggingHelper').adjustLoggerLevel(argv);
+
 Api.createPlatform(projectPath, config, options).done();

http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/036765d3/bin/lib/create.js
----------------------------------------------------------------------
diff --git a/bin/lib/create.js b/bin/lib/create.js
index 530ef9d..3aadba8 100755
--- a/bin/lib/create.js
+++ b/bin/lib/create.js
@@ -24,7 +24,8 @@ var shell = require('shelljs'),
     path = require('path'),
     fs = require('fs'),
     plist = require('plist'),
-    ROOT = path.join(__dirname, '..', '..');
+    ROOT = path.join(__dirname, '..', '..'),
+    events = require('cordova-common').events;
 
 function updateSubprojectHelp() {
     console.log('Updates the subproject path of the CordovaLib entry to point to this script\'s version of Cordova.');
@@ -188,7 +189,7 @@ function relpath(_path, start) {
  * - <project_template_dir>: Path to a project template (override)
  *
  */
-exports.createProject = function(project_path, package_name, project_name, opts, events) {
+exports.createProject = function(project_path, package_name, project_name, opts) {
     package_name = package_name || 'my.cordova.project';
     project_name = project_name || 'CordovaExample';
     var use_shared = !!opts.link;
@@ -221,7 +222,7 @@ exports.createProject = function(project_path, package_name, project_name, opts,
     return Q.resolve();
 };
 
-exports.updateProject = function(projectPath, opts, events) {
+exports.updateProject = function(projectPath, opts) {
     var projectName = detectProjectName(projectPath);
     var project_template_dir = path.join(ROOT, 'bin', 'templates', 'project');
     //Get package_name from existing projectName-Info.plist file

http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/036765d3/bin/templates/scripts/cordova/Api.js
----------------------------------------------------------------------
diff --git a/bin/templates/scripts/cordova/Api.js b/bin/templates/scripts/cordova/Api.js
index 0c5b16d..a51d93b 100644
--- a/bin/templates/scripts/cordova/Api.js
+++ b/bin/templates/scripts/cordova/Api.js
@@ -23,7 +23,19 @@ var fs = require('fs');
 var path = require('path');
 
 var CordovaError = require('cordova-common').CordovaError;
-var ConsoleLogger = require('./lib/ConsoleLogger');
+var CordovaLogger = require('cordova-common').CordovaLogger;
+var events = require('cordova-common').events;
+
+function setupEvents(externalEventEmitter) {
+    if (externalEventEmitter) {
+        // This will make the platform internal events visible outside
+        events.forwardEventsTo(externalEventEmitter);
+    } else {
+        // There is no logger if external emitter is not present, 
+        // so attach a console logger
+        CordovaLogger.get().subscribe(events);
+    }
+}
 
 /**
  * Creates a new PlatformApi instance.
@@ -41,9 +53,8 @@ function Api(platform, platformRootDir, events) {
     this.platform = platform || 'ios';
 
     this.root = platformRootDir || path.resolve(__dirname, '..');
-    this.events = events || ConsoleLogger.get();
-    // NOTE: trick to share one EventEmitter instance across all js code
-    require('cordova-common').events = this.events;
+
+    setupEvents(events);
 
     var xcodeProjDir;
     var xcodeCordovaProj;
@@ -95,8 +106,10 @@ function Api(platform, platformRootDir, events) {
  *   instance or rejected with CordovaError.
  */
 Api.createPlatform = function (destination, config, options, events) {
+    setupEvents(events);
+
     return require('../../../lib/create')
-    .createProject(destination, config.packageName(), config.name(), options, events || ConsoleLogger.get())
+    .createProject(destination, config.packageName(), config.name(), options)
     .then(function () {
         // after platform is created we return Api instance based on new Api.js location
         // This is required to correctly resolve paths in the future api calls
@@ -122,8 +135,10 @@ Api.createPlatform = function (destination, config, options, events) {
  *   instance or rejected with CordovaError.
  */
 Api.updatePlatform = function (destination, options, events) {
+    setupEvents(events);
+
     return require('../../../lib/create')
-    .updateProject(destination, options, events || ConsoleLogger.get())
+    .updateProject(destination, options)
     .then(function () {
         var PlatformApi = require(path.resolve(destination, 'cordova/Api'));
         return new PlatformApi('ios', destination, events);
@@ -184,7 +199,7 @@ Api.prototype.prepare = function (cordovaProject) {
  */
 Api.prototype.addPlugin = function (plugin, installOptions) {
     var Plugman = require('./lib/plugman/Plugman');
-    return Plugman.get(this.locations, this.events).addPlugin(plugin, installOptions);
+    return Plugman.get(this.locations).addPlugin(plugin, installOptions);
 };
 
 /**
@@ -202,7 +217,7 @@ Api.prototype.addPlugin = function (plugin, installOptions) {
  */
 Api.prototype.removePlugin = function (plugin, uninstallOptions) {
     var Plugman = require('./lib/plugman/Plugman');
-    return Plugman.get(this.locations, this.events).removePlugin(plugin, uninstallOptions);
+    return Plugman.get(this.locations).removePlugin(plugin, uninstallOptions);
 };
 
 /**

http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/036765d3/bin/templates/scripts/cordova/build
----------------------------------------------------------------------
diff --git a/bin/templates/scripts/cordova/build b/bin/templates/scripts/cordova/build
index d611709..be7a5d2 100755
--- a/bin/templates/scripts/cordova/build
+++ b/bin/templates/scripts/cordova/build
@@ -44,11 +44,13 @@ var buildOpts = nopt({
     'provisioningProfile': String,
     'buildConfig' : String,
     'noSign' : Boolean
-}, {'-r': '--release'}, args);
+}, { '-r': '--release', 'd' : '--verbose' }, args);
 
 // Make buildOptions compatible with PlatformApi build method spec
 buildOpts.argv = buildOpts.argv.remain;
 
+require('./loggingHelper').adjustLoggerLevel(buildOpts);
+
 new Api().build(buildOpts).done(function() {
         console.log('** BUILD SUCCEEDED **');
     }, function(err) {

http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/036765d3/bin/templates/scripts/cordova/clean
----------------------------------------------------------------------
diff --git a/bin/templates/scripts/cordova/clean b/bin/templates/scripts/cordova/clean
index 1ca371c..8f7d303 100755
--- a/bin/templates/scripts/cordova/clean
+++ b/bin/templates/scripts/cordova/clean
@@ -21,15 +21,27 @@
 
 var Api = require('./Api');
 var path  = require('path');
+var nopt = require('nopt');
 
 if(['--help', '/?', '-h', 'help', '-help', '/help'].indexOf(process.argv[2]) >= 0) {
     console.log('Cleans the project directory.');
     process.exit(0);
 }
 
-new Api().clean({argv: process.argv.slice(2)}).done(function() {
+// Do some basic argument parsing
+var opts = nopt({
+    'verbose' : Boolean,
+    'silent' : Boolean
+}, { 'd' : '--verbose' });
+
+// Make buildOptions compatible with PlatformApi clean method spec
+opts.argv = opts.argv.original;
+
+require('./loggingHelper').adjustLoggerLevel(opts);
+
+new Api().clean(opts).done(function() {
     console.log('** CLEAN SUCCEEDED **');
-},function(err) {
+}, function(err) {
     console.error(err);
     process.exit(2);
 });

http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/036765d3/bin/templates/scripts/cordova/lib/ConsoleLogger.js
----------------------------------------------------------------------
diff --git a/bin/templates/scripts/cordova/lib/ConsoleLogger.js b/bin/templates/scripts/cordova/lib/ConsoleLogger.js
deleted file mode 100644
index cee2dc1..0000000
--- a/bin/templates/scripts/cordova/lib/ConsoleLogger.js
+++ /dev/null
@@ -1,75 +0,0 @@
-/**
-    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.
-*/
-
-var loggerInstance;
-var util = require('util');
-var EventEmitter = require('events').EventEmitter;
-var CordovaError = require('cordova-common').CordovaError;
-
-/**
- * @class ConsoleLogger
- * @extends EventEmitter
- *
- * Implementing basic logging for platform. Inherits regular NodeJS
- *   EventEmitter. All events, emitted on this class instance are immediately
- *   logged to console.
- *
- * Also attaches handler to process' uncaught exceptions, so these exceptions
- *   logged to console similar to regular error events.
- */
-function ConsoleLogger() {
-    EventEmitter.call(this);
-
-    var isVerbose = process.argv.indexOf('-d') >= 0 || process.argv.indexOf('--verbose') >= 0;
-    // For CordovaError print only the message without stack trace unless we
-    // are in a verbose mode.
-    process.on('uncaughtException', function(err){
-        if ((err instanceof CordovaError) && isVerbose) {
-            console.error(err.stack);
-        } else {
-            console.error(err.message);
-        }
-        process.exit(1);
-    });
-
-    this.on('results', console.log);
-    this.on('verbose', function () {
-        if (isVerbose)
-            console.log.apply(console, arguments);
-    });
-    this.on('info', console.log);
-    this.on('log', console.log);
-    this.on('warn', console.warn);
-}
-util.inherits(ConsoleLogger, EventEmitter);
-
-/**
- * Returns already instantiated/newly created instance of ConsoleLogger class.
- *   This method should be used instead of creating ConsoleLogger directly,
- *   otherwise we'll get multiple handlers attached to process'
- *   uncaughtException
- *
- * @return  {ConsoleLogger}  New or already created instance of ConsoleLogger
- */
-ConsoleLogger.get = function () {
-    loggerInstance = loggerInstance || new ConsoleLogger();
-    return loggerInstance;
-};
-
-module.exports = ConsoleLogger;

http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/036765d3/bin/templates/scripts/cordova/lib/plugman/Plugman.js
----------------------------------------------------------------------
diff --git a/bin/templates/scripts/cordova/lib/plugman/Plugman.js b/bin/templates/scripts/cordova/lib/plugman/Plugman.js
index 8c7b115..5855e9e 100644
--- a/bin/templates/scripts/cordova/lib/plugman/Plugman.js
+++ b/bin/templates/scripts/cordova/lib/plugman/Plugman.js
@@ -31,9 +31,8 @@ var configMunger = require('../configMunger');
 var projectFile = require('../projectFile');
 var pluginHandlers = require('./pluginHandlers');
 
-function Plugman(locations, events) {
+function Plugman(locations) {
     this.locations = locations;
-    this.events = events;
 
     this._munger = configMunger.get(this.locations.root);
     this._platformJson = this._munger.platformJson;
@@ -43,10 +42,10 @@ function Plugman(locations, events) {
 // shared Plugman instance
 var _instance = null;
 
-Plugman.get = function(locations, events) {
+Plugman.get = function(locations) {
 
     if (!_instance) {
-        _instance = new Plugman(locations, events);
+        _instance = new Plugman(locations);
     }
     // we use singleton Plugman instance so we don't inistantiate all helper classes
     // for each plugin add or rm

http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/036765d3/bin/templates/scripts/cordova/lib/prepare.js
----------------------------------------------------------------------
diff --git a/bin/templates/scripts/cordova/lib/prepare.js b/bin/templates/scripts/cordova/lib/prepare.js
index 1e90f8e..0bdda47 100644
--- a/bin/templates/scripts/cordova/lib/prepare.js
+++ b/bin/templates/scripts/cordova/lib/prepare.js
@@ -51,7 +51,7 @@ module.exports.prepare = function (cordovaProject) {
         handleSplashScreens(cordovaProject.projectConfig, self.locations.xcodeCordovaProj);
     })
     .then(function () {
-        self.events.emit('verbose', 'updated project successfully');
+        events.emit('verbose', 'updated project successfully');
     });
 };
 

http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/036765d3/bin/templates/scripts/cordova/loggingHelper.js
----------------------------------------------------------------------
diff --git a/bin/templates/scripts/cordova/loggingHelper.js b/bin/templates/scripts/cordova/loggingHelper.js
new file mode 100644
index 0000000..3d28362
--- /dev/null
+++ b/bin/templates/scripts/cordova/loggingHelper.js
@@ -0,0 +1,11 @@
+var CordovaLogger = require('cordova-common').CordovaLogger;
+
+module.exports = {
+    adjustLoggerLevel: function (opts) {
+        if (opts.verbose || (Array.isArray(opts) && opts.indexOf('--verbose') !== -1)) {
+            CordovaLogger.get().setLevel('verbose');
+        } else if (opts.silent || (Array.isArray(opts) && opts.indexOf('--silent') !== -1)) {
+            CordovaLogger.get().setLevel('error');
+        }
+    }
+};

http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/036765d3/bin/templates/scripts/cordova/run
----------------------------------------------------------------------
diff --git a/bin/templates/scripts/cordova/run b/bin/templates/scripts/cordova/run
index 46a3342..470384b 100755
--- a/bin/templates/scripts/cordova/run
+++ b/bin/templates/scripts/cordova/run
@@ -47,11 +47,13 @@ var opts = nopt({
     'provisioningProfile': String,
     'buildConfig' : String,
     'noSign' : Boolean
-}, {}, args);
+}, { 'd' : '--verbose' }, args);
 
 // Make options compatible with PlatformApi build method spec
 opts.argv = opts.argv.remain;
 
+require('./loggingHelper').adjustLoggerLevel(opts);
+
 new Api().run(opts).done(function() {
         console.log('** RUN SUCCEEDED **');
     }, function (err) {

http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/036765d3/bin/update
----------------------------------------------------------------------
diff --git a/bin/update b/bin/update
index 33fac6e..d68f918 100755
--- a/bin/update
+++ b/bin/update
@@ -25,11 +25,13 @@ var args  = require('nopt')({
     'link': Boolean,
     'shared': Boolean, // alias for --link
     'help': Boolean
-});
+}, { 'd' : '--verbose' });
 
 if (args.help || args.argv.remain.length === 0) {
     console.log('Usage: ' + path.relative(process.cwd(), path.join(__dirname, 'update')) + ' <path_to_project> [--link]');
     process.exit(0);
 }
 
+require('./templates/scripts/cordova/loggingHelper').adjustLoggerLevel(args);
+
 Api.updatePlatform(args.argv.remain[0], {link: (args.link || args.shared)}).done();


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org