3

Is there a way to deploy functions to different firebase projects listed inside .firebaserc with a single command?

I have this sample .firebaserc

{
  "projects": {
    "default": "project1",
    "project2": "project2-abcd"
  }
}

When updating functions, I do:

firebase use default && firebase deploy && firebase use project2 && firebase deploy

If I have tons of projects, the command gets longer so I made a node script that automates deploying to all projects listed in .firebaserc:

const { promisify } = require("util");

const exec = promisify(require("child_process").exec);
const readFile = promisify(require("fs").readFile);

const deploy = async () => {
  try {
    const data = await readFile("./.firebaserc", "utf-8");
    const projects = Object.keys(JSON.parse(data).projects);

    for (const proj of projects) {
      console.log(`Deploying functions to ${proj}...`);
      const { stdout, stderr } = await exec(
        `firebase use ${proj} && firebase deploy`
      );

      console.log("stdout:", stdout);
      console.log("stderr:", stderr);
    }
  } catch (e) {
    console.log(e);
  }
};

deploy();

which works but I'm trying to look for an alternative if there is one.

wobsoriano
  • 12,348
  • 24
  • 92
  • 162

1 Answers1

0

Could you use the --project flag?

ex. firebase deploy --project=project2

See https://firebase.google.com/docs/cli#use_aliases .

If you want to run a single command against the Firebase project that you've assigned the prod alias, then you can run, for example, firebase deploy --project=prod.

Updated

Do you want to deploy all projects listed inside .firebaserc?

It may be possible to use like a following one-liner command.

ex.

cat .firebaserc | jq '.projects | keys | .[]' | xargs -I {} firebase deploy --project={}

See:

zkohi
  • 2,486
  • 1
  • 10
  • 20