-
Notifications
You must be signed in to change notification settings - Fork 5.9k
/
Copy pathos.ts
57 lines (46 loc) · 1.33 KB
/
os.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import { OperatingSystem, InitData } from "@coder/protocol";
import { client } from "./client";
class OS {
private _homedir: string | undefined;
private _tmpdir: string | undefined;
private _platform: NodeJS.Platform | undefined;
public constructor() {
client.initData.then((d) => this.initialize(d));
}
public homedir(): string {
if (typeof this._homedir === "undefined") {
throw new Error("trying to access homedir before it has been set");
}
return this._homedir;
}
public tmpdir(): string {
if (typeof this._tmpdir === "undefined") {
throw new Error("trying to access tmpdir before it has been set");
}
return this._tmpdir;
}
public initialize(data: InitData): void {
this._homedir = data.homeDirectory;
this._tmpdir = data.tmpDirectory;
switch (data.os) {
case OperatingSystem.Windows: this._platform = "win32"; break;
case OperatingSystem.Mac: this._platform = "darwin"; break;
default: this._platform = "linux"; break;
}
process.platform = this._platform;
process.env = {};
data.env.forEach((v, k) => {
process.env[k] = v;
});
}
public release(): string {
return "Unknown";
}
public platform(): NodeJS.Platform {
if (typeof this._platform === "undefined") {
throw new Error("trying to access platform before it has been set");
}
return this._platform;
}
}
export = new OS();