Skip to content

Commit e50f537

Browse files
committed
build(gulp): turn off dartfmt logs by default
Closes angular#2105
1 parent ed83647 commit e50f537

2 files changed

Lines changed: 56 additions & 1 deletion

File tree

gulpfile.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,19 @@ var util = require('./tools/build/util');
3434
var bundler = require('./tools/build/bundle');
3535
var replace = require('gulp-replace');
3636
var insert = require('gulp-insert');
37+
var shouldLog = require('./tools/build/logging');
3738

39+
// Make it easy to quiet down portions of the build.
40+
// --logs=all -> log everything (This is the default)
41+
// --logs=quiet -> log nothing
42+
// --logs=<comma-separated-list> -> log listed items.
43+
//
44+
// Not all commands support optional logging, feel free
45+
// to add support by adding a new key to this list,
46+
// and toggling output from the command based on it.
47+
var logs = {
48+
dartfmt: shouldLog('dartfmt')
49+
};
3850

3951
// dynamic require in build.tools so we can bootstrap TypeScript compilation
4052
function throwToolsBuildMissingError() {
@@ -194,7 +206,7 @@ gulp.task('build/pubbuild.dart', pubbuild(gulp, gulpPlugins, {
194206

195207
gulp.task('build/format.dart', function() {
196208
return util.processToPromise(spawn(DART_SDK.DARTFMT, ['-w', CONFIG.dest.dart], {
197-
stdio: 'inherit'
209+
stdio: logs.dartfmt ? 'inherit' : ['ignore', 'ignore', 'inherit']
198210
}));
199211
});
200212

tools/build/logging.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
var kLogsArgument = /^--logs\s*=\s*(.+?)$/;
2+
var kTrimLeft = /^\s+/;
3+
var kTrimRight = /\s+$/;
4+
var kCamelCase = /[-_\s]+(.)?/g;
5+
var logs = findArgvLogs();
6+
7+
function findArgvLogs() {
8+
for (var i = 0; i < process.argv.length; ++i) {
9+
var match = process.argv[i].match(kLogsArgument);
10+
if (match) {
11+
return logsToObject(match[1]);
12+
}
13+
}
14+
return null;
15+
}
16+
17+
function logsToObject(logstr) {
18+
return logstr.
19+
split(',').
20+
reduce(function(obj, key) {
21+
key = camelize(key);
22+
if (key.length > 0) obj[key] = true;
23+
return obj;
24+
}, Object.create(null));
25+
return logs;
26+
}
27+
28+
function camelize(str) {
29+
return str.
30+
replace(kTrimLeft, '').
31+
replace(kTrimRight, '').
32+
replace(kCamelCase, function(match, c) {
33+
return c ? c.toUpperCase() : "";
34+
});
35+
}
36+
37+
function shouldLog(str) {
38+
if (!logs || logs.quiet) return false;
39+
if (logs.all) return true;
40+
return !!logs[camelize(str)];
41+
}
42+
43+
module.exports = shouldLog;

0 commit comments

Comments
 (0)