Skip to content

Commit f90c112

Browse files
committed
Merge branch 'assets' into main
2 parents 0327454 + a88fd3a commit f90c112

File tree

17 files changed

+1026
-6
lines changed

17 files changed

+1026
-6
lines changed

packages/plugin-assets/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Change Log
2+
3+
All notable changes to this project will be documented in this file.
4+
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

packages/plugin-assets/README.md

+126
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
<h1 align="center">@twilio-labs/plugin-assets</h1>
2+
<p align="center">Plugin for the <a href="https://github.com/twilio/twilio-cli">Twilio CLI</a> to easily upload assets to a <a href="https://www.twilio.com/docs/runtime/assets">Twilio Assets</a> service. Part of the <a href="https://github.com/twilio-labs/serverless-toolkit">Serverless Toolkit</a></p>
3+
<p align="center">
4+
<img alt="npm (scoped)" src="https://img.shields.io/npm/v/@twilio-labs/plugin-assets.svg?style=flat-square"> <img alt="npm" src="https://img.shields.io/npm/dt/@twilio-labs/plugin-assets.svg?style=flat-square"> <img alt="GitHub" src="https://img.shields.io/github/license/twilio-labs/plugin-serverless.svg?style=flat-square"> <a href="https://github.com/twilio-labs/.github/blob/main/CODE_OF_CONDUCT.md"><img alt="Code of Conduct" src="https://img.shields.io/badge/%F0%9F%92%96-Code%20of%20Conduct-blueviolet.svg?style=flat-square"></a> <a href="http://makeapullrequest.com"><img src="https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square" alt="PRs Welcome" /></a>
5+
<hr>
6+
7+
This plugin adds functionality to the [Twilio CLI](https://github.com/twilio/twilio-cli) to upload and manage assets to a Twilio Assets service. It's a part of the [Serverless Toolkit](https://github.com/twilio-labs/serverless-toolkit) and uses the [Serverless API](https://github.com/twilio-labs/serverless-toolkit/tree/main/packages/serverless-api).
8+
9+
The plugin creates a new Runtime Service which it then uses as a bucket to which it upload assets. You can upload new files or list your available assets.
10+
11+
<!-- toc -->
12+
13+
<!-- tocstop -->
14+
15+
## Requirements
16+
17+
### Install the Twilio CLI
18+
19+
Via `npm` or `yarn`:
20+
21+
```sh-session
22+
$ npm install -g twilio-cli
23+
$ yarn global add twilio-cli
24+
```
25+
26+
Via `homebrew`:
27+
28+
```sh-session
29+
$ brew tap twilio/brew && brew install twilio
30+
```
31+
32+
## Usage
33+
34+
```sh-session
35+
$ twilio plugins:install @twilio-labs/plugin-assets
36+
$ twilio --help assets
37+
USAGE
38+
$ twilio assets
39+
...
40+
```
41+
42+
## Commands
43+
44+
<!-- commands -->
45+
* [`twilio assets:init`](#twilio-assetsinit)
46+
* [`twilio assets:list`](#twilio-assetslist)
47+
* [`twilio assets:upload FILE`](#twilio-assetsupload-file)
48+
49+
## `twilio assets:init`
50+
51+
Create a new assets service to use as a bucket
52+
53+
```
54+
Create a new assets service to use as a bucket
55+
56+
USAGE
57+
$ twilio assets:init
58+
59+
OPTIONS
60+
-l=(debug|info|warn|error|none) [default: info] Level of logging messages.
61+
-o=(columns|json|tsv) [default: columns] Format of command output.
62+
-p, --profile=profile Shorthand identifier for your profile.
63+
64+
--properties=properties [default: service_sid, sid, domain_name] The asset service environment properties you
65+
would like to display (JSON output always shows all properties).
66+
```
67+
68+
_See code: [src/commands/assets/init.js](https://github.com/twilio-labs/serverless-toolkit/blob/v0.0.1/src/commands/assets/init.js)_
69+
70+
## `twilio assets:list`
71+
72+
List all the assets in the service
73+
74+
```
75+
List all the assets in the service
76+
77+
USAGE
78+
$ twilio assets:list
79+
80+
OPTIONS
81+
-l=(debug|info|warn|error|none) [default: info] Level of logging messages.
82+
-o=(columns|json|tsv) [default: columns] Format of command output.
83+
-p, --profile=profile Shorthand identifier for your profile.
84+
85+
--properties=properties [default: sid, path, url, visibility] The asset properties you would like to display
86+
(JSON output always shows all properties).
87+
```
88+
89+
_See code: [src/commands/assets/list.js](https://github.com/twilio-labs/serverless-toolkit/blob/v0.0.1/src/commands/assets/list.js)_
90+
91+
## `twilio assets:upload FILE`
92+
93+
Upload a new asset to the Assets service
94+
95+
```
96+
Upload a new asset to the Assets service
97+
98+
USAGE
99+
$ twilio assets:upload FILE
100+
101+
ARGUMENTS
102+
FILE The path to the file you want to upload
103+
104+
OPTIONS
105+
-l=(debug|info|warn|error|none) [default: info] Level of logging messages.
106+
-o=(columns|json|tsv) [default: columns] Format of command output.
107+
-p, --profile=profile Shorthand identifier for your profile.
108+
109+
--properties=properties [default: sid, path, url, visibility] The asset properties you would like to display
110+
(JSON output always shows all properties).
111+
```
112+
113+
_See code: [src/commands/assets/upload.js](https://github.com/twilio-labs/serverless-toolkit/blob/v0.0.1/src/commands/assets/upload.js)_
114+
<!-- commandsstop -->
115+
116+
## Contributing
117+
118+
This project welcomes contributions from the community. Please see the [`CONTRIBUTING.md`](CONTRIBUTING.md) file for more details.
119+
120+
### Code of Conduct
121+
122+
Please be aware that this project has a [Code of Conduct](https://github.com/twilio-labs/.github/blob/main/CODE_OF_CONDUCT.md). The tldr; is to just be excellent to each other ❤️
123+
124+
## License
125+
126+
MIT

packages/plugin-assets/bin/run

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/env node
2+
// Load up the command module *first* so that we're the parent rather than
3+
// some other dependency.
4+
const command = require('@oclif/command');
5+
6+
require('@twilio/cli-core').configureEnv();
7+
command.run()
8+
.then(require('@oclif/command/flush'))
9+
.catch(require('@oclif/errors/handle'));

packages/plugin-assets/bin/run.cmd

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@echo off
2+
3+
node "%~dp0\run" %*

packages/plugin-assets/jest.config.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const base = require('../../jest.config.base.js');
2+
const { join } = require('path');
3+
4+
module.exports = {
5+
...base,
6+
preset: null,
7+
name: 'plugin-assets',
8+
displayName: 'plugin-assets',
9+
globalTeardown: join(__dirname, 'jest.teardown.js'),
10+
};
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const { join } = require('path');
2+
const { tmpdir } = require('os');
3+
const rimraf = require('rimraf');
4+
5+
module.exports = () => {
6+
rimraf.sync(join(tmpdir(), 'scratch'));
7+
};

packages/plugin-assets/package.json

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
{
2+
"name": "@twilio-labs/plugin-assets",
3+
"description": "Easily upload assets to a Twilio Assets service",
4+
"version": "0.0.1",
5+
"author": "Twilio Inc. <[email protected]> (https://www.twilio.com/labs)",
6+
"contributors": [
7+
"Phil Nash <[email protected]>"
8+
],
9+
"dependencies": {
10+
"@oclif/command": "^1.5.19",
11+
"@oclif/config": "^1.13.3",
12+
"@twilio-labs/serverless-api": "^5.0.0-beta.0",
13+
"@twilio/cli-core": "^5.22.0",
14+
"inquirer": "^8.0.0",
15+
"ora": "^5.4.0"
16+
},
17+
"devDependencies": {
18+
"@oclif/dev-cli": "^1.22.2",
19+
"@oclif/plugin-help": "^2.2.1",
20+
"@oclif/test": "^1.2.5",
21+
"@twilio/cli-test": "^2.1.1",
22+
"jest": "^26.6.3",
23+
"rimraf": "^3.0.2"
24+
},
25+
"engines": {
26+
"node": ">=10"
27+
},
28+
"files": [
29+
"/oclif.manifest.json",
30+
"/src",
31+
"LICENSE",
32+
"README.md"
33+
],
34+
"keywords": [
35+
"oclif-plugin",
36+
"twilio-cli-plugin",
37+
"twilio-ci",
38+
"twilio",
39+
"assets"
40+
],
41+
"license": "MIT",
42+
"oclif": {
43+
"name": "assets",
44+
"commands": "./src/commands",
45+
"bin": "twilio",
46+
"devPlugins": [
47+
"@oclif/plugin-help"
48+
],
49+
"topics": {
50+
"assets": {
51+
"description": "Easily upload assets to a Twilio Assets service"
52+
},
53+
"assets:init": {
54+
"description": "Create a new assets service to use as a bucket"
55+
},
56+
"assets:upload": {
57+
"description": "Upload a new asset to the Assets service"
58+
},
59+
"assets:list": {
60+
"description": "List all the assets in the service"
61+
}
62+
}
63+
},
64+
"publishConfig": {
65+
"access": "public"
66+
},
67+
"repository": {
68+
"type": "git",
69+
"url": "https://github.com/twilio-labs/serverless-toolkit.git"
70+
},
71+
"homepage": "https://github.com/twilio-labs/serverless-toolkit",
72+
"bugs": {
73+
"url": "https://github.com/twilio-labs/serverless-toolkit/issues"
74+
},
75+
"scripts": {
76+
"postpack": "rm -f oclif.manifest.json",
77+
"prepack": "oclif-dev manifest && oclif-dev readme",
78+
"version": "oclif-dev readme && git add README.md",
79+
"test": "jest"
80+
}
81+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
const { flags } = require('@oclif/command');
2+
const { TwilioClientCommand } = require('@twilio/cli-core').baseCommands;
3+
const { getPluginConfig } = require('../../pluginConfig');
4+
const { init } = require('../../init');
5+
6+
class InitCommand extends TwilioClientCommand {
7+
async run() {
8+
await super.run();
9+
try {
10+
const pluginConfig = getPluginConfig(this);
11+
const result = await init({
12+
apiKey: this.currentProfile.apiKey,
13+
apiSecret: this.currentProfile.apiSecret,
14+
accountSid: this.currentProfile.accountSid,
15+
pluginConfig: pluginConfig,
16+
logger: this.logger,
17+
});
18+
this.output(result, this.flags.properties);
19+
} catch (error) {
20+
this.logger.error(error.message);
21+
}
22+
}
23+
}
24+
25+
InitCommand.flags = {
26+
properties: flags.string({
27+
default: 'service_sid, sid, domain_name',
28+
description:
29+
'The asset service environment properties you would like to display (JSON output always shows all properties).',
30+
}),
31+
...TwilioClientCommand.flags,
32+
};
33+
34+
InitCommand.description = 'Create a new assets service to use as a bucket';
35+
36+
module.exports = InitCommand;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
const { flags } = require('@oclif/command');
2+
const { TwilioClientCommand } = require('@twilio/cli-core').baseCommands;
3+
const { getPluginConfig } = require('../../pluginConfig');
4+
const { list } = require('../../list');
5+
6+
class ListCommand extends TwilioClientCommand {
7+
async run() {
8+
await super.run();
9+
10+
try {
11+
const pluginConfig = getPluginConfig(this);
12+
const assets = await list({
13+
apiKey: this.currentProfile.apiKey,
14+
apiSecret: this.currentProfile.apiSecret,
15+
accountSid: this.currentProfile.accountSid,
16+
pluginConfig: pluginConfig,
17+
logger: this.logger,
18+
});
19+
this.output(assets, this.flags.properties);
20+
} catch (error) {
21+
this.logger.error(error.message);
22+
}
23+
}
24+
}
25+
26+
ListCommand.description = 'List all the assets in the service';
27+
28+
ListCommand.flags = {
29+
properties: flags.string({
30+
default: 'sid, path, url, visibility',
31+
description:
32+
'The asset properties you would like to display (JSON output always shows all properties).',
33+
}),
34+
...TwilioClientCommand.flags,
35+
};
36+
37+
module.exports = ListCommand;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
const { flags } = require('@oclif/command');
2+
const { TwilioClientCommand } = require('@twilio/cli-core').baseCommands;
3+
const { getPluginConfig } = require('../../pluginConfig');
4+
const { upload } = require('../../upload');
5+
6+
class UploadCommand extends TwilioClientCommand {
7+
async run() {
8+
await super.run();
9+
10+
try {
11+
const { args } = this.parse(UploadCommand);
12+
const pluginConfig = getPluginConfig(this);
13+
const assets = await upload({
14+
apiKey: this.currentProfile.apiKey,
15+
apiSecret: this.currentProfile.apiSecret,
16+
accountSid: this.currentProfile.accountSid,
17+
pluginConfig: pluginConfig,
18+
file: args.file,
19+
logger: this.logger,
20+
});
21+
this.output(assets, this.flags.properties);
22+
} catch (error) {
23+
this.logger.error(error.message);
24+
}
25+
}
26+
}
27+
28+
UploadCommand.description = 'Upload a new asset to the Assets service';
29+
30+
UploadCommand.args = [
31+
{
32+
name: 'file',
33+
required: true,
34+
description: 'The path to the file you want to upload',
35+
},
36+
];
37+
38+
UploadCommand.flags = {
39+
properties: flags.string({
40+
default: 'sid, path, url, visibility',
41+
description:
42+
'The asset properties you would like to display (JSON output always shows all properties).',
43+
}),
44+
...TwilioClientCommand.flags,
45+
};
46+
47+
module.exports = UploadCommand;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
const debugFlagMessage =
2+
'Run the command again with the -l debug flag to see more.';
3+
4+
function couldNotGetEnvironment(accountSid, serviceSid, environmentSid) {
5+
return `Could not fetch asset service environment with config:
6+
7+
Account Sid: ${accountSid}
8+
Service Sid ${serviceSid}
9+
Environment Sid: ${environmentSid}
10+
11+
${debugFlagMessage}`;
12+
}
13+
14+
function couldNotGetBuild(serviceSid, environmentSid, buildSid) {
15+
return `Could not fetch last build of asset service environment with config:
16+
17+
Service Sid: ${serviceSid}
18+
Environment Sid: ${environmentSid}
19+
Build Sid: ${buildSid}
20+
21+
${debugFlagMessage}`;
22+
}
23+
24+
module.exports = {
25+
couldNotGetEnvironment,
26+
couldNotGetBuild,
27+
debugFlagMessage,
28+
};

0 commit comments

Comments
 (0)