1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4  value: true
5});
6exports.getApplicationTargetNameForSchemeAsync = getApplicationTargetNameForSchemeAsync;
7exports.getArchiveBuildConfigurationForSchemeAsync = getArchiveBuildConfigurationForSchemeAsync;
8exports.getRunnableSchemesFromXcodeproj = getRunnableSchemesFromXcodeproj;
9exports.getSchemesFromXcodeproj = getSchemesFromXcodeproj;
10
11function _XML() {
12  const data = require("../utils/XML");
13
14  _XML = function () {
15    return data;
16  };
17
18  return data;
19}
20
21function _Paths() {
22  const data = require("./Paths");
23
24  _Paths = function () {
25    return data;
26  };
27
28  return data;
29}
30
31function _Target() {
32  const data = require("./Target");
33
34  _Target = function () {
35    return data;
36  };
37
38  return data;
39}
40
41function _Xcodeproj() {
42  const data = require("./utils/Xcodeproj");
43
44  _Xcodeproj = function () {
45    return data;
46  };
47
48  return data;
49}
50
51function getSchemesFromXcodeproj(projectRoot) {
52  return (0, _Paths().findSchemeNames)(projectRoot);
53}
54
55function getRunnableSchemesFromXcodeproj(projectRoot, {
56  configuration = 'Debug'
57} = {}) {
58  const project = (0, _Xcodeproj().getPbxproj)(projectRoot);
59  return (0, _Target().findSignableTargets)(project).map(([, target]) => {
60    let osType = 'iOS';
61    const type = (0, _Xcodeproj().unquote)(target.productType);
62
63    if (type === _Target().TargetType.WATCH) {
64      osType = 'watchOS';
65    } else if ( // (apps) com.apple.product-type.application
66    // (app clips) com.apple.product-type.application.on-demand-install-capable
67    // NOTE(EvanBacon): This matches against `watchOS` as well so we check for watch first.
68    type.startsWith(_Target().TargetType.APPLICATION)) {
69      // Attempt to resolve the platform SDK for each target so we can filter devices.
70      const xcConfigurationList = project.hash.project.objects.XCConfigurationList[target.buildConfigurationList];
71
72      if (xcConfigurationList) {
73        const buildConfiguration = xcConfigurationList.buildConfigurations.find(value => value.comment === configuration) || xcConfigurationList.buildConfigurations[0];
74
75        if (buildConfiguration !== null && buildConfiguration !== void 0 && buildConfiguration.value) {
76          var _project$hash$project;
77
78          const xcBuildConfiguration = (_project$hash$project = project.hash.project.objects.XCBuildConfiguration) === null || _project$hash$project === void 0 ? void 0 : _project$hash$project[buildConfiguration.value];
79          const buildSdkRoot = xcBuildConfiguration.buildSettings.SDKROOT;
80
81          if (buildSdkRoot === 'appletvos' || 'TVOS_DEPLOYMENT_TARGET' in xcBuildConfiguration.buildSettings) {
82            // Is a TV app...
83            osType = 'tvOS';
84          } else if (buildSdkRoot === 'iphoneos') {
85            osType = 'iOS';
86          }
87        }
88      }
89    }
90
91    return {
92      name: (0, _Xcodeproj().unquote)(target.name),
93      osType,
94      type: (0, _Xcodeproj().unquote)(target.productType)
95    };
96  });
97}
98
99async function readSchemeAsync(projectRoot, scheme) {
100  const allSchemePaths = (0, _Paths().findSchemePaths)(projectRoot);
101  const re = new RegExp(`/${scheme}.xcscheme`, 'i');
102  const schemePath = allSchemePaths.find(i => re.exec(i));
103
104  if (schemePath) {
105    return await (0, _XML().readXMLAsync)({
106      path: schemePath
107    });
108  } else {
109    throw new Error(`scheme '${scheme}' does not exist, make sure it's marked as shared`);
110  }
111}
112
113async function getApplicationTargetNameForSchemeAsync(projectRoot, scheme) {
114  var _schemeXML$Scheme, _schemeXML$Scheme$Bui, _schemeXML$Scheme$Bui2, _schemeXML$Scheme$Bui3, _schemeXML$Scheme$Bui4;
115
116  const schemeXML = await readSchemeAsync(projectRoot, scheme);
117  const buildActionEntry = schemeXML === null || schemeXML === void 0 ? void 0 : (_schemeXML$Scheme = schemeXML.Scheme) === null || _schemeXML$Scheme === void 0 ? void 0 : (_schemeXML$Scheme$Bui = _schemeXML$Scheme.BuildAction) === null || _schemeXML$Scheme$Bui === void 0 ? void 0 : (_schemeXML$Scheme$Bui2 = _schemeXML$Scheme$Bui[0]) === null || _schemeXML$Scheme$Bui2 === void 0 ? void 0 : (_schemeXML$Scheme$Bui3 = _schemeXML$Scheme$Bui2.BuildActionEntries) === null || _schemeXML$Scheme$Bui3 === void 0 ? void 0 : (_schemeXML$Scheme$Bui4 = _schemeXML$Scheme$Bui3[0]) === null || _schemeXML$Scheme$Bui4 === void 0 ? void 0 : _schemeXML$Scheme$Bui4.BuildActionEntry;
118  const targetName = (buildActionEntry === null || buildActionEntry === void 0 ? void 0 : buildActionEntry.length) === 1 ? getBlueprintName(buildActionEntry[0]) : getBlueprintName(buildActionEntry === null || buildActionEntry === void 0 ? void 0 : buildActionEntry.find(entry => {
119    var _entry$BuildableRefer, _entry$BuildableRefer2, _entry$BuildableRefer3, _entry$BuildableRefer4;
120
121    return (_entry$BuildableRefer = entry.BuildableReference) === null || _entry$BuildableRefer === void 0 ? void 0 : (_entry$BuildableRefer2 = _entry$BuildableRefer[0]) === null || _entry$BuildableRefer2 === void 0 ? void 0 : (_entry$BuildableRefer3 = _entry$BuildableRefer2['$']) === null || _entry$BuildableRefer3 === void 0 ? void 0 : (_entry$BuildableRefer4 = _entry$BuildableRefer3.BuildableName) === null || _entry$BuildableRefer4 === void 0 ? void 0 : _entry$BuildableRefer4.endsWith('.app');
122  }));
123
124  if (!targetName) {
125    throw new Error(`${scheme}.xcscheme seems to be corrupted`);
126  }
127
128  return targetName;
129}
130
131async function getArchiveBuildConfigurationForSchemeAsync(projectRoot, scheme) {
132  var _schemeXML$Scheme2, _schemeXML$Scheme2$Ar, _schemeXML$Scheme2$Ar2, _schemeXML$Scheme2$Ar3;
133
134  const schemeXML = await readSchemeAsync(projectRoot, scheme);
135  const buildConfiguration = schemeXML === null || schemeXML === void 0 ? void 0 : (_schemeXML$Scheme2 = schemeXML.Scheme) === null || _schemeXML$Scheme2 === void 0 ? void 0 : (_schemeXML$Scheme2$Ar = _schemeXML$Scheme2.ArchiveAction) === null || _schemeXML$Scheme2$Ar === void 0 ? void 0 : (_schemeXML$Scheme2$Ar2 = _schemeXML$Scheme2$Ar[0]) === null || _schemeXML$Scheme2$Ar2 === void 0 ? void 0 : (_schemeXML$Scheme2$Ar3 = _schemeXML$Scheme2$Ar2['$']) === null || _schemeXML$Scheme2$Ar3 === void 0 ? void 0 : _schemeXML$Scheme2$Ar3.buildConfiguration;
136
137  if (!buildConfiguration) {
138    throw new Error(`${scheme}.xcscheme seems to be corrupted`);
139  }
140
141  return buildConfiguration;
142}
143
144function getBlueprintName(entry) {
145  var _entry$BuildableRefer5, _entry$BuildableRefer6, _entry$BuildableRefer7;
146
147  return entry === null || entry === void 0 ? void 0 : (_entry$BuildableRefer5 = entry.BuildableReference) === null || _entry$BuildableRefer5 === void 0 ? void 0 : (_entry$BuildableRefer6 = _entry$BuildableRefer5[0]) === null || _entry$BuildableRefer6 === void 0 ? void 0 : (_entry$BuildableRefer7 = _entry$BuildableRefer6['$']) === null || _entry$BuildableRefer7 === void 0 ? void 0 : _entry$BuildableRefer7.BlueprintName;
148}
149//# sourceMappingURL=BuildScheme.js.map