-
Notifications
You must be signed in to change notification settings - Fork 1
/
cli.js
47 lines (38 loc) · 985 Bytes
/
cli.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env node
'use strict';
const project = require('commander');
const inquirer = require('inquirer');
const app = require('./app');
const questions = require('./app/questions');
project
.version('0.0.0')
.option('-n, --new <name>', 'create a new project')
.option('-i, --init', 'init the project')
.parse(process.argv);
if (project.new) {
const name = project.new;
app
.checkNameIsUnique(name)
.then(isUnique => {
if (isUnique) {
app.new(name);
process.exit();
}
return askWillReplaceProject();
})
.then(answer => {
if (answer.replace) {
return app.new(name);
}
throw new Error(`Couldn't create the project path. Please, try again.`);
})
.catch(err => console.log(err.message));
}
if (project.init) {
inquirer
.prompt(questions.init)
.then(answers => app.init(answers));
}
function askWillReplaceProject() {
return inquirer.prompt(questions.replaceProject);
}