-
Notifications
You must be signed in to change notification settings - Fork 77
/
Copy pathutil.ts
73 lines (66 loc) · 1.86 KB
/
util.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// Based off https://github.com/Kampfkarren/selene/blob/master/selene-vscode/src/util.ts
// Licensed under https://github.com/Kampfkarren/selene/blob/master/LICENSE.md
import * as vscode from "vscode";
import * as os from "os";
export const getDownloadOutputFilename = () => {
switch (os.platform()) {
case "win32":
return "stylua.exe";
case "linux":
case "darwin":
return "stylua";
default:
throw new Error("platform not supported");
}
};
export const getAssetFilenamePatternForPlatform = (
platform: string,
machine: string
) => {
var platformPattern: string;
switch (platform) {
case "win32":
platformPattern = "(windows|win64)";
break;
case "linux":
platformPattern = "linux";
break;
case "darwin":
platformPattern = "macos";
break;
default:
throw new Error("platform not supported");
}
var archPattern: string;
switch (machine) {
case "arm64":
archPattern = "aarch64";
break;
case "x64":
archPattern = "x86_64";
break;
default:
archPattern = "";
}
return new RegExp(
"stylua(-[\\dw\\-\\.]+)?-" + platformPattern + "(-" + archPattern + ")?.zip"
);
};
export const getAssetFilenamePattern = () => {
return getAssetFilenamePatternForPlatform(os.platform(), process.arch);
};
export const getDesiredVersion = (): string => {
const config = vscode.workspace.getConfiguration("stylua");
const targetVersion = config.get<string>("targetReleaseVersion", "").trim();
if (targetVersion.length === 0) {
return config.get<string>("releaseVersion", "latest");
}
return targetVersion;
};
export const fileExists = (path: vscode.Uri | string): Thenable<boolean> => {
const uri = path instanceof vscode.Uri ? path : vscode.Uri.file(path);
return vscode.workspace.fs.stat(uri).then(
() => true,
() => false
);
};