From 67ab9dadb950f3383460c4e976be857be67192b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Bigio?= Date: Mon, 12 Oct 2015 16:46:52 -0700 Subject: [PATCH] Move oss server to cli MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary: @​public We're moving all the operation from `local-cli` to the `private-cli` and improving the code in the process. On this diff we introduce the `server` command which will be use to start the packager server. On follow up diffs we'll make changes to start using it from `local-cli`. Reviewed By: @vjeux Differential Revision: D2531443 fb-gh-sync-id: 5f7f12a250895265d83d1b076f6bbddb5cbdc257 --- checkNodeVersion.js | 40 ---------------- formatBanner.js | 108 -------------------------------------------- packager.js | 4 +- rn-cli.config.js | 40 ++++++++++++++++ webSocketProxy.js | 2 +- 5 files changed, 43 insertions(+), 151 deletions(-) delete mode 100644 checkNodeVersion.js delete mode 100644 formatBanner.js create mode 100644 rn-cli.config.js diff --git a/checkNodeVersion.js b/checkNodeVersion.js deleted file mode 100644 index 388a0e2f..00000000 --- a/checkNodeVersion.js +++ /dev/null @@ -1,40 +0,0 @@ -/** - * 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'; - -var chalk = require('chalk'); -var semver = require('semver'); - -var formatBanner = require('./formatBanner'); - -function checkNodeVersion() { - if (!semver.satisfies(process.version, '>=4')) { - var engine = semver.satisfies(process.version, '<1 >=4') ? 'Node' : 'io.js'; - var message = 'You are currently running ' + engine + ' ' + - process.version + '.\n' + - '\n' + - 'React Native runs on Node 4.0 or newer. There are several ways to ' + - 'upgrade Node.js depending on your preference.\n' + - '\n' + - 'nvm: nvm install node && nvm alias default node\n' + - 'Homebrew: brew unlink iojs; brew install node\n' + - 'Installer: download the Mac .pkg from https://nodejs.org/\n' + - '\n' + - 'About Node.js: https://nodejs.org\n' + - 'Follow along at: https://github.com/facebook/react-native/issues/2545'; - console.log(formatBanner(message, { - chalkFunction: chalk.green, - marginLeft: 1, - marginRight: 1, - paddingBottom: 1, - })); - } -} - -module.exports = checkNodeVersion; diff --git a/formatBanner.js b/formatBanner.js deleted file mode 100644 index f54095b0..00000000 --- a/formatBanner.js +++ /dev/null @@ -1,108 +0,0 @@ -/** - * 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'; - -var _ = require('underscore'); -var wordwrap = require('wordwrap'); - -var HORIZONTAL_LINE = '\u2500'; -var VERTICAL_LINE = '\u2502'; -var TOP_LEFT = '\u250c'; -var TOP_RIGHT = '\u2510'; -var BOTTOM_LEFT = '\u2514'; -var BOTTOM_RIGHT = '\u2518'; - -/** - * Prints a banner with a border around it containing the given message. The - * following options are supported: - * - * type Options = { - * // A function to apply to each line of text to decorate it - * chalkFunction: (string: message) => string; - * // The total width (max line length) of the banner, including margin and - * // padding (default = 80) - * width: number; - * // How much leading space to prepend to each line (default = 0) - * marginLeft: number; - * // How much trailing space to append to each line (default = 0) - * marginRight: number; - * // Space between the top banner border and the text (default = 0) - * paddingTop: number; - * // Space between the bottom banner border and the text (default = 0) - * paddingBottom: number; - * // Space between the left banner border and the text (default = 2) - * paddingLeft: number; - * // Space between the right banner border and the text (default = 2) - * paddingRight: number; - * }; - */ -function formatBanner(message, options) { - options = options || {}; - _.defaults(options, { - chalkFunction: _.identity, - width: 80, - marginLeft: 0, - marginRight: 0, - paddingTop: 0, - paddingBottom: 0, - paddingLeft: 2, - paddingRight: 2, - }); - - var width = options.width; - var marginLeft = options.marginLeft; - var marginRight = options.marginRight; - var paddingTop = options.paddingTop; - var paddingBottom = options.paddingBottom; - var paddingLeft = options.paddingLeft; - var paddingRight = options.paddingRight; - - var horizSpacing = marginLeft + paddingLeft + paddingRight + marginRight; - // 2 for the banner borders - var maxLineWidth = width - horizSpacing - 2; - var wrap = wordwrap(maxLineWidth); - var body = wrap(message); - - var left = spaces(marginLeft) + VERTICAL_LINE + spaces(paddingLeft); - var right = spaces(paddingRight) + VERTICAL_LINE + spaces(marginRight); - var bodyLines = _.flatten([ - arrayOf('', paddingTop), - body.split('\n'), - arrayOf('', paddingBottom), - ]).map(function(line) { - var padding = spaces(Math.max(0, maxLineWidth - line.length)); - return left + options.chalkFunction(line) + padding + right; - }); - - var horizontalBorderLine = repeatString( - HORIZONTAL_LINE, - width - marginLeft - marginRight - 2 - ); - var top = spaces(marginLeft) + TOP_LEFT + horizontalBorderLine + TOP_RIGHT + - spaces(marginRight); - var bottom = spaces(marginLeft) + BOTTOM_LEFT + horizontalBorderLine + - BOTTOM_RIGHT + spaces(marginRight); - return _.flatten([top, bodyLines, bottom]).join('\n'); -} - -function spaces(number) { - return repeatString(' ', number); -} - -function repeatString(string, number) { - return new Array(number + 1).join(string); -} - -function arrayOf(value, number) { - return _.range(number).map(function() { - return value; - }); -} - -module.exports = formatBanner; diff --git a/packager.js b/packager.js index ddda537f..70324e64 100644 --- a/packager.js +++ b/packager.js @@ -20,10 +20,10 @@ const isAbsolutePath = require('absolute-path'); const blacklist = require('./blacklist.js'); const chalk = require('chalk'); -const checkNodeVersion = require('./checkNodeVersion'); +const checkNodeVersion = require('../private-cli/src/server/checkNodeVersion'); const cpuProfilerMiddleware = require('./cpuProfilerMiddleware'); const connect = require('connect'); -const formatBanner = require('./formatBanner'); +const formatBanner = require('../private-cli/src/server/formatBanner'); const getDevToolsMiddleware = require('./getDevToolsMiddleware'); const loadRawBodyMiddleware = require('./loadRawBodyMiddleware'); const openStackFrameInEditorMiddleware = require('./openStackFrameInEditorMiddleware'); diff --git a/rn-cli.config.js b/rn-cli.config.js new file mode 100644 index 00000000..760f1e87 --- /dev/null +++ b/rn-cli.config.js @@ -0,0 +1,40 @@ +// Copyright 2004-present Facebook. All Rights Reserved. + +/** + * React Native CLI configuration file + */ +'use strict'; + +const blacklist = require('./blacklist.js'); +const path = require('path'); + +module.exports = { + getProjectRoots() { + return this._getRoots(); + }, + + getAssetRoots() { + return this._getRoots(); + }, + + getBlacklistRE() { + return blacklist(''); + }, + + getTransformModulePath() { + return require.resolve('./transformer'); + }, + + _getRoots() { + // match on either path separator + if (__dirname.match(/node_modules[\/\\]react-native[\/\\]packager$/)) { + // packager is running from node_modules of another project + return [path.resolve(__dirname, '../../..')]; + } else if (__dirname.match(/Pods\/React\/packager$/)) { + // packager is running from node_modules of another project + return [path.resolve(__dirname, '../../..')]; + } else { + return [path.resolve(__dirname, '..')]; + } + }, +}; diff --git a/webSocketProxy.js b/webSocketProxy.js index 4f88379b..0562f050 100644 --- a/webSocketProxy.js +++ b/webSocketProxy.js @@ -8,9 +8,9 @@ */ 'use strict'; -var WebSocketServer = require('ws').Server; function attachToServer(server, path) { + var WebSocketServer = require('ws').Server; var wss = new WebSocketServer({ server: server, path: path