react-native-expo-moengage
Version:
MoEngage Expo plugin for integrating MoEngage React-Native SDK
92 lines (91 loc) • 4.06 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.withMoEngageInfoPlist = void 0;
const config_plugins_1 = require("@expo/config-plugins");
const fs = __importStar(require("fs"));
const path = __importStar(require("path"));
const plist = require('plist');
/**
* MoEngage Expo plugin for iOS - Info.plist modifications
*
* This plugin configures the Info.plist file with MoEngage settings, including:
* 1. Importing configuration from the MoEngage plist file
* 2. Setting up notification service extensions
* 3. Configuring required app settings for MoEngage SDK
*
* @param config - The Expo config object
* @param props - The MoEngage plugin properties
* @returns The updated config with Info.plist modifications
*/
const withMoEngageInfoPlist = (config, props) => {
return (0, config_plugins_1.withInfoPlist)(config, (config) => {
const { apple } = props;
// Initialize MoEngage configuration in Info.plist
config.modResults['MoEngage'] = config.modResults['MoEngage'] || {};
// Import configuration from plist file if specified
try {
const configFilePath = path.join(config.modRequest.projectRoot, apple.configFilePath);
if (fs.existsSync(configFilePath)) {
const configPlist = plist.parse(fs.readFileSync(configFilePath, 'utf8'));
// Merge the configuration from the plist file with existing MoEngage settings
config.modResults['MoEngage'] = Object.assign(Object.assign({}, config.modResults['MoEngage']), configPlist);
}
else {
const message = `MoEngage configuration does not exist`;
console.error(message);
throw new Error(message);
}
}
catch (e) {
const message = `Could not import MoEngage configuration: ${e}`;
console.error(message);
throw new Error(message);
}
/**
* Set up Live Activities support in the Info.plist if enabled
*
* This adds the NSSupportsLiveActivities key to Info.plist, which is required
* for the app to support Live Activities on iOS. We only enable this if:
* 1. The app is not a tvOS app (Live Activities aren't supported on tvOS)
* 2. A Live Activity target path has been specified in the plugin configuration
*/
if (!process.env['EXPO_TV'] && apple.liveActivityTargetPath && apple.liveActivityTargetPath.length) {
config.modResults['NSSupportsLiveActivities'] = true;
}
return config;
});
};
exports.withMoEngageInfoPlist = withMoEngageInfoPlist;