mirror of
https://github.com/denoland/deno.git
synced 2025-09-27 04:39:10 +00:00

For instance `deno bundle --outdir dist index.html` It will find scripts referenced in the html, bundle them, and then update the paths in index.html for the bundled assets. Right now it doesn't handle other assets (from `link` elements), but it could
32 lines
926 B
TypeScript
32 lines
926 B
TypeScript
export function assertFileContains(path: string, pattern: string | RegExp) {
|
|
const contents = Deno.readTextFileSync(path);
|
|
let matcher: (s: string) => boolean;
|
|
if (typeof pattern === "string") {
|
|
matcher = (s) => s.includes(pattern);
|
|
} else {
|
|
matcher = (s) => pattern.test(s);
|
|
}
|
|
if (!matcher(contents)) {
|
|
let message = "";
|
|
message += "file does not contain the pattern: " + path + "\n";
|
|
message += "wanted: " + pattern + "\n";
|
|
message += "found: " + contents + "\n";
|
|
throw new Error(message);
|
|
}
|
|
}
|
|
|
|
export function assertFileDoesNotContain(
|
|
path: string,
|
|
pattern: string | RegExp,
|
|
) {
|
|
try {
|
|
assertFileContains(path, pattern);
|
|
} catch (_e) {
|
|
return;
|
|
}
|
|
let message = "";
|
|
message += "file contains the pattern: " + path + "\n";
|
|
message += "did not want: " + pattern + "\n";
|
|
message += "found: " + Deno.readTextFileSync(path) + "\n";
|
|
throw new Error(message);
|
|
}
|