Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@
"get-port": "^3.1.0",
"html-webpack-exclude-assets-plugin": "0.0.5",
"html-webpack-plugin": "^2.28.0",
"inquirer": "^3.2.0",
"ip": "^1.1.5",
"isomorphic-unfetch": "^2.0.0",
"json-loader": "^0.5.4",
Expand Down
33 changes: 30 additions & 3 deletions src/commands/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import fs from 'fs.promised';
import copy from 'recursive-copy';
import mkdirp from 'mkdirp';
import ora from 'ora';
import chalk from 'chalk';
import inquirer from 'inquirer';
import promisify from 'es6-promisify';
import spawn from 'cross-spawn-promise';
import path from 'path';
Expand All @@ -29,6 +31,10 @@ export default asyncCommand({
description: 'Directory to create the app within',
defaultDescription: '<name>'
},
force: {
description: 'Force option to create the directory for the new app',
default: false
},
type: {
description: 'A project template to start from',
choices: [
Expand Down Expand Up @@ -81,16 +87,37 @@ export default asyncCommand({
}
catch (err) {}

if (exists) {
throw Error('Directory already exists.');
if (exists && argv.force) {
const question = {
type: 'confirm',
name: 'enableForce',
message: `You are using '--force'. Do you wish to continue?`,
default: false,
};

let { enableForce } = await inquirer.prompt(question);

if (enableForce) {
process.stdout.write('Initializing project in the current directory...\n');
} else {
process.stderr.write(chalk.red('Error: Cannot initialize in the current directory\n'));
process.exit(1);
}
}

if (exists && !argv.force) {
process.stderr.write(chalk.red('Error: Cannot initialize in the current directory, please specify a different destination\n'));
process.exit(1);
}

let spinner = ora({
text: 'Creating project',
color: 'magenta'
}).start();

await promisify(mkdirp)(target);
if (!exists) {
await promisify(mkdirp)(target);
}

await copy(
path.resolve(__dirname, '../..', template),
Expand Down