Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First pass at auto generating sdk configs #7833

Open
wants to merge 19 commits into
base: master
Choose a base branch
from

Conversation

maneesht
Copy link
Contributor

@maneesht maneesht commented Oct 14, 2024

Fixed:

  • Return type. Originally the return type was set to AppConfigurationData when AppConfig should've been returned instead.
  • When file name is not specified via out and the command attempted to get the default file name, the terminal would output undefined and error out. Now the correct output file is specified and used.

Copy link
Contributor

@joehan joehan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some small stuff around typing & where helper functions live, but this is mostly LGTM!

logPostAppCreationInformation(appData, appPlatform);
return appData;
},
);
export async function sdkInit(appPlatform: AppPlatform, options: any) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would prefer to move this to a separate file - I like to keep these command files as lean as possible and only export the command itself.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, please use the Options type instead of any here too

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we move everything into a new file? Also, we should put that info somewhere, I think other commands have other functions besides just the Command


function checkForApps(apps: AppMetadata[], appPlatform: AppPlatform): void {
export function getSdkOutputPath(appDir: string, platform: Platform): string {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as above - prefer to put this in a separate file than the command

});
} else if (targetPlatform === Platform.FLUTTER) {
logError(
`Flutter is not supported by apps:sdkconfig. Please install the flutterfire CLI and run "flutterfire configure" to set up firebase for your flutter app.`,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Include a link to the flutterfire getting started docs?

appPlatform = appMetadata.platform;
}
const outputDir = path.dirname(outputPath!);
fs.mkdirpSync(outputDir);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL about mkdirp - we probably ought to use it in quite a few other places

}
const outputDir = path.dirname(outputPath!);
fs.mkdirpSync(outputDir);
let sdkConfig: any;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If possible, use a stronger type than any here.

choices: platforms,
});
} else if (targetPlatform === Platform.FLUTTER) {
logError(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Double checking this behavior - what happens after this logging? Should we error out/return instead?

if (appPlatform === AppPlatform.WEB) {
fileInfo.sdkConfig = configData;
if (platform === AppPlatform.WEB) {
console.log(`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use logger.log() or logger.info() instead - console.log circumvents some verbosity/VSCode specific log handling we have in place.

Copy link
Contributor

@joehan joehan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made a driveby type cleanup commit, and a few other nitty things, but LGTM!

sdkConfig = await getSdkConfig(options, getAppPlatform(platform), appId);
} catch (e) {
if ((e as Error).message.includes("associated with this Firebase project")) {
await sdkInit(platform as unknown as AppPlatform, options);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this type washing is now unnecessary (since you strongly typed platform in all locations afaict)

const skipWrite = options.out === false;
const config = options.config;
const appDir = process.cwd();
if (!platform) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this ever hit? I don't think AppPlatform.PLATFORM_UNSPECIFIED is falsey (since its a string enum). Feels like this should maybe be if (platform === AppPlatform.PLATFORM_UNSPECIFIED)

appId = "",
options: AppsSdkConfigOptions,
): Promise<AppConfig> => {
let outputPath: string | undefined = options.out === true ? "" : (options.out as string);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You called it out in the comment above, but this is extremely code smelly. Consider something like:

Suggested change
let outputPath: string | undefined = options.out === true ? "" : (options.out as string);
let outputPath: string | undefined = (options.out || "" ) as string;

import { Options } from "../options";
import * as path from "path";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: prefer grouping this with the other external imports at the top of the file.

throw err;
}
}

export const command = new Command("apps:create [platform] [displayName]")
.description(
"create a new Firebase app. [platform] can be IOS, ANDROID or WEB (case insensitive).",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While you're here, could you add a type for options on this command as well?

@maneesht maneesht marked this pull request as ready for review October 22, 2024 18:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants