Giter Club home page Giter Club logo

create-twilio-function's Introduction

๐Ÿ›‘ create-twilio-function is part of the Serverless Toolkit ๐Ÿ›‘

The Serverless Toolkit is a monorepo containing create-twilio-function, twilio-run, plugin-serverless, and other supporting packages that help you create, run, deploy and update functions and assets to Twilio Functions.

This repo is deprecated and development continues under the Serverless Toolkit repo.

create-twilio-function

A command line tool to setup a new Twilio Function with local testing using twilio-run.

Build Status Maintainability

Read more about this tool in the post start a new Twilio Functions project the easy way

Usage

npm init

There are a number of ways to use this tool. The quickest and easiest is with npm init:

npm init twilio-function function-name
cd function-name
npm start

This will create a new directory named "function-name" and include all the files you need to write and run a Twilio Function locally. Starting the application will host the example function at localhost:3000/example.

Twilio CLI

Make sure you have the Twilio CLI installed with either:

npm install twilio-cli -g

or

brew tap twilio/brew && brew install twilio

Install the Twilio Serverless Toolkit plugin:

twilio plugins:install @twilio-labs/plugin-serverless

Then initialise a new Functions project with:

twilio serverless:init function-name

npx

You can also use npx to run create-twilio-function:

npx create-twilio-function function-name

Global installation

Or you can install the module globally:

npm install create-twilio-function -g
create-twilio-function function-name

Function Templates

create-twilio-function enables you to generate a new empty project or to build a project using any of the templates from the Function Templates repo. All you need to do is pass a --template option with the name of the template you want to download. Like this:

npm init twilio-function function-name --template blank

This works with any of the other ways of calling create-twilio-function. Check out the ever expanding list of function templates here.

TypeScript

If you want to build your Twilio Functions project in TypeScript you can. create-twilio-function supports generating a new project that is set up to use TypeScript too. To generate a TypeScript project, use the --typescript flag, like this:

npm init twilio-function function-name --typescript

Note: there are no Function templates written in TypeScript, so do not use the --template flag alongside the --typescript flag. The basic TypeScript project does come with some example files, but you can generate an empty project combining the --typescript and --empty flags.

Command line arguments

Creates a new Twilio Function project

Commands:
  create-twilio-function <name>          Creates a new Twilio Function project
                                                                       [default]
  create-twilio-function list-templates  Lists the available Twilio Function
                                         templates

Positionals:
  name  Name of your project.                                           [string]

Options:
  --account-sid, -a     The Account SID for your Twilio account         [string]
  --auth-token, -t      Your Twilio account Auth Token                  [string]
  --skip-credentials    Don't ask for Twilio account credentials or import them
                        from the environment          [boolean] [default: false]
  --import-credentials  Import credentials from the environment variables
                        TWILIO_ACCOUNT_SID and TWILIO_AUTH_TOKEN
                                                      [boolean] [default: false]
  --template            Initialize your new project with a template from
                        github.com/twilio-labs/function-templates       [string]
  --empty               Initialize your new project with empty functions and
                        assets directories            [boolean] [default: false]
  --typescript          Initialize your Serverless project with TypeScript
                                                      [boolean] [default: false]
  -h, --help            Show help                                      [boolean]
  -v, --version         Show version number                            [boolean]
  --path                                                        [default: (cwd)]

Contributing

Any help contributing to this project is welcomed. Make sure you read and agree with the code of conduct.

  1. Fork the project
  2. Clone the fork like so:
git clone [email protected]:YOUR_USERNAME/create-twilio-function.git
  1. Install the dependencies
cd create-twilio-function
npm install
  1. Make your changes
  2. Test your changes with
npm test
  1. Commit your changes and open a pull request

LICENSE

MIT

create-twilio-function's People

Contributors

bharatr21 avatar daphnesmit avatar dkundel avatar dlemstra avatar philnash avatar vyaaspranjal avatar wenzdey avatar whitneyrosenberg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

create-twilio-function's Issues

Project is throwing an error when used in Twilio CLI Plugin

If you install the latest version (create-twilio-function@next) and try to use it in the plugin via twilio serverless:init it will create the directory and then throw an error that it exists.

Steps to repo:

  1. clone the plugin repo (https://github.com/twilio-labs/plugin-serverless)
  2. cd plugin-serverless && npm install && npm install create-twilio-function@next
  3. twilio plugin:link .
  4. in a different directory twilio serverless:init pineapple

If you instead locally clone create-twilio-function and change the step 2 to npm install ../create-twilio-function instead it will work.

Add a "npm run deploy" command

It would be nice if we could have instructions for Serverless projects like:

git clone ...
cd project
npm install
cp .env.example .env
# Add credentials to .env
npm run deploy

Display success message at the end of the process

There should be a message displayed at the end of the process with the next steps.

Those next steps are:

  • Change into the directory you just created
  • Start a local server running the functions: npm start
  • Visit the example function at http://localhost:3000/example
  • Create new functions in the functions directory and new assets in the assets directory

Use boxen for display, like twilio-run.

Update node version

The underlying platform continues to update the version of Node 10 that functions uses. We should try to keep up to date somehow.

Is it ok to change the version to "10"? Or should we keep up to date to ensure the absolute latest?

Add an "empty" option to create just the file structure

The default template has some example files in it. The blank template still has a couple of blank files. If you truly want to start a functions project from scratch there is no template available.

If we had an --empty option, we could skip templates and skip the default template and just create the file structure.

Allow for template flag to be passed

twilio-run can now create a new function from a template in twilio-labs/function-templates. create-twilio-function should be able to create a new project from either the default template within this project or by using twilio-run to grab a template.

API ideas:

Create a project called whats-up with the hello-world template.

npx create-twilio-function whats-up --template hello-world

List the available templates (also available in twilio-run). This might be a pain with the yargs default command.

npx create-twilio-function --list-templates

Failure to create a project prints "project already exists" no matter the error

I'm in a directory I don't have write access to and tried to make a new project:

$ ls -a
.		..
$ twilio serverless:init foo
A directory called 'foo' already exists. Please create your function in a new directory.

The error should be "no permission", or even "error creating directory" without the "directory already exists" would be better.

Use fixed window size if it is not available

This package uses the window-size module to make sure the success message formats correctly based on the window size of the user's terminal.

Like in twilio-run/#82, it could break if the window-size module cannot return a width and height.

We should default to a fixed width of, say, 80 in the case where window-size doesn't return a value.

Steps to implement:

  • Create a new file in src/create-twilio-function called window-size.js
  • implement a get function that returns either the object that the window-size module would return or a default of { width: 80, height: 300 } (including tests)
  • replace the use of window-size in success-message.js with this new module

Missing credentials offer sign-up/in pop-up

It would be neat to offer a way that if no credentials are passed to the CLI that people can choose to either enter their credentials or open the Twilio Console in the browser to sign in / retrieve their credentials.

We should make sure to:

  1. it should be descriptive and clear what's happening
  2. include UTM parameters to the URL to indicate the source

Tests are failing

When trying to create a new function using the --template flag with a missing template, the command succeeds.

Suspect this is a problem in twilio-run.

Create function fails on windows with spaces in paths

OS: Windows 10 x64

Attempting to create the function in a directory that has a space throws an error.

C:\Users\Jordan Walsh\projects\launch-phone-redirect>npx create-twilio-function@next example
Error: EPERM: operation not permitted, mkdir 'C:\Users\Jordan'
TypeError: Cannot read property 'get' of undefined
    at errorMessage (C:\Program Files\nodejs\node_modules\npm\lib\utils\error-message.js:38:39)
    at errorHandler (C:\Program Files\nodejs\node_modules\npm\lib\utils\error-handler.js:201:13)
    at C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js:78:20
    at cb (C:\Program Files\nodejs\node_modules\npm\lib\npm.js:225:22)
    at C:\Program Files\nodejs\node_modules\npm\lib\npm.js:263:24
    at C:\Program Files\nodejs\node_modules\npm\lib\config\core.js:83:7
    at Array.forEach (<anonymous>)
    at C:\Program Files\nodejs\node_modules\npm\lib\config\core.js:82:13
    at f (C:\Program Files\nodejs\node_modules\npm\node_modules\once\once.js:25:25)
    at afterExtras (C:\Program Files\nodejs\node_modules\npm\lib\config\core.js:173:20)
C:\Program Files\nodejs\node_modules\npm\lib\utils\error-handler.js:97
  var doExit = npm.config.loaded ? npm.config.get('_exit') : true
                          ^

TypeError: Cannot read property 'loaded' of undefined
    at exit (C:\Program Files\nodejs\node_modules\npm\lib\utils\error-handler.js:97:27)
    at process.errorHandler (C:\Program Files\nodejs\node_modules\npm\lib\utils\error-handler.js:216:3)
    at process.emit (events.js:198:13)
    at process._fatalException (internal/bootstrap/node.js:496:27)
Install for create-twilio-function@next failed with code 7

The same code executed in a directory with no spaces works fine:

c:\projects>create-twilio-function launch-phone-redirect
โˆš Creating project directory
Please enter your Twilio credentials which you can find in your Twilio console (โ€‹https://twil.io/your-consoleโ€‹).
? Twilio Account SID xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
? Twilio auth token [hidden]
โˆš Creating project directories and files
โˆš Downloading .gitignore file
โˆš Installing dependencies
โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚                                                                              โ”‚
โ”‚   Success!                                                                   โ”‚
โ”‚                                                                              โ”‚
โ”‚   Created launch-phone-redirect at c:\projects                               โ”‚
โ”‚                                                                              โ”‚
โ”‚   Inside that directory, you can run the following command:                  โ”‚
โ”‚                                                                              โ”‚
โ”‚   npm start                                                                  โ”‚
โ”‚     Serves all functions in the ./functions subdirectory and assets in the   โ”‚
โ”‚     ./assets directory                                                       โ”‚
โ”‚                                                                              โ”‚
โ”‚   Get started by running:                                                    โ”‚
โ”‚                                                                              โ”‚
โ”‚   cd launch-phone-redirect                                                   โ”‚
โ”‚   npm start                                                                  โ”‚
โ”‚                                                                              โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

c:\projects>

Make it possible to import Account SID and Auth Token from env variables

If a developer is already storing their Account SID and Auth Token in env variables then we should be able to use them.

Implementation:

If Account SID/Auth Token is detected in the environment, prompt to ask whether to use them.
If declined, move on to prompt for the credentials.

Include a flag, --import-credentials, which skips the prompt if the credentials are present (for automation).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.