versionNumberManager.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // Dependecies.
  2. const fs = require('fs-extra');
  3. const path = require('path');
  4. const colorConsole = require("../../NodeHelpers/colorConsole");
  5. // Global Variables.
  6. const config = require("../../Config/config.js");
  7. const enginePath = path.join(config.core.computed.mainDirectory, "Engines/thinEngine.ts");
  8. /**
  9. * Get the version from the engine class for Babylon
  10. */
  11. function getEngineVersion() {
  12. colorConsole.log("Get version from thinEngine.ts", enginePath);
  13. const engineContent = fs.readFileSync(enginePath).toString();
  14. const versionRegex = new RegExp(`public static get Version\\(\\): string {\\s*return "(\\S*)";\\s*}`, "gm");
  15. const match = versionRegex.exec(engineContent);
  16. if (match && match.length) {
  17. const version = match[1];
  18. colorConsole.log("Version found: " + version.green);
  19. colorConsole.emptyLine();
  20. return version;
  21. }
  22. colorConsole.error("Version not found in thinEngine.ts");
  23. process.exit(1);
  24. }
  25. /**
  26. * Update the version in the engine class for Babylon
  27. */
  28. function updateEngineVersion(newVersion) {
  29. colorConsole.log("Updating version in thinEngine.ts to: " + newVersion.green);
  30. let engineContent = fs.readFileSync(enginePath).toString();
  31. let replaced = engineContent.replace(/(public static get Version\(\): string {\s*return ")(.*)(";\s*})/g, "$1" + newVersion + "$3");
  32. replaced = replaced.replace(/(public static get NpmPackage\(\): string {\s*return ")(.*)(";\s*})/g, "$1" + "babylonjs@" + newVersion + "$3");
  33. fs.writeFileSync(enginePath, replaced);
  34. colorConsole.emptyLine();
  35. }
  36. /**
  37. * Update the root package.json version
  38. */
  39. function updateRootPackageVersion(newVersion) {
  40. colorConsole.log("Updating version in /package.json to: " + newVersion.green);
  41. const packageJSONPath = config.core.computed.packageJSONPath;
  42. const packageJson = require(packageJSONPath);
  43. packageJson.version = newVersion;
  44. fs.writeFileSync(packageJSONPath, JSON.stringify(packageJson, null, 4));
  45. colorConsole.emptyLine();
  46. }
  47. module.exports = {
  48. getEngineVersion,
  49. updateEngineVersion,
  50. updateRootPackageVersion
  51. };