Skip to content

Commit dca6542

Browse files
update inquirer messages and add deploy command
1 parent fd6ba2b commit dca6542

File tree

17 files changed

+10115
-99
lines changed

17 files changed

+10115
-99
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@
55
/tmp
66
/yarn.lock
77
node_modules
8-
test
8+
test
9+
model
10+
function

package-lock.json

Lines changed: 9723 additions & 85 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"pretty-json-stringify": "0.0.2",
1717
"request-promise": "^4.2.4",
1818
"simple-git": "^1.124.0",
19+
"twilio-run": "^2.1.1",
1920
"underscore": "^1.9.1"
2021
},
2122
"devDependencies": {

src/commands/autopilot/deploy.js

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
const { TwilioClientCommand } = require('@twilio/cli-core').baseCommands,
2+
path = require('path'),
3+
{flags} = require('@oclif/command'),
4+
AutopilotCore = require('@dabblelab/autopilot-core'),
5+
ora = require('ora');
6+
7+
const {
8+
handler,
9+
cliInfo,
10+
describe,
11+
} = require('../../lib/serverless/deploy');
12+
const {
13+
convertYargsOptionsToOclifFlags,
14+
normalizeFlags,
15+
createExternalCliOptions,
16+
} = require('../../utils');
17+
18+
const updateTaskURL = require('../../lib/serverless/updateTaskURL');
19+
class AssistantsDeploy extends TwilioClientCommand {
20+
constructor(argv, config, secureStorage) {
21+
super(argv, config, secureStorage);
22+
23+
this.showHeaders = true;
24+
}
25+
26+
async runCommand() {
27+
let { flags, args } = this.parse(AssistantsDeploy);
28+
flags = normalizeFlags(flags);
29+
const spinner = ora();
30+
31+
try{
32+
33+
const externalOptions = createExternalCliOptions(flags, this.twilioClient);
34+
let hanlder_response = {};
35+
36+
if(flags.target === 'all' || flags.target === 'function'){
37+
38+
const opts = Object.assign({}, flags, args);
39+
hanlder_response = await handler(opts, externalOptions);
40+
}
41+
42+
const fullPath = path.resolve(process.cwd(), 'model', 'model.json');
43+
if(flags.target === 'all'){
44+
await updateTaskURL(fullPath, hanlder_response.url);
45+
}
46+
47+
if(flags.target === 'all' || flags.target === 'model'){
48+
49+
spinner.start('deploying model...');
50+
if(await AutopilotCore.existAssistant(fullPath, this.twilioClient)){
51+
52+
await AutopilotCore.updateAssistant(fullPath, this.twilioClient);
53+
}else{
54+
55+
await AutopilotCore.createAssistant(fullPath, this.twilioClient);
56+
}
57+
58+
spinner.text = 'Model successfully deployed.'
59+
spinner.succeed();
60+
}
61+
62+
return;
63+
}
64+
catch(err){
65+
66+
spinner.stop()
67+
68+
console.error(`ERROR: ${err}`)
69+
70+
}
71+
72+
}
73+
}
74+
75+
AssistantsDeploy.description = describe;
76+
77+
AssistantsDeploy.flags = Object.assign(
78+
convertYargsOptionsToOclifFlags(cliInfo.options),
79+
{
80+
'target' : flags.string({
81+
char : 't',
82+
description : `deploy function, model or all of them. Options can only be "all", "function" or "model".`,
83+
default : 'all',
84+
options : ['all', 'function', 'model']
85+
})
86+
},
87+
{ profile: TwilioClientCommand.flags.profile }
88+
);
89+
90+
module.exports = AssistantsDeploy;

src/commands/autopilot/fields/create.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class CreateAssistantTaskField extends TwilioClientCommand {
4545
{
4646
type: 'list',
4747
name: 'taskUniqueName',
48-
message: 'Choose your task in which to create: ',
48+
message: 'Select task in which to create: ',
4949
choices: taskChoice
5050
}
5151
]
@@ -74,7 +74,7 @@ class CreateAssistantTaskField extends TwilioClientCommand {
7474
{
7575
type: 'list',
7676
name: 'fieldTypeUniqueName',
77-
message: 'Choose your Field Type to create: ',
77+
message: 'Select Field Type in which to create: ',
7878
choices: f_choices
7979
}
8080
]

src/commands/autopilot/fields/delete.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class DeleteAssistantTaskField extends TwilioClientCommand {
3636
{
3737
type: 'list',
3838
name: 'taskUniqueName',
39-
message: 'Choose your task in which to delete: ',
39+
message: 'Select task in which to delete: ',
4040
choices: taskChoice
4141
}
4242
]
@@ -61,7 +61,7 @@ class DeleteAssistantTaskField extends TwilioClientCommand {
6161
{
6262
type: 'list',
6363
name: 'fieldUniqueName',
64-
message: 'Choose your Field to delete: ',
64+
message: 'Select Field to delete: ',
6565
choices: fieldChoice
6666
}
6767
]

src/commands/autopilot/fields/list.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class ListAssistantTaskFields extends TwilioClientCommand {
3636
{
3737
type: 'list',
3838
name: 'taskUniqueName',
39-
message: 'Choose your task in which to list: ',
39+
message: 'Select task in which to list: ',
4040
choices: taskChoice
4141
}
4242
]

src/commands/autopilot/fieldvalues/upload.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class FieldValuesUpload extends TwilioClientCommand {
4242
{
4343
type: 'list',
4444
name: 'fieldTypeUniqueName',
45-
message: 'Choose your Field Type in which to upload: ',
45+
message: 'Select Field Type in which to upload: ',
4646
choices: fieldTypeChoice
4747
}
4848
]

src/commands/autopilot/list.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const {flags} = require('@oclif/command'),
66
class ListAssistants extends TwilioClientCommand {
77

88
async runCommand() {
9+
910
const spinner = ora().start('Getting assistants...\n');
1011
try{
1112

@@ -15,7 +16,6 @@ class ListAssistants extends TwilioClientCommand {
1516
}catch(err){
1617

1718
spinner.stop()
18-
1919
console.error(`ERROR: ${err}`)
2020
}
2121
}

src/commands/autopilot/samples/upload.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class TaskSamplesUpload extends TwilioClientCommand {
4242
{
4343
type: 'list',
4444
name: 'taskUniqueName',
45-
message: 'Choose your task in which to create: ',
45+
message: 'Select task to upload samples: ',
4646
choices: taskChoice
4747
}
4848
]

0 commit comments

Comments
 (0)