-
Notifications
You must be signed in to change notification settings - Fork 1
/
dialog.js
158 lines (155 loc) · 5.15 KB
/
dialog.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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
var inquirer = require('inquirer');
const defaults = require('./defaults');
const dialog = {
overwrite: function () {
return new Promise((resolve, reject) => {
inquirer
.prompt([
{
type: 'confirm',
name: 'overwrite',
message: 'A settings.json File already exists. Do you want to override?',
default: false,
},
])
.then((answers) => {
resolve(answers.overwrite);
});
});
},
askForConfig: function (previousConfig) {
if (!previousConfig) {
// No previous Configuration
return new Promise((resolve, reject) => {
inquirer
.prompt([
{
type: 'input',
name: 'proxyAddress',
message: `What is the proxy domain you want to use? (e.g. proxy.domain.de)`,
validate: function (input) {
var done = this.async();
if (input == null || input === '') {
done('This Field cannot be blank.');
return;
}
const regex = new RegExp(
'^(?!:\\/\\/)([a-zA-Z0-9-_]+\\.)*[a-zA-Z0-9][a-zA-Z0-9-_]+\\.[a-zA-Z]{2,11}?$'
);
if (!input.match(regex)) {
done('This is not a valid Domain.');
}
// Pass the return value in the done callback
done(null, true);
},
},
{
type: 'input',
name: 'proxyPort',
message: `Which port is the proxy server listening on?`,
default: defaults.proxyPort,
validate: function (input) {
var done = this.async();
if (input == null || input === '') {
done('This Field cannot be blank.');
return;
}
const regex = new RegExp('^\\d*$');
if (!input.match(regex)) {
done('This is not a valid Port.');
}
// Pass the return value in the done callback
done(null, true);
},
},
{
type: 'input',
name: 'network',
message: `Which network should be proxied? (Leave blank to proxy all.)`,
default: '',
},
{
type: 'input',
name: 'containerName',
message: `Should the container use a special name?`,
default: defaults.containerName,
},
])
.then((answers) => {
resolve(answersToConfigObject(answers));
});
});
} else {
console.log('Using previous Config as template');
return new Promise((resolve, reject) => {
inquirer
.prompt([
{
type: 'input',
name: 'proxyAddress',
message: `What is the proxy address you want to use?`,
default: previousConfig.proxyAddress,
validate: function (input) {
var done = this.async();
if (input == null || input === '') {
done('This Field cannot be blank.');
return;
}
const regex = new RegExp(
'^(?!:\\/\\/)([a-zA-Z0-9-_]+\\.)*[a-zA-Z0-9][a-zA-Z0-9-_]+\\.[a-zA-Z]{2,11}?$'
);
if (!input.match(regex)) {
done('This is not a valid Domain.');
}
// Pass the return value in the done callback
done(null, true);
},
},
{
type: 'input',
name: 'proxyPort',
message: `Which port is the proxy server listening on?`,
default: previousConfig.proxyPort,
validate: function (input) {
var done = this.async();
if (input == null || input === '') {
done('This Field cannot be blank.');
return;
}
const regex = new RegExp('^\\d*$');
if (!input.match(regex)) {
done('This is not a valid Port.');
}
// Pass the return value in the done callback
done(null, true);
},
},
{
type: 'input',
name: 'network',
message: `Which network should be proxied? (Leave blank to proxy all.)`,
default: previousConfig.network,
},
{
type: 'input',
name: 'containerName',
message: `Should the container use a special name?`,
default: previousConfig.containerName,
},
])
.then((answers) => {
resolve(answersToConfigObject(answers));
});
});
}
},
};
function answersToConfigObject(answers) {
return {
proxyAddress: answers.proxyAddress,
proxyPort: answers.proxyPort,
network: answers.network,
containerName: answers.containerName,
};
}
module.exports = dialog;