fixCodePush.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. const fs = require("fs");
  2. const path = require("path");
  3. const https = require("https");
  4. module.exports = function (context) {
  5. if (
  6. context.opts.plugin &&
  7. context.opts.plugin.id === "cordova-plugin-code-push"
  8. ) {
  9. const projectRoot = context.opts.projectRoot;
  10. const cordovaCommon = context.requireCordovaModule("cordova-common");
  11. const { ConfigParser } = cordovaCommon;
  12. const appConfig = new ConfigParser(
  13. path.resolve(projectRoot, "config.xml")
  14. );
  15. let projectName = appConfig.name();
  16. function replaceFile(src, dst) {
  17. return new Promise((resolve, reject) => {
  18. https.get(src, (resp) => {
  19. var stream = resp.pipe(
  20. fs.createWriteStream(
  21. path.resolve(
  22. projectRoot,
  23. "platforms",
  24. "ios",
  25. projectName,
  26. "Plugins",
  27. "cordova-plugin-code-push",
  28. dst
  29. )
  30. )
  31. );
  32. stream.on("finish", function () {
  33. console.log(
  34. "saved to " +
  35. path.resolve(
  36. projectRoot,
  37. "platforms",
  38. "ios",
  39. projectName,
  40. "Plugins",
  41. "cordova-plugin-code-push",
  42. dst
  43. )
  44. );
  45. resolve();
  46. });
  47. });
  48. });
  49. }
  50. return Promise.all([
  51. replaceFile(
  52. "https://raw.githubusercontent.com/microsoft/cordova-plugin-code-push/v1.13.1/src/ios/CodePush.m",
  53. "CodePush.m"
  54. ),
  55. replaceFile(
  56. "https://raw.githubusercontent.com/microsoft/cordova-plugin-code-push/v1.13.1/src/ios/CodePushReportingManager.m",
  57. "CodePushReportingManager.m"
  58. ),
  59. ]);
  60. }
  61. };