react-native-navigation的迁移库

123456789101112131415161718192021222324252627282930313233343536373839
  1. // @ts-check
  2. var path = require('./path');
  3. var fs = require("fs");
  4. var {logn, debugn, infon} = require("./log");
  5. class PodfileLinker {
  6. constructor() {
  7. this.podfilePath = path.podFile;
  8. }
  9. link() {
  10. if (this.podfilePath) {
  11. logn("Updating Podfile...")
  12. var podfileContent = fs.readFileSync(this.podfilePath, "utf8");
  13. podfileContent = this._removeRNNPodLink(podfileContent);
  14. fs.writeFileSync(this.podfilePath, podfileContent);
  15. infon("Podfile updated successfully!\n")
  16. }
  17. }
  18. /**
  19. * Removes the RNN pod added by react-native link script.
  20. */
  21. _removeRNNPodLink(contents) {
  22. const rnnPodLink = contents.match(/\s+.*pod 'ReactNativeNavigation'.+react-native-navigation'/)
  23. if (!rnnPodLink) {
  24. debugn(" RNN Pod has not been added to Podfile")
  25. return contents
  26. }
  27. debugn(" Removing RNN Pod from Podfile")
  28. return contents.replace(rnnPodLink, "")
  29. }
  30. }
  31. module.exports = PodfileLinker