-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtool-check.ts
57 lines (47 loc) · 2.05 KB
/
tool-check.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 * as child_process from 'child_process';
import * as semver from 'semver';
import { promisify } from 'util';
import * as vscode from 'vscode';
const execFile = promisify(child_process.execFile);
export const BEST_TOOL_VERSION = '0.2.0';
export function tryPromptForUpdatingTool(version: semver.SemVer | null) {
const disableVersionCheckUpdateSetting = new DisableVersionCheckUpdateSetting();
if (!disableVersionCheckUpdateSetting.isDisabled) {
if (!version) {
promptForUpdatingTool("???", disableVersionCheckUpdateSetting);
} else if (semver.lt(version, BEST_TOOL_VERSION)) {
promptForUpdatingTool(version.format(), disableVersionCheckUpdateSetting);
}
}
}
export async function getToolVersion(executable: string): Promise<semver.SemVer | null> {
const { stdout } = await execFile(executable, ["--version"], { timeout: 2000 });
const matches = /woke version ((?:\d+)\.(?:\d+)(?:\.\d+)*)/.exec(stdout);
if (matches && matches[1]) {
return semver.parse(matches[1]);
}
return null;
}
async function promptForUpdatingTool(currentVersion: string, disableVersionCheckUpdateSetting: DisableVersionCheckUpdateSetting) {
const selected = await vscode.window.showInformationMessage(`The vscode-woke extension requires a newer version of "woke" (You got v${currentVersion}, v${BEST_TOOL_VERSION} or better is required)`, 'Don\'t Show Again', 'Update');
switch (selected) {
case 'Don\'t Show Again':
disableVersionCheckUpdateSetting.persist();
break;
case 'Update':
vscode.env.openExternal(vscode.Uri.parse('https://github.com/get-woke/woke#installation'));
break;
}
}
export class DisableVersionCheckUpdateSetting {
private static key = 'disableVersionCheck';
private config: vscode.WorkspaceConfiguration;
readonly isDisabled: boolean;
constructor() {
this.config = vscode.workspace.getConfiguration('woke', null);
this.isDisabled = this.config.get(DisableVersionCheckUpdateSetting.key) || false;
}
persist() {
this.config.update(DisableVersionCheckUpdateSetting.key, true, true);
}
}