-
Notifications
You must be signed in to change notification settings - Fork 1
/
_windows.ts
61 lines (56 loc) · 1.32 KB
/
_windows.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
import { NpmWrapper, RunnableCommand, createVersionCommand } from "./_utils.ts";
class WindowsWraper implements NpmWrapper {
private readonly windowsCmd = ["cmd", "/c"];
/**
* Builds a subprocess for Windows environments.
* @param command Command to be wrapped
* @param dir Directory for context
* @param stdout Stdout to be used
*/
private createProcessWindows(
command: string[],
stdout?: "piped" | "inherit",
dir?: string,
) {
return Deno.run({
cmd: [...this.windowsCmd, ...command],
cwd: dir,
stdout,
});
}
async isInstalled() {
const { argsChain, output } = createVersionCommand();
try {
const p = this.createProcessWindows(
argsChain,
output,
);
const { success } = await p.status();
p.close();
return success;
} catch {
return false;
}
}
async run(cmd: RunnableCommand) {
const { dir = Deno.cwd(), argsChain, output } = cmd;
try {
const p = this.createProcessWindows(
argsChain,
output,
dir,
);
const { success } = await p.status();
p.close();
return success;
} catch {
return false;
}
}
}
/**
* Creates a new NPM wrapper for Windows environments.
*/
export function createWindowsWrapper(): NpmWrapper {
return new WindowsWraper();
}