From d30384080a1bc7ce862b099855dca750b8db8eaa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Bigio?= Date: Mon, 12 Oct 2015 06:37:12 -0700 Subject: [PATCH] Bring back "download from server" perf optimization Reviewed By: @frantic Differential Revision: D2515566 fb-gh-sync-id: 25771888390154e9962d141f872cef85c08cd1d0 --- private-cli/src/bundle/bundle.js | 33 +------------- .../src/bundle/parseBundleCommandLine.js | 44 +++++++++++++++++++ private-cli/src/cli.js | 11 +++-- 3 files changed, 53 insertions(+), 35 deletions(-) create mode 100644 private-cli/src/bundle/parseBundleCommandLine.js diff --git a/private-cli/src/bundle/bundle.js b/private-cli/src/bundle/bundle.js index f66bda2b5..20bbf59fb 100644 --- a/private-cli/src/bundle/bundle.js +++ b/private-cli/src/bundle/bundle.js @@ -9,7 +9,7 @@ 'use strict'; const log = require('../util/log').out('bundle'); -const parseCommandLine = require('../../../packager/parseCommandLine'); +const parseBundleCommandLine = require('./parseBundleCommandLine'); const processBundle = require('./processBundle'); const Promise = require('promise'); const ReactPackager = require('../../../packager/react-packager'); @@ -25,36 +25,7 @@ function bundle(argv, config) { } function _bundle(argv, config, resolve, reject) { - const args = parseCommandLine([ - { - command: 'entry-file', - description: 'Path to the root JS file, either absolute or relative to JS root', - type: 'string', - required: true, - }, { - command: 'platform', - description: 'Either "ios" or "android"', - type: 'string', - required: true, - }, { - command: 'dev', - description: 'If false, warnings are disabled and the bundle is minified', - default: true, - }, { - command: 'bundle-output', - description: 'File name where to store the resulting bundle, ex. /tmp/groups.bundle', - type: 'string', - required: true, - }, { - command: 'sourcemap-output', - description: 'File name where to store the sourcemap file for resulting bundle, ex. /tmp/groups.map', - type: 'string', - }, { - command: 'assets-dest', - description: 'Directory name where to store assets referenced in the bundle', - type: 'string', - } - ], argv); + const args = parseBundleCommandLine(argv); // This is used by a bazillion of npm modules we don't control so we don't // have other choice than defining it as an env variable here. diff --git a/private-cli/src/bundle/parseBundleCommandLine.js b/private-cli/src/bundle/parseBundleCommandLine.js new file mode 100644 index 000000000..e9f54339c --- /dev/null +++ b/private-cli/src/bundle/parseBundleCommandLine.js @@ -0,0 +1,44 @@ +/** + * Copyright (c) 2015-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ +'use strict'; + +const parseCommandLine = require('../../../packager/parseCommandLine'); + +module.exports = function(argv) { + return parseCommandLine([ + { + command: 'entry-file', + description: 'Path to the root JS file, either absolute or relative to JS root', + type: 'string', + required: true, + }, { + command: 'platform', + description: 'Either "ios" or "android"', + type: 'string', + required: true, + }, { + command: 'dev', + description: 'If false, warnings are disabled and the bundle is minified', + default: true, + }, { + command: 'bundle-output', + description: 'File name where to store the resulting bundle, ex. /tmp/groups.bundle', + type: 'string', + required: true, + }, { + command: 'sourcemap-output', + description: 'File name where to store the sourcemap file for resulting bundle, ex. /tmp/groups.map', + type: 'string', + }, { + command: 'assets-dest', + description: 'Directory name where to store assets referenced in the bundle', + type: 'string', + } + ], argv); +}; diff --git a/private-cli/src/cli.js b/private-cli/src/cli.js index 679c46d00..44dd1d098 100644 --- a/private-cli/src/cli.js +++ b/private-cli/src/cli.js @@ -29,16 +29,16 @@ const hiddenCommands = { */ function run(command, commandArgs) { if (!command) { - throw new Error(helpMessage()); + return Promise.reject(helpMessage()); } commandArgs = commandArgs || []; const commandToExec = documentedCommands[command] || hiddenCommands[command]; if (!commandToExec) { - throw new Error(helpMessage(command)); + return Promise.reject(helpMessage(command)); } - commandToExec(commandArgs, Config.get()).done(); + return commandToExec(commandArgs, Config.get()); } function helpMessage(command) { @@ -61,4 +61,7 @@ function help() { return Promise.resolve(); } -module.exports.run = run; +module.exports = { + run: run, + commands: documentedCommands, +};