-
-
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 2 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,35 @@ 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: true, | ||
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. default should be false 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. Okay, will change it once I reach home. Sent from my OnePlus ONEPLUS A3003 using FastHub |
||
}; | ||
|
||
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 { | ||
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.'); | ||
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. can we write messages using chalk? 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. 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), | ||
|
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