1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4  value: true
5});
6exports.getIosModFileProviders = getIosModFileProviders;
7exports.withIosBaseMods = withIosBaseMods;
8function _jsonFile() {
9  const data = _interopRequireDefault(require("@expo/json-file"));
10  _jsonFile = function () {
11    return data;
12  };
13  return data;
14}
15function _plist() {
16  const data = _interopRequireDefault(require("@expo/plist"));
17  _plist = function () {
18    return data;
19  };
20  return data;
21}
22function _assert() {
23  const data = _interopRequireDefault(require("assert"));
24  _assert = function () {
25    return data;
26  };
27  return data;
28}
29function _fs() {
30  const data = _interopRequireWildcard(require("fs"));
31  _fs = function () {
32    return data;
33  };
34  return data;
35}
36function _path() {
37  const data = _interopRequireDefault(require("path"));
38  _path = function () {
39    return data;
40  };
41  return data;
42}
43function _xcode() {
44  const data = _interopRequireDefault(require("xcode"));
45  _xcode = function () {
46    return data;
47  };
48  return data;
49}
50function _createBaseMod() {
51  const data = require("./createBaseMod");
52  _createBaseMod = function () {
53    return data;
54  };
55  return data;
56}
57function _ios() {
58  const data = require("../ios");
59  _ios = function () {
60    return data;
61  };
62  return data;
63}
64function _Entitlements() {
65  const data = require("../ios/Entitlements");
66  _Entitlements = function () {
67    return data;
68  };
69  return data;
70}
71function _Xcodeproj() {
72  const data = require("../ios/utils/Xcodeproj");
73  _Xcodeproj = function () {
74    return data;
75  };
76  return data;
77}
78function _getInfoPlistPath() {
79  const data = require("../ios/utils/getInfoPlistPath");
80  _getInfoPlistPath = function () {
81    return data;
82  };
83  return data;
84}
85function _modules() {
86  const data = require("../utils/modules");
87  _modules = function () {
88    return data;
89  };
90  return data;
91}
92function _sortObject() {
93  const data = require("../utils/sortObject");
94  _sortObject = function () {
95    return data;
96  };
97  return data;
98}
99function _warnings() {
100  const data = require("../utils/warnings");
101  _warnings = function () {
102    return data;
103  };
104  return data;
105}
106function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
107function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
108function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
109const {
110  readFile,
111  writeFile
112} = _fs().promises;
113function getEntitlementsPlistTemplate() {
114  // TODO: Fetch the versioned template file if possible
115  return {};
116}
117function getInfoPlistTemplate() {
118  // TODO: Fetch the versioned template file if possible
119  return {
120    CFBundleDevelopmentRegion: '$(DEVELOPMENT_LANGUAGE)',
121    CFBundleExecutable: '$(EXECUTABLE_NAME)',
122    CFBundleIdentifier: '$(PRODUCT_BUNDLE_IDENTIFIER)',
123    CFBundleName: '$(PRODUCT_NAME)',
124    CFBundlePackageType: '$(PRODUCT_BUNDLE_PACKAGE_TYPE)',
125    CFBundleInfoDictionaryVersion: '6.0',
126    CFBundleSignature: '????',
127    LSRequiresIPhoneOS: true,
128    NSAppTransportSecurity: {
129      NSAllowsArbitraryLoads: true,
130      NSExceptionDomains: {
131        localhost: {
132          NSExceptionAllowsInsecureHTTPLoads: true
133        }
134      }
135    },
136    UILaunchStoryboardName: 'SplashScreen',
137    UIRequiredDeviceCapabilities: ['armv7'],
138    UIViewControllerBasedStatusBarAppearance: false,
139    UIStatusBarStyle: 'UIStatusBarStyleDefault',
140    CADisableMinimumFrameDurationOnPhone: true
141  };
142}
143const defaultProviders = {
144  dangerous: (0, _createBaseMod().provider)({
145    getFilePath() {
146      return '';
147    },
148    async read() {
149      return {};
150    },
151    async write() {}
152  }),
153  // Append a rule to supply AppDelegate data to mods on `mods.ios.appDelegate`
154  appDelegate: (0, _createBaseMod().provider)({
155    getFilePath({
156      modRequest: {
157        projectRoot
158      }
159    }) {
160      // TODO: Get application AppDelegate file from pbxproj.
161      return _ios().Paths.getAppDelegateFilePath(projectRoot);
162    },
163    async read(filePath) {
164      return _ios().Paths.getFileInfo(filePath);
165    },
166    async write(filePath, {
167      modResults: {
168        contents
169      }
170    }) {
171      await writeFile(filePath, contents);
172    }
173  }),
174  // Append a rule to supply Expo.plist data to mods on `mods.ios.expoPlist`
175  expoPlist: (0, _createBaseMod().provider)({
176    isIntrospective: true,
177    getFilePath({
178      modRequest: {
179        platformProjectRoot,
180        projectName
181      }
182    }) {
183      const supportingDirectory = _path().default.join(platformProjectRoot, projectName, 'Supporting');
184      return _path().default.resolve(supportingDirectory, 'Expo.plist');
185    },
186    async read(filePath, {
187      modRequest: {
188        introspect
189      }
190    }) {
191      try {
192        return _plist().default.parse(await readFile(filePath, 'utf8'));
193      } catch (error) {
194        if (introspect) {
195          return {};
196        }
197        throw error;
198      }
199    },
200    async write(filePath, {
201      modResults,
202      modRequest: {
203        introspect
204      }
205    }) {
206      if (introspect) {
207        return;
208      }
209      await writeFile(filePath, _plist().default.build((0, _sortObject().sortObject)(modResults)));
210    }
211  }),
212  // Append a rule to supply .xcodeproj data to mods on `mods.ios.xcodeproj`
213  xcodeproj: (0, _createBaseMod().provider)({
214    getFilePath({
215      modRequest: {
216        projectRoot
217      }
218    }) {
219      return _ios().Paths.getPBXProjectPath(projectRoot);
220    },
221    async read(filePath) {
222      const project = _xcode().default.project(filePath);
223      project.parseSync();
224      return project;
225    },
226    async write(filePath, {
227      modResults
228    }) {
229      await writeFile(filePath, modResults.writeSync());
230    }
231  }),
232  // Append a rule to supply Info.plist data to mods on `mods.ios.infoPlist`
233  infoPlist: (0, _createBaseMod().provider)({
234    isIntrospective: true,
235    async getFilePath(config) {
236      let project = null;
237      try {
238        project = (0, _Xcodeproj().getPbxproj)(config.modRequest.projectRoot);
239      } catch {
240        // noop
241      }
242
243      // Only check / warn if a project actually exists, this'll provide
244      // more accurate warning messages for users in managed projects.
245      if (project) {
246        const infoPlistBuildProperty = (0, _getInfoPlistPath().getInfoPlistPathFromPbxproj)(project);
247        if (infoPlistBuildProperty) {
248          //: [root]/myapp/ios/MyApp/Info.plist
249          const infoPlistPath = _path().default.join(
250          //: myapp/ios
251          config.modRequest.platformProjectRoot,
252          //: MyApp/Info.plist
253          infoPlistBuildProperty);
254          if ((0, _modules().fileExists)(infoPlistPath)) {
255            return infoPlistPath;
256          }
257          (0, _warnings().addWarningIOS)('mods.ios.infoPlist', `Info.plist file linked to Xcode project does not exist: ${infoPlistPath}`);
258        } else {
259          (0, _warnings().addWarningIOS)('mods.ios.infoPlist', 'Failed to find Info.plist linked to Xcode project.');
260        }
261      }
262      try {
263        // Fallback on glob...
264        return await _ios().Paths.getInfoPlistPath(config.modRequest.projectRoot);
265      } catch (error) {
266        if (config.modRequest.introspect) {
267          // fallback to an empty string in introspection mode.
268          return '';
269        }
270        throw error;
271      }
272    },
273    async read(filePath, config) {
274      // Apply all of the Info.plist values to the expo.ios.infoPlist object
275      // TODO: Remove this in favor of just overwriting the Info.plist with the Expo object. This will enable people to actually remove values.
276      if (!config.ios) config.ios = {};
277      if (!config.ios.infoPlist) config.ios.infoPlist = {};
278      let modResults;
279      try {
280        const contents = await readFile(filePath, 'utf8');
281        (0, _assert().default)(contents, 'Info.plist is empty');
282        modResults = _plist().default.parse(contents);
283      } catch (error) {
284        // Throw errors in introspection mode.
285        if (!config.modRequest.introspect) {
286          throw error;
287        }
288        // Fallback to using the infoPlist object from the Expo config.
289        modResults = getInfoPlistTemplate();
290      }
291      config.ios.infoPlist = {
292        ...(modResults || {}),
293        ...config.ios.infoPlist
294      };
295      return config.ios.infoPlist;
296    },
297    async write(filePath, config) {
298      // Update the contents of the static infoPlist object
299      if (!config.ios) {
300        config.ios = {};
301      }
302      config.ios.infoPlist = config.modResults;
303
304      // Return early without writing, in introspection mode.
305      if (config.modRequest.introspect) {
306        return;
307      }
308      await writeFile(filePath, _plist().default.build((0, _sortObject().sortObject)(config.modResults)));
309    }
310  }),
311  // Append a rule to supply .entitlements data to mods on `mods.ios.entitlements`
312  entitlements: (0, _createBaseMod().provider)({
313    isIntrospective: true,
314    async getFilePath(config) {
315      try {
316        var _Entitlements$getEnti;
317        (0, _Entitlements().ensureApplicationTargetEntitlementsFileConfigured)(config.modRequest.projectRoot);
318        return (_Entitlements$getEnti = _ios().Entitlements.getEntitlementsPath(config.modRequest.projectRoot)) !== null && _Entitlements$getEnti !== void 0 ? _Entitlements$getEnti : '';
319      } catch (error) {
320        if (config.modRequest.introspect) {
321          // fallback to an empty string in introspection mode.
322          return '';
323        }
324        throw error;
325      }
326    },
327    async read(filePath, config) {
328      let modResults;
329      try {
330        if (!config.modRequest.ignoreExistingNativeFiles && _fs().default.existsSync(filePath)) {
331          const contents = await readFile(filePath, 'utf8');
332          (0, _assert().default)(contents, 'Entitlements plist is empty');
333          modResults = _plist().default.parse(contents);
334        } else {
335          modResults = getEntitlementsPlistTemplate();
336        }
337      } catch (error) {
338        // Throw errors in introspection mode.
339        if (!config.modRequest.introspect) {
340          throw error;
341        }
342        // Fallback to using the template file.
343        modResults = getEntitlementsPlistTemplate();
344      }
345
346      // Apply all of the .entitlements values to the expo.ios.entitlements object
347      // TODO: Remove this in favor of just overwriting the .entitlements with the Expo object. This will enable people to actually remove values.
348      if (!config.ios) config.ios = {};
349      if (!config.ios.entitlements) config.ios.entitlements = {};
350      config.ios.entitlements = {
351        ...(modResults || {}),
352        ...config.ios.entitlements
353      };
354      return config.ios.entitlements;
355    },
356    async write(filePath, config) {
357      // Update the contents of the static entitlements object
358      if (!config.ios) {
359        config.ios = {};
360      }
361      config.ios.entitlements = config.modResults;
362
363      // Return early without writing, in introspection mode.
364      if (config.modRequest.introspect) {
365        return;
366      }
367      await writeFile(filePath, _plist().default.build((0, _sortObject().sortObject)(config.modResults)));
368    }
369  }),
370  // Append a rule to supply Podfile.properties.json data to mods on `mods.ios.podfileProperties`
371  podfileProperties: (0, _createBaseMod().provider)({
372    isIntrospective: true,
373    getFilePath({
374      modRequest: {
375        platformProjectRoot
376      }
377    }) {
378      return _path().default.resolve(platformProjectRoot, 'Podfile.properties.json');
379    },
380    async read(filePath) {
381      let results = {};
382      try {
383        results = await _jsonFile().default.readAsync(filePath);
384      } catch {}
385      return results;
386    },
387    async write(filePath, {
388      modResults,
389      modRequest: {
390        introspect
391      }
392    }) {
393      if (introspect) {
394        return;
395      }
396      await _jsonFile().default.writeAsync(filePath, modResults);
397    }
398  })
399};
400function withIosBaseMods(config, {
401  providers,
402  ...props
403} = {}) {
404  return (0, _createBaseMod().withGeneratedBaseMods)(config, {
405    ...props,
406    platform: 'ios',
407    providers: providers !== null && providers !== void 0 ? providers : getIosModFileProviders()
408  });
409}
410function getIosModFileProviders() {
411  return defaultProviders;
412}
413//# sourceMappingURL=withIosBaseMods.js.map