Repository navigation
Expand file tree
/
Copy pathsync-catalog-examples.ts
More file actions
52 lines (44 loc) · 1.89 KB
/
Copy pathsync-catalog-examples.ts
File metadata and controls
52 lines (44 loc) · 1.89 KB
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
import { readFileSync, writeFileSync } from "node:fs";
import { join } from "node:path";
import { catalogNames, catalogPolicy } from "./component-policy.ts";
const adoptDocs = process.argv.includes("--adopt-docs");
const checkOnly = process.argv.includes("--check");
const failures: string[] = [];
const sourceAssets = (html: string): string =>
html
.replaceAll("../../css/preflight.css", "/docs/static/css/preflight.css")
.replaceAll("../../css/angular.css", "/docs/static/css/angular.css")
.replaceAll("../example.css", "/docs/static/examples/example.css")
.replaceAll("../../js/", "/docs/static/js/");
const publishedAssets = (html: string): string =>
html
.replaceAll("/docs/static/css/preflight.css", "../../css/preflight.css")
.replaceAll("/docs/static/css/angular.css", "../../css/angular.css")
.replaceAll("/docs/static/examples/example.css", "../example.css")
.replaceAll("/docs/static/js/", "../../js/");
for (const name of catalogNames) {
const { category } = catalogPolicy[name];
const sourcePath = join("src", category, name, `${name}.html`);
const publishedPath = join("docs/static/examples/components", `${name}.html`);
const inputPath = adoptDocs ? publishedPath : sourcePath;
const outputPath = adoptDocs ? sourcePath : publishedPath;
const expected = adoptDocs
? sourceAssets(readFileSync(inputPath, "utf8"))
: publishedAssets(readFileSync(inputPath, "utf8"));
if (checkOnly) {
if (readFileSync(outputPath, "utf8") !== expected)
failures.push(outputPath);
} else {
writeFileSync(outputPath, expected);
}
}
if (failures.length > 0) {
console.error("Catalog examples are stale:");
console.error(failures.join("\n"));
process.exit(1);
}
console.log(
checkOnly
? `Catalog example check passed for ${catalogNames.length} entries.`
: `${adoptDocs ? "Adopted" : "Published"} ${catalogNames.length} catalog examples.`,
);