Skip to content
This repository has been archived by the owner on Feb 18, 2019. It is now read-only.

Commit

Permalink
Add ability to silence packager logs to stdout
Browse files Browse the repository at this point in the history
Summary:We use a few different modules to output logs to stdout when building a bundle with the packager:
- ##js/react-native-github/packager/react-packager/src/Activity/index.js##
- ##js/react-native-github/local-cli/util/log.js##
- ##https://www.npmjs.com/package/progress##

This diff also adds a ##silent## option to the packager ##Server##, which, when ##true##, will not create a ##progress## instance for the transformer.

Reviewed By: martinbigio

Differential Revision: D3048739

fb-gh-sync-id: a4c6caf36f5127946593f4a0a349fa145ad0d4e6
shipit-source-id: a4c6caf36f5127946593f4a0a349fa145ad0d4e6
  • Loading branch information
sam-swarr authored and Facebook Github Bot 8 committed Mar 15, 2016
1 parent 09820cb commit d5445d5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
10 changes: 10 additions & 0 deletions local-cli/util/log.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,22 @@
*/
'use strict';

var _enabled = true;

function disable() {
_enabled = false;
}

function log(stream, module) {
return function() {
if (!_enabled) {
return;
}
const message = Array.prototype.slice.call(arguments).join(' ');
stream.write(module + ': ' + message + '\n');
};
}

module.exports.out = log.bind(null, process.stdout);
module.exports.err = log.bind(null, process.stderr);
module.exports.disable = disable;
8 changes: 6 additions & 2 deletions packager/react-packager/src/Bundler/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ const validateOpts = declareOpts({
type: 'number',
required: false,
},
silent: {
type: 'boolean',
default: false,
},
});

class Bundler {
Expand Down Expand Up @@ -352,8 +356,8 @@ class Bundler {
const modulesByName = Object.create(null);

if (!resolutionResponse) {
let onProgess;
if (process.stdout.isTTY) {
let onProgess = noop;
if (process.stdout.isTTY && !this._opts.silent) {
const bar = new ProgressBar(
'transformed :current/:total (:percent)',
{complete: '=', incomplete: ' ', width: 40, total: 1},
Expand Down
4 changes: 4 additions & 0 deletions packager/react-packager/src/Server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ const validateOpts = declareOpts({
type: 'string',
required: false,
},
silent: {
type: 'boolean',
default: false,
},
});

const bundleOpts = declareOpts({
Expand Down

0 comments on commit d5445d5

Please sign in to comment.