findLineToAddPod.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = findLineToAddPod;
  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. function findLineToAddPod(podLines, firstTargetLine) {
  14. // match line with new target: target 'project_name' do (most likely target inside podfile main target)
  15. const nextTarget = /target ('|")\w+('|") do/g; // match line that has only 'end' (if we don't catch new target or function, this would mean this is end of current target)
  16. const endOfCurrentTarget = /^\s*end\s*$/g; // match function definition, like: post_install do |installer| (some Podfiles have function defined inside main target
  17. const functionDefinition = /^\s*[a-z_]+\s+do(\s+\|[a-z]+\|)?/g;
  18. for (let i = firstTargetLine; i < podLines.length - 1; i++) {
  19. const matchNextConstruct = podLines[i].match(nextTarget) || podLines[i].match(functionDefinition);
  20. const matchEnd = podLines[i].match(endOfCurrentTarget);
  21. if (matchNextConstruct || matchEnd) {
  22. const firstNonSpaceCharacter = podLines[i].search(/\S/);
  23. return {
  24. indentation: firstNonSpaceCharacter + (matchEnd ? 2 : 0),
  25. line: i
  26. };
  27. }
  28. }
  29. return null;
  30. }
  31. //# sourceMappingURL=findLineToAddPod.js.map