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

google-functions-deploy

v0.0.2

Published

Deploys Google Cloud functions from multiple subdirectories.

Downloads

2

Readme

Google Functions Deploy

A node.js CLI that allows users to deploy multiple Google Cloud functions (in separate folders) using a single command.

Background

A while back, I migrated several cloud functions from Netlify to the Google Cloud platform and noticed that the Google Cloud CLI (gcloud command) requires that developers execute a separate deployment command for each function deployment.

My project had three functions and I wanted a way to deploy all three with a single command. In Google Cloud Multiple Functions in a Project I described how I added code to my project that allowed me to easily do this using Google zx as an execution helper.

In an effort to make that code easier to use across multiple project, I decided to make a node-based CLI that allows me to easily execute batch deploying across multiple Google Cloud Functions projects. This version of the code uses Execa to manage spawning external processes.

To use this module, install it globally then add a simple (automatically generated by the module) configuration file to the project folder. With the correct configuration in place, you can deploy all cloud functions in a project folder using the single gfdeploy command.

Installation

To install the command, open a terminal window, then execute the following command:

npm install -g google-functions-deploy

Note: You should not need to use sudo on linux or macOS to install the module. If you find that you need to or want to, instead go back and fix permissions for your local node.js installation and try it again.

The module adds a gfdeploy command you can use in any Google Cloud Functions project to deploy a function or group of functions in a single command - without requiring any command-line parameters.

Usage

Configuration

The module requires a configuration file, so on first run it will offer to create it for you. To configure the module, open a terminal window in the Google Cloud Functions project then execute the following command:

gfdeploy

Here's an example of automated configuration console output:

┌──────────────────────────────┐
│                              │
│   Deploy Google Functions    │
│                              │
└──────────────────────────────┘
by John M. Wargo (https://johnwargo.com)
Configuration path: D:\dev\node\google-functions-deploy\gfdeploy.json

Configuration file missing:
Rather than requiring the use of a bunch of command-line arguments, this tool uses a configuration file instead.
In the next step, the module will automatically create the configuration file for you.
Once it completes, you can edit the configuration file to change the default values and execute the command again.

√ Create configuration file? ... yes
√ Use default flags? ... yes
√ Select one or more function folders to deploy: » Function1, Function2, Function3

Writing configuration file D:\dev\node\google-functions-deploy\gfdeploy.json
Output file written successfully

Open D:\dev\node\google-functions-deploy\gfdeploy.json in an editor to modify configuration settings.

If you run the command in a terminal window inside Visual Studio Code, the module will open the file in the editor after creating the file.

You can also skip that process altogether and create the file manually. To do that, create a file in the project root called gfdeploy.json and populate it with two JSON arrays: functionFolders and flags as shown in the example below:

{
  "functionFolders": [],
  "flags": []
}

The following table describes each configuration option:

| Configuration Array | Description | | ------------------- | ----------- | | functionFolders | The array of sub-folders that contain Google Cloud Functions functions. Each folder represents a single function. | | flags | The array of gcloud functions deploy command-line arguments required to successfully deploy the function to Google's cloud platform. The module will automatically populate the function name in the command. |

Here's an example of a configuration file populated with configuration information for three functions (Function1, Function2, and Function3) deployed to us-east1 using node.js version 20 with an HTTP trigger allowing unauthenticated access:

{
  "functionFolders": [
    "Function1",
    "Function2",
    "Function3"
  ],
  "flags": [
    "--region=us-east1",
    "--runtime=nodejs20",
    "--trigger-http",
    "--allow-unauthenticated"
  ]
}

Note: The options in the flags array shown in the previous example are the default flags used when you answer Yes to the "Use default flags?" prompt.

The gcloud functions deploy command supports a wide selection of command-line options, refer to the product documentation for information about all of the available options. Rather than code support for every command-line option, all you have to do is populate the flags array with the appropriate settings for your particular project and the module takes care of passing them to the gcloud command.

Function Deployment

With a populated configuration in place, to deploy all of the functions in a project to Google Cloud Functions, open a terminal window in the project folder and execute the following command:

gfdeploy

At this point, the module loops through all the folders listed in the functionsFolders array, and executes the deployment command for each, writing all output to the console as it completes the task.


If this code helps you, please consider buying me a coffee.