fixCodePush.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. if (!fs.existsSync(src)) {
  18. return Promise.resolve();
  19. }
  20. return new Promise((resolve, reject) => {
  21. https.get(src, (resp) => {
  22. var stream = resp.pipe(
  23. fs.createWriteStream(
  24. path.resolve(
  25. projectRoot,
  26. "platforms",
  27. "ios",
  28. projectName,
  29. "Plugins",
  30. "cordova-plugin-code-push",
  31. dst
  32. )
  33. )
  34. );
  35. stream.on("finish", function () {
  36. console.log(
  37. "saved to " +
  38. path.resolve(
  39. projectRoot,
  40. "platforms",
  41. "ios",
  42. projectName,
  43. "Plugins",
  44. "cordova-plugin-code-push",
  45. dst
  46. )
  47. );
  48. resolve();
  49. });
  50. });
  51. });
  52. }
  53. return Promise.all([
  54. replaceFile(
  55. "https://raw.githubusercontent.com/microsoft/cordova-plugin-code-push/v1.13.1/src/ios/CodePush.m",
  56. "CodePush.m"
  57. ),
  58. replaceFile(
  59. "https://raw.githubusercontent.com/microsoft/cordova-plugin-code-push/v1.13.1/src/ios/CodePushReportingManager.m",
  60. "CodePushReportingManager.m"
  61. ),
  62. ]);
  63. }
  64. };