-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.js
executable file
路81 lines (76 loc) 路 1.93 KB
/
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#! /usr/bin/env node
'use strict';
var inquirer = require('inquirer');
var exec = require('child_process').exec;
const chalk = require('chalk');
const log = console.log;
// console.log();
log(chalk.gray('Hello 馃憢馃徎'));
var questions = [
{
type: 'input',
name: 'projName',
message: 'Name of the project?',
},
{
type: 'input',
name: 'projDir',
message: 'Where do you want me to install?',
},
{
type: 'confirm',
name: 'uiLibraries',
message: 'Do you want to install any ui libraries?',
default: false
},
{
type: 'list',
name: 'size',
message: 'Which one do you need?',
choices: ['element-react', 'antd'],
when: function(answers) {
return answers.uiLibraries !== false;
}
},
{
type: 'confirm',
name: 'axios',
message: 'Want axios to be installed?',
default: false
},
{
type: 'confirm',
name: 'reactRouter',
message: 'Want react-router to be installed?',
default: false
},
{
type: 'confirm',
name: 'lodash',
message: 'Want lodash to be installed?',
default: false
},
{
type: 'confirm',
name: 'reactBootstrapTable',
message: 'Want react-bootstrap-table to be installed?',
default: false
},
];
inquirer.prompt(questions).then(answers => {
let arr = ['npm install', 'react', 'react-dom']
if (answers.uiLibraries) arr.push(answers.size);
if (answers.axios) arr.push('axios');
if (answers.reactRouter) arr.push('react-router');
if (answers.lodash) arr.push('lodash');
if (answers.reactBootstrapTable) arr.push('react-bootstrap-table');
let dependencies = arr.join(' ')
log(chalk.gray(`Creating project folder and installing dependencies`));
exec(`cd ${answers.projDir} && mkdir ${answers.projName} && cd ${answers.projName} && npm init --y && ${dependencies}`, (err, stdout, stderr) => {
if (err) {
console.error(err);
return;
}
log(chalk.green("All done 鈿★笍"));
});
});