@domandigital/create-site 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,69 @@
1
+ // House rules that run on every test run, plus a launch check.
2
+ // Written by @domandigital/create-site.
3
+ //
4
+ // pnpm seo:check always-on rules
5
+ // pnpm launch:check adds the "ready to launch" block below
6
+
7
+ import { readdirSync, readFileSync } from "node:fs";
8
+ import { join, relative } from "node:path";
9
+ import { describe, expect, test } from "vitest";
10
+ import { facts } from "~site/facts";
11
+
12
+ const ROOT = process.cwd();
13
+ const SOURCE_DIRS = ["app", "src", "components", "lib", "content"];
14
+ const SOURCE_FILE = /\.(tsx?|jsx?|astro|mdx?)$/;
15
+
16
+ function sourceFiles(): string[] {
17
+ const out: string[] = [];
18
+ const walk = (dir: string) => {
19
+ let entries;
20
+ try {
21
+ entries = readdirSync(dir, { withFileTypes: true });
22
+ } catch {
23
+ return;
24
+ }
25
+ for (const entry of entries) {
26
+ if (entry.name === "node_modules" || entry.name.startsWith(".")) continue;
27
+ const path = join(dir, entry.name);
28
+ if (entry.isDirectory()) walk(path);
29
+ else if (SOURCE_FILE.test(entry.name)) out.push(path);
30
+ }
31
+ };
32
+ for (const dir of SOURCE_DIRS) walk(join(ROOT, dir));
33
+ return out;
34
+ }
35
+
36
+ // vitest sets MODE from --mode; typed loosely so this file needs no Vite types.
37
+ const mode = (import.meta as unknown as { env?: { MODE?: string } }).env?.MODE;
38
+
39
+ describe("the facts file is the single source of contact details", () => {
40
+ test("no page or component hard-codes the phone number, email or postcode from site.facts.ts", () => {
41
+ const values = [facts.phone, facts.email, facts.address?.postalCode].filter((v): v is string => Boolean(v));
42
+ const offenders = sourceFiles().flatMap((file) => {
43
+ const text = readFileSync(file, "utf8");
44
+ return values.filter((v) => text.includes(v)).map((v) => `${relative(ROOT, file)}: ${v}`);
45
+ });
46
+ expect(offenders).toEqual([]);
47
+ });
48
+ });
49
+
50
+ describe.runIf(mode === "launch")("ready to launch", () => {
51
+ test("the designer credit is placed on the site", () => {
52
+ const placed = sourceFiles().some((file) => !/DesignerCredit\.(tsx|astro)$/.test(file) && readFileSync(file, "utf8").includes("<DesignerCredit"));
53
+ expect(placed).toBe(true);
54
+ });
55
+
56
+ test("phone and postcode are filled in", () => {
57
+ expect(facts.phone).not.toBeNull();
58
+ expect(facts.address?.postalCode ?? null).not.toBeNull();
59
+ });
60
+
61
+ test("at least one profile is live", () => {
62
+ expect(facts.profiles.some((p) => p.status === "live")).toBe(true);
63
+ });
64
+
65
+ test("every accreditation has a register link and a date someone checked it", () => {
66
+ const unchecked = facts.accreditations.filter((a) => !a.registerUrl || !a.verifiedOn).map((a) => a.name);
67
+ expect(unchecked).toEqual([]);
68
+ });
69
+ });
@@ -0,0 +1,20 @@
1
+ // Every page and every dynamic route has a policy entry, and every money page
2
+ // has a keyword target. Fails the moment a page is added without one. Written by
3
+ // @domandigital/create-site: the data lives in site.routes.ts.
4
+
5
+ import { describe, expect, test } from "vitest";
6
+ import { findKeywordCannibalization, validateCoverage } from "@domandigital/seo";
7
+ import { moneyRoutes, policy, targets } from "~site/routes";
8
+ import { dynamicRoutesOnDisk, routesOnDisk } from "~site/routes-on-disk";
9
+
10
+ describe("route coverage", () => {
11
+ test("every page and dynamic route on disk has a policy entry, and every money page has a target", () => {
12
+ expect(
13
+ validateCoverage({ routesOnDisk: routesOnDisk(), dynamicRoutesOnDisk: dynamicRoutesOnDisk(), policy, moneyRoutes, targets }),
14
+ ).toEqual([]);
15
+ });
16
+
17
+ test("no two pages chase the same keyword", () => {
18
+ expect(findKeywordCannibalization(targets)).toEqual([]);
19
+ });
20
+ });
@@ -0,0 +1,16 @@
1
+ // Every indexable page's JSON-LD is one connected graph: no dangling @id
2
+ // references, no duplicate ids. Written by @domandigital/create-site.
3
+
4
+ import { describe, expect, test } from "vitest";
5
+ import { findGraphIssues } from "@domandigital/graph";
6
+ import { buildPageGraph } from "~site/page-graph";
7
+ import { policy } from "~site/routes";
8
+
9
+ describe("JSON-LD", () => {
10
+ test("every indexable page builds a graph with no unresolved or duplicate @id", () => {
11
+ const issues = policy
12
+ .filter((entry) => entry.indexable && !entry.isDynamicPattern)
13
+ .flatMap((entry) => findGraphIssues(buildPageGraph({ path: entry.path, name: entry.path })).map((i) => `${entry.path}: ${i}`));
14
+ expect(issues).toEqual([]);
15
+ });
16
+ });
@@ -0,0 +1,25 @@
1
+ // The migration gate: every URL another site links to still lands on a page,
2
+ // in one hop. Record earned links in links.json and moved URLs in
3
+ // redirects.json. Written by @domandigital/create-site.
4
+
5
+ import { describe, expect, test } from "vitest";
6
+ import { liveLinkedUrls, validateRedirects } from "@domandigital/seo";
7
+ import type { BacklinkRegister, RedirectsFile } from "@domandigital/seo";
8
+ import { facts } from "~site/facts";
9
+ import links from "~site/links.json";
10
+ import redirectsFile from "~site/redirects.json";
11
+ import { policy } from "~site/routes";
12
+ import { routesOnDisk } from "~site/routes-on-disk";
13
+
14
+ describe("redirects", () => {
15
+ test("every linked URL resolves, with no chains, loops or dead targets", () => {
16
+ const issues = validateRedirects({
17
+ linkedUrls: liveLinkedUrls(links as BacklinkRegister),
18
+ routesOnDisk: routesOnDisk(),
19
+ redirects: (redirectsFile as RedirectsFile).redirects,
20
+ policy,
21
+ hosts: [new URL(facts.url).hostname, ...facts.previousHosts],
22
+ });
23
+ expect(issues).toEqual([]);
24
+ });
25
+ });