twilio-labs / create-twilio-function Goto Github PK
View Code? Open in Web Editor NEWA CLI tool to generate a new Twilio Functions project that can be run locally with twilio-run.
License: MIT License
A CLI tool to generate a new Twilio Functions project that can be run locally with twilio-run.
License: MIT License
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.
twilio-run
does this and the serverless plugin for the CLI consumes it.
Right now the words don't wrap when the terminal is smaller than the intended size. I would use something like wrap-ansi
to fix that.
Example:
https://github.com/twilio-labs/twilio-run/blob/next/src/printers/utils.ts#L26-L27
In this case it's not used with boxen
but you can also call boxen afterwards around it. You just have to subtract more from the window size
twilio-run
and Twilio Functions don't require these two values so they shouldn't be enforced.
We provide a guide for using TypeScript with Twilio Serverless. It would be good to add first-class support for typescript in create-twilio-function
to make it easier for developers to spin up functions written in TypeScript.
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
.
There should be a message displayed at the end of the process with the next steps.
Those next steps are:
npm start
http://localhost:3000/example
functions
directory and new assets in the assets
directoryUse boxen for display, like twilio-run
.
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).
Setup something like Jest and a testing structure, like in useful-twilio-functions, so that developers are encouraged to test their functions.
This can then prefer yarn over npm if the developer wants to use it.
For next version. There should be an example of public/protected/private assets and functions within the generated example application.
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>
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:
cd plugin-serverless && npm install && npm install create-twilio-function@next
twilio plugin:link .
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.
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:
Should we change for SIGNAL that we always grab the latest version of twilio-run
instead? That way we don't have to release a new version of this for everything. We can still use a semver range like 2.*
instead of a full latest but that way we still don't have to do re-releases
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
I'm sure I had a reason not to use this, but I can't remember it now.
needs to be Node version 8.10.0
Would this project be interested in having eslint
added?
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:
src/create-twilio-function
called window-size.js
get
function that returns either the object that the window-size
module would return or a default of { width: 80, height: 300 }
(including tests)window-size
in success-message.js
with this new moduleThe argument order in the Function template is wrong.
The right order would be context
, event
, callback
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
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?
Probably add some debug logging too. More details to come.
Use the README to point towards the Serverless Toolkit monorepo.
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.