rn-pendo-sdk
Version:
Pendo Mobile React Native SDK
1 lines • 6.08 kB
JavaScript
var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.withPendoAppDelegate=withPendoAppDelegate;exports.withPendoSchemeIOS=exports.withPendoPodfile=void 0;var _asyncToGenerator2=_interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));var _configPlugins=require("@expo/config-plugins");var path=_interopRequireWildcard(require("path"));var _consts=require("./consts");var _log=require("./log");var _utils=require("./utils");function _getRequireWildcardCache(e){if("function"!=typeof WeakMap)return null;var r=new WeakMap(),t=new WeakMap();return(_getRequireWildcardCache=function _getRequireWildcardCache(e){return e?t:r;})(e);}function _interopRequireWildcard(e,r){if(!r&&e&&e.__esModule)return e;if(null===e||"object"!=typeof e&&"function"!=typeof e)return{default:e};var t=_getRequireWildcardCache(r);if(t&&t.has(e))return t.get(e);var n={__proto__:null},a=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var u in e)if("default"!==u&&{}.hasOwnProperty.call(e,u)){var i=a?Object.getOwnPropertyDescriptor(e,u):null;i&&(i.get||i.set)?Object.defineProperty(n,u,i):n[u]=e[u];}return n.default=e,t&&t.set(e,n),n;}var withPendoSchemeIOS=exports.withPendoSchemeIOS=function withPendoSchemeIOS(config,props){_log.PendoLog.debug('****withPendoSchemeIOS****');return(0,_configPlugins.withInfoPlist)(config,function(){var _ref=(0,_asyncToGenerator2.default)(function*(config){if(!config.modResults.CFBundleURLTypes){config.modResults.CFBundleURLTypes=[];}var pendoScheme=config.modResults.CFBundleURLTypes.find(function(item){return item.CFBundleURLName==='pendo-pairing';});if(pendoScheme){_log.PendoLog.debug('withIosCustomScheme - pendo-pairing exists');return config;}var pendoURLScheme={CFBundleURLName:'pendo-pairing',CFBundleURLSchemes:[props['ios-scheme']]};config.modResults.CFBundleURLTypes.push(pendoURLScheme);return config;});return function(_x){return _ref.apply(this,arguments);};}());};function withPendoAppDelegate(expoConfig){_log.PendoLog.debug('****withPendoAppDelegate****');return(0,_configPlugins.withXcodeProject)(expoConfig,function(){var _ref2=(0,_asyncToGenerator2.default)(function*(config){var xcodeProject=config.modResults;var _config$modRequest=config.modRequest,projectName=_config$modRequest.projectName,platformProjectRoot=_config$modRequest.platformProjectRoot;if(projectName===undefined){_log.PendoLog.error('withPendoAppDelegate - Failed to get project name ',null);return config;}var fromPath;var projectPath;try{var testFromPath=_utils.PendoUtils.findFolder(_consts.LOCAL_PATH_EXTERNAL_APP_DELEGATE_FILES);if(testFromPath){fromPath=testFromPath;var testToPath=_utils.PendoUtils.findFolder(path.join(platformProjectRoot,projectName));if(!testToPath){_log.PendoLog.error(`Failed to find ${platformProjectRoot}`,null);return config;}projectPath=testToPath;}else{var _testFromPath=_utils.PendoUtils.findFolder(_consts.LOCAL_PATH_INTERNAL_APP_DELEGATE_FILES);if(_testFromPath){fromPath=_testFromPath;var _testToPath=_utils.PendoUtils.findFolder(path.join(platformProjectRoot,projectName));if(!_testToPath){_log.PendoLog.error(`Failed to find ${platformProjectRoot}`,null);return config;}projectPath=_testToPath;}else{_log.PendoLog.error('withPendoAppDelegate - Failed to find AppDelegate files',null);return config;}}if(shouldCopyFiles(platformProjectRoot)){yield addFilesToPendoXcodeProject(xcodeProject,projectName,projectPath,fromPath);}}catch(err){_log.PendoLog.error(`withPendoAppDelegate failed.`,err);}return config;});return function(_x2){return _ref2.apply(this,arguments);};}());}function addFilesToPendoXcodeProject(_x3,_x4,_x5,_x6){return _addFilesToPendoXcodeProject.apply(this,arguments);}function _addFilesToPendoXcodeProject(){_addFilesToPendoXcodeProject=(0,_asyncToGenerator2.default)(function*(xcodeProject,projectName,projectPath,fromPath){try{var group=xcodeProject.pbxGroupByName(projectName);if(!group){_log.PendoLog.error(`withPendoAppDelegate failed to find pbxGroup ${projectName}`);throw new Error(`Failed to find pbxGroup ${projectName}`);}var key=xcodeProject.findPBXGroupKey({name:group.name,path:group.path});yield copyFiles(xcodeProject,projectName,key,fromPath,projectPath);_log.PendoLog.debug('withPendoAppDelegate successfully completed');}catch(err){_log.PendoLog.error(`withPendoAppDelegate failed to open project file`,err);throw err;}});return _addFilesToPendoXcodeProject.apply(this,arguments);}var COCOAPODS_SOURCE="source 'https://github.com/CocoaPods/Specs.git'";var withPendoPodfile=exports.withPendoPodfile=function withPendoPodfile(config,props){_log.PendoLog.debug('****withPendoPodfile****');var podSource=props['ios-pod-source'];if(podSource){return(0,_configPlugins.withPodfileProperties)(config,function(config){var podfileLocation=path.join(config.modRequest.platformProjectRoot,'Podfile');if(!_utils.PendoUtils.findPath(podfileLocation)){_log.PendoLog.error(`Failed to find podfile in ${podfileLocation}`,null);return config;}var podFile=_utils.PendoUtils.readFromFileSync(podfileLocation);if(podFile.indexOf(podSource)===-1){podFile=`${podSource}\n${COCOAPODS_SOURCE}\n${podFile}`;_utils.PendoUtils.writeToFileSync(podfileLocation,podFile);_log.PendoLog.debug('Podfile updated with Pendo internal source');}return config;});}return config;};function copyFiles(_x7,_x8,_x9,_x10,_x11){return _copyFiles.apply(this,arguments);}function _copyFiles(){_copyFiles=(0,_asyncToGenerator2.default)(function*(xcodeProject,projectName,key,fromPath,toPath){for(var file of _consts.IOS_FILES){var fromFile=path.join(fromPath,file);var toFile=path.join(toPath,file);yield _utils.PendoUtils.copyFile(fromFile,toFile);if(file.endsWith('.h')){xcodeProject.addHeaderFile(path.join(projectName,file),null,key);}else if(file.endsWith('.m')){xcodeProject.addSourceFile(path.join(projectName,file),null,key);}}});return _copyFiles.apply(this,arguments);}function shouldCopyFiles(toPath){var toFile=path.join(toPath,_consts.IOS_FILES[0]);var exists=_utils.PendoUtils.findPath(toFile);return!exists;}