forked from marcy-terui/serverless-alexa-skills
-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
202 lines (194 loc) · 6.02 KB
/
index.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
'use strict';
const BbPromise = require('bluebird');
const initialize = require('./lib/initialize');
const createHttpServer = require('./lib/createHttpServer');
const openAuthorizationUri = require('./lib/openAuthorizationUri');
const getVendorId = require('./lib/getVendorId');
const getToken = require('./lib/getToken');
const getRemoteSkills = require('./lib/getRemoteSkills');
const outputSkills = require('./lib/outputSkills');
const createSkill = require('./lib/createSkill');
const outputSkillId = require('./lib/outputSkillId');
const deleteSkill = require('./lib/deleteSkill');
const diffSkills = require('./lib/diffSkills');
const outputSkillsDiff = require('./lib/outputSkillsDiff');
const updateSkills = require('./lib/updateSkills');
const outputUpdatedSkillIds = require('./lib/outputUpdatedSkillIds');
const getRemoteModels = require('./lib/getRemoteModels');
const outputModels = require('./lib/outputModels');
const diffModels = require('./lib/diffModels');
const outputModelsDiff = require('./lib/outputModelsDiff');
const updateModels = require('./lib/updateModels');
const outputUpdatedModels = require('./lib/outputUpdatedModels');
const excludeTokenFile = require('./lib/excludeTokenFile');
class AlexaSkills {
constructor(serverless, options) {
this.serverless = serverless;
this.options = options || {};
this.provider = this.serverless.getProvider('aws');
this.TOKEN_FILE_NAME = '.alexa-skills-token.json';
Object.assign(
this,
initialize,
createHttpServer,
openAuthorizationUri,
getVendorId,
getToken,
getRemoteSkills,
outputSkills,
createSkill,
outputSkillId,
deleteSkill,
diffSkills,
outputSkillsDiff,
updateSkills,
outputUpdatedSkillIds,
getRemoteModels,
outputModels,
diffModels,
outputModelsDiff,
updateModels,
outputUpdatedModels,
excludeTokenFile
);
this.commands = {
alexa: {
commands: {
auth: {
usage: 'Authenticate with Amazon OAuth2',
lifecycleEvents: [
'auth',
],
},
manifests: {
usage: 'List your Alexa Skill Manifests',
lifecycleEvents: [
'list',
],
},
models: {
usage: 'List your Alexa Interaction Models',
lifecycleEvents: [
'list',
],
},
create: {
usage: 'Create an Alexa Skill',
lifecycleEvents: [
'create',
],
options: {
name: {
type: 'string',
usage: 'Name of the skill',
shortcut: 'n',
required: true,
},
locale: {
type: 'string',
usage: 'First locale of the skill (e.g. "ja-JP", "en-US")',
shortcut: 'l',
required: true,
},
skillType: {
type: 'string',
usage: 'Type of the skill (e.g. "custom", "smartHome", "video")',
shortcut: 't',
required: true,
},
},
},
delete: {
usage: 'Delete an Alexa Skill',
lifecycleEvents: [
'delete',
],
options: {
id: {
type: 'string',
usage: 'Skill ID',
shortcut: 'i',
required: true,
},
},
},
update: {
usage: 'Update your Alexa Skill Manifests',
lifecycleEvents: [
'update',
],
options: {
dryRun: {
type: 'string',
usage: 'Dry run (Only output the diff)',
shortcut: 'd',
},
},
},
build: {
usage: 'Update and buid your Alexa Interaction Models',
lifecycleEvents: [
'build',
],
options: {
dryRun: {
type: 'string',
usage: 'Dry run (Only output the diff)',
shortcut: 'd',
},
},
},
},
},
};
this.hooks = {
'before:package:createDeploymentArtifacts': () => BbPromise.bind(this)
.then(this.initialize)
.then(this.excludeTokenFile),
'alexa:auth:auth': () => BbPromise.bind(this)
.then(this.initialize)
.then(this.createHttpServer)
.then(this.openAuthorizationUri),
'alexa:manifests:list': () => BbPromise.bind(this)
.then(this.initialize)
.then(this.getRemoteSkills)
.then(this.outputSkills),
'alexa:models:list': () => BbPromise.bind(this)
.then(this.initialize)
.then(this.getRemoteModels)
.then(this.outputModels),
'alexa:create:create': () => BbPromise.bind(this)
.then(this.initialize)
.then(this.createSkill)
.then(this.outputSkillId),
'alexa:delete:delete': () => BbPromise.bind(this)
.then(this.initialize)
.then(this.deleteSkill),
'alexa:update:update': () => BbPromise.bind(this)
.then(this.initialize)
.then(this.getRemoteSkills)
.then(this.diffSkills)
.then(this.outputSkillsDiff)
.then(function (diffs) {
if (!('dryRun' in this.options)) {
return this.updateSkills(diffs);
}
return BbPromise.resolve();
})
.then(this.outputUpdatedSkillIds),
'alexa:build:build': () => BbPromise.bind(this)
.then(this.initialize)
.then(this.getRemoteModels)
.then(this.diffModels)
.then(this.outputModelsDiff)
.then(function (diffs) {
if (!('dryRun' in this.options)) {
return this.updateModels(diffs);
}
return BbPromise.resolve();
})
.then(this.outputUpdatedModels),
};
}
}
module.exports = AlexaSkills;