1import path from 'path'; 2 3import { CommandError } from '../../utils/errors'; 4 5export type GradleProps = { 6 /** Directory for the APK based on the `variant`. */ 7 apkVariantDirectory: string; 8 /** Name of the app, used in the `apkVariantDirectory`. */ 9 appName: string; 10 /** First section of the provided `variant`, indicates the last part of the file name for the output APK. */ 11 buildType: string; 12 /** Used to assemble the APK, also included in the output APK filename. */ 13 flavors?: string[]; 14}; 15 16function assertVariant(variant?: string) { 17 if (variant && typeof variant !== 'string') { 18 throw new CommandError('BAD_ARGS', '--variant must be a string'); 19 } 20 return variant ?? 'debug'; 21} 22 23export function resolveGradleProps( 24 projectRoot: string, 25 options: { variant?: string } 26): GradleProps { 27 const variant = assertVariant(options.variant); 28 // NOTE(EvanBacon): Why would this be different? Can we get the different name? 29 const appName = 'app'; 30 31 const apkDirectory = path.join(projectRoot, 'android', appName, 'build', 'outputs', 'apk'); 32 33 // buildDeveloperTrust -> build, developer, trust (where developer, and trust are flavors). 34 // This won't work for non-standard flavor names like "myFlavor" would be treated as "my", "flavor". 35 const [buildType, ...flavors] = variant.split(/(?=[A-Z])/).map((v) => v.toLowerCase()); 36 const apkVariantDirectory = path.join(apkDirectory, ...flavors, buildType); 37 38 return { 39 appName, 40 buildType, 41 flavors, 42 apkVariantDirectory, 43 }; 44} 45