Skip to content
This repository has been archived by the owner on Jan 6, 2023. It is now read-only.

Commit

Permalink
chore(): simplify logging
Browse files Browse the repository at this point in the history
Right now the CLI spits out a lot of messages in various colors. As part
of an effort to simplify things, remove most colored output for now.
  • Loading branch information
tlancina committed Mar 31, 2016
1 parent fef84a6 commit 0384fb0
Show file tree
Hide file tree
Showing 17 changed files with 403 additions and 405 deletions.
4 changes: 2 additions & 2 deletions lib/config-xml.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ var fs = require('fs'),
path = require('path'),
Q = require('q'),
xml2js = require('xml2js'),
logging = require('./logging');
log = require('./logging').logger;

var ConfigXml = module.exports;

Expand Down Expand Up @@ -44,7 +44,7 @@ ConfigXml.setConfigXml = function setConfigXml(appDirectory, options) {
appDirectory = process.cwd();
}

logging.logger.debug('ConfigXml.setConfigXml', appDirectory, options);
log.debug('ConfigXml.setConfigXml', appDirectory, options);

var configXmlPath = path.join(appDirectory, 'config.xml');

Expand Down
12 changes: 6 additions & 6 deletions lib/cordova.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var argv = require('optimist').boolean(['nohooks', 'n', 'r', 'noresources', 'nos
// Hooks = require('./hooks'),
State = require('./state'),
Q = require('q'),
logging = require('./logging');
log = require('./logging').logger;

var Cordova = module.exports;

Expand Down Expand Up @@ -136,7 +136,7 @@ Cordova.runCordova = function runCordova(cmdName) {
Cordova.setupLiveReload = function() {
var d = Q.defer();

logging.logger.info('Setup Live Reload'.green.bold);
log.info('Setup Live Reload');

var self = this;
var serve = new require('./serve');
Expand Down Expand Up @@ -179,7 +179,7 @@ Cordova.setupLiveReload = function() {


Cordova.addPlatform = function addPlatform(projectRoot, platform, savePlatform) {
logging.logger.debug('Cordova.addPlatform: ', projectRoot, platform, savePlatform);
log.debug('Cordova.addPlatform: ', projectRoot, platform, savePlatform);
// var opts = {
// searchpath : args.searchpath
// , noregistry : args.noregistry
Expand All @@ -202,7 +202,7 @@ Cordova.addPlatform = function addPlatform(projectRoot, platform, savePlatform)
//logging.logger.info(('Added ' + platform + ' platform').green);
process.env.PWD = originalPwd;
if (savePlatform) {
logging.logger.debug('Cordova.addPlatform call specified to save platform. Saving to package.json now.');
log.debug('Cordova.addPlatform call specified to save platform. Saving to package.json now.');
return State.savePlatform(projectRoot, platform);
}
});
Expand Down Expand Up @@ -247,7 +247,7 @@ Cordova.runPlatform = function runPlatform(projectRoot, platform) {


Cordova.addPlugin = function addPlugin(projectRoot, pluginId, pluginVariables, savePlugin) {
logging.logger.debug('Cordova.addPlugin: projectRoot', projectRoot, 'pluginId', pluginId, 'pluginVariables', pluginVariables, 'savePlugin', savePlugin);
log.debug('Cordova.addPlugin: projectRoot', projectRoot, 'pluginId', pluginId, 'pluginVariables', pluginVariables, 'savePlugin', savePlugin);
var originalPwd = process.env.PWD;
process.env.PWD = projectRoot;

Expand All @@ -262,7 +262,7 @@ Cordova.addPlugin = function addPlugin(projectRoot, pluginId, pluginVariables, s
}
})
.catch(function(error) {
logging.logger.error('Error occurred while adding plugin: ', error);
log.error('Error occurred while adding plugin: ', error);
throw error;
});
};
Expand Down
24 changes: 11 additions & 13 deletions lib/hooks.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
var fs = require('fs'),
path = require('path'),
shelljs = require('shelljs'),
logging = require('./logging');
log = require('./logging').logger;

var Hooks = module.exports;

Expand Down Expand Up @@ -42,7 +42,7 @@ Hooks.addHookScript = function addHookScript(appDirectory, cliHookPath, hookDire
var cliScript = path.join(cliHookPath, hookFilename);
fs.writeFileSync(projectScript, fs.readFileSync(cliScript));
} catch(e) {
logging.logger.error('addCliHookDirectory fs.createReadStream: %'.error, e, {});
log.error('addCliHookDirectory fs.createReadStream: %', e, {});
return;
}
}
Expand All @@ -51,16 +51,16 @@ Hooks.addHookScript = function addHookScript(appDirectory, cliHookPath, hookDire
try {
fs.chmodSync(projectScript, '755');
} catch(e) {
logging.logger.error('addCliHookDirectory fs.chmodSync: %s'.error, e, {});
log.error('addCliHookDirectory fs.chmodSync: %s', e, {});
}

} catch(e) {
logging.logger.error('Error adding hook script ' + hookDirectoryName + '/' + hookFilename + ', %s', e, {});
log.error('Error adding hook script ' + hookDirectoryName + '/' + hookFilename + ', %s', e, {});
}
};

Hooks.add = function add(appDirectory) {
logging.logger.info('Adding in default Ionic Cordova hooks'.blue.bold);
log.info('Adding in default Ionic Cordova hooks');
// Add hooks which this Ionic project doesn't already have
// note: hook scripts must be executable!

Expand All @@ -80,12 +80,11 @@ Hooks.add = function add(appDirectory) {
}
});

logging.logger.info('Added default Ionic Cordova hooks'.green.bold)

log.info('Added default Ionic Cordova hooks');
};

Hooks.remove = function remove(appDirectory) {
logging.logger.info('Removing the Ionic Cordova plugin hooks'.blue.bold)
log.info('Removing the Ionic Cordova plugin hooks')
var oldPluginHooks = [
'after_platform_add/010_install_plugins.js',
'after_plugin_add/010_register_plugin.js',
Expand All @@ -99,8 +98,7 @@ Hooks.remove = function remove(appDirectory) {
} catch(ex) { }
})

logging.logger.info('Removed the Ionic Cordova hooks'.green.bold);

log.info('Removed the Ionic Cordova hooks');
};


Expand All @@ -127,13 +125,13 @@ Hooks.setHooksPermission = function setHooksPermission(appDirectory) {
try {
fs.chmodSync(path.resolve(hooksPath, hookDir, hook), '755');
} catch(e) {
logging.logger.error('Hooks.setHooksPermission fs.chmodSync: %s'.error, e, {});
log.error('Hooks.setHooksPermission fs.chmodSync: %s', e, {});
}
})
});
} catch (ex) {
logging.logger.error('Error: %s', ex);
log.error('Error: %s', ex);
}

logging.logger.debug('Updated the hooks directory to have execute permissions'.green);
log.debug('Updated the hooks directory to have execute permissions');
};
50 changes: 25 additions & 25 deletions lib/info.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ var path = require('path'),
shelljs = require('shelljs'),
os = require('os'),
semver = require('semver'),
logging = require('./logging');
log = require('./logging').logger;

var Info = module.exports;

Expand Down Expand Up @@ -252,42 +252,42 @@ Info.gatherInfo = function gatherInfo() {
};

Info.printInfo = function printInfo(info) {
logging.logger.info('\nYour system information:\n');
log.info('\nYour system information:\n');

logging.logger.info('Cordova CLI:', info.cordova);
log.info('Cordova CLI:', info.cordova);
if (info.gulp) {
logging.logger.info('Gulp version:', info.gulp);
logging.logger.info('Gulp local: ', info.gulp_local);
log.info('Gulp version:', info.gulp);
log.info('Gulp local: ', info.gulp_local);
}

if (info.ionic) {
logging.logger.info('Ionic Framework Version:', info.ionic);
log.info('Ionic Framework Version:', info.ionic);
}

if (info.ionic_cli) {
logging.logger.info('Ionic CLI Version:', info.ionic_cli);
log.info('Ionic CLI Version:', info.ionic_cli);
}

if (info.ionic_lib) {
logging.logger.info('Ionic App Lib Version:', info.ionic_lib);
log.info('Ionic App Lib Version:', info.ionic_lib);
}

if (info.ios_deploy) {
logging.logger.info('ios-deploy version:', info.ios_deploy)
log.info('ios-deploy version:', info.ios_deploy)
}

if(info.ios_sim) {
logging.logger.info('ios-sim version:', info.ios_sim);
log.info('ios-sim version:', info.ios_sim);
}

logging.logger.info('OS:', info.os);
logging.logger.info('Node Version:', info.node);
log.info('OS:', info.os);
log.info('Node Version:', info.node);

if(info.xcode) {
logging.logger.info('Xcode version:', info.xcode);
log.info('Xcode version:', info.xcode);
}

logging.logger.info('\n');
log.info('\n');
};

Info.checkRuntime = function checkRuntime() {
Expand All @@ -306,7 +306,7 @@ Info.checkRuntime = function checkRuntime() {
} catch (ex) {
}

logging.logger.debug('System Info:', info);
log.debug('System Info:', info);

if (info.ios_sim !== 'Not installed') {
iosSimInstalled = true;
Expand All @@ -323,33 +323,33 @@ Info.checkRuntime = function checkRuntime() {
var showDepdencyWarning = nodeUpgrade || (!cordovaInstalled || cordovaUpgrade) || checkOsxDeps;

if (showDepdencyWarning) {
logging.logger.info('******************************************************'.yellow.bold);
logging.logger.info(' Dependency warning - for the CLI to run correctly, '.yellow.bold);
logging.logger.info(' it is highly recommended to install/upgrade the following: '.yellow.bold);
logging.logger.info('');
log.warn('******************************************************');
log.warn(' Dependency warning - for the CLI to run correctly, ');
log.warn(' it is highly recommended to install/upgrade the following: ');
log.warn('');

if(nodeUpgrade) {
var updateMessage = [' Please update your Node runtime to version ', requirements.node].join(' ');
logging.logger.info(updateMessage.yellow.bold);
log.warn(updateMessage);
validRuntime = false;
}

if(!cordovaInstalled || cordovaUpgrade) {
var action = cordovaInstalled ? 'update' : 'install';
updateMessage = [' Please', action, 'your Cordova CLI to version ', requirements.cordova, '`npm install -g cordova`'].join(' ')
logging.logger.info(updateMessage.yellow.bold);
log.warn(updateMessage);
validRuntime = false;
}

if (info.ios_sim === 'Not installed') {
logging.logger.info(' Install ios-sim to deploy iOS applications. `npm install -g ios-sim` (may require sudo)'.yellow.bold);
log.warn(' Install ios-sim to deploy iOS applications. `npm install -g ios-sim` (may require sudo)');
}
if (info.ios_deploy === 'Not installed') {
logging.logger.info(' Install ios-deploy to deploy iOS applications to devices. `npm install -g ios-deploy` (may require sudo)'.yellow.bold);
log.warn(' Install ios-deploy to deploy iOS applications to devices. `npm install -g ios-deploy` (may require sudo)');
}

logging.logger.info('');
logging.logger.info('******************************************************'.yellow.bold);
log.warn('');
log.warn('******************************************************');
}

return validRuntime;
Expand Down
Loading

0 comments on commit 0384fb0

Please sign in to comment.