Add `--verbose` flag to react native packager cli
Reviewed By: martinbigio Differential Revision: D2517347 fb-gh-sync-id: 02e64f99120b6636d6e7649deb11d0b2f58d9285
This commit is contained in:
parent
c76c22249d
commit
523769faa7
|
@ -68,6 +68,10 @@ var options = parseCommandLine([{
|
||||||
command: 'reset-cache',
|
command: 'reset-cache',
|
||||||
description: 'Removes cached files',
|
description: 'Removes cached files',
|
||||||
default: false,
|
default: false,
|
||||||
|
}, {
|
||||||
|
command: 'verbose',
|
||||||
|
description: 'Enables logging',
|
||||||
|
default: false,
|
||||||
}]);
|
}]);
|
||||||
|
|
||||||
if (options.projectRoots) {
|
if (options.projectRoots) {
|
||||||
|
@ -187,6 +191,7 @@ function getAppMiddleware(options) {
|
||||||
'../Libraries/JavaScriptAppEngine/polyfills/document.js'
|
'../Libraries/JavaScriptAppEngine/polyfills/document.js'
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
verbose: options.verbose,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,12 +12,12 @@ require('../babelRegisterOnly')([/react-packager\/src/]);
|
||||||
|
|
||||||
useGracefulFs();
|
useGracefulFs();
|
||||||
|
|
||||||
|
var debug = require('debug');
|
||||||
|
var omit = require('underscore').omit;
|
||||||
var Activity = require('./src/Activity');
|
var Activity = require('./src/Activity');
|
||||||
var Server = require('./src/Server');
|
|
||||||
var SocketInterface = require('./src/SocketInterface');
|
|
||||||
|
|
||||||
exports.middleware = function(options) {
|
exports.middleware = function(options) {
|
||||||
var server = new Server(options);
|
var server = createServer(options);
|
||||||
return server.processRequest.bind(server);
|
return server.processRequest.bind(server);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ exports.Activity = Activity;
|
||||||
// compat.
|
// compat.
|
||||||
exports.buildPackage =
|
exports.buildPackage =
|
||||||
exports.buildBundle = function(options, bundleOptions) {
|
exports.buildBundle = function(options, bundleOptions) {
|
||||||
var server = createServer(options);
|
var server = createNonPersistentServer(options);
|
||||||
return server.buildBundle(bundleOptions)
|
return server.buildBundle(bundleOptions)
|
||||||
.then(function(p) {
|
.then(function(p) {
|
||||||
server.end();
|
server.end();
|
||||||
|
@ -37,7 +37,7 @@ exports.buildBundle = function(options, bundleOptions) {
|
||||||
|
|
||||||
exports.buildPackageFromUrl =
|
exports.buildPackageFromUrl =
|
||||||
exports.buildBundleFromUrl = function(options, reqUrl) {
|
exports.buildBundleFromUrl = function(options, reqUrl) {
|
||||||
var server = createServer(options);
|
var server = createNonPersistentServer(options);
|
||||||
return server.buildBundleFromUrl(reqUrl)
|
return server.buildBundleFromUrl(reqUrl)
|
||||||
.then(function(p) {
|
.then(function(p) {
|
||||||
server.end();
|
server.end();
|
||||||
|
@ -46,7 +46,7 @@ exports.buildBundleFromUrl = function(options, reqUrl) {
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.getDependencies = function(options, bundleOptions) {
|
exports.getDependencies = function(options, bundleOptions) {
|
||||||
var server = createServer(options);
|
var server = createNonPersistentServer(options);
|
||||||
return server.getDependencies(bundleOptions)
|
return server.getDependencies(bundleOptions)
|
||||||
.then(function(r) {
|
.then(function(r) {
|
||||||
server.end();
|
server.end();
|
||||||
|
@ -55,23 +55,70 @@ exports.getDependencies = function(options, bundleOptions) {
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.createClientFor = function(options) {
|
exports.createClientFor = function(options) {
|
||||||
return SocketInterface.getOrCreateSocketFor(options);
|
if (options.verbose) {
|
||||||
|
enableDebug();
|
||||||
|
}
|
||||||
|
startSocketInterface();
|
||||||
|
return (
|
||||||
|
require('./src/SocketInterface')
|
||||||
|
.getOrCreateSocketFor(omit(options, ['verbose']))
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
SocketInterface.listenOnServerMessages();
|
|
||||||
|
|
||||||
function useGracefulFs() {
|
function useGracefulFs() {
|
||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
var gracefulFs = require('graceful-fs');
|
var gracefulFs = require('graceful-fs');
|
||||||
gracefulFs.gracefulify(fs);
|
gracefulFs.gracefulify(fs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function enableDebug() {
|
||||||
|
// react-packager logs debug messages using the 'debug' npm package, and uses
|
||||||
|
// the following prefix throughout.
|
||||||
|
// To enable debugging, we need to set our pattern or append it to any
|
||||||
|
// existing pre-configured pattern to avoid disabling logging for
|
||||||
|
// other packages
|
||||||
|
var debugPattern = 'ReactNativePackager:*';
|
||||||
|
var existingPattern = debug.load();
|
||||||
|
if (existingPattern) {
|
||||||
|
debugPattern += ',' + existingPattern;
|
||||||
|
}
|
||||||
|
debug.enable(debugPattern);
|
||||||
|
}
|
||||||
|
|
||||||
function createServer(options) {
|
function createServer(options) {
|
||||||
|
// the debug module is configured globally, we need to enable debugging
|
||||||
|
// *before* requiring any packages that use `debug` for logging
|
||||||
|
if (options.verbose) {
|
||||||
|
enableDebug();
|
||||||
|
}
|
||||||
|
|
||||||
|
startSocketInterface();
|
||||||
|
var Server = require('./src/Server');
|
||||||
|
return new Server(omit(options, ['verbose']));
|
||||||
|
}
|
||||||
|
|
||||||
|
function createNonPersistentServer(options) {
|
||||||
Activity.disable();
|
Activity.disable();
|
||||||
// Don't start the filewatcher or the cache.
|
// Don't start the filewatcher or the cache.
|
||||||
if (options.nonPersistent == null) {
|
if (options.nonPersistent == null) {
|
||||||
options.nonPersistent = true;
|
options.nonPersistent = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Server(options);
|
return createServer(options);
|
||||||
|
}
|
||||||
|
|
||||||
|
// we need to listen on a socket as soon as a server is created, but only once.
|
||||||
|
// This file also serves as entry point when spawning a socket server; in that
|
||||||
|
// case we need to start the server immediately.
|
||||||
|
var didStartSocketInterface = false;
|
||||||
|
function startSocketInterface() {
|
||||||
|
if (didStartSocketInterface) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
didStartSocketInterface = true;
|
||||||
|
require('./src/SocketInterface').listenOnServerMessages();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (require.main === module) { // used as entry point
|
||||||
|
startSocketInterface();
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,10 +27,11 @@ const SocketInterface = {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const hash = crypto.createHash('md5');
|
const hash = crypto.createHash('md5');
|
||||||
Object.keys(options).sort().forEach(key => {
|
Object.keys(options).sort().forEach(key => {
|
||||||
if (options[key] && typeof options[key] !== 'string') {
|
const value = options[key];
|
||||||
hash.update(JSON.stringify(options[key]));
|
if (value) {
|
||||||
} else {
|
hash.update(
|
||||||
hash.update(options[key]);
|
typeof value === 'string' ? value : JSON.stringify(value)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -58,7 +58,11 @@ function _bundle(argv, config, resolve, reject) {
|
||||||
command: 'assets-dest',
|
command: 'assets-dest',
|
||||||
description: 'Directory name where to store assets referenced in the bundle',
|
description: 'Directory name where to store assets referenced in the bundle',
|
||||||
type: 'string',
|
type: 'string',
|
||||||
}
|
}, {
|
||||||
|
command: 'verbose',
|
||||||
|
description: 'Enables logging',
|
||||||
|
default: false,
|
||||||
|
},
|
||||||
], argv);
|
], argv);
|
||||||
|
|
||||||
// This is used by a bazillion of npm modules we don't control so we don't
|
// This is used by a bazillion of npm modules we don't control so we don't
|
||||||
|
@ -70,6 +74,7 @@ function _bundle(argv, config, resolve, reject) {
|
||||||
assetRoots: config.getAssetRoots(),
|
assetRoots: config.getAssetRoots(),
|
||||||
blacklistRE: config.getBlacklistRE(args.platform),
|
blacklistRE: config.getBlacklistRE(args.platform),
|
||||||
transformModulePath: args.transformer,
|
transformModulePath: args.transformer,
|
||||||
|
verbose: args.verbose,
|
||||||
};
|
};
|
||||||
|
|
||||||
const requestOpts = {
|
const requestOpts = {
|
||||||
|
|
|
@ -44,6 +44,10 @@ function _dependencies(argv, config, resolve, reject) {
|
||||||
type: 'string',
|
type: 'string',
|
||||||
default: require.resolve('../../../packager/transformer'),
|
default: require.resolve('../../../packager/transformer'),
|
||||||
description: 'Specify a custom transformer to be used (absolute path)'
|
description: 'Specify a custom transformer to be used (absolute path)'
|
||||||
|
}, {
|
||||||
|
command: 'verbose',
|
||||||
|
description: 'Enables logging',
|
||||||
|
default: false,
|
||||||
}
|
}
|
||||||
], argv);
|
], argv);
|
||||||
|
|
||||||
|
@ -57,6 +61,7 @@ function _dependencies(argv, config, resolve, reject) {
|
||||||
assetRoots: config.getAssetRoots(),
|
assetRoots: config.getAssetRoots(),
|
||||||
blacklistRE: config.getBlacklistRE(args.platform),
|
blacklistRE: config.getBlacklistRE(args.platform),
|
||||||
transformModulePath: args.transformer,
|
transformModulePath: args.transformer,
|
||||||
|
verbose: config.verbose,
|
||||||
};
|
};
|
||||||
|
|
||||||
const relativePath = packageOpts.projectRoots.map(root =>
|
const relativePath = packageOpts.projectRoots.map(root =>
|
||||||
|
|
|
@ -62,6 +62,7 @@ function getAppMiddleware(args, config) {
|
||||||
'../../../Libraries/JavaScriptAppEngine/polyfills/document.js'
|
'../../../Libraries/JavaScriptAppEngine/polyfills/document.js'
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
verbose: args.verbose,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -58,6 +58,10 @@ function _server(argv, config, resolve, reject) {
|
||||||
command: 'reset-cache',
|
command: 'reset-cache',
|
||||||
description: 'Removes cached files',
|
description: 'Removes cached files',
|
||||||
default: false,
|
default: false,
|
||||||
|
}, {
|
||||||
|
command: 'verbose',
|
||||||
|
description: 'Enables logging',
|
||||||
|
default: false,
|
||||||
}]);
|
}]);
|
||||||
|
|
||||||
args.projectRoots = args.projectRoots
|
args.projectRoots = args.projectRoots
|
||||||
|
|
Loading…
Reference in New Issue