1"use strict"; 2Object.defineProperty(exports, "__esModule", { value: true }); 3exports.addCameraImport = void 0; 4const config_plugins_1 = require("@expo/config-plugins"); 5const generateCode_1 = require("@expo/config-plugins/build/utils/generateCode"); 6const pkg = require('expo-camera/package.json'); 7const CAMERA_USAGE = 'Allow $(PRODUCT_NAME) to access your camera'; 8const MICROPHONE_USAGE = 'Allow $(PRODUCT_NAME) to access your microphone'; 9// Because we need the package to be added AFTER the React and Google maven packages, we create a new allprojects. 10// It's ok to have multiple allprojects.repositories, so we create a new one since it's cheaper than tokenizing 11// the existing block to find the correct place to insert our camera maven. 12const gradleMaven = [ 13 `def expoCameraMavenPath = new File(["node", "--print", "require.resolve('expo-camera/package.json')"].execute(null, rootDir).text.trim(), "../android/maven")`, 14 `allprojects { repositories { maven { url(expoCameraMavenPath) } } }`, 15].join('\n'); 16const withAndroidCameraGradle = (config) => { 17 return (0, config_plugins_1.withProjectBuildGradle)(config, (config) => { 18 if (config.modResults.language === 'groovy') { 19 config.modResults.contents = addCameraImport(config.modResults.contents).contents; 20 } 21 else { 22 throw new Error('Cannot add camera maven gradle because the build.gradle is not groovy'); 23 } 24 return config; 25 }); 26}; 27function addCameraImport(src) { 28 return appendContents({ 29 tag: 'expo-camera-import', 30 src, 31 newSrc: gradleMaven, 32 comment: '//', 33 }); 34} 35exports.addCameraImport = addCameraImport; 36// Fork of config-plugins mergeContents, but appends the contents to the end of the file. 37function appendContents({ src, newSrc, tag, comment, }) { 38 const header = (0, generateCode_1.createGeneratedHeaderComment)(newSrc, tag, comment); 39 if (!src.includes(header)) { 40 // Ensure the old generated contents are removed. 41 const sanitizedTarget = (0, generateCode_1.removeGeneratedContents)(src, tag); 42 const contentsToAdd = [ 43 // @something 44 header, 45 // contents 46 newSrc, 47 // @end 48 `${comment} @generated end ${tag}`, 49 ].join('\n'); 50 return { 51 contents: sanitizedTarget ?? src + contentsToAdd, 52 didMerge: true, 53 didClear: !!sanitizedTarget, 54 }; 55 } 56 return { contents: src, didClear: false, didMerge: false }; 57} 58const withCamera = (config, { cameraPermission, microphonePermission } = {}) => { 59 config = (0, config_plugins_1.withInfoPlist)(config, (config) => { 60 config.modResults.NSCameraUsageDescription = 61 cameraPermission || config.modResults.NSCameraUsageDescription || CAMERA_USAGE; 62 config.modResults.NSMicrophoneUsageDescription = 63 microphonePermission || config.modResults.NSMicrophoneUsageDescription || MICROPHONE_USAGE; 64 return config; 65 }); 66 config = config_plugins_1.AndroidConfig.Permissions.withPermissions(config, [ 67 'android.permission.CAMERA', 68 // Optional 69 'android.permission.RECORD_AUDIO', 70 ]); 71 return withAndroidCameraGradle(config); 72}; 73exports.default = (0, config_plugins_1.createRunOncePlugin)(withCamera, pkg.name, pkg.version); 74