2016-10-04 23:39:20 -04:00
|
|
|
/**
|
|
|
|
* @license
|
|
|
|
* Copyright Google Inc. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
|
|
* found in the LICENSE file at https://angular.io/license
|
|
|
|
*/
|
|
|
|
|
2015-05-22 11:19:45 -04:00
|
|
|
var kLogsArgument = /^--logs\s*=\s*(.+?)$/;
|
|
|
|
var kTrimLeft = /^\s+/;
|
|
|
|
var kTrimRight = /\s+$/;
|
|
|
|
var kCamelCase = /[-_\s]+(.)?/g;
|
|
|
|
var logs = findArgvLogs();
|
|
|
|
|
|
|
|
function findArgvLogs() {
|
|
|
|
for (var i = 0; i < process.argv.length; ++i) {
|
|
|
|
var match = process.argv[i].match(kLogsArgument);
|
|
|
|
if (match) {
|
|
|
|
return logsToObject(match[1]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
function logsToObject(logstr) {
|
2016-10-04 23:39:20 -04:00
|
|
|
return logstr.split(',').reduce(function(obj, key) {
|
|
|
|
key = camelize(key);
|
|
|
|
if (key.length > 0) obj[key] = true;
|
|
|
|
return obj;
|
|
|
|
}, Object.create(null));
|
2015-05-22 11:19:45 -04:00
|
|
|
return logs;
|
|
|
|
}
|
|
|
|
|
|
|
|
function camelize(str) {
|
2016-10-04 23:39:20 -04:00
|
|
|
return str.replace(kTrimLeft, '').replace(kTrimRight, '').replace(kCamelCase, function(match, c) {
|
|
|
|
return c ? c.toUpperCase() : '';
|
|
|
|
});
|
2015-05-22 11:19:45 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function shouldLog(str) {
|
|
|
|
if (!logs || logs.quiet) return false;
|
|
|
|
if (logs.all) return true;
|
|
|
|
return !!logs[camelize(str)];
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = shouldLog;
|