Skip to content

Commit 1f34e98

Browse files
committed
Responded to code review comments
1 parent 37dcd11 commit 1f34e98

File tree

6 files changed

+56
-188
lines changed

6 files changed

+56
-188
lines changed

src/appUtils.spec.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -255,39 +255,39 @@ describe("appUtils", () => {
255255

256256
it("should return WEB if package.json exists", async () => {
257257
fs.outputFileSync(`${testDir}/package.json`, "{}");
258-
const platform = await getPlatformsFromFolder(testDir);
259-
expect(platform).to.have.deep.members([Platform.WEB]);
258+
const platforms = await getPlatformsFromFolder(testDir);
259+
expect(platforms).to.have.deep.members([Platform.WEB]);
260260
});
261261

262262
it("should return ANDROID if src/main exists", async () => {
263263
fs.mkdirpSync(`${testDir}/src/main`);
264-
const platform = await getPlatformsFromFolder(testDir);
265-
expect(platform).to.have.deep.members([Platform.ANDROID]);
264+
const platforms = await getPlatformsFromFolder(testDir);
265+
expect(platforms).to.have.deep.members([Platform.ANDROID]);
266266
});
267267

268268
it("should return IOS if .xcodeproj exists", async () => {
269269
fs.mkdirpSync(`${testDir}/a.xcodeproj`);
270-
const platform = await getPlatformsFromFolder(testDir);
271-
expect(platform).to.have.deep.members([Platform.IOS]);
270+
const platforms = await getPlatformsFromFolder(testDir);
271+
expect(platforms).to.have.deep.members([Platform.IOS]);
272272
});
273273

274274
it("should return FLUTTER if pubspec.yaml exists", async () => {
275275
fs.outputFileSync(`${testDir}/pubspec.yaml`, "name: test");
276-
const platform = await getPlatformsFromFolder(testDir);
277-
expect(platform).to.have.deep.members([Platform.FLUTTER]);
276+
const platforms = await getPlatformsFromFolder(testDir);
277+
expect(platforms).to.have.deep.members([Platform.FLUTTER]);
278278
});
279279

280280
it("should return FLUTTER and WEB if both identifiers exist", async () => {
281281
fs.outputFileSync(`${testDir}/package.json`, "{}");
282282
fs.outputFileSync(`${testDir}/pubspec.yaml`, "name: test");
283-
const platform = await getPlatformsFromFolder(testDir);
284-
expect(platform).to.have.deep.members([Platform.FLUTTER, Platform.WEB]);
283+
const platforms = await getPlatformsFromFolder(testDir);
284+
expect(platforms).to.have.deep.members([Platform.FLUTTER, Platform.WEB]);
285285
});
286286

287287
it("should return NONE if no identifiers exist", async () => {
288288
fs.mkdirpSync(testDir);
289-
const platform = await getPlatformsFromFolder(testDir);
290-
expect(platform).to.have.deep.members([Platform.NONE]);
289+
const platforms = await getPlatformsFromFolder(testDir);
290+
expect(platforms).to.be.empty;
291291
});
292292
});
293293

src/appUtils.ts

Lines changed: 15 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { PackageJSON } from "./frameworks/compose/discover/runtime/node";
77
* Supported application platforms.
88
*/
99
export enum Platform {
10-
NONE = "NONE",
1110
ANDROID = "ANDROID",
1211
WEB = "WEB",
1312
IOS = "IOS",
@@ -50,33 +49,7 @@ export function appDescription(a: App): string {
5049
*/
5150
export async function getPlatformsFromFolder(dirPath: string): Promise<Platform[]> {
5251
const apps = await detectApps(dirPath);
53-
const hasWeb = apps.some((app) => app.platform === Platform.WEB);
54-
const hasAndroid = apps.some((app) => app.platform === Platform.ANDROID);
55-
const hasIOS = apps.some((app) => app.platform === Platform.IOS);
56-
const hasDart = apps.some((app) => app.platform === Platform.FLUTTER);
57-
58-
if (!hasWeb && !hasAndroid && !hasIOS && !hasDart) {
59-
return [Platform.NONE];
60-
}
61-
62-
const platforms = [];
63-
if (hasWeb) {
64-
platforms.push(Platform.WEB);
65-
}
66-
67-
if (hasAndroid) {
68-
platforms.push(Platform.ANDROID);
69-
}
70-
71-
if (hasIOS) {
72-
platforms.push(Platform.IOS);
73-
}
74-
75-
if (hasDart) {
76-
platforms.push(Platform.FLUTTER);
77-
}
78-
79-
return platforms;
52+
return [...new Set(apps.map((app) => app.platform))];
8053
}
8154

8255
/**
@@ -110,7 +83,7 @@ export async function detectApps(dirPath: string): Promise<App[]> {
11083
return [...webApps, ...flutterApps, ...androidApps, ...iosApps];
11184
}
11285

113-
async function processIosDir(dirPath: string, filePath: string) {
86+
async function processIosDir(dirPath: string, filePath: string): Promise<App[]> {
11487
// Search for apps in the parent directory
11588
const iosDir = path.dirname(filePath);
11689
const iosAppIds = await detectAppIdsForPlatform(dirPath, Platform.IOS);
@@ -133,7 +106,7 @@ async function processIosDir(dirPath: string, filePath: string) {
133106
return iosApps.flat();
134107
}
135108

136-
async function processAndroidDir(dirPath: string, filePath: string) {
109+
async function processAndroidDir(dirPath: string, filePath: string): Promise<App[]> {
137110
// Search for apps in the parent directory, not in the src/main directory
138111
const androidDir = path.dirname(path.dirname(filePath));
139112
const androidAppIds = await detectAppIdsForPlatform(dirPath, Platform.ANDROID);
@@ -158,7 +131,7 @@ async function processAndroidDir(dirPath: string, filePath: string) {
158131
return androidApps.flat();
159132
}
160133

161-
async function processFlutterDir(dirPath: string, filePath: string) {
134+
async function processFlutterDir(dirPath: string, filePath: string): Promise<App[]> {
162135
const flutterDir = path.dirname(filePath);
163136
const flutterAppIds = await detectAppIdsForPlatform(dirPath, Platform.FLUTTER);
164137

@@ -193,7 +166,7 @@ function isPathInside(parent: string, child: string): boolean {
193166

194167
async function packageJsonToWebApp(dirPath: string, packageJsonFile: string): Promise<App> {
195168
const fullPath = path.join(dirPath, packageJsonFile);
196-
const packageJson = JSON.parse((await fs.readFile(fullPath)).toString());
169+
const packageJson = JSON.parse((await fs.readFile(fullPath)).toString()) as PackageJSON;
197170
return {
198171
platform: Platform.WEB,
199172
directory: path.dirname(packageJsonFile),
@@ -214,6 +187,8 @@ async function detectAppIdsForPlatform(
214187
let appIdFiles;
215188
let extractFunc: (fileContent: string) => AppIdentifier[];
216189
switch (platform) {
190+
// Leaving web out of the mix for now because we have no strong conventions
191+
// around where to put Firebase config. It could be anywhere in your codebase.
217192
case Platform.ANDROID:
218193
appIdFiles = await detectFiles(dirPath, "google-services*.json*");
219194
extractFunc = extractAppIdentifiersAndroid;
@@ -244,23 +219,25 @@ function getFrameworksFromPackageJson(packageJson: PackageJSON): Framework[] {
244219
const dependencies = Object.keys(packageJson.dependencies ?? {});
245220
const allDeps = Array.from(new Set([...devDependencies, ...dependencies]));
246221
return WEB_FRAMEWORKS.filter((framework) =>
247-
WEB_FRAMEWORKS_SIGNALS[framework]!.find((dep) => allDeps.includes(dep)),
222+
WEB_FRAMEWORKS_SIGNALS[framework].find((dep) => allDeps.includes(dep)),
248223
);
249224
}
250225

251226
/**
252227
* Reads a firebase_options.dart file and extracts all appIds and bundleIds.
253228
* @param fileContent content of the dart file.
254-
* @returns a list of appIds and bundleIds.
229+
* @return a list of appIds and bundleIds.
255230
*/
256231
export function extractAppIdentifiersFlutter(fileContent: string): AppIdentifier[] {
257232
const optionsRegex = /FirebaseOptions\(([^)]*)\)/g;
233+
const appIdRegex = /appId: '([^']*)'/;
234+
const bundleIdRegex = /iosBundleId: '([^']*)'/;
258235
const matches = fileContent.matchAll(optionsRegex);
259236
const identifiers: AppIdentifier[] = [];
260237
for (const match of matches) {
261238
const optionsContent = match[1];
262-
const appIdMatch = optionsContent.match(/appId: '([^']*)'/);
263-
const bundleIdMatch = optionsContent.match(/iosBundleId: '([^']*)'/);
239+
const appIdMatch = appIdRegex.exec(optionsContent);
240+
const bundleIdMatch = bundleIdRegex.exec(optionsContent);
264241
if (appIdMatch?.[1]) {
265242
identifiers.push({
266243
appId: appIdMatch[1],
@@ -275,7 +252,7 @@ export function extractAppIdentifiersFlutter(fileContent: string): AppIdentifier
275252
/**
276253
* Reads a GoogleService-Info.plist file and extracts the GOOGLE_APP_ID and BUNDLE_ID.
277254
* @param fileContent content of the plist file.
278-
* @returns The GOOGLE_APP_ID and BUNDLE_ID or an empty array.
255+
* @return The GOOGLE_APP_ID and BUNDLE_ID or an empty array.
279256
*/
280257
export function extractAppIdentifierIos(fileContent: string): AppIdentifier[] {
281258
const appIdRegex = /<key>GOOGLE_APP_ID<\/key>\s*<string>([^<]*)<\/string>/;
@@ -296,7 +273,7 @@ export function extractAppIdentifierIos(fileContent: string): AppIdentifier[] {
296273
/**
297274
* Reads a google-services.json file and extracts all mobilesdk_app_id and package_name values.
298275
* @param fileContent content of the google-services.json file.
299-
* @returns a list of mobilesdk_app_id and package_name values.
276+
* @return a list of mobilesdk_app_id and package_name values.
300277
*/
301278
export function extractAppIdentifiersAndroid(fileContent: string): AppIdentifier[] {
302279
const identifiers: AppIdentifier[] = [];

src/dataconnect/appFinder.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,16 @@ export function appDescription(a: App): string {
2323
export async function getPlatformFromFolder(dirPath: string): Promise<Platform> {
2424
const platforms = await getPlatformsFromFolder(dirPath);
2525

26+
if (platforms.length === 0) {
27+
return Platform.NONE;
28+
}
29+
2630
// Its not clear which platform the app directory is
2731
// because we found indicators for multiple platforms.
2832
if (platforms.length > 1) {
2933
return Platform.MULTIPLE;
3034
}
35+
3136
return toDataConnectPlatform(platforms[0]);
3237
}
3338

@@ -43,8 +48,6 @@ export function isPathInside(parent: string, child: string): boolean {
4348

4449
function toDataConnectPlatform(platform: AppUtilsPlatform): Platform {
4550
switch (platform) {
46-
case AppUtilsPlatform.NONE:
47-
return Platform.NONE;
4851
case AppUtilsPlatform.IOS:
4952
return Platform.IOS;
5053
case AppUtilsPlatform.ANDROID:

src/mcp/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,6 @@ export class FirebaseMcpServer {
243243
}
244244

245245
get availableTools(): ServerTool[] {
246-
this.log("error", `active features for prompts: ${this.activeFeatures || "<none>"}`);
247246
return availableTools(
248247
this.activeFeatures?.length ? this.activeFeatures : this.detectedFeatures,
249248
);
@@ -254,7 +253,6 @@ export class FirebaseMcpServer {
254253
}
255254

256255
get availablePrompts(): ServerPrompt[] {
257-
this.log("error", `active features for prompts: ${this.activeFeatures || "<none>"}`);
258256
return availablePrompts(
259257
this.activeFeatures?.length ? this.activeFeatures : this.detectedFeatures,
260258
);

0 commit comments

Comments
 (0)