Firebase-tools: expand the documentation on how to use firebase-tools as a module

Created on 29 Apr 2017  ·  4Comments  ·  Source: firebase/firebase-tools

A lot of the commands you can do via CLI are very hard to figure out how to do programmatically when loading it as a module. Updated documentation on syntax, available commands, etc, would be helpful.

Questions I have (or had but soluved):

  • how to print a list of all keys using tools.functions.config.get
  • how to deploy functions
  • how to get a list of all functions deployed

note on this one: had to really dig into cloudfunctions.js, api.js and auth.js. turns out this functionality is available inside the package, just not surfaced in firebase-tools. this is really helpful.

docs

Most helpful comment

I'm struggling to get anything working here too.
@SJAnderson Can you post some of your examples here? _Particularly the config get (and set if you have it)_ 🙏

All 4 comments

There is a sample

var client = require('firebase-tools');
client.list().then(function(data) {
  console.log(data);
}).catch(function(err) {
  // handle error
});

But I had to install firebase-tools (without -g) for that to work.

Tried something like this

client.database.get('/app-settings/test').then((data) => {
    console.log(data);
}).catch(function (err) {
    console.log(err);
});

due to the lack of documentation but got this error

TypeError: Cannot create property 'project' on string '/app-settings/test'
    at Command._prepare (/Users/someone/Documents/test/node_modules/firebase-tools/lib/command.js:104:19)

A proper set of samples of using this will be great please.

I'm struggling to get anything working here too.
@SJAnderson Can you post some of your examples here? _Particularly the config get (and set if you have it)_ 🙏

I struggled with this until I dug into the source. So, until we have docs for this I think this works:

  • Arguments are passed in to the function as usual
  • Options (--foo bar) need to be passed in as part of an options object
  • The options object must be passed in as the _last_ argument
  • You always merge global options with the command options
  • The global options are the same as command line but with cwd additionally
  • Commands that have a colon are run as client.<command>.<subcommand>

Examples:

firebase target hosting --project foo
==>
client.target("hosting", { project: foo})

firebase deploy --only hosting  --token $FIREBASE_TOKEN
==>
client.deploy({ only: 'hosting', token: process.env.FIREBASE_TOKEN })

firebase target:apply mytype mytarget
==>
client.target.apply('mytype', 'mytarget')     // No options added!

Also, I don't think you need to add a token option in node code if you have have a process.env.FIREBASE_TOKEN, it loads automatically. HTH

Read more in this file and commands directory:
https://github.com/firebase/firebase-tools/blob/master/src/commands/index.js

@jesperp thanks for your clear and concise explanation! Even as someone who "knows" the answer to this, I will refer to your answer when I forget until we get the docs up.

Was this page helpful?
0 / 5 - 0 ratings