"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; result["default"] = mod; return result; }; Object.defineProperty(exports, "__esModule", { value: true }); const fs_extra_1 = __importDefault(require("fs-extra")); const glob_1 = require("glob"); const path = __importStar(require("path")); const errors_1 = require("../utils/errors"); const modules_1 = require("../utils/modules"); async function getProjectFileAsync(projectRoot, name) { const mainActivityJavaPath = glob_1.sync(path.join(projectRoot, `android/app/src/main/java/**/${name}.@(java|kt)`))[0]; errors_1.assert(mainActivityJavaPath, `Project file "${name}" does not exist in android project for root "${projectRoot}"`); const mainActivityPathJava = path.resolve(mainActivityJavaPath, `../${name}.java`); const mainActivityPathKotlin = path.resolve(mainActivityJavaPath, `../${name}.kt`); const isJava = await fs_extra_1.default.pathExists(mainActivityPathJava); const isKotlin = !isJava && (await fs_extra_1.default.pathExists(mainActivityPathKotlin)); if (!isJava && !isKotlin) { throw new Error(`Failed to find '${name}' file for project: ${projectRoot}.`); } const filePath = isJava ? mainActivityPathJava : mainActivityPathKotlin; return { path: path.normalize(filePath), contents: fs_extra_1.default.readFileSync(filePath, 'utf8'), language: isJava ? 'java' : 'kt', }; } async function getMainApplicationAsync(projectRoot) { return getProjectFileAsync(projectRoot, 'MainApplication'); } exports.getMainApplicationAsync = getMainApplicationAsync; async function getMainActivityAsync(projectRoot) { return getProjectFileAsync(projectRoot, 'MainActivity'); } exports.getMainActivityAsync = getMainActivityAsync; async function getGradleFileAsync(projectRoot, gradleName) { const groovyPath = path.resolve(projectRoot, `${gradleName}.gradle`); const ktPath = path.resolve(projectRoot, `${gradleName}.gradle.kts`); const isGroovy = await fs_extra_1.default.pathExists(groovyPath); const isKotlin = !isGroovy && (await fs_extra_1.default.pathExists(ktPath)); if (!isGroovy && !isKotlin) { throw new Error(`Failed to find '${gradleName}.gradle' file for project: ${projectRoot}.`); } const filePath = isGroovy ? groovyPath : ktPath; return { path: path.normalize(filePath), contents: fs_extra_1.default.readFileSync(filePath, 'utf8'), language: isGroovy ? 'groovy' : 'kt', }; } async function getProjectBuildGradleAsync(projectRoot) { return getGradleFileAsync(path.join(projectRoot, 'android'), 'build'); } exports.getProjectBuildGradleAsync = getProjectBuildGradleAsync; async function getSettingsGradleAsync(projectRoot) { return getGradleFileAsync(path.join(projectRoot, 'android'), 'settings'); } exports.getSettingsGradleAsync = getSettingsGradleAsync; async function getAppBuildGradleAsync(projectRoot) { return getGradleFileAsync(path.join(projectRoot, 'android', 'app'), 'build'); } exports.getAppBuildGradleAsync = getAppBuildGradleAsync; function getAppBuildGradle(projectRoot) { return path.join(projectRoot, 'android', 'app', 'build.gradle'); } exports.getAppBuildGradle = getAppBuildGradle; async function getProjectPathOrThrowAsync(projectRoot) { const projectPath = path.join(projectRoot, 'android'); if (await modules_1.directoryExistsAsync(projectPath)) { return projectPath; } throw new Error(`Android project folder is missing in project: ${projectRoot}`); } exports.getProjectPathOrThrowAsync = getProjectPathOrThrowAsync; async function getAndroidManifestAsync(projectRoot) { const projectPath = await getProjectPathOrThrowAsync(projectRoot); const filePath = path.join(projectPath, 'app/src/main/AndroidManifest.xml'); return filePath; } exports.getAndroidManifestAsync = getAndroidManifestAsync; async function getResourceFolderAsync(projectRoot) { const projectPath = await getProjectPathOrThrowAsync(projectRoot); return path.join(projectPath, `app/src/main/res`); } exports.getResourceFolderAsync = getResourceFolderAsync; async function getResourceXMLPathAsync(projectRoot, { kind = 'values', name }) { const resourcePath = await getResourceFolderAsync(projectRoot); const filePath = path.join(resourcePath, `${kind}/${name}.xml`); return filePath; } exports.getResourceXMLPathAsync = getResourceXMLPathAsync; //# sourceMappingURL=Paths.js.map