getHeaderSearchPath.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = getHeaderSearchPath;
  6. function _path() {
  7. const data = require("path");
  8. _path = function () {
  9. return data;
  10. };
  11. return data;
  12. }
  13. function _lodash() {
  14. const data = require("lodash");
  15. _lodash = function () {
  16. return data;
  17. };
  18. return data;
  19. }
  20. /**
  21. * Copyright (c) Facebook, Inc. and its affiliates.
  22. *
  23. * This source code is licensed under the MIT license found in the
  24. * LICENSE file in the root directory of this source tree.
  25. *
  26. */
  27. /**
  28. * Given an array of directories, it returns the one that contains
  29. * all the other directories in a given array inside it.
  30. *
  31. * Example:
  32. * Given an array of directories: ['/Users/Kureev/a', '/Users/Kureev/b']
  33. * the returned folder is `/Users/Kureev`
  34. *
  35. * Check `getHeaderSearchPath.spec.js` for more use-cases.
  36. */
  37. const getOuterDirectory = directories => directories.reduce((topDir, currentDir) => {
  38. const currentFolders = currentDir.split(_path().posix.sep);
  39. const topMostFolders = topDir.split(_path().posix.sep);
  40. if (currentFolders.length === topMostFolders.length && (0, _lodash().last)(currentFolders) !== (0, _lodash().last)(topMostFolders)) {
  41. return currentFolders.slice(0, -1).join(_path().posix.sep);
  42. }
  43. return currentFolders.length < topMostFolders.length ? currentDir : topDir;
  44. });
  45. /**
  46. * Given an array of headers it returns search path so Xcode can resolve
  47. * headers when referenced like below:
  48. * ```
  49. * #import "CodePush.h"
  50. * ```
  51. * If all files are located in one directory (directories.length === 1),
  52. * we simply return a relative path to that location.
  53. *
  54. * Otherwise, we loop through them all to find the outer one that contains
  55. * all the headers inside. That location is then returned with /** appended at
  56. * the end so Xcode marks that location as `recursive` and will look inside
  57. * every folder of it to locate correct headers.
  58. */
  59. function getHeaderSearchPath(sourceDir, headers) {
  60. const directories = (0, _lodash().union)(headers.map(_path().posix.dirname));
  61. return directories.length === 1 ? `"$(SRCROOT)/${_path().posix.relative(sourceDir, directories[0])}"` : `"$(SRCROOT)/${_path().posix.relative(sourceDir, getOuterDirectory(directories))}/**"`;
  62. }
  63. //# sourceMappingURL=getHeaderSearchPath.js.map