-
-
Notifications
You must be signed in to change notification settings - Fork 375
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
Changes from 4 commits
1ab27c7
dd34115
61be8c4
11482b4
fa9b452
aa03d8c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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'; | ||
|
@@ -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: [ | ||
|
@@ -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 forceInit = await inquirer.prompt(question); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
if (forceInit.enableForce) { | ||
process.stdout.write('Initializing project in the current directory...\n'); | ||
} else { | ||
process.stdout.write(`${chalk.red('Error:')} Cannot initialize in the current directory`); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be |
||
process.exit(1); | ||
} | ||
} | ||
|
||
if (exists && !argv.force) { | ||
process.stdout.write(`${chalk.red('Error:')} Cannot initialize in the current directory, please specify a different destination`); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be |
||
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), | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
whitespace <3