Skip to content

Commit 238e391

Browse files
philnashdkundel
andauthored
chore(plugin-serverless): updates to @twilio/cli-core v7 (#420)
* chore(plugin-serverless): updates to @twilio/cli-core v7 Replaces `@oclif/command` and `@oclif/config` with `@oclif/core` Updates `./bin/run` command and adds `./bin/dev` command Sets engines property in package to Node 14 (matches `@oclif/core`) Updates commands to call `await this.parse` - For commands that inherit from `TwilioClientCommand`, flags and args are already parsed into `this.flags` and `this.args` when `super.run()` is called. This removes the call to parse a second time and uses `this.flags` and `this.args` instead * chore(plugin-serverless): adds package.json main property Copied from: https://github.com/oclif/hello-world/blob/main/src/index.ts Co-authored-by: Dominik Kundel <[email protected]>
1 parent 52df97e commit 238e391

File tree

15 files changed

+66
-50
lines changed

15 files changed

+66
-50
lines changed

packages/plugin-serverless/bin/dev

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env node
2+
3+
const oclif = require('@oclif/core');
4+
5+
// In dev mode -> use ts-node and dev plugins
6+
process.env.NODE_ENV = 'development';
7+
8+
// In dev mode, always show stack traces
9+
oclif.settings.debug = true;
10+
11+
// Configure the Twilio CLI environment
12+
require('@twilio/cli-core').configureEnv();
13+
14+
// Start the CLI
15+
oclif.run().then(oclif.flush).catch(oclif.Errors.handle);
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@echo off
2+
3+
node "%~dp0\dev" %*

packages/plugin-serverless/bin/run

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
#!/usr/bin/env node
22
// Load up the command module *first* so that we're the parent rather than
33
// some other dependency.
4-
const command = require('@oclif/command');
4+
const oclif = require('@oclif/core');
55

66
require('@twilio/cli-core').configureEnv();
7-
command.run()
8-
.then(require('@oclif/command/flush'))
9-
.catch(require('@oclif/errors/handle'));
7+
8+
oclif
9+
.run()
10+
.then(require('@oclif/core/flush'))
11+
.catch(require('@oclif/core/handle'));

packages/plugin-serverless/package.json

+5-6
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,22 @@
66
"contributors": [
77
"Dominik Kundel <[email protected]>"
88
],
9+
"main": "src/index.js",
910
"dependencies": {
10-
"@oclif/command": "^1.5.19",
11-
"@oclif/config": "^1.13.3",
12-
"@twilio/cli-core": "^6.0.0",
11+
"@oclif/core": "^1.14.2",
12+
"@twilio/cli-core": "^7.0.0",
1313
"create-twilio-function": "^3.3.5",
1414
"lodash.camelcase": "^4.3.0",
1515
"lodash.kebabcase": "^4.1.1",
1616
"twilio-run": "^3.4.4"
1717
},
1818
"devDependencies": {
19-
"@oclif/dev-cli": "^1.22.2",
20-
"@oclif/plugin-help": "^3.2.3",
19+
"@oclif/plugin-help": "^5.1.12",
2120
"@oclif/test": "^1.2.5",
2221
"@twilio/cli-test": "^2.0.2"
2322
},
2423
"engines": {
25-
"node": ">=12.22.1"
24+
"node": ">=14.0.0"
2625
},
2726
"files": [
2827
"/oclif.manifest.json",

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

+2-3
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,15 @@ class FunctionsDeploy extends TwilioClientCommand {
1818
async run() {
1919
await super.run();
2020

21-
let { flags, args } = this.parse(FunctionsDeploy);
22-
flags = normalizeFlags(flags, aliasMap, process.argv);
21+
const flags = normalizeFlags(this.flags, aliasMap, process.argv);
2322

2423
const externalOptions = createExternalCliOptions(flags, this.twilioClient);
2524

2625
const { edge, region } = getRegionAndEdge(flags, this);
2726
flags.region = region;
2827
flags.edge = edge;
2928

30-
const opts = Object.assign({}, flags, args);
29+
const opts = Object.assign({}, flags, this.args);
3130
return handler(opts, externalOptions);
3231
}
3332
}

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

+2-3
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,9 @@ class FunctionsInit extends TwilioClientCommand {
1616
async run() {
1717
await super.run();
1818

19-
let { flags, args } = this.parse(FunctionsInit);
20-
flags = normalizeFlags(flags, aliasMap, process.argv);
19+
const flags = normalizeFlags(this.flags, aliasMap, process.argv);
2120

22-
const opts = Object.assign({}, flags, args);
21+
const opts = Object.assign({}, flags, this.args);
2322
opts.accountSid = flags.accountSid || this.twilioClient.accountSid;
2423
opts.authToken = flags.authToken || '';
2524

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { Command } = require('@oclif/command');
1+
const { Command } = require('@oclif/core');
22

33
const {
44
handler,
@@ -14,7 +14,7 @@ const { flags, aliasMap } = convertYargsOptionsToOclifFlags(cliInfo.options);
1414

1515
class FunctionsListTemplates extends Command {
1616
async run() {
17-
let { flags, args } = this.parse(FunctionsListTemplates);
17+
let { flags, args } = await this.parse(FunctionsListTemplates);
1818
flags = normalizeFlags(flags, aliasMap, process.argv);
1919

2020
const opts = Object.assign({}, flags, args);

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

+2-3
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,15 @@ class FunctionsList extends TwilioClientCommand {
1414
async run() {
1515
await super.run();
1616

17-
let { flags, args } = this.parse(FunctionsList);
18-
flags = normalizeFlags(flags, aliasMap, process.argv);
17+
const flags = normalizeFlags(this.flags, aliasMap, process.argv);
1918

2019
const externalOptions = createExternalCliOptions(flags, this.twilioClient);
2120

2221
const { edge, region } = getRegionAndEdge(flags, this);
2322
flags.region = region;
2423
flags.edge = edge;
2524

26-
const opts = Object.assign({}, flags, args);
25+
const opts = Object.assign({}, flags, this.args);
2726
return handler(opts, externalOptions);
2827
}
2928
}

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

+2-3
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,15 @@ class LogsList extends TwilioClientCommand {
1515
async run() {
1616
await super.run();
1717

18-
let { flags, args } = this.parse(LogsList);
19-
flags = normalizeFlags(flags, aliasMap, process.argv);
18+
const flags = normalizeFlags(this.flags, aliasMap, process.argv);
2019

2120
const externalOptions = createExternalCliOptions(flags, this.twilioClient);
2221

2322
const { edge, region } = getRegionAndEdge(flags, this);
2423
flags.region = region;
2524
flags.edge = edge;
2625

27-
const opts = Object.assign({}, flags, args);
26+
const opts = Object.assign({}, flags, this.args);
2827
return handler(opts, externalOptions);
2928
}
3029
}

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { Command } = require('@oclif/command');
1+
const { Command } = require('@oclif/core');
22

33
const { handler, cliInfo, describe } = require('twilio-run/dist/commands/new');
44
const {
@@ -10,7 +10,7 @@ const { flags, aliasMap } = convertYargsOptionsToOclifFlags(cliInfo.options);
1010

1111
class FunctionsNew extends Command {
1212
async run() {
13-
let { flags, args } = this.parse(FunctionsNew);
13+
let { flags, args } = await this.parse(FunctionsNew);
1414
flags = normalizeFlags(flags, aliasMap, process.argv);
1515

1616
const opts = Object.assign({}, flags, args);

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

+2-3
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,15 @@ class FunctionsPromote extends TwilioClientCommand {
1818
async run() {
1919
await super.run();
2020

21-
let { flags, args } = this.parse(FunctionsPromote);
22-
flags = normalizeFlags(flags, aliasMap, process.argv);
21+
const flags = normalizeFlags(this.flags, aliasMap, process.argv);
2322

2423
const externalOptions = createExternalCliOptions(flags, this.twilioClient);
2524

2625
const { edge, region } = getRegionAndEdge(flags, this);
2726
flags.region = region;
2827
flags.edge = edge;
2928

30-
const opts = Object.assign({}, flags, args);
29+
const opts = Object.assign({}, flags, this.args);
3130
return handler(opts, externalOptions);
3231
}
3332
}

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { Command } = require('@oclif/command');
1+
const { Command } = require('@oclif/core');
22

33
const {
44
handler,
@@ -14,7 +14,7 @@ const { flags, aliasMap } = convertYargsOptionsToOclifFlags(cliInfo.options);
1414

1515
class FunctionsStart extends Command {
1616
async run() {
17-
let { flags, args } = this.parse(FunctionsStart);
17+
let { flags, args } = await this.parse(FunctionsStart);
1818

1919
flags = normalizeFlags(flags, aliasMap, process.argv);
2020

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
const { run } = require('@oclif/core');
2+
module.exports = run;

packages/plugin-serverless/src/utils.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const path = require('path');
22
const camelCase = require('lodash.camelcase');
3-
const { flags } = require('@oclif/command');
3+
const { Flags } = require('@oclif/core');
44
const pkgJson = require('../package.json');
55

66
function convertYargsOptionsToOclifFlags(options) {
@@ -36,10 +36,10 @@ function convertYargsOptionsToOclifFlags(options) {
3636
flag.required = opt.requiresArg;
3737
}
3838

39-
result[name] = flags[opt.type](flag);
39+
result[name] = Flags[opt.type](flag);
4040

4141
if (opt.alias && opt.alias.length > 1) {
42-
result[opt.alias] = flags[opt.type]({
42+
result[opt.alias] = Flags[opt.type]({
4343
...flag,
4444
default: undefined,
4545
description: `[Alias for "${name}"]`,

packages/plugin-serverless/tests/utils.test.js

+16-16
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { flags } = require('@oclif/command');
1+
const { Flags } = require('@oclif/core');
22
const {
33
normalizeFlags,
44
convertYargsOptionsToOclifFlags,
@@ -86,12 +86,12 @@ describe('convertYargsOptionsToOclifFlags', () => {
8686
expect(result.aliasMap.size).toEqual(0);
8787
expect(result.flags.toString()).toEqual(
8888
{
89-
production: flags.boolean({
89+
production: Flags.boolean({
9090
description: yargsFlags.production.describe,
9191
default: yargsFlags.production.default,
9292
hidden: undefined,
9393
}),
94-
'service-sid': flags.string({
94+
'service-sid': Flags.string({
9595
description: yargsFlags['service-sid'].describe,
9696
default: yargsFlags['service-sid'].default,
9797
hidden: undefined,
@@ -119,12 +119,12 @@ describe('convertYargsOptionsToOclifFlags', () => {
119119
expect(result.aliasMap.size).toEqual(0);
120120
expect(result.flags.toString()).toEqual(
121121
{
122-
production: flags.boolean({
122+
production: Flags.boolean({
123123
description: yargsFlags.production.describe,
124124
default: yargsFlags.production.default,
125125
hidden: undefined,
126126
}),
127-
'service-sid': flags.string({
127+
'service-sid': Flags.string({
128128
description: yargsFlags['service-sid'].describe,
129129
default: yargsFlags['service-sid'].default,
130130
hidden: undefined,
@@ -152,12 +152,12 @@ describe('convertYargsOptionsToOclifFlags', () => {
152152
expect(result.aliasMap.size).toEqual(0);
153153
expect(result.flags.toString()).toEqual(
154154
{
155-
production: flags.boolean({
155+
production: Flags.boolean({
156156
description: yargsFlags.production.describe,
157157
default: yargsFlags.production.default,
158158
hidden: undefined,
159159
}),
160-
port: flags.string({
160+
port: Flags.string({
161161
description: yargsFlags.port.describe,
162162
default: yargsFlags.port.default,
163163
hidden: undefined,
@@ -191,17 +191,17 @@ describe('convertYargsOptionsToOclifFlags', () => {
191191
expect(result.aliasMap.size).toEqual(0);
192192
expect(result.flags.toString()).toEqual(
193193
{
194-
production: flags.boolean({
194+
production: Flags.boolean({
195195
description: yargsFlags.production.describe,
196196
default: yargsFlags.production.default,
197197
hidden: undefined,
198198
}),
199-
'service-sid': flags.string({
199+
'service-sid': Flags.string({
200200
description: yargsFlags['service-sid'].describe,
201201
default: yargsFlags['service-sid'].default,
202202
hidden: undefined,
203203
}),
204-
username: flags.string({
204+
username: Flags.string({
205205
description: yargsFlags['username'].describe,
206206
default: yargsFlags['username'].default,
207207
hidden: undefined,
@@ -245,32 +245,32 @@ describe('convertYargsOptionsToOclifFlags', () => {
245245
]);
246246
expect(result.flags.toString()).toEqual(
247247
{
248-
production: flags.boolean({
248+
production: Flags.boolean({
249249
description: yargsFlags.production.describe,
250250
default: yargsFlags.production.default,
251251
hidden: undefined,
252252
}),
253-
'service-sid': flags.string({
253+
'service-sid': Flags.string({
254254
description: yargsFlags['service-sid'].describe,
255255
default: yargsFlags['service-sid'].default,
256256
hidden: undefined,
257257
}),
258-
'source-environment': flags.string({
258+
'source-environment': Flags.string({
259259
description: yargsFlags['source-environment'].describe,
260260
default: yargsFlags['source-environment'].default,
261261
hidden: undefined,
262262
}),
263-
from: flags.string({
263+
from: Flags.string({
264264
description: '[Alias for "source-environment"]',
265265
default: undefined,
266266
hidden: undefined,
267267
}),
268-
environment: flags.string({
268+
environment: Flags.string({
269269
description: yargsFlags['environment'].describe,
270270
default: yargsFlags['environment'].default,
271271
hidden: undefined,
272272
}),
273-
to: flags.string({
273+
to: Flags.string({
274274
description: '[Alias for "environment"]',
275275
default: undefined,
276276
hidden: undefined,

0 commit comments

Comments
 (0)