react-native-cli
Advanced tools
Comparing version 0.1.4 to 0.1.5
72
index.js
@@ -7,6 +7,9 @@ #!/usr/bin/env node | ||
'use strict'; | ||
var fs = require('fs'); | ||
var path = require('path'); | ||
var exec = require('child_process').exec; | ||
var spawn = require('child_process').spawn; | ||
var prompt = require("prompt"); | ||
var prompt = require('prompt'); | ||
@@ -18,10 +21,13 @@ var CLI_MODULE_PATH = function() { | ||
'react-native', | ||
'cli' | ||
'cli.js' | ||
); | ||
}; | ||
checkForVersionArgument(); | ||
var cli; | ||
try { | ||
cli = require(CLI_MODULE_PATH()); | ||
} catch(e) {} | ||
var cliPath = CLI_MODULE_PATH(); | ||
if (fs.existsSync(cliPath)) { | ||
cli = require(cliPath); | ||
} | ||
@@ -42,6 +48,7 @@ if (cli) { | ||
if (args[1]) { | ||
init(args[1]); | ||
var verbose = process.argv.indexOf('--verbose') >= 0; | ||
init(args[1], verbose); | ||
} else { | ||
console.error( | ||
'Usage: react-native init <ProjectName>' | ||
'Usage: react-native init <ProjectName> [--verbose]' | ||
); | ||
@@ -82,13 +89,13 @@ process.exit(1); | ||
function init(name) { | ||
function init(name, verbose) { | ||
validatePackageName(name); | ||
if (fs.existsSync(name)) { | ||
createAfterConfirmation(name) | ||
createAfterConfirmation(name, verbose); | ||
} else { | ||
createProject(name); | ||
createProject(name, verbose); | ||
} | ||
} | ||
function createAfterConfirmation(name) { | ||
function createAfterConfirmation(name, verbose) { | ||
prompt.start(); | ||
@@ -106,3 +113,3 @@ | ||
if (result.yesno[0] === 'y') { | ||
createProject(name); | ||
createProject(name, verbose); | ||
} else { | ||
@@ -115,3 +122,3 @@ console.log('Project initialization canceled'); | ||
function createProject(name) { | ||
function createProject(name, verbose) { | ||
var root = path.resolve(name); | ||
@@ -140,4 +147,16 @@ var projectName = path.basename(root); | ||
run('npm install --save react-native', function(e) { | ||
console.log('Installing react-native package from npm...'); | ||
if (verbose) { | ||
runVerbose(root, projectName); | ||
} else { | ||
run(root, projectName); | ||
} | ||
} | ||
function run(root, projectName) { | ||
exec('npm install --save react-native', function(e, stdout, stderr) { | ||
if (e) { | ||
console.log(stdout); | ||
console.error(stderr); | ||
console.error('`npm install --save react-native` failed'); | ||
@@ -152,14 +171,21 @@ process.exit(1); | ||
function run(command, cb) { | ||
var parts = command.split(/\s+/); | ||
var cmd = parts[0]; | ||
var args = parts.slice(1); | ||
var proc = spawn(cmd, args, {stdio: 'inherit'}); | ||
proc.on('close', function(code) { | ||
function runVerbose(root, projectName) { | ||
var proc = spawn('npm', ['install', '--verbose', '--save', 'react-native'], {stdio: 'inherit'}); | ||
proc.on('close', function (code) { | ||
if (code !== 0) { | ||
cb(new Error('Command exited with a non-zero status')); | ||
} else { | ||
cb(null); | ||
console.error('`npm install --save react-native` failed'); | ||
return; | ||
} | ||
cli = require(CLI_MODULE_PATH()); | ||
cli.init(root, projectName); | ||
}); | ||
} | ||
function checkForVersionArgument() { | ||
if (process.argv.indexOf('-v') >= 0 || process.argv.indexOf('--version') >= 0) { | ||
var pjson = require('./package.json'); | ||
console.log(pjson.version); | ||
process.exit(); | ||
} | ||
} |
{ | ||
"name": "react-native-cli", | ||
"version": "0.1.4", | ||
"version": "0.1.5", | ||
"description": "The ReactNative cli tools", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "mocha" | ||
}, | ||
"bin": { | ||
@@ -7,0 +10,0 @@ "react-native": "index.js" |
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
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
7993
4
157
0
9
5
3