-
Notifications
You must be signed in to change notification settings - Fork 952
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
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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!
src/commands/apps-create.ts
Outdated
logPostAppCreationInformation(appData, appPlatform); | ||
return appData; | ||
}, | ||
); | ||
export async function sdkInit(appPlatform: AppPlatform, options: any) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
src/commands/apps-sdkconfig.ts
Outdated
|
||
function checkForApps(apps: AppMetadata[], appPlatform: AppPlatform): void { | ||
export function getSdkOutputPath(appDir: string, platform: Platform): string { |
There was a problem hiding this comment.
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
src/commands/apps-sdkconfig.ts
Outdated
}); | ||
} 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.`, |
There was a problem hiding this comment.
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?
src/commands/apps-sdkconfig.ts
Outdated
appPlatform = appMetadata.platform; | ||
} | ||
const outputDir = path.dirname(outputPath!); | ||
fs.mkdirpSync(outputDir); |
There was a problem hiding this comment.
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
src/commands/apps-sdkconfig.ts
Outdated
} | ||
const outputDir = path.dirname(outputPath!); | ||
fs.mkdirpSync(outputDir); | ||
let sdkConfig: any; |
There was a problem hiding this comment.
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.
src/commands/apps-sdkconfig.ts
Outdated
choices: platforms, | ||
}); | ||
} else if (targetPlatform === Platform.FLUTTER) { | ||
logError( |
There was a problem hiding this comment.
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?
src/commands/apps-sdkconfig.ts
Outdated
if (appPlatform === AppPlatform.WEB) { | ||
fileInfo.sdkConfig = configData; | ||
if (platform === AppPlatform.WEB) { | ||
console.log(` |
There was a problem hiding this comment.
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.
…rebase-tools into mtewani/auto-apps-first-pass
There was a problem hiding this 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!
src/commands/apps-sdkconfig.ts
Outdated
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); |
There was a problem hiding this comment.
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)
src/commands/apps-sdkconfig.ts
Outdated
const skipWrite = options.out === false; | ||
const config = options.config; | ||
const appDir = process.cwd(); | ||
if (!platform) { |
There was a problem hiding this comment.
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)
src/commands/apps-sdkconfig.ts
Outdated
appId = "", | ||
options: AppsSdkConfigOptions, | ||
): Promise<AppConfig> => { | ||
let outputPath: string | undefined = options.out === true ? "" : (options.out as string); |
There was a problem hiding this comment.
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:
let outputPath: string | undefined = options.out === true ? "" : (options.out as string); | |
let outputPath: string | undefined = (options.out || "" ) as string; |
src/commands/apps-sdkconfig.ts
Outdated
import { Options } from "../options"; | ||
import * as path from "path"; |
There was a problem hiding this comment.
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.
src/commands/apps-create.ts
Outdated
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).", |
There was a problem hiding this comment.
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?
…irst-pass' into mtewani/auto-apps-first-pass
Fixed:
AppConfigurationData
whenAppConfig
should've been returned instead.out
and the command attempted to get the default file name, the terminal would outputundefined
and error out. Now the correct output file is specified and used.