Skip to content

Commit fa0d973

Browse files
authored
docs: improves the usage section of the README (#151)
1 parent 0a4f542 commit fa0d973

File tree

1 file changed

+85
-31
lines changed

1 file changed

+85
-31
lines changed

README.md

+85-31
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,36 @@
55
<a href="https://travis-ci.com/twilio-labs/twilio-run"><img alt="Travis (.com)" src="https://img.shields.io/travis/com/twilio-labs/twilio-run.svg?style=flat-square"></a>
66
<hr>
77

8-
* [About](#about)
9-
* [Installation](#installation)
10-
* [Usage](#usage)
11-
* [Commands](#commands)
12-
* [`twilio-run start [dir]`](#twilio-run-start-dir)
13-
* [Examples](#examples)
14-
* [`twilio-run deploy`](#twilio-run-deploy)
15-
* [Examples](#examples-1)
16-
* [`twilio-run list-templates`](#twilio-run-list-templates)
17-
* [Examples](#examples-2)
18-
* [`twilio-run new [namespace]`](#twilio-run-new-namespace)
19-
* [Examples](#examples-3)
20-
* [`twilio-run list [types]`](#twilio-run-list-types)
21-
* [Examples](#examples-4)
22-
* [`twilio-run activate`](#twilio-run-activate)
23-
* [Examples](#examples-5)
24-
* [`twilio-run logs`](#twilio-run-logs)
25-
* [Examples](#examples-6)
26-
* [API](#api)
27-
* [`runDevServer(port: number, baseDir: string): Promise<Express.Application>`](#rundevserverport-number-basedir-string-promiseexpressapplication)
28-
* [`handleToExpressRoute(handler: TwilioHandlerFunction): Express.RequestHandler`](#handletoexpressroutehandler-twiliohandlerfunction-expressrequesthandler)
29-
* [Error Handling in Dev Server](#error-handling-in-dev-server)
30-
* [Contributing](#contributing)
31-
* [Code of Conduct](#code-of-conduct)
32-
* [Contributors](#contributors)
33-
* [License](#license)
8+
- [About](#about)
9+
- [Installation](#installation)
10+
- [Usage](#usage)
11+
- [Create a new project](#create-a-new-project)
12+
- [Project conventions](#project-conventions)
13+
- [Function templates](#function-templates)
14+
- [Deploy a project](#deploy-a-project)
15+
- [Commands](#commands)
16+
- [`twilio-run start [dir]`](#twilio-run-start-dir)
17+
- [Examples](#examples)
18+
- [`twilio-run deploy`](#twilio-run-deploy)
19+
- [Examples](#examples-1)
20+
- [`twilio-run list-templates`](#twilio-run-list-templates)
21+
- [Examples](#examples-2)
22+
- [`twilio-run new [namespace]`](#twilio-run-new-namespace)
23+
- [Examples](#examples-3)
24+
- [`twilio-run list [types]`](#twilio-run-list-types)
25+
- [Examples](#examples-4)
26+
- [`twilio-run activate`](#twilio-run-activate)
27+
- [Examples](#examples-5)
28+
- [`twilio-run logs`](#twilio-run-logs)
29+
- [Examples](#examples-6)
30+
- [API](#api)
31+
- [`runDevServer(port: number, baseDir: string): Promise<Express.Application>`](#rundevserverport-number-basedir-string-promiseexpressapplication)
32+
- [`handleToExpressRoute(handler: TwilioHandlerFunction): Express.RequestHandler`](#handletoexpressroutehandler-twiliohandlerfunction-expressrequesthandler)
33+
- [Error Handling in Dev Server](#error-handling-in-dev-server)
34+
- [Contributing](#contributing)
35+
- [Code of Conduct](#code-of-conduct)
36+
- [Contributors](#contributors)
37+
- [License](#license)
3438

3539
## About
3640

@@ -54,18 +58,68 @@ npx twilio-run
5458

5559
## Usage
5660

61+
Check out the [commands](#commands) for in depth usage, but here are some things you will want to know:
62+
63+
### Create a new project
64+
65+
To create a new project with the Twilio Serverless Toolkit you can use [`create-twilio-function`](https://github.com/twilio-labs/create-twilio-function/) which will scaffold a new project that is ready to be used with `twilio-run`.
66+
5767
```bash
5868
# Create a valid project, for example:
59-
npx create-twilio-function my-project
69+
npm init twilio-function my-project
6070

6171
# Navigate into project
6272
cd my-project
73+
```
6374

64-
# Start local development server
65-
twilio-run start
75+
You can then use `twilio-run` to run a local development server to serve your functions and assets.
6676

67-
# Deploy to Twilio
68-
twilio-run deploy
77+
```bash
78+
npx twilio-run start
79+
```
80+
81+
### Project conventions
82+
83+
By default JavaScript Functions should be placed in the `functions` directory and assets, which can be JavaScript, images, CSS, or any static asset, should be placed in the `assets` directory. You can choose other directories by providing a `--functions-folder` or `--assets-folder` option to `twilio-run` commands.
84+
85+
Twilio Functions and Assets can be public, protected or private. The differences are:
86+
87+
* **Public**: Any one with the URL can visit the Function or Asset
88+
* **Protected**: Twilio signs webhook requests, making a Twilio Function protected means that the Function will validate the webhook signature and reject any incoming requests that don't match
89+
* **Private**: The Function or Asset doesn't a URL, it can only be required within another Function or Asset
90+
91+
Within `twilio-run` you can make your Functions or Assets public, protected or private by adding to the function filename. Functions and Assets are public by default. To make a Function or Asset protected or private, add `.protected` or `.private` to the filename before the extension. For example: `functions/secret.protected.js` or `assets/hidden.private.jpg`.
92+
93+
### Function templates
94+
95+
There are a number of pre-written Function templates that you can add to your project. The [templates are available on GitHub](https://github.com/twilio-labs/function-templates) and you can also propose your own via pull request.
96+
97+
To list the available templates you can run:
98+
99+
```bash
100+
npx twilio-run list-templates
101+
```
102+
103+
To add a new function into your project from a template you can run:
104+
105+
```bash
106+
npx twilio-run new namespace
107+
```
108+
109+
The command will walk you through choosing the template.
110+
111+
### Deploy a project
112+
113+
To deploy a project to the Twilio infrastructure you can run the command:
114+
115+
```bash
116+
npx twilio-run deploy
117+
```
118+
119+
This will deploy your project to the "dev" environment by default. You can then promote the project from "dev" to other environments with the command:
120+
121+
```bash
122+
npx twilio-run promote --from=dev --to=stage
69123
```
70124

71125
## Commands

0 commit comments

Comments
 (0)