getGroup.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = getGroup;
  6. /**
  7. * Copyright (c) Facebook, Inc. and its affiliates.
  8. *
  9. * This source code is licensed under the MIT license found in the
  10. * LICENSE file in the root directory of this source tree.
  11. *
  12. */
  13. const getFirstProject = project => project.getFirstProject().firstProject;
  14. const findGroup = (groups, name) => groups.children.find(group => group.comment === name);
  15. /**
  16. * Returns group from .xcodeproj if one exists, null otherwise
  17. *
  18. * Unlike node-xcode `pbxGroupByName` - it does not return `first-matching`
  19. * group if multiple groups with the same name exist
  20. *
  21. * If path is not provided, it returns top-level group
  22. */
  23. function getGroup(project, path) {
  24. const firstProject = getFirstProject(project);
  25. let groups = project.getPBXGroupByKey(firstProject.mainGroup);
  26. if (!path) {
  27. return groups;
  28. }
  29. for (const name of path.split('/')) {
  30. const foundGroup = findGroup(groups, name);
  31. if (foundGroup) {
  32. groups = project.getPBXGroupByKey(foundGroup.value);
  33. } else {
  34. groups = null;
  35. break;
  36. }
  37. }
  38. return groups;
  39. }
  40. //# sourceMappingURL=getGroup.js.map