-
Notifications
You must be signed in to change notification settings - Fork 22
/
check_command.ts
41 lines (37 loc) · 1.14 KB
/
check_command.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
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
import { CheckCommand } from "../args.ts";
import { colors } from "../deps.ts";
import { runPreBuild } from "../pre_build.ts";
export async function runCheckCommand(args: CheckCommand) {
const output = await runPreBuild(args);
const originalHash = await getOriginalSourceHash();
if (originalHash === output.sourceHash) {
console.log(
`${colors.bold(colors.green("Success"))} ` +
`wasmbuild output is up to date.`,
);
} else {
console.error(
`${colors.bold(colors.red("Error"))} ` +
`wasmbuild output is out of date (found hash ${output.sourceHash}, expected ${originalHash}).`,
);
Deno.exit(1);
}
async function getOriginalSourceHash() {
try {
return getSourceHashFromText(
await Deno.readTextFile(output.bindingJsPath),
);
} catch (err) {
if (err instanceof Deno.errors.NotFound) {
return undefined;
} else {
throw err;
}
}
}
function getSourceHashFromText(text: string) {
const result = text.match(/source-hash: (.+)\b/);
return result?.[1];
}
}