Firebase-tools: setup.web() doesn't work anymore in 8.*

Created on 9 Apr 2020  路  9Comments  路  Source: firebase/firebase-tools



This Firebase blog post no longer works because setup.web() function was removed in the 8.0.0 release

What is the correct way to get firebase config variables now that setup.web() has been removed?

[REQUIRED] Environment info

firebase-tools:

8.0.2

Platform:

Windows

[REQUIRED] Test case

[REQUIRED] Steps to reproduce

[REQUIRED] Expected behavior

[REQUIRED] Actual behavior

[REQUIRED] Environment info

firebase-tools:

Platform:

[REQUIRED] Test case

[REQUIRED] Steps to reproduce

[REQUIRED] Expected behavior

[REQUIRED] Actual behavior

All 9 comments

This issue does not have all the information required by the template. Looks like you forgot to fill out some sections. Please update the issue with more information.

This isn't a bug. You removed the functionality.

My suggestion is to remove the blog post referenced above.

@jkarst the firebase apps:sdkconfig command is what you're looking for, thanks for calling this out!

Hi @samtstern , thank you but I'm looking for the equivalent command in code, not the CLI command.

So, whatever is supposed to replace setup.web()

E.g.:

const fbcli = require('firebase-tools')

// by default, uses the current project and logged in user
fbcli.setup.web().then(config => {
console.log(config)
})

Any ideas?

@jkarst the commands are the same, when you import the CLI as a Node module you're just getting the same commands in a different form.

So:

fbcli.apps.sdkconfig({ ... }).then(...)

This guide will tell you a bit more about how to translate CLI commands to node:
https://github.com/firebase/firebase-tools#using-as-a-module

Hi @samtstern, I don't think that's working right.

When I do:

var client = require("firebase-tools");
client
  .apps.sdkconfig()
  .then(function(data) {
    console.log(data);
  })
  .catch(function(err) {
    console.log(err)
  });

I get this:

TypeError: platform.toUpperCase is not a function
    at Object.getAppPlatform (C:\p\fates\node_modules\firebase-tools\lib\management\apps.js:31:22)

Which makes sense because I didn't specify the platform, as I would using the command line.

So if I try:

client.apps.sdkconfig('web')

I get this:

TypeError: Cannot create property 'project' on string 'web'
    at Command.prepare (C:\p\fates\node_modules\firebase-tools\lib\command.js:104:25)

It looks like it's expecting an object. When I try:

client.apps.sdkconfig({ platform: 'web' })

I get this again:

TypeError: platform.toUpperCase is not a function
    at Object.getAppPlatform (C:\p\fates\node_modules\firebase-tools\lib\management\apps.js:31:22)

In app.js, the error is here:

function getAppPlatform(platform) {
    switch (platform.toUpperCase()) {

It's expecting a string.

But in lib/commands/apps-sdkconfig.js where it is called, the sdkconfig function is passing an object

module.exports = new command_1.Command("apps:sdkconfig [platform] [appId]")
    .description("print the Google Services config of a Firebase app. " +
    "[platform] can be IOS, ANDROID or WEB (case insensitive)")
    .option("-o, --out [file]", "(optional) write config output to a file")
    .before(requireAuth_1.requireAuth)
    .action((platform = "", appId = "", options) => __awaiter(void 0, void 0, void 0, function* () {
    let appPlatform = apps_1.getAppPlatform(platform);

Whatever I pass in the sdkadmin() function, the properties are added to the platform object.

I don't see see how this could ever work. But maybe I'm doing something obviously wrong. Please advise?

The signature of the function is: sdkconfig(platform: string, appId: string, options: { project: string }) (roughly, you get the idea about options).

I added a test in commit c5ca576 (that I'm making a PR for, since it's written) that demonstrates this usage.

Thanks @bkendall !

@jkarst check out the example here:
https://github.com/firebase/firebase-tools/pull/2130

Thanks guys! I really appreciate the attention and effort here.

I've been able to rebuild my old workflow using this:

const client = require('firebase-tools')

client.use(null, {projectRoot: __dirname})
.then(projectId  => client.apps.list('web', {project: projectId}))
.then(apps => client.apps.sdkconfig('web', apps[0].appId, { project: apps[0].projectId}))
.then(config => {
    // do build stuff with this
    console.log(config.sdkConfig)
})
.catch(error => console.log(error))

Super basic, but something that can be built from for whatever your setup is.

Was this page helpful?
0 / 5 - 0 ratings