-
Notifications
You must be signed in to change notification settings - Fork 0
/
prompts.js
141 lines (138 loc) · 3.27 KB
/
prompts.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/**
* @file 用户交互,获取用户配置信息
*/
const inquirer = require('inquirer');
// 验证npm包名是否满足npm的规则
const validate = require('validate-npm-package-name');
const { isEmail } = require('validator');
async function runPrompts() {
const questions = [
{
type: 'input',
name: 'projectName',
message: 'project name(default is myLib):',
default: 'myLib',
validate: (val) => {
if (!val) {
return 'please input the project name';
}
if (val.match(/\s+/g)) {
// 名字不能是连续的空白字符
return 'Forbidden project name';
}
return true;
},
},
{
type: 'input',
name: 'packageName',
message: 'package name(default is lib):',
default: 'lib',
validate: (val) => {
if (!validate(val).validForNewPackages) {
// 不满足创建新包的命名规则
return 'Forbidden package name!';
}
return true;
},
},
{
type: 'input',
name: 'description',
message: 'package description:',
default: '',
},
{
type: 'list',
name: 'template',
message: 'choose template:',
choices: ['@mxydl2009/lib-template'],
},
{
type: 'list',
name: 'license',
message: 'choose license:',
choices: ['MIT', 'GPL-2.0+', 'LGPL-2.0+', 'BSD-2-Clause', 'Apache-2.0'],
},
{
type: 'input',
name: 'author',
message: 'author email',
default: '',
validate: (val) => {
if (!isEmail(val)) {
return 'Forbidden email address!';
}
return true;
},
},
{
type: 'confirm',
name: 'prettier',
message: 'use prettier?',
default: true,
},
{
type: 'confirm',
name: 'eslint',
message: 'use eslint?',
default: true,
},
{
type: 'checkbox',
name: 'eslintEnv',
message: 'Where does your code run?',
choices: ['browser', 'node'],
when: (answers) => answers.eslint === true,
validate: (val) => {
if (val.length === 0) {
return 'must choose one!';
}
return true;
},
},
{
type: 'confirm',
name: 'eslintWithTypeScript',
message: 'use typescript with eslint?',
default: false,
when: (answers) => answers.eslint === true,
},
{
type: 'confirm',
name: 'husky',
message: 'use husky?',
default: true,
},
{
type: 'confirm',
name: 'commitizen',
message: 'use commitizen? Attention: conflict with commitlint!',
default: false,
},
{
type: 'confirm',
name: 'commitlint',
message: 'use commitlint?',
default: true,
when: (answers) => answers.commitizen === false,
},
// {
// type: "list",
// name: "ci",
// message: "use ci:",
// choices: ["github", "circleci", "travis", "none"],
// filter: (value) => {
// return {
// github: "github",
// circleci: "circleci",
// travis: "travis",
// none: null,
// }[value];
// },
// },
];
const answers = await inquirer.prompt(questions);
return answers;
}
module.exports = runPrompts;