-
Notifications
You must be signed in to change notification settings - Fork 7
/
deploy.js
73 lines (59 loc) · 2.16 KB
/
deploy.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
const { TwilioClientCommand } = require("@twilio/cli-core").baseCommands,
path = require("path"),
AutopilotCore = require("@dabblelab/autopilot-core"),
ora = require("ora");
const { handler } = require("../../lib/serverless/deploy"),
{
convertYargsOptionsToOclifFlags,
normalizeFlags,
createExternalCliOptions,
} = require("../../utils"),
updateTaskURL = require("../../lib/serverless/updateTaskURL"),
{ options, describe } = require("../../lib/options/deploy");
class AssistantsDeploy extends TwilioClientCommand {
constructor(argv, config, secureStorage) {
super(argv, config, secureStorage);
this.showHeaders = true;
}
async run() {
await super.run();
let { flags, args } = await this.parse(AssistantsDeploy);
flags = normalizeFlags(flags);
const spinner = ora();
try {
const externalOptions = createExternalCliOptions(
flags,
this.twilioClient
);
let hanlder_response = {};
if (flags.target === "all" || flags.target === "function") {
const opts = Object.assign({}, flags, args);
hanlder_response = await handler(opts, externalOptions);
}
const fullPath = path.resolve(process.cwd(), "model", "schema.json");
if (flags.target === "all") {
await updateTaskURL(fullPath, hanlder_response.url);
}
if (flags.target === "all" || flags.target === "model") {
spinner.start("deploying model...");
if (await AutopilotCore.existAssistant(fullPath, this.twilioClient)) {
await AutopilotCore.updateAssistant(fullPath, this.twilioClient);
} else {
await AutopilotCore.createAssistant(fullPath, this.twilioClient);
}
spinner.text = "Model successfully deployed";
spinner.succeed();
}
return;
} catch (err) {
spinner.stop();
console.error(`ERROR: ${err}`);
}
}
}
AssistantsDeploy.description = describe;
AssistantsDeploy.flags = Object.assign(
convertYargsOptionsToOclifFlags(options),
{ profile: TwilioClientCommand.flags.profile }
);
module.exports = AssistantsDeploy;