changeVersion.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  1. const fs = require("fs");
  2. const path = require("path");
  3. module.exports = function (context) {
  4. const projectRoot = context.opts.projectRoot;
  5. const cordovaCommon = context.requireCordovaModule("cordova-common");
  6. const { ConfigParser } = cordovaCommon;
  7. const appConfig = new ConfigParser(path.resolve(projectRoot, "config.xml"));
  8. let baseUrl = "https://www.raex.vip";
  9. if (context.cmdLine.includes("--test")) {
  10. baseUrl = "https://test.raex.vip";
  11. }
  12. if (context.cmdLine.includes("--dev")) {
  13. baseUrl = "http://192.168.6.116:8082/";
  14. }
  15. let channel = "default";
  16. let match = context.cmdLine.match(/channel=(.+?)(\s|$)/);
  17. if (match) {
  18. channel = match[1];
  19. console.log("channel: " + channel);
  20. }
  21. fs.writeFileSync(
  22. path.resolve(projectRoot, "www", "index.html"),
  23. fs
  24. .readFileSync(path.resolve(projectRoot, "www", "template.html"))
  25. .toString()
  26. .replace("${version}", appConfig.version())
  27. .replace("${iosCFBundleVersion}", appConfig.ios_CFBundleVersion())
  28. .replace("${androidVersionCode}", appConfig.android_versionCode())
  29. .replace(/\$\{baseUrl\}/g, baseUrl)
  30. .replaceAll('$channel', channel)
  31. );
  32. };