react-native-cli
Advanced tools
Comparing version 0.1.5 to 0.1.7
62
index.js
#!/usr/bin/env node | ||
/** | ||
* Copyright 2004-present Facebook. All Rights Reserved. | ||
* 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. | ||
*/ | ||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
// /!\ DO NOT MODIFY THIS FILE /!\ | ||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
// | ||
// react-native-cli is installed globally on people's computers. This means | ||
// that it is extremely difficult to have them upgrade the version and | ||
// because there's only one global version installed, it is very prone to | ||
// breaking changes. | ||
// | ||
// The only job of react-native-cli is to init the repository and then | ||
// forward all the commands to the local version of react-native. | ||
// | ||
// If you need to add a new command, please add it to local-cli/. | ||
// | ||
// The only reason to modify this file is to add more warnings and | ||
// troubleshooting information for the `react-native init` command. | ||
// | ||
// Do not make breaking changes! We absolutely don't want to have to | ||
// tell people to update their global version of react-native-cli. | ||
// | ||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
// /!\ DO NOT MODIFY THIS FILE /!\ | ||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
'use strict'; | ||
@@ -13,3 +42,5 @@ | ||
var spawn = require('child_process').spawn; | ||
var chalk = require('chalk'); | ||
var prompt = require('prompt'); | ||
var semver = require('semver'); | ||
@@ -25,2 +56,11 @@ var CLI_MODULE_PATH = function() { | ||
var REACT_NATIVE_PACKAGE_JSON_PATH = function() { | ||
return path.resolve( | ||
process.cwd(), | ||
'node_modules', | ||
'react-native', | ||
'package.json' | ||
); | ||
}; | ||
checkForVersionArgument(); | ||
@@ -137,3 +177,3 @@ | ||
scripts: { | ||
start: 'node_modules/react-native/packager/packager.sh' | ||
start: 'react-native start' | ||
} | ||
@@ -162,2 +202,4 @@ }; | ||
checkNodeVersion(); | ||
var cli = require(CLI_MODULE_PATH()); | ||
@@ -181,2 +223,18 @@ cli.init(root, projectName); | ||
function checkNodeVersion() { | ||
var packageJson = require(REACT_NATIVE_PACKAGE_JSON_PATH()); | ||
if (!packageJson.engines || !packageJson.engines.node) { | ||
return; | ||
} | ||
if (!semver.satisfies(process.version, packageJson.engines.node)) { | ||
console.error(chalk.red( | ||
'You are currently running Node %s but React Native requires %s. ' + | ||
'Please use a supported version of Node.\n' + | ||
'See https://facebook.github.io/react-native/docs/getting-started.html' | ||
), | ||
process.version, | ||
packageJson.engines.node); | ||
} | ||
} | ||
function checkForVersionArgument() { | ||
@@ -183,0 +241,0 @@ if (process.argv.indexOf('-v') >= 0 || process.argv.indexOf('--version') >= 0) { |
{ | ||
"name": "react-native-cli", | ||
"version": "0.1.5", | ||
"description": "The ReactNative cli tools", | ||
"version": "0.1.7", | ||
"description": "The React Native CLI tools", | ||
"main": "index.js", | ||
"engines": { | ||
"node": ">=4" | ||
}, | ||
"scripts": { | ||
@@ -13,4 +16,6 @@ "test": "mocha" | ||
"dependencies": { | ||
"prompt": "^0.2.14" | ||
"chalk": "^1.1.1", | ||
"prompt": "^0.2.14", | ||
"semver": "^5.0.3" | ||
} | ||
} |
112
README.md
@@ -1,8 +0,108 @@ | ||
Use react-native-cli to initialize a working starter React Native app using the latest react-native version in npm. This package should be installed globally. | ||
## Running CLI with local modifications | ||
Usage: | ||
React Native is distributed as two npm packages, `react-native-cli` and `react-native`. The first one is a lightweight package that should be installed globally (`npm install -g react-native-cli`), while the second one contains the actual React Native framework code and is installed locally into your project when you run `react-native init`. | ||
``` | ||
% npm install -g react-native-cli | ||
% react-native init MyApplication | ||
``` | ||
Because `react-native init` calls `npm install react-native`, simply linking your local github clone into npm is not enough to test local changes. | ||
### Introducing Sinopia | ||
[Sinopia] is an npm registry that runs on your local machine and allows you to publish packages to it. Everything else is proxied from `npmjs.com`. We'll set up sinopia for React Native CLI development. First, install it with: | ||
$ npm install -g sinopia | ||
Then, open `~/.config/sinopia/config.yaml` and configure it like this (note the `max_body_size`): | ||
storage: ./storage | ||
auth: | ||
htpasswd: | ||
file: ./htpasswd | ||
uplinks: | ||
npmjs: | ||
url: https://registry.npmjs.org/ | ||
packages: | ||
'react-native': | ||
allow_access: $all | ||
allow_publish: $all | ||
'react-native-cli': | ||
allow_access: $all | ||
allow_publish: $all | ||
'*': | ||
allow_access: $all | ||
proxy: npmjs | ||
logs: | ||
- {type: stdout, format: pretty, level: http} | ||
max_body_size: '50mb' | ||
Now you can run sinopia by simply doing: | ||
$ sinopia | ||
### Publishing to sinopia | ||
Now we need to publish the two React Native packages to our local registry. To do this, we configure npm to use the new registry, unpublish any existing packages and then publish the new ones: | ||
react-native$ npm set registry http://localhost:4873/ | ||
react-native$ npm adduser --registry http://localhost:4873/ | ||
# Check that it worked: | ||
react-native$ npm config list | ||
react-native$ npm unpublish --force | ||
react-native$ npm publish | ||
react-native$ cd react-native-cli/ | ||
react-native-cli$ npm unpublish --force | ||
react-native-cli$ npm publish | ||
### Running the local CLI | ||
Now that the packages are installed in sinopia, you can install the new `react-native-cli` package globally and when you use `react-native init`, it will install the new `react-native` package as well: | ||
$ npm uninstall -g react-native-cli | ||
$ npm install -g react-native-cli | ||
$ react-native init AwesomeApp | ||
## Testing changes | ||
Most of the CLI code is covered by jest tests, which you can run with: | ||
$ npm test | ||
Project generation is also covered by e2e tests, which you can run with: | ||
$ ./scripts/e2e-test.sh | ||
These tests actually create a very similar setup to what is described above (using sinopia) and they also run iOS-specific tests, so you will need to run this on OSX and have [xctool] installed. | ||
Both of these types of tests also run on Travis both continuously and on pull requests. | ||
[sinopia]: https://www.npmjs.com/package/sinopia | ||
[xctool]: https://github.com/facebook/xctool | ||
## Clean up | ||
To unset the npm registry, do: | ||
$ npm set registry https://registry.npmjs.org/ | ||
# Check that it worked: | ||
$ npm config list | ||
## Troubleshooting | ||
##### Sinopia crashes with "Module version mismatch" | ||
This usually happens when you install a package using one version of Node and then change to a different version. This can happen when you update Node, or switch to a different version with nvm. Do: | ||
$ npm uninstall -g sinopia | ||
$ npm install -g sinopia | ||
After upgrading to Node 4 you might also need to reinstall npm. What worked for me was: | ||
$ npm uninstall -g npm | ||
$ nvm install npm | ||
See the [nvm guide](https://github.com/creationix/nvm#usage) for more info. |
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
10022
211
109
2
3
3
6
+ Addedchalk@^1.1.1
+ Addedsemver@^5.0.3
+ Addedansi-regex@2.1.1(transitive)
+ Addedansi-styles@2.2.1(transitive)
+ Addedchalk@1.1.3(transitive)
+ Addedescape-string-regexp@1.0.5(transitive)
+ Addedhas-ansi@2.0.0(transitive)
+ Addedsemver@5.7.2(transitive)
+ Addedstrip-ansi@3.0.1(transitive)
+ Addedsupports-color@2.0.0(transitive)