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