leftShift2doLast.js 1.1 KB

1234567891011121314151617181920212223242526272829303132
  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 projectName = appConfig.name();
  9. const file = path.resolve(
  10. projectRoot,
  11. "platforms",
  12. "android",
  13. "cordova-plugin-code-push",
  14. `${appConfig.packageName().split(".").slice(-1)[0]}-build-extras.gradle`
  15. );
  16. if (!fs.existsSync(file)) {
  17. return;
  18. }
  19. let content = fs.readFileSync(file).toString();
  20. let lines = content.split("\n");
  21. let index = lines.findIndex(
  22. (i) => i.trim() === 'def newTask = task("cdvCreateAssetManifest") << {'
  23. );
  24. if (index > -1) {
  25. lines[index] = ' def newTask = task("cdvCreateAssetManifest") {';
  26. lines.splice(index + 18, 0, "}\n");
  27. lines.splice(index + 1, 0, "doLast {\n");
  28. }
  29. fs.writeFileSync(file, lines.join("\n"));
  30. };