// Copyright 2015-present 650 Industries. All rights reserved. 'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.renderPodfileAsync = exports.renderExpoKitPodspecAsync = undefined; var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; let _renderVersionedReactNativeDependenciesAsync = (() => { var _ref = _asyncToGenerator(function* (templatesDirectory, versionedReactNativePath, expoSubspecs) { let result = yield _concatTemplateFilesInDirectoryAsync(_path.default.join(templatesDirectory, 'versioned-react-native', 'dependencies')); expoSubspecs = expoSubspecs.map(function (subspec) { return `'${subspec}'`; }).join(', '); result = result.replace(/\$\{VERSIONED_REACT_NATIVE_PATH\}/g, versionedReactNativePath); result = result.replace(/\$\{REACT_NATIVE_EXPO_SUBSPECS\}/g, expoSubspecs); return result; }); return function _renderVersionedReactNativeDependenciesAsync(_x, _x2, _x3) { return _ref.apply(this, arguments); }; })(); let _renderVersionedReactNativePostinstallsAsync = (() => { var _ref2 = _asyncToGenerator(function* (templatesDirectory) { return _concatTemplateFilesInDirectoryAsync(_path.default.join(templatesDirectory, 'versioned-react-native', 'postinstalls')); }); return function _renderVersionedReactNativePostinstallsAsync(_x4) { return _ref2.apply(this, arguments); }; })(); let _concatTemplateFilesInDirectoryAsync = (() => { var _ref3 = _asyncToGenerator(function* (directory) { let templateFilenames = yield (0, (_globPromise || _load_globPromise()).default)(_path.default.join(directory, '*.rb')); let templateStrings = []; yield Promise.all(templateFilenames.map((() => { var _ref4 = _asyncToGenerator(function* (filename) { let templateString = yield (_fsExtra || _load_fsExtra()).default.readFile(filename, 'utf8'); if (templateString) { templateStrings.push(templateString); } }); return function (_x6) { return _ref4.apply(this, arguments); }; })())); return templateStrings.join('\n'); }); return function _concatTemplateFilesInDirectoryAsync(_x5) { return _ref3.apply(this, arguments); }; })(); let _renderPodDependenciesAsync = (() => { var _ref5 = _asyncToGenerator(function* (dependenciesConfigPath, options) { let dependencies = yield new (_jsonFile || _load_jsonFile()).default(dependenciesConfigPath).readAsync(); let type = options.isPodfile ? 'pod' : 'ss.dependency'; let depsStrings = dependencies.map(function (dependency) { return ` ${type} '${dependency.name}', '${dependency.version}'`; }); return depsStrings.join('\n'); }); return function _renderPodDependenciesAsync(_x7, _x8) { return _ref5.apply(this, arguments); }; })(); let renderExpoKitPodspecAsync = (() => { var _ref6 = _asyncToGenerator(function* (pathToTemplate, pathToOutput, moreSubstitutions) { let templatesDirectory = _path.default.dirname(pathToTemplate); let templateString = yield (_fsExtra || _load_fsExtra()).default.readFile(pathToTemplate, 'utf8'); let dependencies = yield _renderPodDependenciesAsync(_path.default.join(templatesDirectory, 'dependencies.json'), { isPodfile: false }); let result = templateString.replace(/\$\{IOS_EXPOKIT_DEPS\}/g, (0, (_indentString || _load_indentString()).default)(dependencies, 2)); if (moreSubstitutions && moreSubstitutions.IOS_EXPONENT_CLIENT_VERSION) { result = result.replace(/\$\{IOS_EXPONENT_CLIENT_VERSION\}/g, moreSubstitutions.IOS_EXPONENT_CLIENT_VERSION); } yield (_fsExtra || _load_fsExtra()).default.writeFile(pathToOutput, result); }); return function renderExpoKitPodspecAsync(_x9, _x10, _x11) { return _ref6.apply(this, arguments); }; })(); /** * @param pathToTemplate path to template Podfile * @param pathToOutput path to render final Podfile * @param moreSubstitutions dictionary of additional substitution keys and values to replace * in the template, such as: TARGET_NAME, REACT_NATIVE_PATH */ let renderPodfileAsync = (() => { var _ref7 = _asyncToGenerator(function* (pathToTemplate, pathToOutput, moreSubstitutions, sdkVersion = 'UNVERSIONED') { if (!moreSubstitutions) { moreSubstitutions = {}; } let templatesDirectory = _path.default.dirname(pathToTemplate); let templateString = yield (_fsExtra || _load_fsExtra()).default.readFile(pathToTemplate, 'utf8'); let reactNativePath = moreSubstitutions.REACT_NATIVE_PATH; let rnDependencyOptions; if (reactNativePath) { rnDependencyOptions = { reactNativePath }; } else { rnDependencyOptions = {}; } const expoKitPath = moreSubstitutions.EXPOKIT_PATH; const expoKitTag = moreSubstitutions.EXPOKIT_TAG; let expoKitDependencyOptions = {}; if (expoKitPath) { expoKitDependencyOptions = { expoKitPath }; } else if (expoKitTag) { expoKitDependencyOptions = { expoKitTag }; } let versionedRnPath = moreSubstitutions.VERSIONED_REACT_NATIVE_PATH; if (!versionedRnPath) { versionedRnPath = './versioned-react-native'; } let rnExpoSubspecs = moreSubstitutions.REACT_NATIVE_EXPO_SUBSPECS; if (!rnExpoSubspecs) { rnExpoSubspecs = ['Expo']; } let versionedDependencies = yield _renderVersionedReactNativeDependenciesAsync(templatesDirectory, versionedRnPath, rnExpoSubspecs); let versionedPostinstalls = yield _renderVersionedReactNativePostinstallsAsync(templatesDirectory); let podDependencies = yield _renderPodDependenciesAsync(_path.default.join(templatesDirectory, 'dependencies.json'), { isPodfile: true }); let substitutions = _extends({ EXPONENT_CLIENT_DEPS: podDependencies, EXPOKIT_DEPENDENCY: _renderExpoKitDependency(expoKitDependencyOptions), PODFILE_UNVERSIONED_RN_DEPENDENCY: _renderUnversionedReactNativeDependency(rnDependencyOptions, sdkVersion), PODFILE_UNVERSIONED_POSTINSTALL: _renderUnversionedPostinstall(), PODFILE_DETACHED_POSTINSTALL: _renderDetachedPostinstall(sdkVersion), PODFILE_VERSIONED_RN_DEPENDENCIES: versionedDependencies, PODFILE_VERSIONED_POSTINSTALLS: versionedPostinstalls, PODFILE_TEST_TARGET: _renderTestTarget(reactNativePath) }, moreSubstitutions); _validatePodfileSubstitutions(substitutions); let result = templateString; for (let key in substitutions) { if (substitutions.hasOwnProperty(key)) { let replacement = substitutions[key]; result = result.replace(new RegExp(`\\\$\\\{${key}\\\}`, 'g'), replacement); } } yield (_fsExtra || _load_fsExtra()).default.writeFile(pathToOutput, result); }); return function renderPodfileAsync(_x12, _x13, _x14) { return _ref7.apply(this, arguments); }; })(); var _fsExtra; function _load_fsExtra() { return _fsExtra = _interopRequireDefault(require('fs-extra')); } var _globPromise; function _load_globPromise() { return _globPromise = _interopRequireDefault(require('glob-promise')); } var _indentString; function _load_indentString() { return _indentString = _interopRequireDefault(require('indent-string')); } var _jsonFile; function _load_jsonFile() { return _jsonFile = _interopRequireDefault(require('@expo/json-file')); } var _path = _interopRequireDefault(require('path')); var _ExponentTools; function _load_ExponentTools() { return _ExponentTools = require('./ExponentTools'); } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; } function _validatePodfileSubstitutions(substitutions) { const validKeys = [ // a pod dependency on ExpoKit (can be local or remote) 'EXPOKIT_DEPENDENCY', // local path to ExpoKit dependency 'EXPOKIT_PATH', // tag to use for ExpoKit dependency 'EXPOKIT_TAG', // the contents of dependencies.json enumerated as deps in podfile format 'EXPONENT_CLIENT_DEPS', // postinstall for detached projects (defines EX_DETACHED among other things) 'PODFILE_DETACHED_POSTINSTALL', // ExponentIntegrationTests 'PODFILE_TEST_TARGET', // unversioned react native pod dependency, probably at the path given in // REACT_NATIVE_PATH, with a bunch of subspecs. 'PODFILE_UNVERSIONED_RN_DEPENDENCY', // postinstall hook for unversioned deps 'PODFILE_UNVERSIONED_POSTINSTALL', // versioned rn dependencies (paths to versioned-react-native directories) // read from template files 'PODFILE_VERSIONED_RN_DEPENDENCIES', // versioned rn postinstall hooks read from template files 'PODFILE_VERSIONED_POSTINSTALLS', // list of generated Expo subspecs to include under a versioned react native dependency 'REACT_NATIVE_EXPO_SUBSPECS', // path to use for the unversioned react native dependency 'REACT_NATIVE_PATH', // name of the main build target, e.g. Exponent 'TARGET_NAME', // path from Podfile to versioned-react-native 'VERSIONED_REACT_NATIVE_PATH']; for (const key in substitutions) { if (substitutions.hasOwnProperty(key)) { if (!validKeys.includes(key)) { throw new Error(`Unrecognized Podfile template key: ${key}`); } } } return true; } function _renderExpoKitDependency(options) { let attributes; if (options.expoKitPath) { attributes = { path: options.expoKitPath }; } else if (options.expoKitTag) { attributes = { git: 'http://github.com/expo/expo.git', tag: options.expoKitTag }; } else { attributes = { git: 'http://github.com/expo/expo.git', branch: 'master' }; } attributes.subspecs = ['Core', 'CPP']; let dependency = `pod 'ExpoKit', ${(0, (_indentString || _load_indentString()).default)(_renderDependencyAttributes(attributes), 2)}`; return (0, (_indentString || _load_indentString()).default)(dependency, 2); } /** * @param sdkVersion if specified, indicates which sdkVersion this project uses * as 'UNVERSIONED', e.g. if we are detaching a sdk15 project, we render * an unversioned dependency pointing at RN#sdk-15. */ function _renderUnversionedReactNativeDependency(options, sdkVersion) { let sdkMajorVersion = (0, (_ExponentTools || _load_ExponentTools()).parseSdkMajorVersion)(sdkVersion); if (sdkMajorVersion === 14) { return (0, (_indentString || _load_indentString()).default)(` ${_renderUnversionedReactDependency(options)} `, 2); } else if (sdkMajorVersion < 21) { return (0, (_indentString || _load_indentString()).default)(` ${_renderUnversionedReactDependency(options, sdkVersion)} ${_renderUnversionedYogaDependency(options, sdkVersion)} `, 2); } else { return (0, (_indentString || _load_indentString()).default)(` ${_renderUnversionedReactDependency(options, sdkVersion)} ${_renderUnversionedYogaDependency(options, sdkVersion)} ${_renderUnversionedThirdPartyDependency('DoubleConversion', _path.default.join('third-party-podspecs', 'DoubleConversion.podspec'), options)} ${_renderUnversionedThirdPartyDependency('Folly', _path.default.join('third-party-podspecs', 'Folly.podspec'), options)} ${_renderUnversionedThirdPartyDependency('GLog', _path.default.join('third-party-podspecs', 'GLog.podspec'), options)} `, 2); } } function _renderUnversionedReactDependency(options, sdkVersion) { let attributes; if (options.reactNativePath) { attributes = { path: options.reactNativePath }; } else { throw new Error(`Unsupported options for RN dependency: ${options}`); } attributes.subspecs = ['Core', 'ART', 'RCTActionSheet', 'RCTAnimation', 'RCTCameraRoll', 'RCTGeolocation', 'RCTImage', 'RCTNetwork', 'RCTText', 'RCTVibration', 'RCTWebSocket']; let sdkMajorVersion = (0, (_ExponentTools || _load_ExponentTools()).parseSdkMajorVersion)(sdkVersion); if (!(sdkMajorVersion < 16)) { attributes.subspecs.push('DevSupport'); } if (!(sdkMajorVersion < 21)) { attributes.subspecs.push('CxxBridge'); } else if (!(sdkMajorVersion < 18)) { attributes.subspecs.push('BatchedBridge'); } return `pod 'React', ${(0, (_indentString || _load_indentString()).default)(_renderDependencyAttributes(attributes), 2)}`; } function _renderUnversionedYogaDependency(options, sdkVersion) { let attributes; let sdkMajorVersion = (0, (_ExponentTools || _load_ExponentTools()).parseSdkMajorVersion)(sdkVersion); if (options.reactNativePath) { attributes = { path: _path.default.join(options.reactNativePath, 'ReactCommon', sdkMajorVersion < 22 ? 'Yoga' : 'yoga') }; } else { throw new Error(`Unsupported options for Yoga dependency: ${options}`); } return `pod '${sdkMajorVersion < 22 ? 'Yoga' : 'yoga'}', ${(0, (_indentString || _load_indentString()).default)(_renderDependencyAttributes(attributes), 2)}`; } function _renderUnversionedThirdPartyDependency(podName, podspecRelativePath, options) { let attributes; if (options.reactNativePath) { attributes = { podspec: _path.default.join(options.reactNativePath, podspecRelativePath), inhibit_warnings: true }; } else { throw new Error(`Unsupported options for ${podName} dependency: ${options}`); } return `pod '${podName}', ${(0, (_indentString || _load_indentString()).default)(_renderDependencyAttributes(attributes), 2)}`; } function _renderDependencyAttributes(attributes) { let attributesStrings = []; for (let key of Object.keys(attributes)) { let value = JSON.stringify(attributes[key], null, 2); attributesStrings.push(`:${key} => ${value}`); } return attributesStrings.join(',\n'); } function _renderDetachedPostinstall(sdkVersion) { let podsRootSub = '${PODS_ROOT}'; return ` if target.pod_name == 'ExpoKit' target.native_target.build_configurations.each do |config| config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= ['$(inherited)'] config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] << 'EX_DETACHED=1' # needed for GoogleMaps 2.x config.build_settings['FRAMEWORK_SEARCH_PATHS'] ||= [] config.build_settings['FRAMEWORK_SEARCH_PATHS'] << '${podsRootSub}/GoogleMaps/Base/Frameworks' config.build_settings['FRAMEWORK_SEARCH_PATHS'] << '${podsRootSub}/GoogleMaps/Maps/Frameworks' end end `; } function _renderUnversionedPostinstall() { // TODO: switch to `installer.pods_project.targets.each` in postinstall // see: https://stackoverflow.com/questions/37160688/set-deployment-target-for-cocoapodss-pod const podsToChangeDeployTarget = ['Amplitude-iOS', 'Analytics', 'AppAuth', 'Branch', 'CocoaLumberjack', 'FBSDKCoreKit', 'FBSDKLoginKit', 'FBSDKShareKit', 'GPUImage', 'JKBigInteger2']; const podsToChangeRB = `[${podsToChangeDeployTarget.map(pod => `'${pod}'`).join(',')}]`; return ` if ${podsToChangeRB}.include? target.pod_name target.native_target.build_configurations.each do |config| config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '9.0' end end # Build React Native with RCT_DEV enabled next unless target.pod_name == 'React' target.native_target.build_configurations.each do |config| config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= ['$(inherited)'] config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] << 'RCT_DEV=1' end `; } function _renderTestTarget(reactNativePath) { return ` target 'ExponentIntegrationTests' do inherit! :search_paths end `; } exports.renderExpoKitPodspecAsync = renderExpoKitPodspecAsync; exports.renderPodfileAsync = renderPodfileAsync; //# sourceMappingURL=../__sourcemaps__/detach/IosPodsTools.js.map