nativescript
Version:
Command-line interface for building NativeScript projects
124 lines • 4.99 kB
JavaScript
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.HostInfo = void 0;
const decorators_1 = require("./decorators");
const _ = require("lodash");
const yok_1 = require("./yok");
class HostInfo {
get $childProcess() {
return this.$injector.resolve("childProcess");
}
get $osInfo() {
return this.$injector.resolve("osInfo");
}
get $logger() {
return this.$injector.resolve("logger");
}
constructor($errors, $injector) {
this.$errors = $errors;
this.$injector = $injector;
}
get isWindows() {
return process.platform === HostInfo.WIN32_NAME;
}
get isWindows64() {
return (this.isWindows &&
(process.arch === "x64" ||
process.env.hasOwnProperty(HostInfo.PROCESSOR_ARCHITEW6432)));
}
get isWindows32() {
return this.isWindows && !this.isWindows64;
}
get isDarwin() {
return process.platform === HostInfo.DARWIN_OS_NAME;
}
get isLinux() {
return process.platform === HostInfo.LINUX_OS_NAME;
}
get isLinux64() {
return this.isLinux && process.config.variables.host_arch === "x64";
}
async getMacOSVersion() {
if (!this.isDarwin) {
return null;
}
const systemProfileCommand = "system_profiler SPSoftwareDataType -detailLevel mini";
this.$logger.trace("Trying to get macOS version.");
let macOSVersion;
try {
const systemProfileOutput = await this.$childProcess.exec(systemProfileCommand);
const versionRegExp = /System Version:\s+?macOS\s+?(\d+\.\d+)(\.\d+)?\s+/g;
const regExpMatchers = versionRegExp.exec(systemProfileOutput);
macOSVersion = regExpMatchers && regExpMatchers[1];
if (macOSVersion) {
this.$logger.trace(`macOS version based on system_profiler is ${macOSVersion}.`);
return macOSVersion;
}
this.$logger.trace(`Unable to get macOS version from ${systemProfileCommand} output.`);
}
catch (err) {
this.$logger.trace(`Unable to get macOS version from ${systemProfileCommand}. Error is: ${err}`);
}
// https://en.wikipedia.org/wiki/Darwin_(operating_system)#Release_history
// Each macOS version is labeled 10.<version>, where it looks like <versions> is taken from the major version returned by os.release() (16.x.x for example) and subtracting 4 from it.
// So the version becomes "10.12" in this case.
const osRelease = this.$osInfo.release();
const majorVersion = osRelease && _.first(osRelease.split("."));
macOSVersion = majorVersion && `10.${+majorVersion - 4}`;
this.$logger.trace(`macOS version based on os.release() (${osRelease}) is ${macOSVersion}.`);
return macOSVersion;
}
dotNetVersion() {
if (this.isWindows) {
return new Promise((resolve, reject) => {
const Winreg = require("winreg");
const regKey = new Winreg({
hive: Winreg.HKLM,
key: HostInfo.DOT_NET_REGISTRY_PATH,
});
regKey.get("Version", (err, value) => {
if (err) {
reject(err);
}
else {
resolve(value.value);
}
});
});
}
else {
return Promise.resolve(null);
}
}
async isDotNet40Installed(message) {
if (this.isWindows) {
try {
await this.dotNetVersion();
return true;
}
catch (e) {
this.$errors.fail(message || "An error occurred while reading the registry.");
}
}
else {
return false;
}
}
}
exports.HostInfo = HostInfo;
HostInfo.WIN32_NAME = "win32";
HostInfo.PROCESSOR_ARCHITEW6432 = "PROCESSOR_ARCHITEW6432";
HostInfo.DARWIN_OS_NAME = "darwin";
HostInfo.LINUX_OS_NAME = "linux";
HostInfo.DOT_NET_REGISTRY_PATH = "\\Software\\Microsoft\\NET Framework Setup\\NDP\\v4\\Client";
__decorate([
(0, decorators_1.cache)()
], HostInfo.prototype, "getMacOSVersion", null);
yok_1.injector.register("hostInfo", HostInfo);
//# sourceMappingURL=host-info.js.map
;