Skip to content

Commit

Permalink
Allow react-native init <version> + removed sinopia from being requir…
Browse files Browse the repository at this point in the history
…ed for e2e testing

Reviewed By: mkonicek, frantic

Differential Revision: D3087524

fb-gh-sync-id: 048e23b55916a6be17fa9fabb6e41b0b2f3f7a16
shipit-source-id: 048e23b55916a6be17fa9fabb6e41b0b2f3f7a16
  • Loading branch information
bestander authored and Facebook Github Bot 9 committed Mar 24, 2016
1 parent ad41a0b commit 993835c
Show file tree
Hide file tree
Showing 10 changed files with 81 additions and 144 deletions.
6 changes: 1 addition & 5 deletions Releases.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ Release schedule:
- 0.24.0 - Apr 18
- ...

## One time setup

Set up Sinopia: https://github.com/facebook/react-native/tree/master/react-native-cli

#### Check that everything works

Make absolutely sure a basic iOS and Android workflow works on the commit you are going to use for release.
Expand Down Expand Up @@ -79,7 +75,7 @@ git pull origin 0.version_you_are_releasing-stable # e.g. git pull origin 0.22-
# Cherry-pick those commits
git cherry-pick commitHash1
# test everything again using sinopia
# test everything again
./scripts/test-manual-e2e.sh
# Check that you can Reload JS and the Chrome debugger works
Expand Down
3 changes: 0 additions & 3 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ dependencies:
- npm install
# for eslint bot
- npm install [email protected]
# for deployment scripts
- npm install [email protected]
- cd website && npm install
cache_directories:
- "ReactAndroid/build/downloads"
Expand Down Expand Up @@ -78,7 +76,6 @@ test:
- ./gradlew :ReactAndroid:installDebugAndroidTest
- source scripts/circle-ci-android-setup.sh && retry3 ./scripts/run-android-instrumentation-tests.sh com.facebook.react.tests.gradle

# Publish to Sinopia, create a new app using 'react-native init' and check the packager starts
- ./scripts/e2e-test.sh --packager

# testing docs generation is not broken
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@
"flow-bin": "0.22.0",
"jest-cli": "0.9.2",
"portfinder": "0.4.0",
"react": "^0.14.5"
"react": "^0.14.5",
"shelljs": "0.6.0"
}
}
67 changes: 46 additions & 21 deletions react-native-cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,19 @@ var spawn = require('child_process').spawn;
var chalk = require('chalk');
var prompt = require('prompt');
var semver = require('semver');
/**
* Used arguments:
* -v --version - to print current version of react-native-cli and react-native dependency
* if you are in a RN app folder
* init - to create a new project and npm install it
* --verbose - to print logs while init
* --version <alternative react-native package> - override default (https://registry.npmjs.org/react-native@latest),
* package to install, examples:
* - "0.22.0-rc1" - A new app will be created using a specific version of React Native from npm repo
* - "https://registry.npmjs.org/react-native/-/react-native-0.20.0.tgz" - a .tgz archive from any npm repo
* - "/Users/home/react-native/react-native-0.22.0.tgz" - for package prepared with `npm pack`, useful for e2e tests
*/
var argv = require('minimist')(process.argv.slice(2));

var CLI_MODULE_PATH = function() {
return path.resolve(
Expand Down Expand Up @@ -69,34 +82,34 @@ if (fs.existsSync(cliPath)) {
cli = require(cliPath);
}

// minimist api
var commands = argv._;
if (cli) {
cli.run();
} else {
var args = process.argv.slice(2);
if (args.length === 0) {
if (commands.length === 0) {
console.error(
'You did not pass any commands, did you mean to run `react-native init`?'
);
process.exit(1);
}

switch (args[0]) {
switch (commands[0]) {
case 'init':
if (args[1]) {
var verbose = process.argv.indexOf('--verbose') >= 0;
init(args[1], verbose);
} else {
if (!commands[1]) {
console.error(
'Usage: react-native init <ProjectName> [--verbose]'
);
process.exit(1);
} else {
init(commands[1], argv.verbose, argv.version);
}
break;
default:
console.error(
'Command `%s` unrecognized. ' +
'Did you mean to run this inside a react-native project?',
args[0]
commands[0]
);
process.exit(1);
break;
Expand All @@ -123,17 +136,17 @@ function validatePackageName(name) {
}
}

function init(name, verbose) {
function init(name, verbose, rnPackage) {
validatePackageName(name);

if (fs.existsSync(name)) {
createAfterConfirmation(name, verbose);
createAfterConfirmation(name, verbose, rnPackage);
} else {
createProject(name, verbose);
createProject(name, verbose, rnPackage);
}
}

function createAfterConfirmation(name, verbose) {
function createAfterConfirmation(name, verbose, rnPackage) {
prompt.start();

var property = {
Expand All @@ -146,15 +159,15 @@ function createAfterConfirmation(name, verbose) {

prompt.get(property, function (err, result) {
if (result.yesno[0] === 'y') {
createProject(name, verbose);
createProject(name, verbose, rnPackage);
} else {
console.log('Project initialization canceled');
process.exit();
}
});
}

function createProject(name, verbose) {
function createProject(name, verbose, rnPackage) {
var root = path.resolve(name);
var projectName = path.basename(root);

Expand All @@ -181,14 +194,26 @@ function createProject(name, verbose) {
console.log('Installing react-native package from npm...');

if (verbose) {
runVerbose(root, projectName);
runVerbose(root, projectName, rnPackage);
} else {
run(root, projectName);
run(root, projectName, rnPackage);
}
}

function getInstallPackage(rnPackage) {
var packageToInstall = 'react-native';
var valideSemver = semver.valid(rnPackage);
if (valideSemver) {
packageToInstall += '@' + valideSemver;
} else if (rnPackage) {
// for tar.gz or alternative paths
packageToInstall = rnPackage;
}
return packageToInstall;
}

function run(root, projectName) {
exec('npm install --save react-native', function(e, stdout, stderr) {
function run(root, projectName, rnPackage) {
exec('npm install --save ' + getInstallPackage(rnPackage), function(e, stdout, stderr) {
if (e) {
console.log(stdout);
console.error(stderr);
Expand All @@ -203,8 +228,8 @@ function run(root, projectName) {
});
}

function runVerbose(root, projectName) {
var proc = spawn('npm', ['install', '--verbose', '--save', 'react-native'], {stdio: 'inherit'});
function runVerbose(root, projectName, rnPackage) {
var proc = spawn('npm', ['install', '--verbose', '--save', getInstallPackage(rnPackage)], {stdio: 'inherit'});
proc.on('close', function (code) {
if (code !== 0) {
console.error('`npm install --save react-native` failed');
Expand Down Expand Up @@ -233,7 +258,7 @@ function checkNodeVersion() {
}

function checkForVersionArgument() {
if (process.argv.indexOf('-v') >= 0 || process.argv.indexOf('--version') >= 0) {
if (argv._.length === 0 && (argv.v || argv.version)) {
console.log('react-native-cli: ' + require('./package.json').version);
try {
console.log('react-native: ' + require(REACT_NATIVE_PACKAGE_JSON_PATH()).version);
Expand Down
5 changes: 3 additions & 2 deletions react-native-cli/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "react-native-cli",
"version": "0.1.10",
"license" : "BSD-3-Clause",
"version": "0.2.0",
"license": "BSD-3-Clause",
"description": "The React Native CLI tools",
"main": "index.js",
"engines": {
Expand All @@ -19,6 +19,7 @@
},
"dependencies": {
"chalk": "^1.1.1",
"minimist": "^1.2.0",
"prompt": "^0.2.14",
"semver": "^5.0.3"
}
Expand Down
5 changes: 0 additions & 5 deletions scripts/e2e-npmrc

This file was deleted.

23 changes: 0 additions & 23 deletions scripts/e2e-sinopia-lego.config.yml

This file was deleted.

23 changes: 0 additions & 23 deletions scripts/e2e-sinopia.config.yml

This file was deleted.

37 changes: 11 additions & 26 deletions scripts/e2e-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,46 +43,31 @@ function cleanup {

rm $MARKER_IOS
rm $MARKER_ANDROID
[ $SINOPIA_PID ] && kill -9 $SINOPIA_PID
[ $SERVER_PID ] && kill -9 $SERVER_PID
[ -f ~/.npmrc.bak ] && mv ~/.npmrc.bak ~/.npmrc
}
trap cleanup EXIT

cd $TEMP

# sinopia is npm registry proxy, it is used to make npm
# think react-native and react-native-cli are actually
# published on npm
# Temporarily installing sinopia from a github fork
# TODO t10060166 use npm repo when bug is fixed
which sinopia || npm install -g git://github.com/bestander/sinopia.git#68707efbab90569d5f52193138936f9281cc410c
# pack react-native into a .tgz file
npm pack
PACKAGE=$(pwd)/react-native-*.tgz

# but in order to make npm use sinopia we temporarily
# replace its config file
[ -f ~/.npmrc ] && cp ~/.npmrc ~/.npmrc.bak
cp $SCRIPTS/e2e-npmrc ~/.npmrc
# get react-native-cli dependencies
cd react-native-cli
npm pack
CLI_PACKAGE=$(pwd)/react-native-cli-*.tgz

sinopia --config $SCRIPTS/e2e-sinopia.config.yml &
SINOPIA_PID=$!

# Make sure to remove old version of react-native in
# case it was cached
npm cache clear
npm unpublish react-native --force
npm unpublish react-native-cli --force
npm publish $ROOT
npm publish $ROOT/react-native-cli
cd $TEMP

npm install -g react-native-cli
react-native init EndToEndTest
npm install -g $CLI_PACKAGE
react-native init EndToEndTest --version $PACKAGE
cd EndToEndTest

case $1 in
"--packager"*)
echo "Running a basic packager test"
# Check the packager produces a bundle (doesn't throw an error)
react-native bundle --platform android --dev true --entry-file index.android.js --bundle-output android-bundle.js
# TODO do flow check
;;
"--ios"*)
echo "Running an iOS app"
Expand Down
Loading

0 comments on commit 993835c

Please sign in to comment.