-
Notifications
You must be signed in to change notification settings - Fork 6
/
util.ts
38 lines (31 loc) · 1.01 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
// Copyright 2020 Yoshiya Hinosawa. All rights reserved. MIT license.
import { posix, win32 } from "./deps.ts";
const decoder = new TextDecoder();
export const decode = (data: Uint8Array): string => decoder.decode(data);
const encoder = new TextEncoder();
export const encode = (str: string): Uint8Array => encoder.encode(str);
async function run(args: string[], cwd?: string): Promise<Uint8Array> {
const p = Deno.run({
cmd: Deno.build.os === "windows" ? ["cmd.exe", "/c", ...args] : args,
stdout: "piped",
cwd,
});
const result = await p.output();
p.close();
return result;
}
export async function xrun(args: string[], cwd?: string): Promise<string> {
return decode(await run(args, cwd));
}
export function relative(base: string, path: string): string {
if (Deno.build.os === "windows") {
return win32.relative(base, path);
} else {
return posix.relative(base, path);
}
}
export function delay(n: number) {
return new Promise((resolve, _) => {
setTimeout(() => resolve(), n);
});
}