1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4  value: true
5});
6exports.findSchemeNames = findSchemeNames;
7exports.findSchemePaths = findSchemePaths;
8exports.getAllEntitlementsPaths = getAllEntitlementsPaths;
9exports.getAllInfoPlistPaths = getAllInfoPlistPaths;
10exports.getAllPBXProjectPaths = getAllPBXProjectPaths;
11exports.getAllXcodeProjectPaths = getAllXcodeProjectPaths;
12exports.getAppDelegate = getAppDelegate;
13exports.getAppDelegateFilePath = getAppDelegateFilePath;
14exports.getAppDelegateHeaderFilePath = getAppDelegateHeaderFilePath;
15exports.getAppDelegateObjcHeaderFilePath = getAppDelegateObjcHeaderFilePath;
16exports.getEntitlementsPath = getEntitlementsPath;
17exports.getExpoPlistPath = getExpoPlistPath;
18exports.getFileInfo = getFileInfo;
19exports.getInfoPlistPath = getInfoPlistPath;
20exports.getPBXProjectPath = getPBXProjectPath;
21exports.getSourceRoot = getSourceRoot;
22exports.getSupportingPath = getSupportingPath;
23exports.getXcodeProjectPath = getXcodeProjectPath;
24
25function _fs() {
26  const data = require("fs");
27
28  _fs = function () {
29    return data;
30  };
31
32  return data;
33}
34
35function _glob() {
36  const data = require("glob");
37
38  _glob = function () {
39    return data;
40  };
41
42  return data;
43}
44
45function path() {
46  const data = _interopRequireWildcard(require("path"));
47
48  path = function () {
49    return data;
50  };
51
52  return data;
53}
54
55function _errors() {
56  const data = require("../utils/errors");
57
58  _errors = function () {
59    return data;
60  };
61
62  return data;
63}
64
65function _warnings() {
66  const data = require("../utils/warnings");
67
68  _warnings = function () {
69    return data;
70  };
71
72  return data;
73}
74
75function Entitlements() {
76  const data = _interopRequireWildcard(require("./Entitlements"));
77
78  Entitlements = function () {
79    return data;
80  };
81
82  return data;
83}
84
85function _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); }
86
87function _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; }
88
89const ignoredPaths = ['**/@(Carthage|Pods|vendor|node_modules)/**'];
90
91function getAppDelegateHeaderFilePath(projectRoot) {
92  const [using, ...extra] = (0, _glob().sync)('ios/*/AppDelegate.h', {
93    absolute: true,
94    cwd: projectRoot,
95    ignore: ignoredPaths
96  });
97
98  if (!using) {
99    throw new (_errors().UnexpectedError)(`Could not locate a valid AppDelegate header at root: "${projectRoot}"`);
100  }
101
102  if (extra.length) {
103    warnMultipleFiles({
104      tag: 'app-delegate-header',
105      fileName: 'AppDelegate',
106      projectRoot,
107      using,
108      extra
109    });
110  }
111
112  return using;
113}
114
115function getAppDelegateFilePath(projectRoot) {
116  const [using, ...extra] = (0, _glob().sync)('ios/*/AppDelegate.@(m|mm|swift)', {
117    absolute: true,
118    cwd: projectRoot,
119    ignore: ignoredPaths
120  });
121
122  if (!using) {
123    throw new (_errors().UnexpectedError)(`Could not locate a valid AppDelegate at root: "${projectRoot}"`);
124  }
125
126  if (extra.length) {
127    warnMultipleFiles({
128      tag: 'app-delegate',
129      fileName: 'AppDelegate',
130      projectRoot,
131      using,
132      extra
133    });
134  }
135
136  return using;
137}
138
139function getAppDelegateObjcHeaderFilePath(projectRoot) {
140  const [using, ...extra] = (0, _glob().sync)('ios/*/AppDelegate.h', {
141    absolute: true,
142    cwd: projectRoot,
143    ignore: ignoredPaths
144  });
145
146  if (!using) {
147    throw new (_errors().UnexpectedError)(`Could not locate a valid AppDelegate.h at root: "${projectRoot}"`);
148  }
149
150  if (extra.length) {
151    warnMultipleFiles({
152      tag: 'app-delegate-objc-header',
153      fileName: 'AppDelegate.h',
154      projectRoot,
155      using,
156      extra
157    });
158  }
159
160  return using;
161}
162
163function getLanguage(filePath) {
164  const extension = path().extname(filePath);
165
166  switch (extension) {
167    case '.mm':
168      return 'objcpp';
169
170    case '.m':
171    case '.h':
172      return 'objc';
173
174    case '.swift':
175      return 'swift';
176
177    default:
178      throw new (_errors().UnexpectedError)(`Unexpected iOS file extension: ${extension}`);
179  }
180}
181
182function getFileInfo(filePath) {
183  return {
184    path: path().normalize(filePath),
185    contents: (0, _fs().readFileSync)(filePath, 'utf8'),
186    language: getLanguage(filePath)
187  };
188}
189
190function getAppDelegate(projectRoot) {
191  const filePath = getAppDelegateFilePath(projectRoot);
192  return getFileInfo(filePath);
193}
194
195function getSourceRoot(projectRoot) {
196  const appDelegate = getAppDelegate(projectRoot);
197  return path().dirname(appDelegate.path);
198}
199
200function findSchemePaths(projectRoot) {
201  return (0, _glob().sync)('ios/*.xcodeproj/xcshareddata/xcschemes/*.xcscheme', {
202    absolute: true,
203    cwd: projectRoot,
204    ignore: ignoredPaths
205  });
206}
207
208function findSchemeNames(projectRoot) {
209  const schemePaths = findSchemePaths(projectRoot);
210  return schemePaths.map(schemePath => path().parse(schemePath).name);
211}
212
213function getAllXcodeProjectPaths(projectRoot) {
214  const iosFolder = 'ios';
215  const pbxprojPaths = (0, _glob().sync)('ios/**/*.xcodeproj', {
216    cwd: projectRoot,
217    ignore: ignoredPaths
218  }).filter(project => !/test|example|sample/i.test(project) || path().dirname(project) === iosFolder) // sort alphabetically to ensure this works the same across different devices (Fail in CI (linux) without this)
219  .sort().sort((a, b) => {
220    const isAInIos = path().dirname(a) === iosFolder;
221    const isBInIos = path().dirname(b) === iosFolder; // preserve previous sort order
222
223    if (isAInIos && isBInIos || !isAInIos && !isBInIos) {
224      return 0;
225    }
226
227    return isAInIos ? -1 : 1;
228  });
229
230  if (!pbxprojPaths.length) {
231    throw new (_errors().UnexpectedError)(`Failed to locate the ios/*.xcodeproj files relative to path "${projectRoot}".`);
232  }
233
234  return pbxprojPaths.map(value => path().join(projectRoot, value));
235}
236/**
237 * Get the pbxproj for the given path
238 */
239
240
241function getXcodeProjectPath(projectRoot) {
242  const [using, ...extra] = getAllXcodeProjectPaths(projectRoot);
243
244  if (extra.length) {
245    warnMultipleFiles({
246      tag: 'xcodeproj',
247      fileName: '*.xcodeproj',
248      projectRoot,
249      using,
250      extra
251    });
252  }
253
254  return using;
255}
256
257function getAllPBXProjectPaths(projectRoot) {
258  const projectPaths = getAllXcodeProjectPaths(projectRoot);
259  const paths = projectPaths.map(value => path().join(value, 'project.pbxproj')).filter(value => (0, _fs().existsSync)(value));
260
261  if (!paths.length) {
262    throw new (_errors().UnexpectedError)(`Failed to locate the ios/*.xcodeproj/project.pbxproj files relative to path "${projectRoot}".`);
263  }
264
265  return paths;
266}
267
268function getPBXProjectPath(projectRoot) {
269  const [using, ...extra] = getAllPBXProjectPaths(projectRoot);
270
271  if (extra.length) {
272    warnMultipleFiles({
273      tag: 'project-pbxproj',
274      fileName: 'project.pbxproj',
275      projectRoot,
276      using,
277      extra
278    });
279  }
280
281  return using;
282}
283
284function getAllInfoPlistPaths(projectRoot) {
285  const paths = (0, _glob().sync)('ios/*/Info.plist', {
286    absolute: true,
287    cwd: projectRoot,
288    ignore: ignoredPaths
289  }).sort( // longer name means more suffixes, we want the shortest possible one to be first.
290  (a, b) => a.length - b.length);
291
292  if (!paths.length) {
293    throw new (_errors().UnexpectedError)(`Failed to locate Info.plist files relative to path "${projectRoot}".`);
294  }
295
296  return paths;
297}
298
299function getInfoPlistPath(projectRoot) {
300  const [using, ...extra] = getAllInfoPlistPaths(projectRoot);
301
302  if (extra.length) {
303    warnMultipleFiles({
304      tag: 'info-plist',
305      fileName: 'Info.plist',
306      projectRoot,
307      using,
308      extra
309    });
310  }
311
312  return using;
313}
314
315function getAllEntitlementsPaths(projectRoot) {
316  const paths = (0, _glob().sync)('ios/*/*.entitlements', {
317    absolute: true,
318    cwd: projectRoot,
319    ignore: ignoredPaths
320  });
321  return paths;
322}
323/**
324 * @deprecated: use Entitlements.getEntitlementsPath instead
325 */
326
327
328function getEntitlementsPath(projectRoot) {
329  return Entitlements().getEntitlementsPath(projectRoot);
330}
331
332function getSupportingPath(projectRoot) {
333  return path().resolve(projectRoot, 'ios', path().basename(getSourceRoot(projectRoot)), 'Supporting');
334}
335
336function getExpoPlistPath(projectRoot) {
337  const supportingPath = getSupportingPath(projectRoot);
338  return path().join(supportingPath, 'Expo.plist');
339}
340
341function warnMultipleFiles({
342  tag,
343  fileName,
344  projectRoot,
345  using,
346  extra
347}) {
348  const usingPath = projectRoot ? path().relative(projectRoot, using) : using;
349  const extraPaths = projectRoot ? extra.map(v => path().relative(projectRoot, v)) : extra;
350  (0, _warnings().addWarningIOS)(`paths-${tag}`, `Found multiple ${fileName} file paths, using "${usingPath}". Ignored paths: ${JSON.stringify(extraPaths)}`);
351}
352//# sourceMappingURL=Paths.js.map