macosVersion.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.isMacOsCatalina = exports.isMacOsSierra = exports.isMacOsHighSierra = void 0;
  4. const fs_extra_1 = require("fs-extra");
  5. const lazy_val_1 = require("lazy-val");
  6. const semver = require("semver");
  7. const log_1 = require("builder-util/out/log");
  8. const os_1 = require("os");
  9. const macOsVersion = new lazy_val_1.Lazy(async () => {
  10. const file = await (0, fs_extra_1.readFile)("/System/Library/CoreServices/SystemVersion.plist", "utf8");
  11. const matches = /<key>ProductVersion<\/key>[\s\S]*<string>([\d.]+)<\/string>/.exec(file);
  12. if (!matches) {
  13. throw new Error("Couldn't find the macOS version");
  14. }
  15. log_1.log.debug({ version: matches[1] }, "macOS version");
  16. return clean(matches[1]);
  17. });
  18. function clean(version) {
  19. return version.split(".").length === 2 ? `${version}.0` : version;
  20. }
  21. async function isOsVersionGreaterThanOrEqualTo(input) {
  22. return semver.gte(await macOsVersion.value, clean(input));
  23. }
  24. function isMacOsHighSierra() {
  25. // 17.7.0 === 10.13.6
  26. return process.platform === "darwin" && semver.gte((0, os_1.release)(), "17.7.0");
  27. }
  28. exports.isMacOsHighSierra = isMacOsHighSierra;
  29. async function isMacOsSierra() {
  30. return process.platform === "darwin" && (await isOsVersionGreaterThanOrEqualTo("10.12.0"));
  31. }
  32. exports.isMacOsSierra = isMacOsSierra;
  33. function isMacOsCatalina() {
  34. return process.platform === "darwin" && semver.gte((0, os_1.release)(), "19.0.0");
  35. }
  36. exports.isMacOsCatalina = isMacOsCatalina;
  37. //# sourceMappingURL=macosVersion.js.map