diff --git a/react-native-cli/index.js b/react-native-cli/index.js index 7bd237e02..02a1cfdd2 100755 --- a/react-native-cli/index.js +++ b/react-native-cli/index.js @@ -7,6 +7,7 @@ var fs = require('fs'); var path = require('path'); var spawn = require('child_process').spawn; +var prompt = require("prompt"); var CLI_MODULE_PATH = function() { return path.resolve( @@ -65,6 +66,35 @@ function init(name) { process.exit(1); } + if (fs.existsSync(name)) { + createAfterConfirmation(name) + } else { + createProject(name); + } +} + +function createAfterConfirmation(name) { + prompt.start(); + + var property = { + name: 'yesno', + message: 'Directory ' + name + ' already exist. Continue?', + validator: /y[es]*|n[o]?/, + warning: 'Must respond yes or no', + default: 'no' + }; + + prompt.get(property, function (err, result) { + if (result.yesno[0] === 'y') { + createProject(name); + } else { + console.log('Project initialization canceled'); + process.exit(); + } + }); +} + +function createProject(name) { var root = path.resolve(name); var projectName = path.basename(root); diff --git a/react-native-cli/package.json b/react-native-cli/package.json index 8644e7eae..90450c3ea 100644 --- a/react-native-cli/package.json +++ b/react-native-cli/package.json @@ -5,5 +5,8 @@ "main": "index.js", "bin": { "react-native": "index.js" + }, + "dependencies": { + "prompt": "^0.2.14" } }