diff --git a/lib/project.js b/lib/project.js index 514ce63..46a539c 100644 --- a/lib/project.js +++ b/lib/project.js @@ -1,5 +1,6 @@ var fs = require('fs'), - path = require('path'); + path = require('path') + log = require('./logging').logger; var Project = module.exports; @@ -43,22 +44,22 @@ Project.load = function load(appDirectory) { data = JSON.parse(fs.readFileSync(projectFile)); found = true; if (fs.existsSync(oldV2ProjectFile)) { - console.warn('WARN: ionic.config.js has been deprecated, you can remove it.'); + log.warn('WARN: ionic.config.js has been deprecated, you can remove it.'); } } catch(e) { if (e instanceof SyntaxError) { - console.error('Uh oh! There\'s a syntax error in your ' + Project.PROJECT_FILE + ' file:\n' + e.stack); + log.error('Uh oh! There\'s a syntax error in your ' + Project.PROJECT_FILE + ' file:\n' + e.stack); process.exit(1); } } if (!found) { try { data = JSON.parse(fs.readFileSync(oldProjectFile)); - console.warn('WARN: ionic.project has been renamed to ' + Project.PROJECT_FILE + ', please rename it.'); + log.warn('WARN: ionic.project has been renamed to ' + Project.PROJECT_FILE + ', please rename it.'); found = true; } catch(e) { if (e instanceof SyntaxError) { - console.error('Uh oh! There\'s a syntax error in your ionic.project file:\n' + e.stack); + log.error('Uh oh! There\'s a syntax error in your ionic.project file:\n' + e.stack); process.exit(1); } } @@ -66,8 +67,8 @@ Project.load = function load(appDirectory) { if (!found) { data = Project.PROJECT_DEFAULT; if (fs.existsSync(oldV2ProjectFile)) { - console.warn('WARN: ionic.config.js has been deprecated in favor of ionic.config.json.'); - console.info('Creating default ionic.config.json for you now...\n'); + log.warn('WARN: ionic.config.js has been deprecated in favor of ionic.config.json.'); + log.info('Creating default ionic.config.json for you now...\n'); data.v2 = true; if (fs.existsSync('tsconfig.json')) { data.typescript = true; @@ -93,16 +94,16 @@ Project.create = function create(appDirectory, name) { Project.save = function save(appDirectory, data) { if (!data) { - console.trace(); - console.error('This should never happen!'); + throw new Error('No data passed to Project.save'); } + try { var filePath = path.join(appDirectory, Project.PROJECT_FILE), jsonData = JSON.stringify(data, null, 2); fs.writeFileSync(filePath, jsonData + '\n'); } catch(e) { - console.error('Unable to save settings file:', e); + log.error('Unable to save settings file:', e); } }; diff --git a/lib/start.js b/lib/start.js index 43991b0..dbcf5b8 100644 --- a/lib/start.js +++ b/lib/start.js @@ -133,7 +133,7 @@ Start.startApp = function startApp(options) { }) .catch(function(ex) { if (errorWithStart) { - console.error('ERROR WITH START', ex.stack); + log.error('Error with start', ex.stack); throw ex; } //Might be a default error - ios already added. Ignore it. @@ -331,7 +331,7 @@ Start.fetchCreatorApp = function(options) { }); readStream.pipe(writeStream); } catch(e) { - console.error(e); + log.error(e); q.reject(e); } @@ -752,7 +752,7 @@ Start.initCordova = function(options, appSetup) { var q; try { if (!options.isCordovaProject) { - console.log('not a cordova project, no cordova options to initialize'); + log.info('not a cordova project, no cordova options to initialize'); return Q.resolve(); } @@ -812,7 +812,7 @@ Start.initCordova = function(options, appSetup) { function(err, stdout, stderr) { bar.tick(30); if(err) { - console.log(err, stderr); + log.error(err, stderr); Utils.fail('Unable to add plugins. Perhaps your version of Cordova is too old. ' + 'Try updating (npm install -g cordova), removing this project folder, and trying again:', stderr); q.reject(stderr); @@ -868,8 +868,7 @@ Start.updateConfigXml = function(targetPath, packageName, appName, ios, android) } catch(e) { // return self.ionic.fail('Error updating config.xml file: ' + e); - log.error('Error updating config.xml file: %s', e, {}) - console.error(e.stack); + log.error('Error updating config.xml file: %s', e.stack); } return q.promise; @@ -1191,7 +1190,7 @@ Start.promptForOverwrite = function promptForOverwrite(targetPath) { if (areYouSure == 'yes' || areYouSure == 'y') { rm('-rf', targetPath); // Empty line - console.log(''); + log.info(''); q.resolve(true); } else { q.resolve(false); diff --git a/lib/upload.js b/lib/upload.js index 6fc6931..a7febe8 100644 --- a/lib/upload.js +++ b/lib/upload.js @@ -355,7 +355,7 @@ Upload.addCacheBusters = function addCacheBusters(indexPath) { fs.writeFileSync(indexPath, htmlToSave); q.resolve(); } catch(e) { - console.error("Unable to append cachebusters to index.html asset urls. Err: " + e); + log.error("Unable to append cachebusters to index.html asset urls. Err: " + e); q.reject(e); } @@ -395,7 +395,7 @@ Upload.removeCacheBusters = function removeCacheBusters(indexPath) { fs.writeFileSync(indexPath, $.html()); q.resolve(); } catch(e) { - console.error("Unable to remove cachebusters from index.html asset urls. Err: " + e); + log.error("Unable to remove cachebusters from index.html asset urls. Err: " + e); q.reject(e); } return q.promise; diff --git a/lib/utils.js b/lib/utils.js index 08ad58b..f7da845 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -124,16 +124,16 @@ Utils.fetchArchive = function fetchArchive(targetPath, archiveUrl, isGui) { return; } if(!res) { - console.error('Invalid response:'.error.bold, archiveUrl); + log.error('Invalid response:'.red.bold, archiveUrl); q.reject('Unable to fetch response: ' + archiveUrl); return; } if(res.statusCode !== 200) { if(res.statusCode === 404 || res.statusCode === 406) { - console.error('Not found:'.error.bold, archiveUrl, '(' + res.statusCode + ')'); - console.error('Please verify the url and try again.'.error.bold); + log.error('Not found:'.error.bold, archiveUrl, '(' + res.statusCode + ')'); + log.error('Please verify the url and try again.'.red.bold); } else { - console.error('Invalid response status:'.error.bold, archiveUrl, '(' + res.statusCode + ')'); + log.error('Invalid response status:'.red.bold, archiveUrl, '(' + res.statusCode + ')'); } q.reject(res); return; @@ -261,14 +261,12 @@ Utils.getContentSrc = function getContentSrc(appDirectory) { try { contentSrc = jsonConfig.widget.content[0].$.src; } catch(e) { - return Utils.fail('Error parsing ' + configXmlPath + ': ' + e); + return Utils.fail('Error parsing ' + configXmlPath + ': ' + e.stack); } }); } catch(e) { - log.debug('Utils.getContentSrc failed', e); - console.log(e.stack); - return Utils.fail('Error loading ' + configXmlPath + ': ' + e); + return Utils.fail('Error loading ' + configXmlPath + ': ' + e.stack); } return contentSrc; @@ -349,7 +347,7 @@ Utils.findIonicRoot = function findIonicRoot(dir) { } dir = parentDir; } - console.error('Hit an unhandled case in utils.findIonicRoot'); + log.error('Hit an unhandled case in utils.findIonicRoot'); return null; }; @@ -359,7 +357,7 @@ Utils.cdIonicRoot = function cdIonicRoot(isV2) { log.debug('Looking up Ionic root, cwd:', process.cwd()); var rootDir = this.findIonicRoot(); if (!rootDir) { - console.error('Couldn\'t find ' + IonicProject.PROJECT_FILE + ' file. Are you in an Ionic project?'); + log.error('Couldn\'t find ' + IonicProject.PROJECT_FILE + ' file. Are you in an Ionic project?'); process.exit(1); } log.debug('Ionic root directory: ', process.cwd());