nativescript
Version:
Command-line interface for building NativeScript projects
115 lines • 4.79 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.VirtualBoxService = void 0;
const path = require("path");
const os_1 = require("os");
const _ = require("lodash");
const decorators_1 = require("../../../decorators");
const helpers_1 = require("../../../helpers");
const yok_1 = require("../../../yok");
class VirtualBoxService {
constructor($childProcess, $fs, $hostInfo, $logger) {
this.$childProcess = $childProcess;
this.$fs = $fs;
this.$hostInfo = $hostInfo;
this.$logger = $logger;
}
async listVms() {
let result = null;
let vms = [];
const vBoxManagePath = await this.getvBoxManagePath();
if (vBoxManagePath) {
result = await this.$childProcess.trySpawnFromCloseEvent(vBoxManagePath, [
"list",
"vms",
]);
if (result && result.stdout) {
vms = result.stdout
.split(os_1.EOL)
.filter((row) => !!row)
.map((row) => {
// Example row: "Google Nexus 4 - 5.0.0 - API 21 - 768x1280" {9d9beef2-cc60-4a54-bcc0-cc1dbf89811f}
const [rawName, rawId] = row.split('" ');
const id = rawId.substr(1, rawId.length - 2);
const name = rawName.substr(1, rawName.length - 1);
return { id, name };
});
}
}
return { vms, error: result && result.stderr };
}
async enumerateGuestProperties(id) {
let result = null;
const vBoxManagePath = await this.getvBoxManagePath();
if (vBoxManagePath) {
result = await this.$childProcess.trySpawnFromCloseEvent(vBoxManagePath, [
"guestproperty",
"enumerate",
id,
]);
}
return {
properties: result && result.stdout,
error: result && result.stderr,
};
}
async getvBoxManageSearchPaths() {
const searchPaths = {
darwin: ["/usr/local/bin"],
linux: ["/opt", "/opt/local", "/usr", "/usr/local", "~"],
win32: [
`${process.env["PROGRAMFILES"]}\\Oracle\\VirtualBox`,
`${process.env["PROGRAMFILES(X86)"]}\\Oracle\\VirtualBox`,
],
};
if (this.$hostInfo.isWindows) {
let searchPath = null;
try {
/* This can be used as interface!!!!
arch:null
hive:"HKLM"
host:""
key:"\Software\Oracle\VirtualBox"
name:"InstallDir"
type:"REG_SZ"
value:"C:\Program Files\Oracle\VirtualBox\"
*/
const result = await (0, helpers_1.getWinRegPropertyValue)("\\Software\\Oracle\\VirtualBox", "InstallDir");
searchPath = result && result.value ? result.value : null;
}
catch (err) {
this.$logger.trace(`Error while trying to get InstallDir property for \\Software\\Oracle\\VirtualBox. More info: ${err}.`);
}
if (searchPath && !_.includes(searchPaths["win32"], searchPath)) {
searchPaths["win32"].unshift(searchPath);
}
}
return searchPaths;
}
get vBoxManageExecutableNames() {
return {
darwin: "VBoxManage",
linux: "VBoxManage",
win32: "VBoxManage.exe",
};
}
async getvBoxManagePath() {
const searchPaths = (await this.getvBoxManageSearchPaths())[process.platform];
const result = searchPaths
.map((searchPath) => path.join(searchPath, this.vBoxManageExecutableNames[process.platform]))
.find((searchPath) => this.$fs.exists(searchPath));
return result;
}
}
exports.VirtualBoxService = VirtualBoxService;
__decorate([
(0, decorators_1.cache)()
], VirtualBoxService.prototype, "getvBoxManagePath", null);
yok_1.injector.register("virtualBoxService", VirtualBoxService);
//# sourceMappingURL=virtualbox-service.js.map
;