@@ -7,7 +7,6 @@ import { PackageJSON } from "./frameworks/compose/discover/runtime/node";
7
7
* Supported application platforms.
8
8
*/
9
9
export enum Platform {
10
- NONE = "NONE" ,
11
10
ANDROID = "ANDROID" ,
12
11
WEB = "WEB" ,
13
12
IOS = "IOS" ,
@@ -50,33 +49,7 @@ export function appDescription(a: App): string {
50
49
*/
51
50
export async function getPlatformsFromFolder ( dirPath : string ) : Promise < Platform [ ] > {
52
51
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 ) ) ] ;
80
53
}
81
54
82
55
/**
@@ -110,7 +83,7 @@ export async function detectApps(dirPath: string): Promise<App[]> {
110
83
return [ ...webApps , ...flutterApps , ...androidApps , ...iosApps ] ;
111
84
}
112
85
113
- async function processIosDir ( dirPath : string , filePath : string ) {
86
+ async function processIosDir ( dirPath : string , filePath : string ) : Promise < App [ ] > {
114
87
// Search for apps in the parent directory
115
88
const iosDir = path . dirname ( filePath ) ;
116
89
const iosAppIds = await detectAppIdsForPlatform ( dirPath , Platform . IOS ) ;
@@ -133,7 +106,7 @@ async function processIosDir(dirPath: string, filePath: string) {
133
106
return iosApps . flat ( ) ;
134
107
}
135
108
136
- async function processAndroidDir ( dirPath : string , filePath : string ) {
109
+ async function processAndroidDir ( dirPath : string , filePath : string ) : Promise < App [ ] > {
137
110
// Search for apps in the parent directory, not in the src/main directory
138
111
const androidDir = path . dirname ( path . dirname ( filePath ) ) ;
139
112
const androidAppIds = await detectAppIdsForPlatform ( dirPath , Platform . ANDROID ) ;
@@ -158,7 +131,7 @@ async function processAndroidDir(dirPath: string, filePath: string) {
158
131
return androidApps . flat ( ) ;
159
132
}
160
133
161
- async function processFlutterDir ( dirPath : string , filePath : string ) {
134
+ async function processFlutterDir ( dirPath : string , filePath : string ) : Promise < App [ ] > {
162
135
const flutterDir = path . dirname ( filePath ) ;
163
136
const flutterAppIds = await detectAppIdsForPlatform ( dirPath , Platform . FLUTTER ) ;
164
137
@@ -193,7 +166,7 @@ function isPathInside(parent: string, child: string): boolean {
193
166
194
167
async function packageJsonToWebApp ( dirPath : string , packageJsonFile : string ) : Promise < App > {
195
168
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 ;
197
170
return {
198
171
platform : Platform . WEB ,
199
172
directory : path . dirname ( packageJsonFile ) ,
@@ -214,6 +187,8 @@ async function detectAppIdsForPlatform(
214
187
let appIdFiles ;
215
188
let extractFunc : ( fileContent : string ) => AppIdentifier [ ] ;
216
189
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.
217
192
case Platform . ANDROID :
218
193
appIdFiles = await detectFiles ( dirPath , "google-services*.json*" ) ;
219
194
extractFunc = extractAppIdentifiersAndroid ;
@@ -244,23 +219,25 @@ function getFrameworksFromPackageJson(packageJson: PackageJSON): Framework[] {
244
219
const dependencies = Object . keys ( packageJson . dependencies ?? { } ) ;
245
220
const allDeps = Array . from ( new Set ( [ ...devDependencies , ...dependencies ] ) ) ;
246
221
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 ) ) ,
248
223
) ;
249
224
}
250
225
251
226
/**
252
227
* Reads a firebase_options.dart file and extracts all appIds and bundleIds.
253
228
* @param fileContent content of the dart file.
254
- * @returns a list of appIds and bundleIds.
229
+ * @return a list of appIds and bundleIds.
255
230
*/
256
231
export function extractAppIdentifiersFlutter ( fileContent : string ) : AppIdentifier [ ] {
257
232
const optionsRegex = / F i r e b a s e O p t i o n s \( ( [ ^ ) ] * ) \) / g;
233
+ const appIdRegex = / a p p I d : ' ( [ ^ ' ] * ) ' / ;
234
+ const bundleIdRegex = / i o s B u n d l e I d : ' ( [ ^ ' ] * ) ' / ;
258
235
const matches = fileContent . matchAll ( optionsRegex ) ;
259
236
const identifiers : AppIdentifier [ ] = [ ] ;
260
237
for ( const match of matches ) {
261
238
const optionsContent = match [ 1 ] ;
262
- const appIdMatch = optionsContent . match ( / a p p I d : ' ( [ ^ ' ] * ) ' / ) ;
263
- const bundleIdMatch = optionsContent . match ( / i o s B u n d l e I d : ' ( [ ^ ' ] * ) ' / ) ;
239
+ const appIdMatch = appIdRegex . exec ( optionsContent ) ;
240
+ const bundleIdMatch = bundleIdRegex . exec ( optionsContent ) ;
264
241
if ( appIdMatch ?. [ 1 ] ) {
265
242
identifiers . push ( {
266
243
appId : appIdMatch [ 1 ] ,
@@ -275,7 +252,7 @@ export function extractAppIdentifiersFlutter(fileContent: string): AppIdentifier
275
252
/**
276
253
* Reads a GoogleService-Info.plist file and extracts the GOOGLE_APP_ID and BUNDLE_ID.
277
254
* @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.
279
256
*/
280
257
export function extractAppIdentifierIos ( fileContent : string ) : AppIdentifier [ ] {
281
258
const appIdRegex = / < k e y > G O O G L E _ A P P _ I D < \/ k e y > \s * < s t r i n g > ( [ ^ < ] * ) < \/ s t r i n g > / ;
@@ -296,7 +273,7 @@ export function extractAppIdentifierIos(fileContent: string): AppIdentifier[] {
296
273
/**
297
274
* Reads a google-services.json file and extracts all mobilesdk_app_id and package_name values.
298
275
* @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.
300
277
*/
301
278
export function extractAppIdentifiersAndroid ( fileContent : string ) : AppIdentifier [ ] {
302
279
const identifiers : AppIdentifier [ ] = [ ] ;
0 commit comments