1"use strict"; 2 3Object.defineProperty(exports, "__esModule", { 4 value: true 5}); 6exports.getAndroidModFileProviders = getAndroidModFileProviders; 7exports.sortAndroidManifest = sortAndroidManifest; 8exports.withAndroidBaseMods = withAndroidBaseMods; 9 10function _fs() { 11 const data = require("fs"); 12 13 _fs = function () { 14 return data; 15 }; 16 17 return data; 18} 19 20function _path() { 21 const data = _interopRequireDefault(require("path")); 22 23 _path = function () { 24 return data; 25 }; 26 27 return data; 28} 29 30function _android() { 31 const data = require("../android"); 32 33 _android = function () { 34 return data; 35 }; 36 37 return data; 38} 39 40function _XML() { 41 const data = require("../utils/XML"); 42 43 _XML = function () { 44 return data; 45 }; 46 47 return data; 48} 49 50function _sortObject() { 51 const data = require("../utils/sortObject"); 52 53 _sortObject = function () { 54 return data; 55 }; 56 57 return data; 58} 59 60function _createBaseMod() { 61 const data = require("./createBaseMod"); 62 63 _createBaseMod = function () { 64 return data; 65 }; 66 67 return data; 68} 69 70function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } 71 72const { 73 readFile, 74 writeFile 75} = _fs().promises; 76 77function getAndroidManifestTemplate(config) { 78 var _config$android$packa, _config$android; 79 80 // Keep in sync with https://github.com/expo/expo/blob/master/templates/expo-template-bare-minimum/android/app/src/main/AndroidManifest.xml 81 // TODO: Read from remote template when possible 82 return (0, _XML().parseXMLAsync)(` 83 <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="${(_config$android$packa = (_config$android = config.android) === null || _config$android === void 0 ? void 0 : _config$android.package) !== null && _config$android$packa !== void 0 ? _config$android$packa : 'com.placeholder.appid'}"> 84 85 <uses-permission android:name="android.permission.INTERNET"/> 86 <!-- OPTIONAL PERMISSIONS, REMOVE WHATEVER YOU DO NOT NEED --> 87 <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/> 88 <!-- These require runtime permissions on M --> 89 <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/> 90 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> 91 <!-- END OPTIONAL PERMISSIONS --> 92 93 <queries> 94 <!-- Support checking for http(s) links via the Linking API --> 95 <intent> 96 <action android:name="android.intent.action.VIEW" /> 97 <category android:name="android.intent.category.BROWSABLE" /> 98 <data android:scheme="https" /> 99 </intent> 100 </queries> 101 102 <application 103 android:name=".MainApplication" 104 android:label="@string/app_name" 105 android:icon="@mipmap/ic_launcher" 106 android:roundIcon="@mipmap/ic_launcher_round" 107 android:allowBackup="false" 108 android:theme="@style/AppTheme" 109 android:usesCleartextTraffic="true" 110 > 111 <meta-data android:name="expo.modules.updates.EXPO_UPDATE_URL" android:value="YOUR-APP-URL-HERE"/> 112 <meta-data android:name="expo.modules.updates.EXPO_SDK_VERSION" android:value="YOUR-APP-SDK-VERSION-HERE"/> 113 <activity 114 android:name=".MainActivity" 115 android:label="@string/app_name" 116 android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode" 117 android:launchMode="singleTask" 118 android:windowSoftInputMode="adjustResize" 119 android:theme="@style/Theme.App.SplashScreen" 120 > 121 <intent-filter> 122 <action android:name="android.intent.action.MAIN"/> 123 <category android:name="android.intent.category.LAUNCHER"/> 124 </intent-filter> 125 </activity> 126 <activity android:name="com.facebook.react.devsupport.DevSettingsActivity"/> 127 </application> 128 </manifest> 129 `); 130} 131 132function sortAndroidManifest(obj) { 133 if (obj.manifest) { 134 // Reverse sort so application is last and permissions are first 135 obj.manifest = (0, _sortObject().sortObject)(obj.manifest, _sortObject().reverseSortString); 136 137 if (Array.isArray(obj.manifest['uses-permission'])) { 138 // Sort permissions alphabetically 139 obj.manifest['uses-permission'].sort((a, b) => { 140 if (a.$['android:name'] < b.$['android:name']) return -1; 141 if (a.$['android:name'] > b.$['android:name']) return 1; 142 return 0; 143 }); 144 } 145 146 if (Array.isArray(obj.manifest.application)) { 147 // reverse sort applications so activity is towards the end and meta-data is towards the front. 148 obj.manifest.application = obj.manifest.application.map(application => { 149 application = (0, _sortObject().sortObjWithOrder)(application, ['meta-data', 'service', 'activity']); 150 151 if (Array.isArray(application['meta-data'])) { 152 // Sort metadata alphabetically 153 application['meta-data'].sort((a, b) => { 154 if (a.$['android:name'] < b.$['android:name']) return -1; 155 if (a.$['android:name'] > b.$['android:name']) return 1; 156 return 0; 157 }); 158 } 159 160 return application; 161 }); 162 } 163 } 164 165 return obj; 166} 167 168const defaultProviders = { 169 dangerous: (0, _createBaseMod().provider)({ 170 getFilePath() { 171 return ''; 172 }, 173 174 async read() { 175 return { 176 filePath: '', 177 modResults: {} 178 }; 179 }, 180 181 async write() {} 182 183 }), 184 // Append a rule to supply gradle.properties data to mods on `mods.android.gradleProperties` 185 manifest: (0, _createBaseMod().provider)({ 186 isIntrospective: true, 187 188 getFilePath({ 189 modRequest: { 190 platformProjectRoot 191 } 192 }) { 193 return _path().default.join(platformProjectRoot, 'app/src/main/AndroidManifest.xml'); 194 }, 195 196 async read(filePath, config) { 197 try { 198 return await _android().Manifest.readAndroidManifestAsync(filePath); 199 } catch (error) { 200 if (!config.modRequest.introspect) { 201 throw error; 202 } 203 } 204 205 return await getAndroidManifestTemplate(config); 206 }, 207 208 async write(filePath, { 209 modResults, 210 modRequest: { 211 introspect 212 } 213 }) { 214 if (introspect) return; 215 await _android().Manifest.writeAndroidManifestAsync(filePath, sortAndroidManifest(modResults)); 216 } 217 218 }), 219 // Append a rule to supply gradle.properties data to mods on `mods.android.gradleProperties` 220 gradleProperties: (0, _createBaseMod().provider)({ 221 isIntrospective: true, 222 223 getFilePath({ 224 modRequest: { 225 platformProjectRoot 226 } 227 }) { 228 return _path().default.join(platformProjectRoot, 'gradle.properties'); 229 }, 230 231 async read(filePath, config) { 232 try { 233 return await _android().Properties.parsePropertiesFile(await readFile(filePath, 'utf8')); 234 } catch (error) { 235 if (!config.modRequest.introspect) { 236 throw error; 237 } 238 } 239 240 return []; 241 }, 242 243 async write(filePath, { 244 modResults, 245 modRequest: { 246 introspect 247 } 248 }) { 249 if (introspect) return; 250 await writeFile(filePath, _android().Properties.propertiesListToString(modResults)); 251 } 252 253 }), 254 // Append a rule to supply strings.xml data to mods on `mods.android.strings` 255 strings: (0, _createBaseMod().provider)({ 256 isIntrospective: true, 257 258 async getFilePath({ 259 modRequest: { 260 projectRoot, 261 introspect 262 } 263 }) { 264 try { 265 return await _android().Strings.getProjectStringsXMLPathAsync(projectRoot); 266 } catch (error) { 267 if (!introspect) { 268 throw error; 269 } 270 } 271 272 return ''; 273 }, 274 275 async read(filePath, config) { 276 try { 277 return await _android().Resources.readResourcesXMLAsync({ 278 path: filePath 279 }); 280 } catch (error) { 281 if (!config.modRequest.introspect) { 282 throw error; 283 } 284 } 285 286 return { 287 resources: {} 288 }; 289 }, 290 291 async write(filePath, { 292 modResults, 293 modRequest: { 294 introspect 295 } 296 }) { 297 if (introspect) return; 298 await (0, _XML().writeXMLAsync)({ 299 path: filePath, 300 xml: modResults 301 }); 302 } 303 304 }), 305 colors: (0, _createBaseMod().provider)({ 306 isIntrospective: true, 307 308 async getFilePath({ 309 modRequest: { 310 projectRoot, 311 introspect 312 } 313 }) { 314 try { 315 return await _android().Colors.getProjectColorsXMLPathAsync(projectRoot); 316 } catch (error) { 317 if (!introspect) { 318 throw error; 319 } 320 } 321 322 return ''; 323 }, 324 325 async read(filePath, { 326 modRequest: { 327 introspect 328 } 329 }) { 330 try { 331 return await _android().Resources.readResourcesXMLAsync({ 332 path: filePath 333 }); 334 } catch (error) { 335 if (!introspect) { 336 throw error; 337 } 338 } 339 340 return { 341 resources: {} 342 }; 343 }, 344 345 async write(filePath, { 346 modResults, 347 modRequest: { 348 introspect 349 } 350 }) { 351 if (introspect) return; 352 await (0, _XML().writeXMLAsync)({ 353 path: filePath, 354 xml: modResults 355 }); 356 } 357 358 }), 359 colorsNight: (0, _createBaseMod().provider)({ 360 isIntrospective: true, 361 362 async getFilePath({ 363 modRequest: { 364 projectRoot, 365 introspect 366 } 367 }) { 368 try { 369 return await _android().Colors.getProjectColorsXMLPathAsync(projectRoot, { 370 kind: 'values-night' 371 }); 372 } catch (error) { 373 if (!introspect) { 374 throw error; 375 } 376 } 377 378 return ''; 379 }, 380 381 async read(filePath, config) { 382 try { 383 return await _android().Resources.readResourcesXMLAsync({ 384 path: filePath 385 }); 386 } catch (error) { 387 if (!config.modRequest.introspect) { 388 throw error; 389 } 390 } 391 392 return { 393 resources: {} 394 }; 395 }, 396 397 async write(filePath, { 398 modResults, 399 modRequest: { 400 introspect 401 } 402 }) { 403 if (introspect) return; 404 await (0, _XML().writeXMLAsync)({ 405 path: filePath, 406 xml: modResults 407 }); 408 } 409 410 }), 411 styles: (0, _createBaseMod().provider)({ 412 isIntrospective: true, 413 414 async getFilePath({ 415 modRequest: { 416 projectRoot, 417 introspect 418 } 419 }) { 420 try { 421 return await _android().Styles.getProjectStylesXMLPathAsync(projectRoot); 422 } catch (error) { 423 if (!introspect) { 424 throw error; 425 } 426 } 427 428 return ''; 429 }, 430 431 async read(filePath, config) { 432 var _styles$resources$$; 433 434 let styles = { 435 resources: {} 436 }; 437 438 try { 439 // Adds support for `tools:x` 440 styles = await _android().Resources.readResourcesXMLAsync({ 441 path: filePath, 442 fallback: `<?xml version="1.0" encoding="utf-8"?><resources xmlns:tools="http://schemas.android.com/tools"></resources>` 443 }); 444 } catch (error) { 445 if (!config.modRequest.introspect) { 446 throw error; 447 } 448 } // Ensure support for tools is added... 449 450 451 if (!styles.resources.$) { 452 styles.resources.$ = {}; 453 } 454 455 if (!((_styles$resources$$ = styles.resources.$) !== null && _styles$resources$$ !== void 0 && _styles$resources$$['xmlns:tools'])) { 456 styles.resources.$['xmlns:tools'] = 'http://schemas.android.com/tools'; 457 } 458 459 return styles; 460 }, 461 462 async write(filePath, { 463 modResults, 464 modRequest: { 465 introspect 466 } 467 }) { 468 if (introspect) return; 469 await (0, _XML().writeXMLAsync)({ 470 path: filePath, 471 xml: modResults 472 }); 473 } 474 475 }), 476 projectBuildGradle: (0, _createBaseMod().provider)({ 477 getFilePath({ 478 modRequest: { 479 projectRoot 480 } 481 }) { 482 return _android().Paths.getProjectBuildGradleFilePath(projectRoot); 483 }, 484 485 async read(filePath) { 486 return _android().Paths.getFileInfo(filePath); 487 }, 488 489 async write(filePath, { 490 modResults: { 491 contents 492 } 493 }) { 494 await writeFile(filePath, contents); 495 } 496 497 }), 498 settingsGradle: (0, _createBaseMod().provider)({ 499 getFilePath({ 500 modRequest: { 501 projectRoot 502 } 503 }) { 504 return _android().Paths.getSettingsGradleFilePath(projectRoot); 505 }, 506 507 async read(filePath) { 508 return _android().Paths.getFileInfo(filePath); 509 }, 510 511 async write(filePath, { 512 modResults: { 513 contents 514 } 515 }) { 516 await writeFile(filePath, contents); 517 } 518 519 }), 520 appBuildGradle: (0, _createBaseMod().provider)({ 521 getFilePath({ 522 modRequest: { 523 projectRoot 524 } 525 }) { 526 return _android().Paths.getAppBuildGradleFilePath(projectRoot); 527 }, 528 529 async read(filePath) { 530 return _android().Paths.getFileInfo(filePath); 531 }, 532 533 async write(filePath, { 534 modResults: { 535 contents 536 } 537 }) { 538 await writeFile(filePath, contents); 539 } 540 541 }), 542 mainActivity: (0, _createBaseMod().provider)({ 543 getFilePath({ 544 modRequest: { 545 projectRoot 546 } 547 }) { 548 return _android().Paths.getProjectFilePath(projectRoot, 'MainActivity'); 549 }, 550 551 async read(filePath) { 552 return _android().Paths.getFileInfo(filePath); 553 }, 554 555 async write(filePath, { 556 modResults: { 557 contents 558 } 559 }) { 560 await writeFile(filePath, contents); 561 } 562 563 }), 564 mainApplication: (0, _createBaseMod().provider)({ 565 getFilePath({ 566 modRequest: { 567 projectRoot 568 } 569 }) { 570 return _android().Paths.getProjectFilePath(projectRoot, 'MainApplication'); 571 }, 572 573 async read(filePath) { 574 return _android().Paths.getFileInfo(filePath); 575 }, 576 577 async write(filePath, { 578 modResults: { 579 contents 580 } 581 }) { 582 await writeFile(filePath, contents); 583 } 584 585 }) 586}; 587 588function withAndroidBaseMods(config, { 589 providers, 590 ...props 591} = {}) { 592 return (0, _createBaseMod().withGeneratedBaseMods)(config, { ...props, 593 platform: 'android', 594 providers: providers !== null && providers !== void 0 ? providers : getAndroidModFileProviders() 595 }); 596} 597 598function getAndroidModFileProviders() { 599 return defaultProviders; 600} 601//# sourceMappingURL=withAndroidBaseMods.js.map