changeVersion.js 759 B

12345678910111213141516171819
  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. fs.writeFileSync(
  9. path.resolve(projectRoot, "www", "index.html"),
  10. fs
  11. .readFileSync(path.resolve(projectRoot, "www", "template.html"))
  12. .toString()
  13. .replace("${version}", appConfig.version())
  14. .replace("${iosCFBundleVersion}", appConfig.ios_CFBundleVersion())
  15. .replace("${androidVersionCode}", appConfig.android_versionCode())
  16. );
  17. };