forked from Watson-Personal-Assistant/SkillBoilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup-wizard.js
executable file
·227 lines (217 loc) · 6.74 KB
/
setup-wizard.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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
const inquirer = require("inquirer");
const fs = require('fs');
const yaml = require('yamljs');
const questions = [
{
type: 'input',
name: 'skillName',
message: 'Please enter the name of your skill:\t',
default: 'i.e. small-talk'
},
{
type: 'input',
name: 'author',
message: 'Please enter the author\'s name\t',
default: 'Your name'
},
{
type: 'confirm',
name: 'pushScript',
message: 'Do you want to setup your Bluemix deployment credentials?'
},
{
when: function(response) {
return response.pushScript;
},
type: 'input',
name: 'hostName',
message: 'Please enter your host name\t',
default: 'If the address is small-talk.mybluemix.net it would be small-talk'
},
{
when: function(response) {
return response.pushScript;
},
type: 'input',
name: 'domainName',
message: 'Please enter your domain name\t',
default: 'If the address is small-talk.mybluemix.net it would be mybluemix.net'
},
{
when: function(response) {
return response.pushScript;
},
type: 'input',
name: 'spaceName',
message: 'Please enter your Bluemix space name\t',
default: 'i.e. dev, test, prod'
},
{
when: function(response) {
return response.pushScript;
},
type: 'input',
name: 'organization',
message: 'Please enter your Bluemix organization name\t'
},
{
type: 'confirm',
name: 'WCSCredentials',
message: 'Do you want to enter your WCS credentials?\t',
},
{
when: function(response) {
return response.WCSCredentials;
},
type: 'input',
name: 'WCSUrl',
message: 'Please enter your WCS url:\t',
default: 'i.e. https://gateway.watsonplatform.net/conversation/api'
},
{
when: function(response) {
return response.WCSCredentials;
},
type: 'input',
name: 'WCSUsername',
message: 'Please enter your WCS username:\t'
},
{
when: function(response) {
return response.WCSCredentials;
},
type: 'input',
name: 'WCSPassword',
message: 'Please enter your WCS password:\t'
},
{
when: function(response) {
return response.WCSCredentials;
},
type: 'input',
name: 'version',
message: 'Please enter your WCS version:\t',
default: 'e.g. v1'
},
{
when: function (response) {
return response.WCSCredentials;
},
type: 'input',
name: 'versionDate',
message: 'Please enter your WCS version date:\t',
default: 'e.g. 2017-04-21'
},
{
when: function (response) {
return response.WCSCredentials;
},
type: 'input',
name: 'workspaceID',
message: 'Please enter your WCS workspace id:\t',
},
{
when: function (response) {
return response.WCSCredentials;
},
type: 'input',
name: 'workspaceName',
message: 'Please enter your WCS workspace name:\t',
},
{
type: "checkbox",
name: "nlu",
message: "What nlu engines will your skill use?\t",
choices: ['wcs', 'regexp','skill'],
default: 'select using space button'
}
];
inquirer.prompt(questions).then(function(response) {
let skillName = response.skillName;
let author = response.author;
let nlu = response.nlu;
// create manifest.json file
fs.readFile('res/assets/manifest.json', 'utf8', function (err, data) {
if (err) {
return console.log(err);
}
let manifestJSON = JSON.parse(data);
manifestJSON.author = author;
manifestJSON.nlu = nlu;
fs.writeFile('res/assets/manifest.json', JSON.stringify(manifestJSON, null, 2), function (err) {
if (err) {
return console.log(err);
}
console.log('Manifest json saved');
});
});
if (response.WCSCredentials) {
//create wcs.json file
let version = response.version;
let WCSUrl = response.WCSUrl;
let WCSPassword = response.WCSPassword;
let WCSUsername = response.WCSUsername;
let versionDate = response.versionDate;
let workspaceID = response.workspaceID;
let workspaceName = response.workspaceName;
let WCSJSON = {
'workspace': {
'en-US': {
'name': workspaceName,
'workspace_id': workspaceID
}
},
'credentials': {
'url': WCSUrl,
'version': version,
'version_date': versionDate,
'password': WCSPassword,
'username': WCSUsername
}
};
fs.writeFile('res/nlu/wcs.json', JSON.stringify(WCSJSON, null, 2), function (err) {
if (err) {
return console.log(err);
}
console.log('WCS json saved');
});
}
if(response.pushScript) {
let organization = response.organization;
let spaceName = response.spaceName;
let manifestYaml = yaml.load('manifest.yml');
manifestYaml.applications[0].name = skillName;
manifestYaml.applications[0].host = response.hostName;
manifestYaml.applications[0].domain = response.domainName;
fs.writeFile('manifest.yml', yaml.stringify(manifestYaml, 4), function (err) {
if (err) {
return console.log(err);
}
console.log('Manifest yml saved');
});
let pushScript = 'YML="manifest.yml"\n\nSPACE="' + spaceName + '"\n\nORGANIZATION="' + organization + '"\n\nbx target -s $SPACE -o $ORGANIZATION\nbx app push -f $YML';
fs.writeFile('push.sh', pushScript, function (err) {
if (err) {
return console.log(err);
}
console.log('Push script saved');
});
}
fs.readFile('package.json', 'utf8', function (err, data) {
if (err) {
return console.log(err);
}
let packageJSON = JSON.parse(data);
packageJSON.name = skillName;
packageJSON.author = author;
fs.writeFile('package.json', JSON.stringify(packageJSON, null, 2), function (err) {
if (err) {
return console.log(err);
}
console.log('package.json saved');
});
});
setTimeout(function() {
console.log('\n----------- Your skill is ready to go! ------------\n');
}, 500);
});