UNPKG

2.53 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.setGradleMaven = void 0;
4const config_plugins_1 = require("@expo/config-plugins");
5const pkg = require('expo-camera/package.json');
6const CAMERA_USAGE = 'Allow $(PRODUCT_NAME) to access your camera';
7const MICROPHONE_USAGE = 'Allow $(PRODUCT_NAME) to access your microphone';
8// Because we need the package to be added AFTER the React and Google maven packages, we create a new allprojects.
9// It's ok to have multiple allprojects.repositories, so we create a new one since it's cheaper than tokenizing
10// the existing block to find the correct place to insert our camera maven.
11const gradleMaven = 'allprojects { repositories { maven { url "$rootDir/../node_modules/expo-camera/android/maven" } } }';
12const withAndroidCameraGradle = config => {
13 return config_plugins_1.withProjectBuildGradle(config, config => {
14 if (config.modResults.language === 'groovy') {
15 config.modResults.contents = setGradleMaven(config.modResults.contents);
16 }
17 else {
18 throw new Error('Cannot add camera maven gradle because the build.gradle is not groovy');
19 }
20 return config;
21 });
22};
23function setGradleMaven(buildGradle) {
24 // If this specific line is present, skip.
25 // This also enables users in bare workflow to comment out the line to prevent expo-camera from adding it back.
26 if (buildGradle.includes('expo-camera/android/maven')) {
27 return buildGradle;
28 }
29 return buildGradle + `\n${gradleMaven}\n`;
30}
31exports.setGradleMaven = setGradleMaven;
32const withCamera = (config, { cameraPermission, microphonePermission } = {}) => {
33 if (!config.ios)
34 config.ios = {};
35 if (!config.ios.infoPlist)
36 config.ios.infoPlist = {};
37 config.ios.infoPlist.NSCameraUsageDescription =
38 cameraPermission || config.ios.infoPlist.NSCameraUsageDescription || CAMERA_USAGE;
39 config.ios.infoPlist.NSMicrophoneUsageDescription =
40 microphonePermission || config.ios.infoPlist.NSMicrophoneUsageDescription || MICROPHONE_USAGE;
41 return config_plugins_1.withPlugins(config, [
42 [
43 config_plugins_1.AndroidConfig.Permissions.withPermissions,
44 [
45 'android.permission.CAMERA',
46 // Optional
47 'android.permission.RECORD_AUDIO',
48 ],
49 ],
50 withAndroidCameraGradle,
51 ]);
52};
53exports.default = config_plugins_1.createRunOncePlugin(withCamera, pkg.name, pkg.version);