UNPKG

4.44 kBJavaScriptView Raw
1"use strict";
2// *****************************************************************************
3// Copyright (C) 2018-2020 Red Hat, Inc. and others.
4//
5// This program and the accompanying materials are made available under the
6// terms of the Eclipse Public License v. 2.0 which is available at
7// http://www.eclipse.org/legal/epl-2.0.
8//
9// This Source Code may also be made available under the following Secondary
10// Licenses when the conditions for such availability set forth in the Eclipse
11// Public License v. 2.0 are satisfied: GNU General Public License, version 2
12// with the GNU Classpath Exception which is available at
13// https://www.gnu.org/software/classpath/license.html.
14//
15// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
16// *****************************************************************************
17var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
18 var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
19 if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
20 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;
21 return c > 3 && r && Object.defineProperty(target, key, r), r;
22};
23var __metadata = (this && this.__metadata) || function (k, v) {
24 if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
25};
26Object.defineProperty(exports, "__esModule", { value: true });
27exports.EnvVariablesServerImpl = void 0;
28const path_1 = require("path");
29const os_1 = require("os");
30const inversify_1 = require("inversify");
31const drivelist = require("drivelist");
32const os_2 = require("../../common/os");
33const file_uri_1 = require("../file-uri");
34let EnvVariablesServerImpl = class EnvVariablesServerImpl {
35 constructor() {
36 this.envs = {};
37 this.homeDirUri = file_uri_1.FileUri.create((0, os_1.homedir)()).toString();
38 this.configDirUri = this.createConfigDirUri();
39 this.configDirUri.then(configDirUri => console.log(`Configuration directory URI: '${configDirUri}'`));
40 const prEnv = process.env;
41 Object.keys(prEnv).forEach((key) => {
42 let keyName = key;
43 if (os_2.isWindows) {
44 keyName = key.toLowerCase();
45 }
46 this.envs[keyName] = { 'name': keyName, 'value': prEnv[key] };
47 });
48 }
49 async createConfigDirUri() {
50 return file_uri_1.FileUri.create(process.env.THEIA_CONFIG_DIR || (0, path_1.join)((0, os_1.homedir)(), '.theia')).toString();
51 }
52 async getExecPath() {
53 return process.execPath;
54 }
55 async getVariables() {
56 return Object.keys(this.envs).map(key => this.envs[key]);
57 }
58 async getValue(key) {
59 if (os_2.isWindows) {
60 key = key.toLowerCase();
61 }
62 return this.envs[key];
63 }
64 getConfigDirUri() {
65 return this.configDirUri;
66 }
67 async getHomeDirUri() {
68 return this.homeDirUri;
69 }
70 async getDrives() {
71 const uris = [];
72 const drives = await drivelist.list();
73 for (const drive of drives) {
74 for (const mountpoint of drive.mountpoints) {
75 if (this.filterHiddenPartitions(mountpoint.path)) {
76 uris.push(file_uri_1.FileUri.create(mountpoint.path).toString());
77 }
78 }
79 }
80 return uris;
81 }
82 /**
83 * Filters hidden and system partitions.
84 */
85 filterHiddenPartitions(path) {
86 // OS X: This is your sleep-image. When your Mac goes to sleep it writes the contents of its memory to the hard disk. (https://bit.ly/2R6cztl)
87 if (path === '/private/var/vm') {
88 return false;
89 }
90 // Ubuntu: This system partition is simply the boot partition created when the computers mother board runs UEFI rather than BIOS. (https://bit.ly/2N5duHr)
91 if (path === '/boot/efi') {
92 return false;
93 }
94 return true;
95 }
96};
97EnvVariablesServerImpl = __decorate([
98 (0, inversify_1.injectable)(),
99 __metadata("design:paramtypes", [])
100], EnvVariablesServerImpl);
101exports.EnvVariablesServerImpl = EnvVariablesServerImpl;
102//# sourceMappingURL=env-variables-server.js.map
\No newline at end of file