This package has been deprecated

Author message:

Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

wtw

0.1.10 • Public • Published

wtw - WebTask Workflow

A simple workflow for the Webtask CLI

Installation and quickstart

Assuming you already know and have a Webtask account:

npm i -g wt-cli
npm i -g wtw
wtw --help
wt init

This last command will go trough the account setup to use the remote runtimes provided by webtask.io

Now, let's create a remote webtask from an existing file (wraps 'wt create'):

wtw create myfile.js

Jump to Usage section to see more examples.

Motivations, approach and conventions

Why Webtask

Webtask is a general purpose Function as a Service (or serverless) provider. Simple NodeJS functions can be a task executed on a remote server almost instantly and has a public accessible URL. That's a Webtask

Why an addional CLI

Webtask comes with a convenient CLI that already offer all basic commands. As always, it get useful to have some basic best practices and standard workflows to deal with frameworks and service providers.

What problems addresses

wt-cli-workflow deals with

  1. providing easy to use CLI commands to create and run webtasks based on some conventions
  2. define a set standard run mode and make it easy to work with them: local, development, test, stage, production
  3. make it easy to setup a continuous testing, integration and deliver environment based on Webtask (TBD)

Conventions

  • Use .env files to store keys, credentials and various secrets
  • env is used as suffix in .env files (eg: .env.dev, .env.prod)
  • env is used as suffix in deploying the webtask (eg: myfile-test, myfile-prod)
  • task name is the file name without the '.js' extension

Usage

Pre-requisites

Obviously, Webtask is required. The setup takes 1 minute Create an account and a install a CLI with npm following this instructions

Once the basic environment has been setup, working with serverless functions is mostly about:

  1. Creating a new function (not very often)
  2. code, test, deploy, release (most of the time)

Well, exactly what happens in any other kind of development, right? Webtask cli offer great foundamentals but in real world there are 2 things we almost always need that are not immediate (for lazy people like me) to get with simple commands:

  1. secret environment variable to connect to databases, APIs...
  2. different environments for development, testing, staging, production...

Here comes wt-cli-workflow, or wtw.

Setup webtask profile

We want to create a new Node8 based container and test it:

wt init -p node8 --url https://sandbox.auth0-extend.com
echo "module.exports = function (cb) { cb(null, versions: process.versions); }" > hello.js
wt create hello.js

NOTE: there was a but in wt-cli that require some manual change in ~/.webtask. If the new profile to not run node8, then the bug is still there.

Create

wtw create myfile.js

This will create a new function named "myfile-dev", with a specific url that will look like this: https://XXX-some-code-XXX.sandbox.auth0-extend.com/myfile-dev And the .env file will be used

To publish a different version for example to be used for testing

wtw create myfile.js test

This will create a new function named "myfile-test", with a specific url that will look like this: https://XXX-some-code-XXX.sandbox.auth0-extend.com/myfile-test And the test.env file will be used

Run

Run the file after it has already been created

wtw run myfile.js

This will update the myfile-dev version with the latest local code and will stay open to publish any new local changes

Here as well, a second parameter will change the environment, affecting which .env file will be used and the remote URL

Scheduled functions with cron

Crete a function that with a specified schedule using cron

wtw cron myfile.js "*/10 * * * *"

That schedule mean every ten minues past the hour. Use Corntab to master cron :)

More utilities commands

wtw ls // accepts a search params that grep TS out of standard 'wt ls'
wtw rm //accepts a series of webtasks named and removed them using basic 'wt rm'

Please let me know what commands you would like to see, or feel free to fork and make pull requests :)

Developers

Setup development environment

Checkout the code, then

npm install
npm link

This will create a symbolic link under user home, something like

~/.nvm/versions/node/{NODE_VERSION}/lib/node_modules/wt-cli-workflow -> ~/{project folder}/wt-cli-workflow

Now create a symbolic link to use the CLI globally. In Ubuntu I recommend:

// sudo update-alternatives --install /usr/bin/wtw-dev wtw-dev ~/.nvm/versions/node/{NODE_VERSION}/lib/node_modules/wt-cli-workflow/src/cli.js 1
sudo update-alternatives --install /usr/bin/wtw-dev wtw-dev /usr/local/bin/wtw 1

Change {NODE_VERSION} with your installed version of node I call this command wtw-dev so it will not be confused with released version on npmjs

Now this will show the cli help in the console.

$ wtw-dev -h

Use local version

Using generator is simple to create a basic Webtask function to be used as a test.

npm install -g generate generate-webtask
generate webtask:context
touch .env.dev
wtw-dev create index.js
wtw-dev run index.js

Package Sidebar

Install

npm i wtw

Weekly Downloads

0

Version

0.1.10

License

MIT

Unpacked Size

17.4 kB

Total Files

9

Last publish

Collaborators

  • ildella