1"use strict"; 2 3Object.defineProperty(exports, "__esModule", { 4 value: true 5}); 6exports.getAndroidManifestAsync = getAndroidManifestAsync; 7exports.getAppBuildGradleAsync = getAppBuildGradleAsync; 8exports.getAppBuildGradleFilePath = getAppBuildGradleFilePath; 9exports.getFileInfo = getFileInfo; 10exports.getGradleFilePath = getGradleFilePath; 11exports.getMainActivityAsync = getMainActivityAsync; 12exports.getMainApplicationAsync = getMainApplicationAsync; 13exports.getProjectBuildGradleAsync = getProjectBuildGradleAsync; 14exports.getProjectBuildGradleFilePath = getProjectBuildGradleFilePath; 15exports.getProjectFilePath = getProjectFilePath; 16exports.getProjectPathOrThrowAsync = getProjectPathOrThrowAsync; 17exports.getResourceFolderAsync = getResourceFolderAsync; 18exports.getResourceXMLPathAsync = getResourceXMLPathAsync; 19exports.getSettingsGradleAsync = getSettingsGradleAsync; 20exports.getSettingsGradleFilePath = getSettingsGradleFilePath; 21 22function _assert() { 23 const data = _interopRequireDefault(require("assert")); 24 25 _assert = function () { 26 return data; 27 }; 28 29 return data; 30} 31 32function _fs() { 33 const data = _interopRequireDefault(require("fs")); 34 35 _fs = function () { 36 return data; 37 }; 38 39 return data; 40} 41 42function _glob() { 43 const data = require("glob"); 44 45 _glob = function () { 46 return data; 47 }; 48 49 return data; 50} 51 52function path() { 53 const data = _interopRequireWildcard(require("path")); 54 55 path = function () { 56 return data; 57 }; 58 59 return data; 60} 61 62function _errors() { 63 const data = require("../utils/errors"); 64 65 _errors = function () { 66 return data; 67 }; 68 69 return data; 70} 71 72function _modules() { 73 const data = require("../utils/modules"); 74 75 _modules = function () { 76 return data; 77 }; 78 79 return data; 80} 81 82function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } 83 84function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } 85 86function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } 87 88function getProjectFilePath(projectRoot, name) { 89 const filePath = (0, _glob().sync)(path().join(projectRoot, `android/app/src/main/java/**/${name}.@(java|kt)`))[0]; 90 (0, _assert().default)(filePath, `Project file "${name}" does not exist in android project for root "${projectRoot}"`); 91 return filePath; 92} 93 94function getLanguage(filePath) { 95 const extension = path().extname(filePath); 96 97 switch (extension) { 98 case '.java': 99 return 'java'; 100 101 case '.kts': 102 case '.kt': 103 return 'kt'; 104 105 case '.groovy': 106 case '.gradle': 107 return 'groovy'; 108 109 default: 110 throw new (_errors().UnexpectedError)(`Unexpected Android file extension: ${extension}`); 111 } 112} 113 114function getFileInfo(filePath) { 115 return { 116 path: path().normalize(filePath), 117 contents: _fs().default.readFileSync(filePath, 'utf8'), 118 language: getLanguage(filePath) 119 }; 120} 121 122async function getMainApplicationAsync(projectRoot) { 123 const filePath = getProjectFilePath(projectRoot, 'MainApplication'); 124 return getFileInfo(filePath); 125} 126 127async function getMainActivityAsync(projectRoot) { 128 const filePath = getProjectFilePath(projectRoot, 'MainActivity'); 129 return getFileInfo(filePath); 130} 131 132function getGradleFilePath(projectRoot, gradleName) { 133 const groovyPath = path().resolve(projectRoot, `${gradleName}.gradle`); 134 const ktPath = path().resolve(projectRoot, `${gradleName}.gradle.kts`); 135 136 const isGroovy = _fs().default.existsSync(groovyPath); 137 138 const isKotlin = !isGroovy && _fs().default.existsSync(ktPath); 139 140 if (!isGroovy && !isKotlin) { 141 throw new Error(`Failed to find '${gradleName}.gradle' file for project: ${projectRoot}.`); 142 } 143 144 const filePath = isGroovy ? groovyPath : ktPath; 145 return filePath; 146} 147 148function getProjectBuildGradleFilePath(projectRoot) { 149 return getGradleFilePath(path().join(projectRoot, 'android'), 'build'); 150} 151 152async function getProjectBuildGradleAsync(projectRoot) { 153 return getFileInfo(getProjectBuildGradleFilePath(projectRoot)); 154} 155 156function getSettingsGradleFilePath(projectRoot) { 157 return getGradleFilePath(path().join(projectRoot, 'android'), 'settings'); 158} 159 160async function getSettingsGradleAsync(projectRoot) { 161 return getFileInfo(getSettingsGradleFilePath(projectRoot)); 162} 163 164function getAppBuildGradleFilePath(projectRoot) { 165 return getGradleFilePath(path().join(projectRoot, 'android', 'app'), 'build'); 166} 167 168async function getAppBuildGradleAsync(projectRoot) { 169 return getFileInfo(getAppBuildGradleFilePath(projectRoot)); 170} 171 172async function getProjectPathOrThrowAsync(projectRoot) { 173 const projectPath = path().join(projectRoot, 'android'); 174 175 if (await (0, _modules().directoryExistsAsync)(projectPath)) { 176 return projectPath; 177 } 178 179 throw new Error(`Android project folder is missing in project: ${projectRoot}`); 180} 181 182async function getAndroidManifestAsync(projectRoot) { 183 const projectPath = await getProjectPathOrThrowAsync(projectRoot); 184 const filePath = path().join(projectPath, 'app/src/main/AndroidManifest.xml'); 185 return filePath; 186} 187 188async function getResourceFolderAsync(projectRoot) { 189 const projectPath = await getProjectPathOrThrowAsync(projectRoot); 190 return path().join(projectPath, `app/src/main/res`); 191} 192 193async function getResourceXMLPathAsync(projectRoot, { 194 kind = 'values', 195 name 196}) { 197 const resourcePath = await getResourceFolderAsync(projectRoot); 198 const filePath = path().join(resourcePath, `${kind}/${name}.xml`); 199 return filePath; 200} 201//# sourceMappingURL=Paths.js.map