Skip to content

Commit 14e15b0

Browse files
committed
feat: pass CLI info to twilio-run for cleaner structure
* feat: pass CLI info to twilio-run * chore(npm): upgrade twilio-run to rc.2
1 parent 48ddcd4 commit 14e15b0

File tree

7 files changed

+30
-34
lines changed

7 files changed

+30
-34
lines changed

packages/plugin-serverless/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"create-twilio-function": "^2.0.0-alpha.4",
1212
"lodash.camelcase": "^4.3.0",
1313
"lodash.kebabcase": "^4.1.1",
14-
"twilio-run": "^2.0.0-rc.1"
14+
"twilio-run": "^2.0.0-rc.2"
1515
},
1616
"devDependencies": {
1717
"@oclif/dev-cli": "^1.21.3",

packages/plugin-serverless/src/commands/serverless/activate.js

+3-10
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const {
88
const {
99
convertYargsOptionsToOclifFlags,
1010
normalizeFlags,
11+
createExternalCliOptions,
1112
} = require('../../utils');
1213

1314
class FunctionsActivate extends TwilioClientCommand {
@@ -21,18 +22,10 @@ class FunctionsActivate extends TwilioClientCommand {
2122
let { flags, args } = this.parse(FunctionsActivate);
2223
flags = normalizeFlags(flags);
2324

24-
if (flags.project === 'default') {
25-
flags._cliDefault = {
26-
username: this.twilioClient.username,
27-
password: this.twilioClient.password,
28-
};
29-
} else {
30-
flags.accountSid = flags.accountSid || this.twilioClient.username;
31-
flags.authToken = flags.authToken || this.twilioClient.password;
32-
}
25+
const externalOptions = createExternalCliOptions(flags, this.twilioClient);
3326

3427
const opts = Object.assign({}, flags, args);
35-
return handler(opts);
28+
return handler(opts, externalOptions);
3629
}
3730
}
3831

packages/plugin-serverless/src/commands/serverless/deploy.js

+3-10
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const {
88
const {
99
convertYargsOptionsToOclifFlags,
1010
normalizeFlags,
11+
createExternalCliOptions,
1112
} = require('../../utils');
1213

1314
class FunctionsDeploy extends TwilioClientCommand {
@@ -21,18 +22,10 @@ class FunctionsDeploy extends TwilioClientCommand {
2122
let { flags, args } = this.parse(FunctionsDeploy);
2223
flags = normalizeFlags(flags);
2324

24-
if (flags.project === 'default') {
25-
flags._cliDefault = {
26-
username: this.twilioClient.username,
27-
password: this.twilioClient.password,
28-
};
29-
} else {
30-
flags.accountSid = flags.accountSid || this.twilioClient.username;
31-
flags.authToken = flags.authToken || this.twilioClient.password;
32-
}
25+
const externalOptions = createExternalCliOptions(flags, this.twilioClient);
3326

3427
const opts = Object.assign({}, flags, args);
35-
return handler(opts);
28+
return handler(opts, externalOptions);
3629
}
3730
}
3831

packages/plugin-serverless/src/commands/serverless/list.js

+3-10
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const { handler, cliInfo, describe } = require('twilio-run/dist/commands/list');
55
const {
66
convertYargsOptionsToOclifFlags,
77
normalizeFlags,
8+
createExternalCliOptions,
89
} = require('../../utils');
910

1011
class FunctionsList extends TwilioClientCommand {
@@ -18,18 +19,10 @@ class FunctionsList extends TwilioClientCommand {
1819
let { flags, args } = this.parse(FunctionsList);
1920
flags = normalizeFlags(flags);
2021

21-
if (flags.project === 'default') {
22-
flags._cliDefault = {
23-
username: this.twilioClient.username,
24-
password: this.twilioClient.password,
25-
};
26-
} else {
27-
flags.accountSid = flags.accountSid || this.twilioClient.username;
28-
flags.authToken = flags.authToken || this.twilioClient.password;
29-
}
22+
const externalOptions = createExternalCliOptions(flags, this.twilioClient);
3023

3124
const opts = Object.assign({}, flags, args);
32-
return handler(opts);
25+
return handler(opts, externalOptions);
3326
}
3427
}
3528

packages/plugin-serverless/src/commands/serverless/new.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class FunctionsNew extends Command {
1818
flags = normalizeFlags(flags);
1919

2020
const opts = Object.assign({}, flags, args);
21-
return handler(opts);
21+
return handler(opts, undefined);
2222
}
2323
}
2424

packages/plugin-serverless/src/commands/serverless/start.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class FunctionsStart extends Command {
2323
flags = normalizeFlags(flags);
2424

2525
const opts = Object.assign({}, flags, args);
26-
return handler(opts);
26+
return handler(opts, undefined);
2727
}
2828
}
2929

packages/plugin-serverless/src/utils.js

+18-1
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,21 @@ function normalizeFlags(flags) {
4949
return result;
5050
}
5151

52-
module.exports = { convertYargsOptionsToOclifFlags, normalizeFlags };
52+
function createExternalCliOptions(flags, twilioClient) {
53+
const project = flags.project;
54+
55+
return {
56+
username: twilioClient.username,
57+
password: twilioClient.password,
58+
accountSid: twilioClient.accountSid,
59+
project,
60+
logLevel: undefined,
61+
outputFormat: undefined,
62+
};
63+
}
64+
65+
module.exports = {
66+
convertYargsOptionsToOclifFlags,
67+
normalizeFlags,
68+
createExternalCliOptions,
69+
};

0 commit comments

Comments
 (0)