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):
tools.functions.config.get
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.
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:
cwd
additionallyclient.<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.
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)_ 🙏