Skip to content

FDC SDK init use the same outputDir pattern for both CLI and VS Code#7790

Merged
fredzqm merged 37 commits intomasterfrom
fz/sdk-init
Oct 7, 2024
Merged

FDC SDK init use the same outputDir pattern for both CLI and VS Code#7790
fredzqm merged 37 commits intomasterfrom
fz/sdk-init

Conversation

@fredzqm
Copy link
Copy Markdown
Contributor

@fredzqm fredzqm commented Oct 6, 2024

Description

Currently, VS Code button configure outputDir to dataconnect-generated under appDir. CLI configures outputDir to generated/${language}/${package}.

I like the idea of the dataconnect-generated as the gen SDK convention. Clear name to remind customers that this is generated by dataconnect. We also should add a sub folder within it to signal language in case there are >1 apps in the folder.

How about dataconnect-generated/{js,swift,kotlin}/${package} as the gen SDK output path to consolidate both ideas?
Note: ${package} is part of outputDir of JS and Dart, but implicitly included for Swift and Kotlin.

Updated the default package generation algorithm based on offline discussions.

  • ConnectorID: default
  • JS: @firebasegen/default-connector
  • Dart: default_connector
  • Android: connectors.default
  • IOS: DefaultConnector

Other bug fixes:

  • Always override the gen SDK config. Previously, we could get in state with old package but new outputDir...
  • Javascript.packageJsonDir is always set to appDir. There is little downside since emulator would ignore it gracefully. We should improve emulator logging though: http://cl/682785528

Scenarios Tested

Added lots of unit tests for each platform. Run with npx mocha src/dataconnect/fileUtils.spec.ts.

Sample Commands

@fredzqm fredzqm changed the title Consolidate FDC SDK init to use a consistent shared output path Consolidate FDC SDK init to use a consistent output path dataconnect-generated/{language} Oct 6, 2024
Comment thread src/init/features/dataconnect/sdk.ts
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Oct 6, 2024

Codecov Report

Attention: Patch coverage is 63.63636% with 8 lines in your changes missing coverage. Please review.

Project coverage is 51.14%. Comparing base (7ab6507) to head (6027a9e).
Report is 7 commits behind head on master.

Files with missing lines Patch % Lines
src/init/features/dataconnect/sdk.ts 63.63% 8 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #7790      +/-   ##
==========================================
+ Coverage   51.12%   51.14%   +0.02%     
==========================================
  Files         418      419       +1     
  Lines       28908    28939      +31     
  Branches     5910     5904       -6     
==========================================
+ Hits        14779    14801      +22     
- Misses      12814    12823       +9     
  Partials     1315     1315              
Flag Coverage Δ
?

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@fredzqm fredzqm changed the title Consolidate FDC SDK init to use a consistent output path dataconnect-generated/{language} FDC SDK init use the same pattern for both CLI and VS Code Oct 6, 2024
@fredzqm fredzqm changed the title FDC SDK init use the same pattern for both CLI and VS Code FDC SDK init use the same outputDir pattern for both CLI and VS Code Oct 6, 2024
@fredzqm fredzqm requested review from hlshen and maneesht October 7, 2024 16:08
const candidateDir = path.join(appDir, candidateSubdir);
if (fs.existsSync(candidateDir)) {
baseDir = candidateDir;
if (dirExistsSync(candidateDir)) {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Had to change this to use the helper because fs.existsSync don't work well work mock-fs

Comment thread src/dataconnect/fileUtils.spec.ts Outdated
Comment thread src/init/features/dataconnect/sdk.ts Outdated
connectorDir,
path.join(appDir, `dataconnect-generated/dart/${snakeCase(connectorYaml.connectorId)}`),
),
package: snakeCase(connectorYaml.connectorId),
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@maneesht brought this up in chat.

default isn't a valid dart package name, but out default connector name is default. Need a better pattern here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated the default package generation algorithm based on offline discussions.

ConnectorID: default
JS: @firebasegen/default-connector
Dart: default_connector
Android: connectors.default # this is fine as-is
IOS: DefaultConnector

@fredzqm
Copy link
Copy Markdown
Contributor Author

fredzqm commented Oct 7, 2024

Updated the default package. Ready for another pass

Comment thread src/dataconnect/types.ts
WEB = "WEB",
IOS = "IOS",
DART = "DART",
FLUTTER = "FLUTTER",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ah, nice catch here

Comment thread src/dataconnect/fileUtils.spec.ts
outputDir,
package: pkg,
packageJsonDir: newConnectorYaml.generate.javascriptSdk?.packageJsonDir,
outputDir: path.relative(connectorDir, path.join(appDir, `dataconnect-generated/js/${pkg}`)),
Copy link
Copy Markdown
Contributor

@maneesht maneesht Oct 7, 2024

Choose a reason for hiding this comment

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

This seems different from the swiftSdk outputDir. Is there a reason for that?

Copy link
Copy Markdown
Contributor Author

@fredzqm fredzqm Oct 7, 2024

Choose a reason for hiding this comment

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

Aim for the same pattern dataconnect-generated/{js,swift,kotlin,dart}/${package} for all platforms.

${package} is part of outputDir of JS and Dart, but implicitly included for Swift and Kotlin.

I considered making JS and Dart automatically include package as well, but am afraid that would be a breaking change.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why would it be a breaking change? Isn't this just for when the user hasn't created a generated SDK for the platform yet?

Comment thread src/dataconnect/fileUtils.spec.ts
@fredzqm fredzqm merged commit 158c2b5 into master Oct 7, 2024
@fredzqm fredzqm deleted the fz/sdk-init branch October 7, 2024 20:51
@fredzqm
Copy link
Copy Markdown
Contributor Author

fredzqm commented Oct 7, 2024

Thanks for the detailed review!

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.

3 participants