Skip to content

Commit

Permalink
Merge pull request #200 from developit/currDest
Browse files Browse the repository at this point in the history
enabling create app in current directory
  • Loading branch information
reznord authored Jul 12, 2017
2 parents 12baec8 + aa03d8c commit 0f235f1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
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 @@ -28,6 +30,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 @@ -80,16 +86,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

0 comments on commit 0f235f1

Please sign in to comment.