react-native-cli
Advanced tools
Comparing version 0.1.10 to 0.2.0
67
index.js
@@ -45,2 +45,15 @@ #!/usr/bin/env node | ||
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)); | ||
@@ -73,7 +86,8 @@ var CLI_MODULE_PATH = function() { | ||
// 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( | ||
@@ -85,8 +99,5 @@ 'You did not pass any commands, did you mean to run `react-native init`?' | ||
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( | ||
@@ -96,2 +107,4 @@ 'Usage: react-native init <ProjectName> [--verbose]' | ||
process.exit(1); | ||
} else { | ||
init(commands[1], argv.verbose, argv.version); | ||
} | ||
@@ -103,3 +116,3 @@ break; | ||
'Did you mean to run this inside a react-native project?', | ||
args[0] | ||
commands[0] | ||
); | ||
@@ -131,13 +144,13 @@ process.exit(1); | ||
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(); | ||
@@ -155,3 +168,3 @@ | ||
if (result.yesno[0] === 'y') { | ||
createProject(name, verbose); | ||
createProject(name, verbose, rnPackage); | ||
} else { | ||
@@ -164,3 +177,3 @@ console.log('Project initialization canceled'); | ||
function createProject(name, verbose) { | ||
function createProject(name, verbose, rnPackage) { | ||
var root = path.resolve(name); | ||
@@ -192,10 +205,22 @@ var projectName = path.basename(root); | ||
if (verbose) { | ||
runVerbose(root, projectName); | ||
runVerbose(root, projectName, rnPackage); | ||
} else { | ||
run(root, projectName); | ||
run(root, projectName, rnPackage); | ||
} | ||
} | ||
function run(root, projectName) { | ||
exec('npm install --save react-native', function(e, stdout, stderr) { | ||
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, rnPackage) { | ||
exec('npm install --save ' + getInstallPackage(rnPackage), function(e, stdout, stderr) { | ||
if (e) { | ||
@@ -215,4 +240,4 @@ console.log(stdout); | ||
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) { | ||
@@ -246,3 +271,3 @@ if (code !== 0) { | ||
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); | ||
@@ -249,0 +274,0 @@ try { |
{ | ||
"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", | ||
@@ -22,2 +22,3 @@ "main": "index.js", | ||
"chalk": "^1.1.1", | ||
"minimist": "^1.2.0", | ||
"prompt": "^0.2.14", | ||
@@ -24,0 +25,0 @@ "semver": "^5.0.3" |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
12502
239
4
3
+ Addedminimist@^1.2.0