Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enabling create app in current directory #200

Merged
merged 6 commits into from
Jul 12, 2017
Merged
Show file tree
Hide file tree
Changes from 2 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
31 changes: 28 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,35 @@ export default asyncCommand({
}
catch (err) {}

if (exists) {
throw Error('Directory already exists.');
if (exists && argv.force) {
const question = {
type: 'confirm',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whitespace <3

name: 'enableForce',
message: `You are using '--force'. Do you wish to continue?`,
default: true,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

default should be false

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, will change it once I reach home.

Sent from my OnePlus ONEPLUS A3003 using FastHub

};

let forceInit = await inquirer.prompt(question);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hint: let { enableForce } = , also enableForce:
enableForce


if (forceInit.enableForce) {
process.stdout.write('Initializing project in the current directory...\n');
} else {
throw Error('Cannot initialize the project in the current directory');
}
}

if (exists && !argv.force) {
throw Error('Cannot intialize in the current directory, please specify a different destination.');
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we write messages using chalk?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh sure, not a problem at all. Red color?

Sent from my OnePlus ONEPLUS A3003 using FastHub

}

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