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

Commit

Permalink
chore(): remove console statements in favor of logger
Browse files Browse the repository at this point in the history
  • Loading branch information
tlancina committed Apr 1, 2016
1 parent 55270e4 commit f997aad
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 29 deletions.
21 changes: 11 additions & 10 deletions lib/project.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var fs = require('fs'),
path = require('path');
path = require('path')
log = require('./logging').logger;

var Project = module.exports;

Expand Down Expand Up @@ -43,31 +44,31 @@ 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);
}
}
}
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;
Expand All @@ -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);
}
};

Expand Down
13 changes: 6 additions & 7 deletions lib/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -331,7 +331,7 @@ Start.fetchCreatorApp = function(options) {
});
readStream.pipe(writeStream);
} catch(e) {
console.error(e);
log.error(e);
q.reject(e);
}

Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions lib/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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;
Expand Down
18 changes: 8 additions & 10 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
};

Expand All @@ -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());
Expand Down

0 comments on commit f997aad

Please sign in to comment.