Skip to content

Commit 0f235f1

Browse files
authored
Merge pull request #200 from developit/currDest
enabling create app in current directory
2 parents 12baec8 + aa03d8c commit 0f235f1

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@
126126
"get-port": "^3.1.0",
127127
"html-webpack-exclude-assets-plugin": "0.0.5",
128128
"html-webpack-plugin": "^2.28.0",
129+
"inquirer": "^3.2.0",
129130
"ip": "^1.1.5",
130131
"isomorphic-unfetch": "^2.0.0",
131132
"json-loader": "^0.5.4",

src/commands/create.js

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import fs from 'fs.promised';
33
import copy from 'recursive-copy';
44
import mkdirp from 'mkdirp';
55
import ora from 'ora';
6+
import chalk from 'chalk';
7+
import inquirer from 'inquirer';
68
import promisify from 'es6-promisify';
79
import spawn from 'cross-spawn-promise';
810
import path from 'path';
@@ -28,6 +30,10 @@ export default asyncCommand({
2830
description: 'Directory to create the app within',
2931
defaultDescription: '<name>'
3032
},
33+
force: {
34+
description: 'Force option to create the directory for the new app',
35+
default: false
36+
},
3137
type: {
3238
description: 'A project template to start from',
3339
choices: [
@@ -80,16 +86,37 @@ export default asyncCommand({
8086
}
8187
catch (err) {}
8288

83-
if (exists) {
84-
throw Error('Directory already exists.');
89+
if (exists && argv.force) {
90+
const question = {
91+
type: 'confirm',
92+
name: 'enableForce',
93+
message: `You are using '--force'. Do you wish to continue?`,
94+
default: false,
95+
};
96+
97+
let { enableForce } = await inquirer.prompt(question);
98+
99+
if (enableForce) {
100+
process.stdout.write('Initializing project in the current directory...\n');
101+
} else {
102+
process.stderr.write(chalk.red('Error: Cannot initialize in the current directory\n'));
103+
process.exit(1);
104+
}
105+
}
106+
107+
if (exists && !argv.force) {
108+
process.stderr.write(chalk.red('Error: Cannot initialize in the current directory, please specify a different destination\n'));
109+
process.exit(1);
85110
}
86111

87112
let spinner = ora({
88113
text: 'Creating project',
89114
color: 'magenta'
90115
}).start();
91116

92-
await promisify(mkdirp)(target);
117+
if (!exists) {
118+
await promisify(mkdirp)(target);
119+
}
93120

94121
await copy(
95122
path.resolve(__dirname, '../..', template),

0 commit comments

Comments
 (0)