MCPcopy
hub / github.com/ionic-team/capacitor / getAndroidVariablesAndClasspaths

Function getAndroidVariablesAndClasspaths

cli/src/tasks/migrate.ts:396–432  ·  view source on GitHub ↗
(config: Config)

Source from the content-addressed store, hash-verified

394}
395
396async function getAndroidVariablesAndClasspaths(config: Config) {
397 const tempAndroidTemplateFolder = join(config.cli.assetsDirAbs, 'tempAndroidTemplate');
398 await extractTemplate(config.cli.assets.android.platformTemplateArchiveAbs, tempAndroidTemplateFolder);
399 const variablesGradleFile = readFile(join(tempAndroidTemplateFolder, 'variables.gradle'));
400 const buildGradleFile = readFile(join(tempAndroidTemplateFolder, 'build.gradle'));
401 if (!variablesGradleFile || !buildGradleFile) {
402 return;
403 }
404 deleteFolderRecursive(tempAndroidTemplateFolder);
405
406 const firstIndxOfCATBGV = buildGradleFile.indexOf(`classpath 'com.android.tools.build:gradle:`) + 42;
407 const firstIndxOfCGGGS = buildGradleFile.indexOf(`com.google.gms:google-services:`) + 31;
408 const comAndroidToolsBuildGradleVersion =
409 '' + buildGradleFile.substring(firstIndxOfCATBGV, buildGradleFile.indexOf("'", firstIndxOfCATBGV));
410 const comGoogleGmsGoogleServices =
411 '' + buildGradleFile.substring(firstIndxOfCGGGS, buildGradleFile.indexOf("'", firstIndxOfCGGGS));
412
413 const variablesGradleAsJSON = JSON.parse(
414 variablesGradleFile
415 .replace('ext ', '')
416 .replace(/=/g, ':')
417 .replace(/\n/g, ',')
418 .replace(/,([^:]+):/g, function (_k, p1) {
419 return `,"${p1}":`;
420 })
421 .replace('{,', '{')
422 .replace(',}', '}')
423 .replace(/\s/g, '')
424 .replace(/'/g, '"'),
425 );
426
427 return {
428 variables: variablesGradleAsJSON,
429 'com.android.tools.build:gradle': comAndroidToolsBuildGradleVersion,
430 'com.google.gms:google-services': comGoogleGmsGoogleServices,
431 };
432}
433
434function readFile(filename: string): string | undefined {
435 try {

Callers 1

migrateCommandFunction · 0.85

Calls 4

extractTemplateFunction · 0.90
deleteFolderRecursiveFunction · 0.90
readFileFunction · 0.85
parseMethod · 0.45

Tested by

no test coverage detected