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

Added dart to firebase CLI #7569

Merged
merged 9 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/commands/dataconnect-sdk-generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import { load } from "../dataconnect/load";
import { readFirebaseJson } from "../dataconnect/fileUtils";
import { logger } from "../logger";
import * as experiments from "../experiments";

Check failure on line 10 in src/commands/dataconnect-sdk-generate.ts

View workflow job for this annotation

GitHub Actions / unit (18)

'experiments' is defined but never used

Check failure on line 10 in src/commands/dataconnect-sdk-generate.ts

View workflow job for this annotation

GitHub Actions / lint (20)

'experiments' is defined but never used

Check failure on line 10 in src/commands/dataconnect-sdk-generate.ts

View workflow job for this annotation

GitHub Actions / unit (18)

'experiments' is defined but never used
Copy link
Contributor

Choose a reason for hiding this comment

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

Unused, remove.


export const command = new Command("dataconnect:sdk:generate")
.description("generates typed SDKs for your Data Connect connectors")
Expand All @@ -21,7 +22,8 @@
return (
c.connectorYaml.generate?.javascriptSdk ||
c.connectorYaml.generate?.kotlinSdk ||
c.connectorYaml.generate?.swiftSdk
c.connectorYaml.generate?.swiftSdk ||
c.connectorYaml.generate?.dartSdk
);
});
if (!hasGeneratables) {
Expand Down
38 changes: 38 additions & 0 deletions src/dataconnect/fileUtils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,31 @@ describe("getPlatformFromFolder", () => {
},
output: Platform.IOS,
},
{
desc: "Dart identifier 1",
folderName: "is/this/a/dart/test",
folderItems: {
file1: "contents",
"pubspec.yaml": "my deps",
},
output: Platform.DART,
},
{
desc: "Dart identifier 2",
folderName: "is/this/a/dart/test",
folderItems: {
"pubspec.lock": "my deps",
},
output: Platform.DART,
},
{
desc: "Dart identifier with experiment disabled",
folderName: "is/this/a/dart/test",
folderItems: {
"pubspec.mispelled": "my deps",
},
output: Platform.UNDETERMINED,
},
{
desc: "multiple identifiers, returns undetermined",
folderName: "test/",
Expand Down Expand Up @@ -157,6 +182,19 @@ describe("generateSdkYaml", () => {
});
});

it("should add Dart SDK generation for DART platform", () => {
const modifiedYaml = generateSdkYaml(
Platform.DART,
sampleConnectorYaml,
connectorYamlFolder,
appFolder,
);
expect(modifiedYaml.generate?.dartSdk).to.deep.equal({
outputDir: "../dataconnect-generated",
package: "test_connector",
});
});

it("should create generate object if it doesn't exist", () => {
const yamlWithoutGenerate: ConnectorYaml = { connectorId: "test_connector" };
const modifiedYaml = generateSdkYaml(
Expand Down
18 changes: 15 additions & 3 deletions src/dataconnect/fileUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
const WEB_INDICATORS = ["package.json", "package-lock.json", "node_modules"];
const IOS_INDICATORS = ["info.plist", "podfile", "package.swift"];
const ANDROID_INDICATORS = ["androidmanifest.xml", "build.gradle", "build.gradle.kts"];
const DART_INDICATORS = ["pubspec.yaml", "pubspec.lock"];

// endswith match
const IOS_POSTFIX_INDICATORS = [".xcworkspace", ".xcodeproj"];
Expand All @@ -123,20 +124,25 @@
let hasWeb = false;
let hasAndroid = false;
let hasIOS = false;
let hasDart = false;
for (const fileName of fileNames) {
const cleanedFileName = fileName.toLowerCase();
hasWeb ||= WEB_INDICATORS.some((indicator) => indicator === cleanedFileName);
hasAndroid ||= ANDROID_INDICATORS.some((indicator) => indicator === cleanedFileName);
hasIOS ||=
IOS_INDICATORS.some((indicator) => indicator === cleanedFileName) ||
IOS_POSTFIX_INDICATORS.some((indicator) => cleanedFileName.endsWith(indicator));
hasDart ||=

Check failure on line 135 in src/dataconnect/fileUtils.ts

View workflow job for this annotation

GitHub Actions / unit (18)

Delete `⏎·····`

Check failure on line 135 in src/dataconnect/fileUtils.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Delete `⏎·····`

Check failure on line 135 in src/dataconnect/fileUtils.ts

View workflow job for this annotation

GitHub Actions / unit (18)

Delete `⏎·····`
DART_INDICATORS.some((indicator) => indicator === cleanedFileName);
}
if (hasWeb && !hasAndroid && !hasIOS) {
if (hasWeb && !hasAndroid && !hasIOS && !hasDart) {
return Platform.WEB;
} else if (hasAndroid && !hasWeb && !hasIOS) {
} else if (hasAndroid && !hasWeb && !hasIOS && !hasDart) {
return Platform.ANDROID;
} else if (hasIOS && !hasWeb && !hasAndroid) {
} else if (hasIOS && !hasWeb && !hasAndroid && !hasDart) {
return Platform.IOS;
} else if (hasDart && !hasWeb && !hasIOS && !hasAndroid) {
return Platform.DART;
}
// At this point, its not clear which platform the app directory is
// (either because we found no indicators, or indicators for multiple platforms)
Expand Down Expand Up @@ -179,5 +185,11 @@
package: `connectors.${connectorYaml.connectorId}`,
};
}
if (platform === Platform.DART) {
connectorYaml.generate.dartSdk = {
outputDir,
package: connectorYaml.connectorId,
};
}
return connectorYaml;
}
6 changes: 6 additions & 0 deletions src/dataconnect/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ export interface Generate {
javascriptSdk?: JavascriptSDK;
swiftSdk?: SwiftSDK;
kotlinSdk?: KotlinSDK;
dartSdk?: DartSDK;
}

export interface JavascriptSDK {
Expand All @@ -148,11 +149,16 @@ export interface KotlinSDK {
outputDir: string;
package: string;
}
export interface DartSDK {
outputDir: string;
package: string;
}

export enum Platform {
ANDROID = "ANDROID",
WEB = "WEB",
IOS = "IOS",
DART = "DART",
UNDETERMINED = "UNDETERMINED",
}

Expand Down
1 change: 1 addition & 0 deletions src/emulator/dataconnectEmulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@
`--config_dir=${args.configDir}`,
`--connector_id=${args.connectorId}`,
];

Check failure on line 187 in src/emulator/dataconnectEmulator.ts

View workflow job for this annotation

GitHub Actions / unit (18)

Delete `····`

Check failure on line 187 in src/emulator/dataconnectEmulator.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Delete `····`

Check failure on line 187 in src/emulator/dataconnectEmulator.ts

View workflow job for this annotation

GitHub Actions / unit (18)

Delete `····`
const res = childProcess.spawnSync(commandInfo.binary, cmd, { encoding: "utf-8" });

logger.info(res.stderr);
Expand Down
1 change: 0 additions & 1 deletion src/experiments.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { bold, italic } from "colorette";
import * as leven from "leven";
import { basename } from "path";

import { configstore } from "./configstore";
import { FirebaseError } from "./error";
import { isRunningInGithubAction } from "./init/features/hosting/github";
Expand Down
29 changes: 24 additions & 5 deletions src/init/features/dataconnect/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import {
ConnectorInfo,
ConnectorYaml,
DartSDK,
JavascriptSDK,
KotlinSDK,
Platform,
Expand All @@ -23,6 +24,7 @@
import { FirebaseError } from "../../../error";
import { camelCase, snakeCase, upperFirst } from "lodash";
import { logSuccess, logBullet } from "../../../utils";
import * as experiments from "../../../experiments";

Check failure on line 27 in src/init/features/dataconnect/sdk.ts

View workflow job for this annotation

GitHub Actions / unit (18)

'experiments' is defined but never used

Check failure on line 27 in src/init/features/dataconnect/sdk.ts

View workflow job for this annotation

GitHub Actions / lint (20)

'experiments' is defined but never used

Check failure on line 27 in src/init/features/dataconnect/sdk.ts

View workflow job for this annotation

GitHub Actions / unit (18)

'experiments' is defined but never used
Copy link
Contributor

Choose a reason for hiding this comment

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

Unused?


export type SDKInfo = {
connectorYamlContents: string;
Expand Down Expand Up @@ -87,14 +89,16 @@
} else {
// If we still can't autodetect, just ask the user
logBullet("Couldn't automatically detect your app's platform.");
const platforms = [
{ name: "iOS (Swift)", value: Platform.IOS },
{ name: "Web (JavaScript)", value: Platform.WEB },
{ name: "Android (Kotlin)", value: Platform.ANDROID },
{ name: "Flutter (Dart)", value: Platform.DART },
];
targetPlatform = await promptOnce({
message: "Which platform do you want to set up a generated SDK for?",
type: "list",
choices: [
{ name: "iOS (Swift)", value: Platform.IOS },
{ name: "Web (JavaScript)", value: Platform.WEB },
{ name: "Android (Kotlin)", value: Platform.ANDROID },
],
choices: platforms,
});
}
}
Expand Down Expand Up @@ -144,6 +148,21 @@
newConnectorYaml.generate.javascriptSdk = javascriptSdk;
}

if (targetPlatform === Platform.DART) {
const outputDir =
newConnectorYaml.generate.dartSdk?.outputDir ||
path.relative(
connectorInfo.directory,
path.join(appDir, `generated/dart/${newConnectorYaml.connectorId}`),
);
const pkg = newConnectorYaml.generate.dartSdk?.package ?? newConnectorYaml.connectorId;
const dartSdk: DartSDK = {
outputDir,
package: pkg,
};
newConnectorYaml.generate.dartSdk = dartSdk;
}

if (targetPlatform === Platform.ANDROID) {
// app/src/main/kotlin and app/src/main/java are conventional for Android,
// but not required or enforced. If one of them is present (preferring the
Expand Down
Loading