npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

worker-setup

v1.5.3

Published

Interactive setup and deployment of pre-made Cloudflare Workers

Downloads

36

Readme

⚠️ Still under development ⚠️

Worker Setup

Node CI Release CI GitHub David

Interactive setup and deployment of pre-made Cloudflare Workers

demo

👋 Introduction

While wrangler generate is meant to generate a completely new worker from an existing template, worker-setup is meant to setup a pre-made Worker like cf-worker-redirect.

The basic wrangler configuration, required KV Namespaces, secrets and environment variables are stored in the workerConfig.toml file. When a user wants to setup your Worker, they can simply run worker-setup deploy and they will be guided through the process of logging in to their account, setting up and deploying the Worker. Required KV Namespaces are automatically created and the user is asked to input all required secrets and environment variables.

⭐ Features

  • Generates ready-to-use wrangler.toml file filled with user specific values like Account/Zone/KV Namespace ID
  • Installs and configures Wrangler (Including authenticating with Cloudflare)
  • Automatically creates required KV Namespaces
  • Prompts the user for required Secrets and Environment Variables (and uploads them)
  • Lets the user choose between deploying to workers.dev or a custom Zone
  • Can dynamically fill wrangler.toml with user specific values using environment variables (useful for CI)

🚀 Get started

Install worker-setup via npm:

npm install worker-setup

See below on how to configure worker-setup for your own Worker.

📚 Usage

Run worker-setup help to see all available commands and options.

Here's an overview of the available commands:

Deploy

worker-setup deploy

Will start the interactive deployment process. You will be asked to login with Cloudflare if not already logged in. Required KV Namespaces are automatically created and you are asked to input all required secrets and environment variables. The final wrangler.toml will be generated from the template.

Generate

worker-setup generate

Will use a local workerConfig.toml and environment variables/.env file to generate a wrangler.toml (useful for CI purposes).

Login

worker-setup login

Will authenticate Wrangler with Cloudflare, either via the browser or by specifying an API token.

Migrate

worker-setup migrate

Will migrate your old wrangler.toml to a new workerConfig.toml by removing all personal fields, like account/zone id as well as the ids for kv_namespaces and values for environment variables and adding wrangler.toml to your .gitignore file. All other options will be transfered to the new config.

🛠️ Setup

worker-setup uses a workerConfig.toml file which replaces your normal wrangler.toml. It supports everything you normally put into your wrangler.toml file as well as more (see below).

If you have an existing wrangler.toml, run the following to generate a new workerConfig.toml from your config:

worker-setup migrate

If not, create a new workerConfig.toml file and fill it with your normal Wrangler configuration options manually.

If your Worker uses Workers KV or requires secrets/environment variables add the binding/keys as well.

When you run worker-setup deploy, worker-setup will use the workerConfig.toml file to know what your Worker needs and asks the user to input the required values, as well as create the required KV Namespaces. Once everything is done, it will output a normal wrangler.toml file and deploy the worker with wrangler.

⚙️ Configuration

The workerConfig.toml file supports the following configuration options:

| Key | Description | Required | | ------------- | ------------- | ------------- | | name | The default name of your Worker (can be changed by the user during setup) | Yes | | type | Specifies how wrangler build will build your project. | Yes | | webpack_config | This is the path to a custom webpack configuration file for your worker. | No | | site | Determines the local folder to upload and serve from a Worker | No | | usage_model | Specifies the Usage Model for your Worker. | No | | ​triggers | Configures cron triggers for executing a Worker on a schedule | No | | dev | Arguments for wrangler dev, configure local server | No | | ​build | Allows configuring a custom build step to be run by wrangler when building your worker. | No |

See wrangler's docs for more info on each option.

As well as these additional options:

| Key | Description | Required | Example | | ------------- | ------------- | ------------- | ------------- | | kv_namespaces | Specify the required KV namespace bindings (will be created during setup) | No | [ "EXAMPLE_KV" ] | | secrets | Specify the required secrets (user will be asked to input during setup) | No | [ "EXAMPLE_SECRET" ] | | variables | Specify the required plain-text variables (user will be asked to input during setup) | No | [ "EXAMPLE_VARIABLE" ] | | recommended_route | A recommended route to be used with the Worker (will be shown to user) | No | "*example.com/test" | | instructions | Specify additional instructions to be printed after deploying the worker | No | Learn how to use the Worker at example.com |

📖 Examples

Here are a few examples to help you get started!

📝 Intructions for your README

Here are example intructions you can use in the README for your Worker:


If you want to deploy this Worker yourself, clone this repo and cd into it:

git clone https://github.com/betahuhn/cf-worker-redirect && cd cf-worker-redirect

Next start the interactive deployment process:

worker-setup deploy

You will be asked to login to Cloudflare if not already authenticated. The programm will guide you through the process of setting up and deploying the Worker under your own Cloudflare Account.


💻 Development

  • run yarn lint or npm run lint to run eslint.
  • run npm link to setup the program for development.
  • run yarn build or npm run build to produce a compiled version in the dist folder.

❔ About

This project was developed by me (@betahuhn) in my free time. If you want to support me:

Donate via PayPal

ko-fi

worker-setup is in no way affiliated with Cloudflare.

📄 License

Copyright 2021 Maximilian Schiller

This project is licensed under the MIT License - see the LICENSE file for details.