Translate the root README into Polish, link it from each language switcher, and include it in README synchronization and asset checks.
29 lines
1.2 KiB
JavaScript
29 lines
1.2 KiB
JavaScript
import { describe, expect, test } from "bun:test";
|
|
import { existsSync, readFileSync, statSync } from "node:fs";
|
|
import { resolve } from "node:path";
|
|
|
|
const repositoryRoot = resolve(import.meta.dir, "..");
|
|
const readmes = ["README.md", "README.zh-CN.md", "README.zh-TW.md", "README.ja.md", "README.pl-PL.md"];
|
|
const remoteSource = /^(?:[a-z][a-z\d+.-]*:|\/\/|#)/i;
|
|
|
|
const localHtmlImageSources = (markdown) =>
|
|
[...markdown.matchAll(/<img\b[^>]*\bsrc=["']([^"']+)["'][^>]*>/gi)]
|
|
.map((match) => match[1])
|
|
.filter((source) => !remoteSource.test(source));
|
|
|
|
describe("README image assets", () => {
|
|
for (const readme of readmes) {
|
|
test(`${readme} only references existing local image files`, () => {
|
|
const markdown = readFileSync(resolve(repositoryRoot, readme), "utf8");
|
|
const sources = localHtmlImageSources(markdown);
|
|
|
|
expect(sources.length).toBeGreaterThan(0);
|
|
for (const source of sources) {
|
|
const assetPath = resolve(repositoryRoot, decodeURIComponent(source));
|
|
expect(existsSync(assetPath), `${readme}: missing ${source}`).toBe(true);
|
|
expect(statSync(assetPath).isFile(), `${readme}: not a file ${source}`).toBe(true);
|
|
}
|
|
});
|
|
}
|
|
});
|