text: "use strict";
  Object.defineProperty(exports, "__esModule", { value: true });
  exports.findNativeTargetByName = exports.findFirstNativeTarget = exports.getNativeTargets = exports.findApplicationTargetWithDependenciesAsync = exports.TargetType = void 0;
  const BuildScheme_1 = require("./BuildScheme");
  const Xcodeproj_1 = require("./utils/Xcodeproj");
  var TargetType;
  (function (TargetType) {
      TargetType["APPLICATION"] = "com.apple.product-type.application";
      TargetType["EXTENSION"] = "com.apple.product-type.app-extension";
      TargetType["OTHER"] = "other";
  })(TargetType = exports.TargetType || (exports.TargetType = {}));
  async function findApplicationTargetWithDependenciesAsync(projectRoot, scheme) {
      const applicationTargetName = await BuildScheme_1.getApplicationTargetNameForSchemeAsync(projectRoot, scheme);
      const project = Xcodeproj_1.getPbxproj(projectRoot);
      const [, applicationTarget] = findNativeTargetByName(project, applicationTargetName);
      const dependencies = applicationTarget.dependencies.map(({ value }) => {
          const { target: targetId } = project.getPBXGroupByKeyAndType(value, 'PBXTargetDependency');
          const [, target] = findNativeTargetById(project, targetId);
          const type = target.productType === TargetType.EXTENSION ||
              target.productType === `"${TargetType.EXTENSION}"`
              ? TargetType.EXTENSION
              : TargetType.OTHER;
          return {
              name: target.name,
              type,
          };
      });
      return {
          name: applicationTarget.name,
          type: TargetType.APPLICATION,
          dependencies,
      };
  }
  exports.findApplicationTargetWithDependenciesAsync = findApplicationTargetWithDependenciesAsync;
  function getNativeTargets(project) {
      const section = project.pbxNativeTargetSection();
      return Object.entries(section).filter(Xcodeproj_1.isNotComment);
  }
  exports.getNativeTargets = getNativeTargets;
  function findFirstNativeTarget(project) {
      const targets = getNativeTargets(project);
      if (targets.length === 0) {
          throw new Error(`Could not find any target in project.pbxproj`);
      }
      return targets[0];
  }
  exports.findFirstNativeTarget = findFirstNativeTarget;
  function findNativeTargetByName(project, targetName) {
      const nativeTargets = getNativeTargets(project);
      const nativeTargetEntry = nativeTargets.find(([, i]) => i.name === targetName || i.name === `"${targetName}"`);
      if (!nativeTargetEntry) {
          throw new Error(`Could not find target '${targetName}' in project.pbxproj`);
      }
      return nativeTargetEntry;
  }
  exports.findNativeTargetByName = findNativeTargetByName;
  function findNativeTargetById(project, targetId) {
      const nativeTargets = getNativeTargets(project);
      const nativeTargetEntry = nativeTargets.find(([key]) => key === targetId);
      if (!nativeTargetEntry) {
          throw new Error(`Could not find target with id '${targetId}' in project.pbxproj`);
      }
      return nativeTargetEntry;
  }
  //# sourceMappingURL=Target.js.map