mirror of
https://github.com/status-im/react-native.git
synced 2025-02-09 16:14:47 +00:00
Merge pull request #1293 from skv-headless/confirm-init-overwrite
Ask confirmation on init command
This commit is contained in:
commit
f2b76566f3
30
react-native-cli/index.js
vendored
30
react-native-cli/index.js
vendored
@ -7,6 +7,7 @@
|
|||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
var path = require('path');
|
var path = require('path');
|
||||||
var spawn = require('child_process').spawn;
|
var spawn = require('child_process').spawn;
|
||||||
|
var prompt = require("prompt");
|
||||||
|
|
||||||
var CLI_MODULE_PATH = function() {
|
var CLI_MODULE_PATH = function() {
|
||||||
return path.resolve(
|
return path.resolve(
|
||||||
@ -69,6 +70,35 @@ function validatePackageName(name) {
|
|||||||
function init(name) {
|
function init(name) {
|
||||||
validatePackageName(name);
|
validatePackageName(name);
|
||||||
|
|
||||||
|
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 root = path.resolve(name);
|
||||||
var projectName = path.basename(root);
|
var projectName = path.basename(root);
|
||||||
|
|
||||||
|
@ -5,5 +5,8 @@
|
|||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"bin": {
|
"bin": {
|
||||||
"react-native": "index.js"
|
"react-native": "index.js"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"prompt": "^0.2.14"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user