create-ailk 0.47.0 → 0.48.1

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.
Files changed (137) hide show
  1. package/README.md +192 -43
  2. package/component-catalog.json +223 -285
  3. package/component-catalog.md +1 -1
  4. package/dist/apply-design.d.ts +26 -68
  5. package/dist/apply-design.js +150 -322
  6. package/dist/cli.js +152 -17
  7. package/dist/compare-chrome.d.ts +108 -0
  8. package/dist/compare-chrome.js +481 -0
  9. package/dist/compare-look.d.ts +94 -0
  10. package/dist/compare-look.js +378 -0
  11. package/dist/copy.js +1 -1
  12. package/dist/design-compile.d.ts +17 -21
  13. package/dist/design-compile.js +32 -56
  14. package/dist/design-files.d.ts +93 -0
  15. package/dist/design-files.js +312 -0
  16. package/dist/design-home.d.ts +4 -2
  17. package/dist/design-home.js +88 -6
  18. package/dist/design-names.d.ts +13 -0
  19. package/dist/design-names.js +76 -0
  20. package/dist/design-package.d.ts +46 -56
  21. package/dist/design-package.js +285 -288
  22. package/dist/design-presets.d.ts +41 -0
  23. package/dist/design-presets.js +83 -4
  24. package/dist/design-scaffold.d.ts +12 -2
  25. package/dist/design-scaffold.js +72 -34
  26. package/dist/generated/design-settings.d.ts +56 -0
  27. package/dist/generated/design-settings.js +237 -0
  28. package/dist/index.d.ts +1 -1
  29. package/dist/index.js +2 -2
  30. package/dist/inventory.d.ts +3 -2
  31. package/dist/inventory.js +10 -4
  32. package/dist/lib/design-checks.d.ts +46 -0
  33. package/dist/lib/design-checks.js +79 -1
  34. package/dist/lib/env-catalog.js +1 -1
  35. package/dist/lib/module-license-gate.d.ts +1 -1
  36. package/dist/lib/module-license-gate.js +1 -1
  37. package/dist/lib/render-verdict.d.ts +13 -1
  38. package/dist/lib/render-verdict.js +41 -1
  39. package/dist/look-hub.d.ts +44 -0
  40. package/dist/look-hub.js +130 -0
  41. package/dist/look-record.d.ts +35 -0
  42. package/dist/look-record.js +85 -0
  43. package/dist/look-samples.d.ts +66 -0
  44. package/dist/look-samples.js +456 -0
  45. package/dist/look-settings.d.ts +53 -0
  46. package/dist/look-settings.js +807 -0
  47. package/dist/module-architecture.js +12 -0
  48. package/dist/parse-args.d.ts +10 -6
  49. package/dist/parse-args.js +26 -13
  50. package/dist/programmatic.d.ts +1 -19
  51. package/dist/programmatic.js +65 -103
  52. package/dist/retired-design-bodies.d.ts +29 -0
  53. package/dist/retired-design-bodies.js +51 -0
  54. package/dist/seed-flows.d.ts +1 -1
  55. package/dist/seed-flows.js +12 -14
  56. package/dist/seed-workspace.d.ts +4 -1
  57. package/dist/seed-workspace.js +139 -17
  58. package/dist/site-chrome.d.ts +42 -41
  59. package/dist/site-chrome.js +51 -70
  60. package/dist/site-fonts.d.ts +14 -14
  61. package/dist/site-fonts.js +9 -4
  62. package/dist/starter-grid.d.ts +2 -2
  63. package/dist/strip-look-copies.d.ts +67 -0
  64. package/dist/strip-look-copies.js +591 -0
  65. package/dist/template-manifest.d.ts +6 -14
  66. package/dist/template-manifest.js +0 -9
  67. package/dist/template-record.d.ts +3 -1
  68. package/dist/template-record.js +3 -1
  69. package/dist/topology.d.ts +15 -0
  70. package/dist/topology.js +60 -0
  71. package/dist/update.d.ts +57 -1
  72. package/dist/update.js +742 -13
  73. package/package.json +3 -4
  74. package/site-templates/aliases/hub.TEMPLATE-MANIFEST.json +2 -31
  75. package/site-templates/designs/minimalism/DESIGN.md +163 -297
  76. package/site-templates/designs/minimalism/LOOK.md +42 -0
  77. package/site-templates/designs/minimalism/design.yaml +167 -0
  78. package/site-templates/designs/standard/DESIGN.md +145 -149
  79. package/site-templates/designs/standard/LOOK.md +42 -0
  80. package/site-templates/designs/standard/design.yaml +72 -0
  81. package/site-templates/marketing-site/TEMPLATE-MANIFEST.json +2 -31
  82. package/site-templates/marketing-site/TEMPLATE-MANIFEST.md +1 -25
  83. package/site-templates/marketing-site-free/TEMPLATE-MANIFEST.json +2 -31
  84. package/site-templates/marketing-site-free/TEMPLATE-MANIFEST.md +1 -25
  85. package/site-templates/shapes/local-business-service/TEMPLATE-MANIFEST.json +2 -31
  86. package/site-templates/shapes/local-business-service/TEMPLATE-MANIFEST.md +1 -25
  87. package/site-templates/shapes/organization-service/TEMPLATE-MANIFEST.json +2 -31
  88. package/site-templates/shapes/organization-service/TEMPLATE-MANIFEST.md +1 -25
  89. package/site-templates/shapes/person-service/TEMPLATE-MANIFEST.json +2 -31
  90. package/site-templates/shapes/person-service/TEMPLATE-MANIFEST.md +1 -25
  91. package/site-templates/shapes/person-service/content/_site.mdx +0 -26
  92. package/templates/.claude/rules/extending.md +3 -2
  93. package/templates/.env.example +11 -4
  94. package/templates/CLAUDE.md +1 -1
  95. package/templates/DESIGN.md +145 -149
  96. package/templates/README.md +15 -16
  97. package/templates/apps/api/.env.example +11 -4
  98. package/templates/apps/api/CLAUDE.md +6 -4
  99. package/templates/apps/api/src/lib/__mocks__/prisma.ts +15 -5
  100. package/templates/apps/mcp/CLAUDE.md +4 -2
  101. package/templates/apps/web/.env.example +10 -3
  102. package/templates/apps/web/CLAUDE.md +14 -3
  103. package/templates/apps/web/app/[locale]/layout.tsx +53 -50
  104. package/templates/apps/web/app/not-found.tsx +11 -11
  105. package/templates/apps/web/auth.ts +48 -35
  106. package/templates/apps/web/jest.config.cjs +5 -0
  107. package/templates/apps/web/lib/__tests__/hub-site-config.test.ts +179 -31
  108. package/templates/apps/web/lib/__tests__/library-fonts.test.ts +35 -0
  109. package/templates/apps/web/lib/__tests__/page-chrome-navigation.test.ts +71 -32
  110. package/templates/apps/web/lib/__tests__/page-chrome.test.ts +123 -26
  111. package/templates/apps/web/lib/__tests__/section-look.test.ts +150 -0
  112. package/templates/apps/web/lib/__tests__/site-theme.test.ts +81 -289
  113. package/templates/apps/web/lib/deck-page.ts +3 -10
  114. package/templates/apps/web/lib/deploy-fonts.ts +12 -0
  115. package/templates/apps/web/lib/hub-site-config.ts +97 -14
  116. package/templates/apps/web/lib/library-fonts.ts +41 -0
  117. package/templates/apps/web/lib/mcp-oauth.ts +11 -4
  118. package/templates/apps/web/lib/page-chrome.ts +52 -34
  119. package/templates/apps/web/lib/section-look.ts +28 -0
  120. package/templates/apps/web/lib/site-design.ts +205 -0
  121. package/templates/apps/web/lib/site-theme-head.ts +98 -13
  122. package/templates/apps/web/lib/site-theme.ts +40 -62
  123. package/templates/apps/web/messages/en.json +0 -6
  124. package/templates/apps/web/next.config.mjs +195 -6
  125. package/templates/apps/web/package.json +2 -0
  126. package/templates/apps/web/site-pages.config.tsx +4 -2
  127. package/templates/content/_site.mdx +0 -26
  128. package/templates/design.yaml +75 -0
  129. package/templates/project.yaml +14 -0
  130. package/versions.json +52 -51
  131. package/site-templates/marketing-site/DESIGN.md +0 -259
  132. package/site-templates/marketing-site-free/DESIGN.md +0 -259
  133. package/site-templates/saas-product/DESIGN.md +0 -259
  134. package/templates/apps/web/lib/__tests__/deck-page.test.ts +0 -288
  135. package/templates/apps/web/lib/__tests__/site-theme-head.test.ts +0 -70
  136. package/templates/apps/web/lib/site-chrome.ts +0 -46
  137. package/templates/apps/web/lib/site-fonts.ts +0 -15
@@ -0,0 +1,93 @@
1
+ /** The site-root settings file, and the guide beside it. */
2
+ export declare const DESIGN_SETTINGS_FILE = "design.yaml";
3
+ export declare const DESIGN_GUIDE_FILE = "DESIGN.md";
4
+ /** The look's image direction, beside the guide (#12472 D2). */
5
+ export declare const LOOK_FILE = "LOOK.md";
6
+ /** A LOOK.md's `started_from`: the look contract's pattern (`look.v1.schema.json`, which create-ailk cannot import), and its bound. */
7
+ export declare const STARTED_FROM_PATTERN: RegExp;
8
+ export declare const STARTED_FROM_MAX = 64;
9
+ /**
10
+ * The largest design file `planDesignFiles` reads from a design's directory: a
11
+ * generous bound (the shipped guides are under 20 KB) that keeps a third-party
12
+ * design from feeding create-ailk an arbitrarily large file.
13
+ */
14
+ export declare const MAX_DESIGN_FILE_BYTES: number;
15
+ /** Thrown by `planDesignFiles` before any write: a symlink at a site-root design path, or a design's file that is not a regular file or is too large. */
16
+ export declare class DesignFilesError extends Error {
17
+ readonly path: string;
18
+ readonly reason: string;
19
+ constructor(path: string, reason: string);
20
+ }
21
+ export declare const SYMLINK_REASON = "a symlink \u2014 create-ailk never writes through one";
22
+ export type GuidePlan = {
23
+ action: "write";
24
+ text: string;
25
+ from: string;
26
+ } | {
27
+ action: "remove";
28
+ } | {
29
+ action: "keep";
30
+ } | {
31
+ action: "none";
32
+ };
33
+ /** LOOK.md is planned by the guide's rule (#12472 D4). */
34
+ export type LookPlan = GuidePlan;
35
+ export interface DesignFilesPlan {
36
+ designYaml: string;
37
+ guide: GuidePlan;
38
+ look: LookPlan;
39
+ }
40
+ /**
41
+ * True when `text` is in the retired settings format: a `---` fenced header
42
+ * whose column-0 keys include `layout` and are all among the old header's ten
43
+ * keys. impeccable's guide (it carries `components`), the Admin's DESIGN.md
44
+ * and the entity design systems all fail it.
45
+ */
46
+ export declare function isLegacyDesignMd(text: string): boolean;
47
+ /** The header text of a retired-format file, byte for byte between its fences (with LF line endings). */
48
+ export declare function legacyHeaderText(text: string): string;
49
+ /**
50
+ * The sha256 of a retired-format file's body, normalised (D6 step 2): the
51
+ * text after the closing `---` line, LF line endings, and — inside the
52
+ * leading `<!-- … -->` comment only — every line whose trimmed text starts
53
+ * `Source template:`, `Design:` or `Version:` dropped. The same line anywhere
54
+ * else is the site's own text and changes the hash.
55
+ */
56
+ export declare function legacyBodyHash(text: string): string;
57
+ /** The provenance comment lines of a retired DESIGN.md, as `# ` lines (each only when present). */
58
+ export declare function legacyProvenanceLines(text: string): string;
59
+ /** `path` is a symlink, dangling or not. */
60
+ export declare function isSymlink(path: string): boolean;
61
+ /** Refuse a symlink — dangling or not — at a site-root design path (SEC-12468-1). */
62
+ export declare function assertNotSymlink(path: string): void;
63
+ /** Where a planned guide write came from, when that is outside the shipped designs (SEC-12468-7); else undefined. */
64
+ export declare function guideCopiedFrom(guide: GuidePlan, designsDir: string): string | undefined;
65
+ /**
66
+ * #12472 D4 (SEC-12472-6) — the look a design's LOOK.md (`text`, read from
67
+ * `designDir`) started from, once accepted: its `started_from` matches the
68
+ * look contract's pattern and bound, and is the design directory's basename,
69
+ * or names a shipped design (found by listing `designsDir`, never by
70
+ * resolving a joined path) whose own LOOK.md has the same bytes — a
71
+ * byte-identical copy of that shipped look under another folder name
72
+ * (#6813 D11).
73
+ *
74
+ * @throws DesignFilesError naming `started_from`, before any other file is read.
75
+ */
76
+ export declare function acceptedStartedFrom(text: string, designDir: string, designsDir: string): string;
77
+ /**
78
+ * Plan a site's `design.yaml` and `DESIGN.md` for wearing the design in
79
+ * `designDir` (D4). Reads only; the caller writes.
80
+ *
81
+ * @throws DesignFilesError when any site-root path is a symlink; the
82
+ * design's `design.yaml`, `DESIGN.md` or `LOOK.md` is not a regular file or
83
+ * is larger than MAX_DESIGN_FILE_BYTES; or its LOOK.md's `started_from` is
84
+ * not accepted (`acceptedStartedFrom`).
85
+ */
86
+ export declare function planDesignFiles(input: {
87
+ designDir: string;
88
+ designsDir: string;
89
+ siteDir: string;
90
+ recorded: string;
91
+ sourceTemplate?: string;
92
+ version: string;
93
+ }): DesignFilesPlan;
@@ -0,0 +1,312 @@
1
+ /**
2
+ * A site's design files (#12468, spec
3
+ * docs/specs/12468-our-design-settings-file-becomes-spec.md D4): `design.yaml`,
4
+ * the settings of the design the site wears, and `DESIGN.md`, that design's
5
+ * guide — impeccable's document, copied byte for byte and never edited here.
6
+ * #12472 D4 adds `LOOK.md`, the look's image direction, planned by the
7
+ * guide's rule.
8
+ *
9
+ * `planDesignFiles` is the one planner the scaffold and `apply-design` write
10
+ * every one of them from. It reads the site's root files and writes nothing; a
11
+ * symlink at any root path is refused (SEC-12468-1), so no caller ever
12
+ * writes through one.
13
+ */
14
+ import { existsSync, lstatSync, readdirSync, readFileSync } from "node:fs";
15
+ import { basename, join, resolve, sep } from "node:path";
16
+ import { sha256Hex } from "./template-record.js";
17
+ /** The site-root settings file, and the guide beside it. */
18
+ export const DESIGN_SETTINGS_FILE = "design.yaml";
19
+ export const DESIGN_GUIDE_FILE = "DESIGN.md";
20
+ /** The look's image direction, beside the guide (#12472 D2). */
21
+ export const LOOK_FILE = "LOOK.md";
22
+ /** A LOOK.md's `started_from`: the look contract's pattern (`look.v1.schema.json`, which create-ailk cannot import), and its bound. */
23
+ export const STARTED_FROM_PATTERN = /^[a-z0-9]+(-[a-z0-9]+)*$/;
24
+ export const STARTED_FROM_MAX = 64;
25
+ /** The ten top-level keys of the retired settings format (the old DESIGN.md header). */
26
+ const LEGACY_HEADER_KEYS = new Set([
27
+ "name",
28
+ "description",
29
+ "colors",
30
+ "typography",
31
+ "rounded",
32
+ "spacing",
33
+ "layout",
34
+ "treatments",
35
+ "sections",
36
+ "copy",
37
+ ]);
38
+ /** The provenance lines a site's design files carry, in this order. */
39
+ const PROVENANCE_LABELS = ["Source template", "Design", "Version"];
40
+ /** A `design.yaml`'s leading `# <label>:` provenance comment lines. */
41
+ const LEADING_PROVENANCE = /^(?:#[ \t]*(?:Source template|Design|Version):.*\r?\n)+/;
42
+ /**
43
+ * The largest design file `planDesignFiles` reads from a design's directory: a
44
+ * generous bound (the shipped guides are under 20 KB) that keeps a third-party
45
+ * design from feeding create-ailk an arbitrarily large file.
46
+ */
47
+ export const MAX_DESIGN_FILE_BYTES = 1024 * 1024;
48
+ /** Thrown by `planDesignFiles` before any write: a symlink at a site-root design path, or a design's file that is not a regular file or is too large. */
49
+ export class DesignFilesError extends Error {
50
+ path;
51
+ reason;
52
+ constructor(path, reason) {
53
+ super(`${path}: ${reason}`);
54
+ this.path = path;
55
+ this.reason = reason;
56
+ this.name = "DesignFilesError";
57
+ }
58
+ }
59
+ export const SYMLINK_REASON = "a symlink — create-ailk never writes through one";
60
+ const NOT_A_FILE_REASON = "not a regular file — a design's settings and guide are read only from regular files in its own directory";
61
+ const TOO_LARGE_REASON = `larger than ${MAX_DESIGN_FILE_BYTES} bytes`;
62
+ function lf(text) {
63
+ return text.replace(/\r\n/g, "\n");
64
+ }
65
+ /** The header text between an opening `---` line and the next `---` line, and the body after it; undefined when unfenced. */
66
+ function splitFrontmatter(text) {
67
+ const normalised = lf(text);
68
+ if (!normalised.startsWith("---\n"))
69
+ return undefined;
70
+ const close = normalised.indexOf("\n---\n", 3);
71
+ if (close !== -1) {
72
+ return {
73
+ header: normalised.slice(4, close + 1),
74
+ body: normalised.slice(close + "\n---\n".length),
75
+ };
76
+ }
77
+ if (normalised.endsWith("\n---")) {
78
+ return { header: normalised.slice(4, normalised.length - 3), body: "" };
79
+ }
80
+ return undefined;
81
+ }
82
+ /**
83
+ * True when `text` is in the retired settings format: a `---` fenced header
84
+ * whose column-0 keys include `layout` and are all among the old header's ten
85
+ * keys. impeccable's guide (it carries `components`), the Admin's DESIGN.md
86
+ * and the entity design systems all fail it.
87
+ */
88
+ export function isLegacyDesignMd(text) {
89
+ const split = splitFrontmatter(text);
90
+ if (split === undefined)
91
+ return false;
92
+ const keys = [];
93
+ for (const line of split.header.split("\n")) {
94
+ const m = /^([A-Za-z0-9_-]+):/.exec(line);
95
+ if (m)
96
+ keys.push(m[1]);
97
+ }
98
+ return (keys.includes("layout") && keys.every((key) => LEGACY_HEADER_KEYS.has(key)));
99
+ }
100
+ /** The header text of a retired-format file, byte for byte between its fences (with LF line endings). */
101
+ export function legacyHeaderText(text) {
102
+ const split = splitFrontmatter(text);
103
+ if (split === undefined)
104
+ throw new Error("not a fenced DESIGN.md");
105
+ return split.header;
106
+ }
107
+ /**
108
+ * The sha256 of a retired-format file's body, normalised (D6 step 2): the
109
+ * text after the closing `---` line, LF line endings, and — inside the
110
+ * leading `<!-- … -->` comment only — every line whose trimmed text starts
111
+ * `Source template:`, `Design:` or `Version:` dropped. The same line anywhere
112
+ * else is the site's own text and changes the hash.
113
+ */
114
+ export function legacyBodyHash(text) {
115
+ const split = splitFrontmatter(text);
116
+ if (split === undefined)
117
+ throw new Error("not a fenced DESIGN.md");
118
+ const open = /^\s*<!--/.exec(split.body);
119
+ const close = open === null ? -1 : split.body.indexOf("-->", open[0].length);
120
+ const commentEnd = close === -1 ? 0 : close + "-->".length;
121
+ const comment = split.body
122
+ .slice(0, commentEnd)
123
+ .split("\n")
124
+ .filter((line) => !PROVENANCE_LABELS.some((label) => line.trim().startsWith(`${label}:`)))
125
+ .join("\n");
126
+ return sha256Hex(Buffer.from(comment + split.body.slice(commentEnd), "utf8"));
127
+ }
128
+ /**
129
+ * The value of one provenance line: `# <label>: <v>` in a `design.yaml`, or
130
+ * `<label>: <v>` (indented, in the header comment) in a retired DESIGN.md.
131
+ */
132
+ function provenance(text, label, form) {
133
+ const prefix = form === "yaml" ? "#[ \\t]*" : "[ \\t]*";
134
+ // A retired file's provenance sits in its body's header comment, never among the settings.
135
+ const searched = form === "yaml" ? lf(text) : (splitFrontmatter(text)?.body ?? "");
136
+ const m = new RegExp(`^${prefix}${label}:[ \\t]*(.*?)[ \\t]*$`, "m").exec(searched);
137
+ return m?.[1] !== undefined && m[1] !== "" ? m[1] : undefined;
138
+ }
139
+ /** The provenance comment lines of a retired DESIGN.md, as `# ` lines (each only when present). */
140
+ export function legacyProvenanceLines(text) {
141
+ return PROVENANCE_LABELS.map((label) => {
142
+ const value = provenance(text, label, "legacy");
143
+ return value === undefined ? "" : `# ${label}: ${value}\n`;
144
+ }).join("");
145
+ }
146
+ /** `path` is a symlink, dangling or not. */
147
+ export function isSymlink(path) {
148
+ try {
149
+ return lstatSync(path).isSymbolicLink();
150
+ }
151
+ catch {
152
+ return false; // absent
153
+ }
154
+ }
155
+ /** Refuse a symlink — dangling or not — at a site-root design path (SEC-12468-1). */
156
+ export function assertNotSymlink(path) {
157
+ if (isSymlink(path))
158
+ throw new DesignFilesError(path, SYMLINK_REASON);
159
+ }
160
+ function readIfPresent(path) {
161
+ return existsSync(path) ? readFileSync(path, "utf8") : undefined;
162
+ }
163
+ /**
164
+ * Read a file from a design's directory (M1): `lstat`, never followed — a
165
+ * symlink, a directory or any other non-regular entry is refused naming the
166
+ * path, as is a file over MAX_DESIGN_FILE_BYTES. Undefined when absent.
167
+ */
168
+ function readDesignFile(path) {
169
+ let stat;
170
+ try {
171
+ stat = lstatSync(path);
172
+ }
173
+ catch {
174
+ return undefined; // absent
175
+ }
176
+ if (!stat.isFile())
177
+ throw new DesignFilesError(path, NOT_A_FILE_REASON);
178
+ if (stat.size > MAX_DESIGN_FILE_BYTES)
179
+ throw new DesignFilesError(path, TOO_LARGE_REASON);
180
+ return readFileSync(path, "utf8");
181
+ }
182
+ /** Where a planned guide write came from, when that is outside the shipped designs (SEC-12468-7); else undefined. */
183
+ export function guideCopiedFrom(guide, designsDir) {
184
+ return guide.action === "write" &&
185
+ !resolve(guide.from).startsWith(resolve(designsDir) + sep)
186
+ ? guide.from
187
+ : undefined;
188
+ }
189
+ /** The names of the shipped designs: the direct child directories of `designsDir`, found by listing it. */
190
+ function shippedDesignNames(designsDir) {
191
+ if (!existsSync(designsDir))
192
+ return [];
193
+ return readdirSync(designsDir, { withFileTypes: true })
194
+ .filter((entry) => entry.isDirectory())
195
+ .map((entry) => entry.name);
196
+ }
197
+ /** Every shipped design's `file`, by bytes (D4's "byte-equal to some `<designsDir>/*\/DESIGN.md`"; #12472 D4's LOOK.md). */
198
+ function shippedFiles(designsDir, file) {
199
+ return shippedDesignNames(designsDir)
200
+ .map((name) => readIfPresent(join(designsDir, name, file)))
201
+ .filter((text) => text !== undefined);
202
+ }
203
+ /** A LOOK.md's frontmatter `started_from`, unquoted; undefined when it has no fenced header or no such line. */
204
+ function startedFromField(text) {
205
+ const header = splitFrontmatter(text)?.header;
206
+ if (header === undefined)
207
+ return undefined;
208
+ const m = /^started_from:[ \t]*(.*?)[ \t]*$/m.exec(header);
209
+ if (m === null)
210
+ return undefined;
211
+ const value = m[1];
212
+ const quoted = /^(["'])(.*)\1$/.exec(value);
213
+ return quoted !== null ? quoted[2] : value;
214
+ }
215
+ /**
216
+ * #12472 D4 (SEC-12472-6) — the look a design's LOOK.md (`text`, read from
217
+ * `designDir`) started from, once accepted: its `started_from` matches the
218
+ * look contract's pattern and bound, and is the design directory's basename,
219
+ * or names a shipped design (found by listing `designsDir`, never by
220
+ * resolving a joined path) whose own LOOK.md has the same bytes — a
221
+ * byte-identical copy of that shipped look under another folder name
222
+ * (#6813 D11).
223
+ *
224
+ * @throws DesignFilesError naming `started_from`, before any other file is read.
225
+ */
226
+ export function acceptedStartedFrom(text, designDir, designsDir) {
227
+ const lookPath = join(designDir, LOOK_FILE);
228
+ const value = startedFromField(text);
229
+ if (value === undefined ||
230
+ value.length > STARTED_FROM_MAX ||
231
+ !STARTED_FROM_PATTERN.test(value)) {
232
+ throw new DesignFilesError(lookPath, `started_from must be a library look's directory name (lowercase letters and digits in runs joined by single hyphens, at most ${STARTED_FROM_MAX} characters), not ${JSON.stringify(value ?? "")}`);
233
+ }
234
+ if (value === basename(resolve(designDir)))
235
+ return value;
236
+ if (shippedDesignNames(designsDir).includes(value) &&
237
+ readIfPresent(join(designsDir, value, LOOK_FILE)) === text) {
238
+ return value;
239
+ }
240
+ throw new DesignFilesError(lookPath, `started_from names ${JSON.stringify(value)}, which is neither this design's folder name nor a shipped look this LOOK.md is a byte-identical copy of`);
241
+ }
242
+ /** One root file planned by the guide's rule: the design's copy replaces ours (absent, or byte-equal to a shipped one), never the site's own. */
243
+ function planCopied(designText, from, currentText, ours) {
244
+ if (designText !== undefined) {
245
+ if (!ours)
246
+ return { action: "keep" };
247
+ if (currentText === designText)
248
+ return { action: "none" };
249
+ return { action: "write", text: designText, from };
250
+ }
251
+ if (currentText === undefined)
252
+ return { action: "none" };
253
+ return ours ? { action: "remove" } : { action: "keep" };
254
+ }
255
+ /**
256
+ * Plan a site's `design.yaml` and `DESIGN.md` for wearing the design in
257
+ * `designDir` (D4). Reads only; the caller writes.
258
+ *
259
+ * @throws DesignFilesError when any site-root path is a symlink; the
260
+ * design's `design.yaml`, `DESIGN.md` or `LOOK.md` is not a regular file or
261
+ * is larger than MAX_DESIGN_FILE_BYTES; or its LOOK.md's `started_from` is
262
+ * not accepted (`acceptedStartedFrom`).
263
+ */
264
+ export function planDesignFiles(input) {
265
+ const settingsPath = join(input.siteDir, DESIGN_SETTINGS_FILE);
266
+ const guidePath = join(input.siteDir, DESIGN_GUIDE_FILE);
267
+ const lookPath = join(input.siteDir, LOOK_FILE);
268
+ assertNotSymlink(settingsPath);
269
+ assertNotSymlink(guidePath);
270
+ assertNotSymlink(lookPath);
271
+ const currentSettings = readIfPresent(settingsPath);
272
+ const currentGuide = readIfPresent(guidePath);
273
+ const legacy = currentGuide !== undefined && isLegacyDesignMd(currentGuide);
274
+ const current = (label) => (currentSettings !== undefined
275
+ ? provenance(currentSettings, label, "yaml")
276
+ : undefined) ??
277
+ (legacy ? provenance(currentGuide, label, "legacy") : undefined);
278
+ const sourceSettingsPath = join(input.designDir, DESIGN_SETTINGS_FILE);
279
+ const sourceSettings = readDesignFile(sourceSettingsPath);
280
+ if (sourceSettings === undefined)
281
+ throw new DesignFilesError(sourceSettingsPath, "absent");
282
+ const sourceGuidePath = join(input.designDir, DESIGN_GUIDE_FILE);
283
+ const sourceGuide = readDesignFile(sourceGuidePath);
284
+ const sourceLookPath = join(input.designDir, LOOK_FILE);
285
+ const sourceLook = readDesignFile(sourceLookPath);
286
+ if (sourceLook !== undefined)
287
+ acceptedStartedFrom(sourceLook, input.designDir, input.designsDir);
288
+ const sourceTemplate = input.sourceTemplate ?? current("Source template");
289
+ const version = current("Version") ?? `create-ailk ${input.version}`;
290
+ const designYaml = (sourceTemplate !== undefined
291
+ ? `# Source template: ${sourceTemplate}\n`
292
+ : "") +
293
+ `# Design: ${input.recorded}\n` +
294
+ `# Version: ${version}\n` +
295
+ // A source that is itself a site root carries provenance lines of its own: never stacked.
296
+ sourceSettings.replace(LEADING_PROVENANCE, "");
297
+ const ours = currentGuide === undefined ||
298
+ legacy ||
299
+ shippedFiles(input.designsDir, DESIGN_GUIDE_FILE).includes(currentGuide);
300
+ // A retired-format file beside a design's settings is not a guide: never copied into a site.
301
+ const designGuide = sourceGuide !== undefined && !isLegacyDesignMd(sourceGuide)
302
+ ? sourceGuide
303
+ : undefined;
304
+ const guide = planCopied(designGuide, sourceGuidePath, currentGuide, ours);
305
+ const currentLook = readIfPresent(lookPath);
306
+ const look = planCopied(sourceLook, sourceLookPath, currentLook,
307
+ // A site's LOOK.md byte-equal to the design's plans `none`, a path design's included (D4).
308
+ currentLook === undefined ||
309
+ currentLook === sourceLook ||
310
+ shippedFiles(input.designsDir, LOOK_FILE).includes(currentLook));
311
+ return { designYaml, guide, look };
312
+ }
@@ -74,9 +74,11 @@ export declare function siteIdentityName(siteMdx: string | undefined): string |
74
74
  * A home's content fingerprint (D3): per section in order, its type and its
75
75
  * non-look `data` entries as `[key, normalized raw value]`, sorted by key.
76
76
  * A reflow, a look-field change or a preset leaves it unchanged; ids, the
77
- * title, the description and the body are not in it.
77
+ * title, the description and the body are not in it. #12472 D3 — nor is a
78
+ * look's sample fill: a home whose only change is sample fills is still a
79
+ * placeholder, while a person's own picture makes it authored.
78
80
  */
79
- export declare function fingerprint(text: string, catalog: SectionLookCatalog, file?: string): string;
81
+ export declare function fingerprint(page: string, catalog: SectionLookCatalog, file?: string): string;
80
82
  /**
81
83
  * The seed's `sections:` value with D4's carry applied from `home`: a seed
82
84
  * `logoCloud` (its `logos: []`) takes the raw `logos` of the home's first
@@ -24,11 +24,13 @@
24
24
  import { existsSync, readdirSync, readFileSync } from "node:fs";
25
25
  import { join } from "node:path";
26
26
  import { buildScaffoldMarkers } from "./copy.js";
27
+ import { shippedDesigns } from "./design-names.js";
27
28
  import { DesignPackageError } from "./design-package.js";
28
- import { locatePageSections, pageTypeOf, } from "./design-presets.js";
29
+ import { locatePageSections, pageTypeOf, parseFlowMapping, parseFlowSequence, scalarText, skipSpace, } from "./design-presets.js";
30
+ import { SAMPLE_FILL_MEMBERS, isSampleFill } from "./look-samples.js";
29
31
  import { RECOGNIZED_SHAPES } from "./parse-args.js";
30
32
  import { substituteMarkers } from "./substitute.js";
31
- import { STARTER_DESIGNS, TemplateError } from "./template-manifest.js";
33
+ import { TemplateError } from "./template-manifest.js";
32
34
  /** Where a site's home page lives, site-relative. */
33
35
  export const HOME_PAGE_PATH = "content/en/HomePage/home.mdx";
34
36
  /** Where a site's contact page lives, site-relative (#8661 D11). */
@@ -162,14 +164,14 @@ export function readDesignHomeSeeds(dir, opts) {
162
164
  export function designHomeSeeds(resolved, opts) {
163
165
  if (existsSync(join(resolved.dir, opts.page ?? "home")))
164
166
  return readDesignHomeSeeds(resolved.dir, opts);
165
- if (STARTER_DESIGNS.includes(resolved.recorded)) {
167
+ if (shippedDesigns().includes(resolved.recorded)) {
166
168
  return readDesignHomeSeeds(join(opts.designsDir, resolved.recorded), opts);
167
169
  }
168
170
  return [];
169
171
  }
170
172
  /** Every shipped design's seeds (D3's placeholder set reads them all). */
171
173
  export function shippedHomeSeeds(opts) {
172
- return STARTER_DESIGNS.flatMap((name) => readDesignHomeSeeds(join(opts.designsDir, name), opts));
174
+ return shippedDesigns().flatMap((name) => readDesignHomeSeeds(join(opts.designsDir, name), opts));
173
175
  }
174
176
  /** The shape's own home (or contact page): its shape tree's, else the overlay's (spec § 1.4). */
175
177
  export function shapeHomePath(shape, opts) {
@@ -260,13 +262,93 @@ function locate(text, file) {
260
262
  throw new TemplateError(`${file}: sections — the page has none`);
261
263
  return sections;
262
264
  }
265
+ /** The spans that remove `removed` children, one span per run, so no two overlap. */
266
+ function removalSpans(children, removed) {
267
+ const spans = [];
268
+ for (let i = 0; i < children.length; i++) {
269
+ if (!removed.has(i))
270
+ continue;
271
+ let j = i;
272
+ while (removed.has(j + 1))
273
+ j++;
274
+ const next = children[j + 1];
275
+ if (next !== undefined)
276
+ spans.push([children[i].keyStart, next.keyStart]);
277
+ else if (i > 0)
278
+ spans.push([children[i - 1].end, children[j].end]);
279
+ else
280
+ spans.push([children[0].keyStart, children[j].end]);
281
+ i = j;
282
+ }
283
+ return spans;
284
+ }
285
+ /**
286
+ * #12472 D3 — the spans that strip a look's sample fill from the flow value
287
+ * at `[start, valueEnd)`, at any depth. A fill writes only its four members
288
+ * (`SAMPLE_FILL_MEMBERS`), onto an image object it created or one that held
289
+ * no source, so stripping removes those four from an object `isSampleFill`
290
+ * names; an object left with no member — like an empty object or a null a
291
+ * placeholder held there — is dropped with its key, so absent, `{}`, `null`
292
+ * and a filled object read alike. A list keeps every item. `empty` when the
293
+ * value is an object with no member left, or null.
294
+ */
295
+ function sampleFillStrip(text, start, valueEnd, end) {
296
+ if (text[start] === "[") {
297
+ const list = parseFlowSequence(text, start, end);
298
+ return {
299
+ spans: (list?.items ?? []).flatMap((item) => sampleFillStrip(text, item.start, item.end, end).spans),
300
+ empty: false,
301
+ };
302
+ }
303
+ if (text[start] !== "{")
304
+ return { spans: [], empty: ["null", "~"].includes(text.slice(start, valueEnd).trim()) };
305
+ const mapping = parseFlowMapping(text, start, end);
306
+ if (mapping === undefined)
307
+ return { spans: [], empty: false };
308
+ const scalar = (name) => {
309
+ const e = mapping.entries.find((x) => x.key === name);
310
+ return e === undefined ? "" : (scalarText(text.slice(e.valueStart, e.valueEnd)) ?? "");
311
+ };
312
+ const fill = isSampleFill(scalar("src"), scalar("alt"));
313
+ const children = mapping.entries.map((e, n, all) => ({
314
+ start: e.valueStart,
315
+ end: e.valueEnd,
316
+ // A key starts after the `,` that ends the entry before it (or after the `{`).
317
+ keyStart: n === 0 ? skipSpace(text, start + 1, end) : skipSpace(text, skipSpace(text, all[n - 1].valueEnd, end) + 1, end),
318
+ }));
319
+ const removed = new Set();
320
+ const nested = [];
321
+ mapping.entries.forEach((entry, n) => {
322
+ if (fill && SAMPLE_FILL_MEMBERS.includes(entry.key)) {
323
+ removed.add(n);
324
+ return;
325
+ }
326
+ const inner = sampleFillStrip(text, entry.valueStart, entry.valueEnd, end);
327
+ if (inner.empty)
328
+ removed.add(n);
329
+ else
330
+ nested.push(...inner.spans);
331
+ });
332
+ return { spans: [...nested, ...removalSpans(children, removed)], empty: removed.size === children.length };
333
+ }
334
+ /** `text` with every sample fill stripped from its sections' data (D3); unchanged when it holds none. */
335
+ function withoutSampleFills(text, file) {
336
+ const spans = locate(text, file).flatMap((section) => section.form === "flow" ? sampleFillStrip(text, section.dataOpen, section.dataClose + 1, section.end).spans : []);
337
+ let out = text;
338
+ for (const [start, end] of spans.sort((a, b) => b[0] - a[0]))
339
+ out = out.slice(0, start) + out.slice(end);
340
+ return out;
341
+ }
263
342
  /**
264
343
  * A home's content fingerprint (D3): per section in order, its type and its
265
344
  * non-look `data` entries as `[key, normalized raw value]`, sorted by key.
266
345
  * A reflow, a look-field change or a preset leaves it unchanged; ids, the
267
- * title, the description and the body are not in it.
346
+ * title, the description and the body are not in it. #12472 D3 — nor is a
347
+ * look's sample fill: a home whose only change is sample fills is still a
348
+ * placeholder, while a person's own picture makes it authored.
268
349
  */
269
- export function fingerprint(text, catalog, file = "home.mdx") {
350
+ export function fingerprint(page, catalog, file = "home.mdx") {
351
+ const text = withoutSampleFills(page, file);
270
352
  const sections = locate(text, file);
271
353
  return JSON.stringify(sections.map((section) => {
272
354
  const look = new Set(catalog[section.type]?.look ?? []);
@@ -0,0 +1,13 @@
1
+ /**
2
+ * The looks under `dir`, sorted: each entry that is a real directory (a
3
+ * symlink is skipped), whose name is a look name, and that holds a
4
+ * `design.yaml` that is a regular file (a symlink is skipped). `[]` for a
5
+ * directory that does not exist.
6
+ */
7
+ export declare function listDesigns(dir: string): string[];
8
+ /** `listDesigns(dir)`, refusing an empty list — so an unreadable directory never falls through to a path lookup. */
9
+ export declare function readShippedDesigns(dir: string): string[];
10
+ /** This installer's own design directory, `site-templates/designs/` beside its module files. */
11
+ export declare function shippedDesignsDir(): string;
12
+ /** The looks this installer ships: its `site-templates/designs/` directory, read on the first call and kept. */
13
+ export declare function shippedDesigns(): readonly string[];
@@ -0,0 +1,76 @@
1
+ /**
2
+ * The looks this installer ships, read from its own design directory
3
+ * (#12500 D6) — never a typed list. A look is a directory under
4
+ * `site-templates/designs/` holding a `design.yaml`; admitting one to the
5
+ * design library changes no file here, and shipping one adds its directory.
6
+ *
7
+ * A leaf: it imports nothing from the registry, so `parse-args.ts`'s
8
+ * runtime-cycle note still holds. Nothing here reads a file when the module
9
+ * is imported (SEC-12500-4): the licence issuer loads this graph through
10
+ * `template-manifest.js` and its bundle need not carry the design directory,
11
+ * so the list is read on the first call to `shippedDesigns()` and kept.
12
+ */
13
+ import { existsSync, lstatSync, readdirSync } from "node:fs";
14
+ import { dirname, join, resolve } from "node:path";
15
+ import { fileURLToPath } from "node:url";
16
+ /** A look's directory name — lowercase letters, digits and hyphens (SEC-12500-5). */
17
+ const DESIGN_NAME_RE = /^[a-z0-9][a-z0-9-]*$/;
18
+ /**
19
+ * The looks under `dir`, sorted: each entry that is a real directory (a
20
+ * symlink is skipped), whose name is a look name, and that holds a
21
+ * `design.yaml` that is a regular file (a symlink is skipped). `[]` for a
22
+ * directory that does not exist.
23
+ */
24
+ export function listDesigns(dir) {
25
+ if (!existsSync(dir))
26
+ return [];
27
+ return readdirSync(dir)
28
+ .filter((name) => {
29
+ if (!DESIGN_NAME_RE.test(name))
30
+ return false;
31
+ if (!lstatSync(join(dir, name)).isDirectory())
32
+ return false;
33
+ const settings = join(dir, name, "design.yaml");
34
+ return existsSync(settings) && lstatSync(settings).isFile();
35
+ })
36
+ .sort();
37
+ }
38
+ /** `listDesigns(dir)`, refusing an empty list — so an unreadable directory never falls through to a path lookup. */
39
+ export function readShippedDesigns(dir) {
40
+ const names = listDesigns(dir);
41
+ if (names.length === 0) {
42
+ throw new Error(`installer design directory unreadable: ${dir}`);
43
+ }
44
+ return names;
45
+ }
46
+ /**
47
+ * This module's own file — `dist/design-names.js` when built, `src/design-names.ts`
48
+ * under Jest — read from the V8 call site of this function. `import.meta.url`
49
+ * would say the same, but it is a SyntaxError under Jest's CommonJS transform
50
+ * (`copy.ts`'s note), which loads this module through `parse-args.ts`.
51
+ */
52
+ function ownFile() {
53
+ // eslint-disable-next-line @typescript-eslint/unbound-method -- held only to restore it below, never called here
54
+ const original = Error.prepareStackTrace;
55
+ try {
56
+ Error.prepareStackTrace = (_error, frames) => frames;
57
+ const frames = new Error().stack;
58
+ const name = frames[0]?.getFileName();
59
+ if (name === undefined || name === null)
60
+ throw new Error("design-names: cannot locate its own module file");
61
+ return name.startsWith("file:") ? fileURLToPath(name) : name;
62
+ }
63
+ finally {
64
+ Error.prepareStackTrace = original;
65
+ }
66
+ }
67
+ let shipped;
68
+ /** This installer's own design directory, `site-templates/designs/` beside its module files. */
69
+ export function shippedDesignsDir() {
70
+ return resolve(dirname(ownFile()), "..", "site-templates", "designs");
71
+ }
72
+ /** The looks this installer ships: its `site-templates/designs/` directory, read on the first call and kept. */
73
+ export function shippedDesigns() {
74
+ shipped ??= readShippedDesigns(shippedDesignsDir());
75
+ return shipped;
76
+ }