@se-studio/site-check 2.13.1 → 2.14.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.
- package/CHANGELOG.md +28 -0
- package/README.md +89 -0
- package/check-cms-driven.mjs +405 -0
- package/docs/llms.md +18 -0
- package/package.json +8 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,33 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 2.14.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 40eac4a: Add `check-cms-driven` so a site can fail CI when a layout or route handler special-cases a slug or content type. R2 is on by default for BasicLayout, route handlers, and app layouts. R1 (literal chrome colours) stays off until `cms-driven.config.json` sets `r1`. The `se-exception` line comment still opts a single line out.
|
|
8
|
+
|
|
9
|
+
`articleType` and `customType` URL calculators now take an optional `indexPageSlug` from the CMS. Calculators that ignore it keep their current URLs. example-empty uses `indexPageSlug ?? slug` for those index paths.
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- Updated dependencies [40eac4a]
|
|
14
|
+
- @se-studio/contentful-rest-api@2.2.0
|
|
15
|
+
- @se-studio/core-data-types@2.0.5
|
|
16
|
+
|
|
17
|
+
## 2.13.3
|
|
18
|
+
|
|
19
|
+
### Patch Changes
|
|
20
|
+
|
|
21
|
+
- Updated dependencies [68a909d]
|
|
22
|
+
- @se-studio/contentful-rest-api@2.1.3
|
|
23
|
+
|
|
24
|
+
## 2.13.2
|
|
25
|
+
|
|
26
|
+
### Patch Changes
|
|
27
|
+
|
|
28
|
+
- Updated dependencies [7ad2d79]
|
|
29
|
+
- @se-studio/contentful-rest-api@2.1.2
|
|
30
|
+
|
|
3
31
|
## 2.13.1
|
|
4
32
|
|
|
5
33
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -260,6 +260,95 @@ check-publish-state --type template --include-links
|
|
|
260
260
|
|
|
261
261
|
Programmatic: `import { checkPublishState } from '@se-studio/site-check/publish-state'`. Requires `CONTENTFUL_SPACE_ID`, `CONTENTFUL_ACCESS_TOKEN`, `CONTENTFUL_PREVIEW_ACCESS_TOKEN`, and optionally `CONTENTFUL_ENVIRONMENT`. See `docs/RELEASE_VERIFICATION.md`.
|
|
262
262
|
|
|
263
|
+
## CMS-driven layouts (`check-cms-driven`)
|
|
264
|
+
|
|
265
|
+
Fails when a layout or route handler special-cases a page by slug or content type. Page-specific chrome belongs in a CMS template. The check is **not** part of customer site CI until that site has removed its own special cases and opts in.
|
|
266
|
+
|
|
267
|
+
Run it from the **app root** (where `src/project/BasicLayout.tsx` lives):
|
|
268
|
+
|
|
269
|
+
```bash
|
|
270
|
+
pnpm exec check-cms-driven
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
Opt in by adding the bin to that app's `package.json` and to its `validate` script:
|
|
274
|
+
|
|
275
|
+
```json
|
|
276
|
+
{
|
|
277
|
+
"scripts": {
|
|
278
|
+
"check:cms-driven": "check-cms-driven",
|
|
279
|
+
"validate": "pnpm check && pnpm check:cms-driven"
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
`apps/example-empty` already does this, so a new site copied from the skeleton inherits R2. Existing customer sites add the script in a later PR, after their own cleanup.
|
|
285
|
+
|
|
286
|
+
### R2 (on by default)
|
|
287
|
+
|
|
288
|
+
Checked files:
|
|
289
|
+
|
|
290
|
+
- `src/project/BasicLayout.tsx` (also in `apps/*/src/project/`)
|
|
291
|
+
- `src/lib/route-handlers.ts`
|
|
292
|
+
- `src/app/**/layout.tsx`, including `src/app/layout.tsx`
|
|
293
|
+
|
|
294
|
+
Not checked: `page.tsx`, components, and `pathname ===` branches. R2 looks for:
|
|
295
|
+
|
|
296
|
+
- `isArticle`, `isPerson`, or `isPage`
|
|
297
|
+
- `articleType.slug` / `personType.slug` compared with `===` or `!==`
|
|
298
|
+
- `contentType ===` (and the other equality forms)
|
|
299
|
+
|
|
300
|
+
`BasicLayout.tsx` also fails when it imports a project component from `./components/…` or `@/project/components/…`, other than shared chrome. The default allowlist is `Footer`, `Navigation`, `Banner`, `CmsNavigationMenu`, `CmsFooter`, `ExternalLinkWarning`, and `MarkVisibility`.
|
|
301
|
+
|
|
302
|
+
Replace that list with `importAllowlist` in `cms-driven.config.json` (this replaces the default; copy the names you still want):
|
|
303
|
+
|
|
304
|
+
```json
|
|
305
|
+
{
|
|
306
|
+
"importAllowlist": ["Footer", "Navigation", "Banner", "SiteHeader"]
|
|
307
|
+
}
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
### R1 (opt-in)
|
|
311
|
+
|
|
312
|
+
R1 forbids literal colours in chrome files and in footer/nav rules in CSS (hex, `rgb()` / `hsl()`, palette utilities, arbitrary colour values, quoted palette names). It stays **off** until `cms-driven.config.json` includes an `r1` object. Do not enable it on a site that has not moved chrome colours into the CMS.
|
|
313
|
+
|
|
314
|
+
```json
|
|
315
|
+
{
|
|
316
|
+
"r1": {
|
|
317
|
+
"chrome": [
|
|
318
|
+
"src/project/BasicLayout.tsx",
|
|
319
|
+
"src/project/components/Footer/",
|
|
320
|
+
"src/project/components/Navigation/"
|
|
321
|
+
],
|
|
322
|
+
"palette": ["white", "black", "navy"],
|
|
323
|
+
"paletteNames": ["White", "Black", "Navy"],
|
|
324
|
+
"skipFiles": ["src/project/chrome-colour.ts"],
|
|
325
|
+
"cssFiles": ["src/app/globals.css"]
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
`chrome` is required. A path ending in `/` is a directory. `palette` and `paletteNames` add class and quoted-name checks; hex and colour functions are always checked once R1 is on. `skipFiles` defaults to none. `cssFiles` defaults to `src/app/globals.css`. CSS checks run on rules whose selector mentions `footer`, `site-end`, `site-sitemap`, or `site-nav`.
|
|
331
|
+
|
|
332
|
+
```bash
|
|
333
|
+
check-cms-driven --config cms-driven.config.json
|
|
334
|
+
```
|
|
335
|
+
|
|
336
|
+
With no `--config`, a `cms-driven.config.json` next to the app root is used when it exists. R1 is still off if that file has no `r1` key.
|
|
337
|
+
|
|
338
|
+
### Escape hatch
|
|
339
|
+
|
|
340
|
+
A rare, explained exception stays on the offending line:
|
|
341
|
+
|
|
342
|
+
```tsx
|
|
343
|
+
if (model.articleType?.slug === 'work') { /* … */ } // se-exception: template field not shipped yet
|
|
344
|
+
```
|
|
345
|
+
|
|
346
|
+
```css
|
|
347
|
+
color: #111; /* se-exception: print stylesheet, no CMS colour */
|
|
348
|
+
```
|
|
349
|
+
|
|
350
|
+
The reason after `se-exception:` is required. A comment with no reason still fails.
|
|
351
|
+
|
|
263
352
|
## Exit codes
|
|
264
353
|
|
|
265
354
|
- `0` — Validation passed (sitemap.xml required; llms.txt and sitemap-unindexed.xml optional). If `--check-rewrites` was set, no unexpected rewrites. Every sitemap page returned 200 for its `.md` URL and files were saved (or in compare mode: all production sitemap pages exist on development and, if `--check-rewrites`, no unexpected rewrites).
|
|
@@ -0,0 +1,405 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Guard: page-specific chrome comes from the CMS, not from a slug or type branch.
|
|
4
|
+
*
|
|
5
|
+
* R2 (default) — layouts and route handlers must not special-case a page type:
|
|
6
|
+
* - src/project/BasicLayout.tsx
|
|
7
|
+
* - src/lib/route-handlers.ts
|
|
8
|
+
* - src/app layouts, including the root layout (page files are not checked)
|
|
9
|
+
* Type guards: isArticle / isPerson / isPage, articleType.slug / personType.slug
|
|
10
|
+
* comparisons, and contentType comparisons.
|
|
11
|
+
* BasicLayout.tsx also must not import a one-type project component. The allowlist
|
|
12
|
+
* defaults to shared chrome (Footer, Navigation, Banner, and the usual site aliases).
|
|
13
|
+
*
|
|
14
|
+
* R1 (opt-in) — literal colours in chrome files and footer/nav CSS. Off until
|
|
15
|
+
* cms-driven.config.json sets `r1`. See the package README.
|
|
16
|
+
*
|
|
17
|
+
* Escape hatch (needs a reason): a line comment "se-exception: <reason>",
|
|
18
|
+
* or the same words inside a CSS block comment on that line.
|
|
19
|
+
*
|
|
20
|
+
* Run from the app root:
|
|
21
|
+
* check-cms-driven
|
|
22
|
+
* check-cms-driven --config cms-driven.config.json
|
|
23
|
+
*/
|
|
24
|
+
import { existsSync, readdirSync, readFileSync, realpathSync } from 'node:fs';
|
|
25
|
+
import { join, relative, sep } from 'node:path';
|
|
26
|
+
import { fileURLToPath } from 'node:url';
|
|
27
|
+
|
|
28
|
+
export const DEFAULT_IMPORT_ALLOWLIST = [
|
|
29
|
+
'Footer',
|
|
30
|
+
'Navigation',
|
|
31
|
+
'Banner',
|
|
32
|
+
'CmsNavigationMenu',
|
|
33
|
+
'CmsFooter',
|
|
34
|
+
'ExternalLinkWarning',
|
|
35
|
+
'MarkVisibility',
|
|
36
|
+
];
|
|
37
|
+
|
|
38
|
+
const CONFIG_NAME = 'cms-driven.config.json';
|
|
39
|
+
const TOP_LEVEL_KEYS = new Set(['importAllowlist', 'r1']);
|
|
40
|
+
const R1_KEYS = new Set(['chrome', 'palette', 'paletteNames', 'skipFiles', 'cssFiles']);
|
|
41
|
+
const SKIP_DIRS = new Set([
|
|
42
|
+
'node_modules',
|
|
43
|
+
'.git',
|
|
44
|
+
'.next',
|
|
45
|
+
'dist',
|
|
46
|
+
'generated',
|
|
47
|
+
'coverage',
|
|
48
|
+
'.turbo',
|
|
49
|
+
'out',
|
|
50
|
+
]);
|
|
51
|
+
|
|
52
|
+
const TYPE_RULES = [
|
|
53
|
+
{ re: /\bisArticle\b|\bisPerson\b|\bisPage\b/, what: 'page-type guard in a layout' },
|
|
54
|
+
{
|
|
55
|
+
re: /\b(?:articleType|personType)\??\.slug\s*[!=]==?/,
|
|
56
|
+
what: 'page-type slug branch in a layout',
|
|
57
|
+
},
|
|
58
|
+
{ re: /\bcontentType\s*[!=]==?/, what: 'contentType branch in a layout' },
|
|
59
|
+
];
|
|
60
|
+
|
|
61
|
+
const HELP = `check-cms-driven
|
|
62
|
+
|
|
63
|
+
R2 is on by default. It checks BasicLayout.tsx, src/lib/route-handlers.ts, and
|
|
64
|
+
src/app layouts (not pages) for slug or content-type branches.
|
|
65
|
+
|
|
66
|
+
Opt in from the app root:
|
|
67
|
+
"check:cms-driven": "check-cms-driven"
|
|
68
|
+
and add that script to "validate".
|
|
69
|
+
|
|
70
|
+
R1 (literal chrome colours) stays off until cms-driven.config.json includes "r1".
|
|
71
|
+
See @se-studio/site-check README, "CMS-driven layouts".
|
|
72
|
+
|
|
73
|
+
check-cms-driven [--config <file>]
|
|
74
|
+
`;
|
|
75
|
+
|
|
76
|
+
function escapeRegExp(value) {
|
|
77
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function toPosix(filePath) {
|
|
81
|
+
return filePath.split(sep).join('/');
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function assertStringList(value, label) {
|
|
85
|
+
if (!Array.isArray(value) || value.some((item) => typeof item !== 'string' || item === '')) {
|
|
86
|
+
throw new Error(`${label} must be a list of non-empty strings`);
|
|
87
|
+
}
|
|
88
|
+
return value;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function unknownKeys(object, allowed) {
|
|
92
|
+
return Object.keys(object).filter((key) => !allowed.has(key));
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* @param {string} root
|
|
97
|
+
* @param {string | undefined} configPath explicit path; the default file is optional
|
|
98
|
+
*/
|
|
99
|
+
export function loadCmsDrivenConfig(root, configPath) {
|
|
100
|
+
const explicit = Boolean(configPath);
|
|
101
|
+
const file = configPath
|
|
102
|
+
? configPath.startsWith('/')
|
|
103
|
+
? configPath
|
|
104
|
+
: join(root, configPath)
|
|
105
|
+
: join(root, CONFIG_NAME);
|
|
106
|
+
|
|
107
|
+
/** @type {{ importAllowlist: string[], r1: null | { chrome: string[], palette: string[], paletteNames: string[], skipFiles: string[], cssFiles: string[] } }} */
|
|
108
|
+
const config = {
|
|
109
|
+
importAllowlist: [...DEFAULT_IMPORT_ALLOWLIST],
|
|
110
|
+
r1: null,
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
if (!existsSync(file)) {
|
|
114
|
+
if (explicit) throw new Error(`config not found: ${file}`);
|
|
115
|
+
return config;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
let raw;
|
|
119
|
+
try {
|
|
120
|
+
raw = JSON.parse(readFileSync(file, 'utf8'));
|
|
121
|
+
} catch (error) {
|
|
122
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
123
|
+
throw new Error(`cannot read ${toPosix(relative(root, file))}: ${message}`);
|
|
124
|
+
}
|
|
125
|
+
if (!raw || typeof raw !== 'object' || Array.isArray(raw)) {
|
|
126
|
+
throw new Error(`${CONFIG_NAME} must be a JSON object`);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const extra = unknownKeys(raw, TOP_LEVEL_KEYS);
|
|
130
|
+
if (extra.length > 0) {
|
|
131
|
+
throw new Error(`${CONFIG_NAME} has unknown keys: ${extra.join(', ')}`);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
if (raw.importAllowlist !== undefined) {
|
|
135
|
+
config.importAllowlist = assertStringList(raw.importAllowlist, 'importAllowlist');
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
if (raw.r1 === undefined) return config;
|
|
139
|
+
if (!raw.r1 || typeof raw.r1 !== 'object' || Array.isArray(raw.r1)) {
|
|
140
|
+
throw new Error('r1 must be an object with a chrome list');
|
|
141
|
+
}
|
|
142
|
+
const r1Extra = unknownKeys(raw.r1, R1_KEYS);
|
|
143
|
+
if (r1Extra.length > 0) {
|
|
144
|
+
throw new Error(`r1 has unknown keys: ${r1Extra.join(', ')}`);
|
|
145
|
+
}
|
|
146
|
+
const chrome = assertStringList(raw.r1.chrome, 'r1.chrome');
|
|
147
|
+
if (chrome.length === 0) throw new Error('r1.chrome must list at least one file or directory');
|
|
148
|
+
|
|
149
|
+
config.r1 = {
|
|
150
|
+
chrome,
|
|
151
|
+
palette: raw.r1.palette === undefined ? [] : assertStringList(raw.r1.palette, 'r1.palette'),
|
|
152
|
+
paletteNames:
|
|
153
|
+
raw.r1.paletteNames === undefined
|
|
154
|
+
? []
|
|
155
|
+
: assertStringList(raw.r1.paletteNames, 'r1.paletteNames'),
|
|
156
|
+
skipFiles:
|
|
157
|
+
raw.r1.skipFiles === undefined ? [] : assertStringList(raw.r1.skipFiles, 'r1.skipFiles'),
|
|
158
|
+
cssFiles:
|
|
159
|
+
raw.r1.cssFiles === undefined
|
|
160
|
+
? ['src/app/globals.css']
|
|
161
|
+
: assertStringList(raw.r1.cssFiles, 'r1.cssFiles'),
|
|
162
|
+
};
|
|
163
|
+
return config;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
function pathMatches(file, pattern) {
|
|
167
|
+
if (pattern.endsWith('/')) {
|
|
168
|
+
return file.startsWith(pattern) || file.includes(`/${pattern}`);
|
|
169
|
+
}
|
|
170
|
+
return file === pattern || file.endsWith(`/${pattern}`);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
function matchesAny(file, patterns) {
|
|
174
|
+
return patterns.some((pattern) => pathMatches(file, pattern));
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* @returns {'shell' | 'routes' | 'layout' | null}
|
|
179
|
+
*/
|
|
180
|
+
function r2Role(file) {
|
|
181
|
+
if (/(?:^|\/)src\/project\/BasicLayout\.tsx$/.test(file)) return 'shell';
|
|
182
|
+
if (/(?:^|\/)src\/lib\/route-handlers\.ts$/.test(file)) return 'routes';
|
|
183
|
+
if (/(?:^|\/)src\/app\/(?:.*\/)?layout\.tsx$/.test(file)) return 'layout';
|
|
184
|
+
return null;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function excepted(line) {
|
|
188
|
+
return /se-exception:\s*\S/.test(line);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
function isComment(line) {
|
|
192
|
+
return /^\s*(\/\/|\*|\/\*)/.test(line);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function walk(dir, out = []) {
|
|
196
|
+
if (!existsSync(dir)) return out;
|
|
197
|
+
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
198
|
+
if (SKIP_DIRS.has(entry.name)) continue;
|
|
199
|
+
const full = join(dir, entry.name);
|
|
200
|
+
if (entry.isDirectory()) walk(full, out);
|
|
201
|
+
else if (entry.isFile()) out.push(full);
|
|
202
|
+
}
|
|
203
|
+
return out;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
function importedComponent(line) {
|
|
207
|
+
const match = line.match(/from\s+['"]((?:\.\/|@\/project\/)components\/[^'"]+)['"]/);
|
|
208
|
+
if (!match?.[1]) return null;
|
|
209
|
+
const rest = match[1].replace(/^(?:\.\/|@\/project\/)components\//, '');
|
|
210
|
+
const segment = rest.split('/')[0]?.replace(/\.(?:tsx|ts|jsx|js)$/, '');
|
|
211
|
+
return segment || null;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
function mockLineIndexes(lines) {
|
|
215
|
+
const skip = new Set();
|
|
216
|
+
let depth = 0;
|
|
217
|
+
let inMock = false;
|
|
218
|
+
for (let i = 0; i < lines.length; i++) {
|
|
219
|
+
const line = lines[i] ?? '';
|
|
220
|
+
if (
|
|
221
|
+
!inMock &&
|
|
222
|
+
/\b(?:showcase|mock|fixture)[A-Za-z]*\s*[:=]|\bmockData\b|\bshowcaseMock/i.test(line)
|
|
223
|
+
) {
|
|
224
|
+
inMock = true;
|
|
225
|
+
depth = 0;
|
|
226
|
+
}
|
|
227
|
+
if (!inMock) continue;
|
|
228
|
+
skip.add(i);
|
|
229
|
+
const opens = line.match(/[{[(]/g)?.length ?? 0;
|
|
230
|
+
const closes = line.match(/[}\])]/g)?.length ?? 0;
|
|
231
|
+
depth += opens - closes;
|
|
232
|
+
if (depth <= 0 && /[}\])];?,?\s*$/.test(line)) inMock = false;
|
|
233
|
+
}
|
|
234
|
+
return skip;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
function codeColourRules(r1) {
|
|
238
|
+
const rules = [
|
|
239
|
+
{ re: /#[0-9a-fA-F]{3,8}\b/, what: 'hex colour' },
|
|
240
|
+
{ re: /\b(?:rgba?|hsla?|oklch|oklab)\(/, what: 'colour function' },
|
|
241
|
+
{
|
|
242
|
+
re: /(?<![\w-])(?:bg|text|from|via|to|border|fill|stroke)-\[[^\]]*\]/,
|
|
243
|
+
what: 'arbitrary value',
|
|
244
|
+
},
|
|
245
|
+
];
|
|
246
|
+
if (r1.palette.length > 0) {
|
|
247
|
+
const palette = r1.palette.map(escapeRegExp).join('|');
|
|
248
|
+
rules.push({
|
|
249
|
+
re: new RegExp(
|
|
250
|
+
`(?<![\\w-])(?:bg|text|from|via|to|border|fill|stroke|outline|ring|shadow|decoration|accent|caret|divide)-(?:${palette})(?:/[\\d.]+)?(?![\\w-])`,
|
|
251
|
+
),
|
|
252
|
+
what: 'palette utility class',
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
if (r1.paletteNames.length > 0) {
|
|
256
|
+
const names = r1.paletteNames.map(escapeRegExp).join('|');
|
|
257
|
+
rules.push({
|
|
258
|
+
re: new RegExp(`['"](?:${names})['"]`),
|
|
259
|
+
what: 'palette name literal',
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
return rules;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* @param {string} root
|
|
267
|
+
* @param {{ configPath?: string }} [options]
|
|
268
|
+
* @returns {string[]}
|
|
269
|
+
*/
|
|
270
|
+
export function checkCmsDriven(root, options = {}) {
|
|
271
|
+
const config = loadCmsDrivenConfig(root, options.configPath);
|
|
272
|
+
const allow = new Set(config.importAllowlist);
|
|
273
|
+
const violations = [];
|
|
274
|
+
const colourRules = config.r1 ? codeColourRules(config.r1) : [];
|
|
275
|
+
const paletteVar = config.r1?.palette.length
|
|
276
|
+
? new RegExp(`var\\(--color-(?:${config.r1.palette.map(escapeRegExp).join('|')})\\)`)
|
|
277
|
+
: null;
|
|
278
|
+
|
|
279
|
+
const report = (file, index, rule, what, text) => {
|
|
280
|
+
violations.push(`${file}:${index + 1} ${rule} ${what}: ${text.trim().slice(0, 100)}`);
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
for (const abs of walk(root)) {
|
|
284
|
+
const file = toPosix(relative(root, abs));
|
|
285
|
+
const role = r2Role(file);
|
|
286
|
+
const isCss = config.r1 ? matchesAny(file, config.r1.cssFiles) : false;
|
|
287
|
+
const inChrome =
|
|
288
|
+
config.r1 &&
|
|
289
|
+
/\.(tsx|ts|jsx|js)$/.test(file) &&
|
|
290
|
+
matchesAny(file, config.r1.chrome) &&
|
|
291
|
+
!matchesAny(file, config.r1.skipFiles);
|
|
292
|
+
|
|
293
|
+
if (!role && !inChrome && !isCss) continue;
|
|
294
|
+
|
|
295
|
+
const lines = readFileSync(abs, 'utf8').split('\n');
|
|
296
|
+
|
|
297
|
+
if (inChrome) {
|
|
298
|
+
const mocks = mockLineIndexes(lines);
|
|
299
|
+
for (let i = 0; i < lines.length; i++) {
|
|
300
|
+
const line = lines[i] ?? '';
|
|
301
|
+
if (excepted(line) || mocks.has(i) || isComment(line)) continue;
|
|
302
|
+
for (const { re, what } of colourRules) {
|
|
303
|
+
if (re.test(line)) report(file, i, 'R1', what, line);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
if (isCss && config.r1) {
|
|
309
|
+
let selector = '';
|
|
310
|
+
for (let i = 0; i < lines.length; i++) {
|
|
311
|
+
const line = lines[i] ?? '';
|
|
312
|
+
if (/\{\s*$/.test(line) && !/^\s*(@media|@supports|@layer)/.test(line)) selector = line;
|
|
313
|
+
const chromeRule = /footer|site-end|site-sitemap|site-nav/i.test(selector);
|
|
314
|
+
if (!chromeRule || excepted(line) || /^\s*(\/\*|\*)/.test(line)) continue;
|
|
315
|
+
if (/--[\w-]+\s*:/.test(line)) continue;
|
|
316
|
+
if (/#[0-9a-fA-F]{3,8}\b/.test(line)) report(file, i, 'R1', 'hex colour', line);
|
|
317
|
+
if (/\b(?:rgba?|hsla?|oklch|oklab)\(/.test(line))
|
|
318
|
+
report(file, i, 'R1', 'colour function', line);
|
|
319
|
+
if (paletteVar?.test(line)) report(file, i, 'R1', 'palette variable', line);
|
|
320
|
+
if (/brightness\(0\)\s*invert\(1\)/.test(line))
|
|
321
|
+
report(file, i, 'R1', 'forced white filter', line);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
if (!role) continue;
|
|
326
|
+
for (let i = 0; i < lines.length; i++) {
|
|
327
|
+
const line = lines[i] ?? '';
|
|
328
|
+
if (excepted(line) || isComment(line)) continue;
|
|
329
|
+
for (const { re, what } of TYPE_RULES) {
|
|
330
|
+
if (re.test(line)) report(file, i, 'R2', what, line);
|
|
331
|
+
}
|
|
332
|
+
if (role !== 'shell') continue;
|
|
333
|
+
const component = importedComponent(line);
|
|
334
|
+
if (component && !allow.has(component)) {
|
|
335
|
+
report(
|
|
336
|
+
file,
|
|
337
|
+
i,
|
|
338
|
+
'R2',
|
|
339
|
+
'project component imported into a layout (put it in a CMS template)',
|
|
340
|
+
line,
|
|
341
|
+
);
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
return violations;
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
function parseArgs(argv) {
|
|
350
|
+
/** @type {{ help: boolean, configPath?: string }} */
|
|
351
|
+
const args = { help: false };
|
|
352
|
+
for (let i = 0; i < argv.length; i++) {
|
|
353
|
+
const arg = argv[i];
|
|
354
|
+
if (arg === '--help' || arg === '-h') {
|
|
355
|
+
args.help = true;
|
|
356
|
+
} else if (arg === '--config') {
|
|
357
|
+
const next = argv[i + 1];
|
|
358
|
+
if (!next) throw new Error('--config needs a path');
|
|
359
|
+
args.configPath = next;
|
|
360
|
+
i += 1;
|
|
361
|
+
} else {
|
|
362
|
+
throw new Error(`unknown argument: ${arg}`);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
return args;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
function isDirectRun() {
|
|
369
|
+
const entry = process.argv[1];
|
|
370
|
+
if (!entry) return false;
|
|
371
|
+
try {
|
|
372
|
+
// pnpm's bin shim is a symlink. Compare real paths so the CLI still runs.
|
|
373
|
+
return realpathSync(entry) === realpathSync(fileURLToPath(import.meta.url));
|
|
374
|
+
} catch {
|
|
375
|
+
return false;
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
function main() {
|
|
380
|
+
try {
|
|
381
|
+
const args = parseArgs(process.argv.slice(2));
|
|
382
|
+
if (args.help) {
|
|
383
|
+
console.log(HELP);
|
|
384
|
+
return;
|
|
385
|
+
}
|
|
386
|
+
const violations = checkCmsDriven(process.cwd(), { configPath: args.configPath });
|
|
387
|
+
if (violations.length === 0) {
|
|
388
|
+
console.log('check-cms-driven: ok');
|
|
389
|
+
return;
|
|
390
|
+
}
|
|
391
|
+
console.error('check-cms-driven: layouts must take page-specific content from the CMS.\n');
|
|
392
|
+
for (const violation of violations) console.error(` ${violation}`);
|
|
393
|
+
console.error(
|
|
394
|
+
`\n${violations.length} violation(s). R2: make it a registered component in a CMS template. ` +
|
|
395
|
+
'R1 is opt-in (cms-driven.config.json). Escape hatch: // se-exception: <reason>',
|
|
396
|
+
);
|
|
397
|
+
process.exit(1);
|
|
398
|
+
} catch (error) {
|
|
399
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
400
|
+
console.error(`check-cms-driven: ${message}`);
|
|
401
|
+
process.exit(2);
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
if (isDirectRun()) main();
|
package/docs/llms.md
CHANGED
|
@@ -114,6 +114,24 @@ After a production build (or when `.next` already exists for `smoke-test:deploy-
|
|
|
114
114
|
**Proper fix (allowed):** shared package `peerDependencies` for `@se-studio/core-ui` + app `dependenciesMeta.<shared>.injected: true`.
|
|
115
115
|
**Banned on develop/main:** webpack `resolve.alias` for `@se-studio/core-ui`, pnpm `overrides` for it, `public-hoist-pattern` hacks — run `check-no-context-workarounds`.
|
|
116
116
|
|
|
117
|
+
### check-cms-driven
|
|
118
|
+
|
|
119
|
+
Bin: `check-cms-driven`. Run from the app root. **R2 is on by default. R1 is opt-in. Customer sites do not run this in CI until they opt in.**
|
|
120
|
+
|
|
121
|
+
R2 files: `src/project/BasicLayout.tsx`, `src/lib/route-handlers.ts`, and `src/app` layouts (including the root layout). Not `page.tsx`. It fails on `isArticle` / `isPerson` / `isPage`, `articleType.slug` or `personType.slug` comparisons, and `contentType` comparisons. Only `BasicLayout.tsx` also fails on a `./components/` or `@/project/components/` import outside the allowlist (`Footer`, `Navigation`, `Banner`, `CmsNavigationMenu`, `CmsFooter`, `ExternalLinkWarning`, `MarkVisibility`).
|
|
122
|
+
|
|
123
|
+
Opt in:
|
|
124
|
+
|
|
125
|
+
```json
|
|
126
|
+
"check:cms-driven": "check-cms-driven"
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
Add that script to the app `validate` script. `apps/example-empty` already does. A site replaces the import allowlist with `importAllowlist` in `cms-driven.config.json` (the key replaces the default list).
|
|
130
|
+
|
|
131
|
+
R1 (literal chrome colours) runs only when that file has an `r1` object: `chrome` (required paths; a trailing `/` is a directory), optional `palette`, `paletteNames`, `skipFiles`, and `cssFiles` (default `src/app/globals.css`).
|
|
132
|
+
|
|
133
|
+
Escape hatch on the same line: `// se-exception: <reason>` or `/* se-exception: <reason> */`. The reason is required.
|
|
134
|
+
|
|
117
135
|
### check-no-context-workarounds
|
|
118
136
|
|
|
119
137
|
```bash
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@se-studio/site-check",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.14.0",
|
|
4
4
|
"description": "Validate SE marketing sites (sitemap, llms.txt) and download markdown files preserving structure",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -57,7 +57,8 @@
|
|
|
57
57
|
"develop-sites-timing": "./develop-sites-timing.mjs",
|
|
58
58
|
"markdown-accuracy-audit": "./markdown-accuracy-audit.mjs",
|
|
59
59
|
"check-no-context-workarounds": "./check-no-context-workarounds.mjs",
|
|
60
|
-
"check-publish-state": "./check-publish-state.mjs"
|
|
60
|
+
"check-publish-state": "./check-publish-state.mjs",
|
|
61
|
+
"check-cms-driven": "./check-cms-driven.mjs"
|
|
61
62
|
},
|
|
62
63
|
"files": [
|
|
63
64
|
"dist",
|
|
@@ -73,7 +74,8 @@
|
|
|
73
74
|
"develop-sites-timing.mjs",
|
|
74
75
|
"markdown-accuracy-audit.mjs",
|
|
75
76
|
"check-no-context-workarounds.mjs",
|
|
76
|
-
"check-publish-state.mjs"
|
|
77
|
+
"check-publish-state.mjs",
|
|
78
|
+
"check-cms-driven.mjs"
|
|
77
79
|
],
|
|
78
80
|
"keywords": [
|
|
79
81
|
"sitemap",
|
|
@@ -91,8 +93,8 @@
|
|
|
91
93
|
"url": "https://github.com/Something-Else-Studio/se-core-product/issues"
|
|
92
94
|
},
|
|
93
95
|
"dependencies": {
|
|
94
|
-
"@se-studio/contentful-rest-api": "2.
|
|
95
|
-
"@se-studio/core-data-types": "2.0.
|
|
96
|
+
"@se-studio/contentful-rest-api": "2.2.0",
|
|
97
|
+
"@se-studio/core-data-types": "2.0.5"
|
|
96
98
|
},
|
|
97
99
|
"devDependencies": {
|
|
98
100
|
"@biomejs/biome": "^2.6.6",
|
|
@@ -105,6 +107,6 @@
|
|
|
105
107
|
"type-check": "tsc --noEmit",
|
|
106
108
|
"lint": "biome lint .",
|
|
107
109
|
"clean": "rm -rf dist .turbo *.tsbuildinfo",
|
|
108
|
-
"test": "pnpm build && node --test scripts/screaming-frog-audit.test.mjs scripts/production-audit.test.mjs scripts/discovery.test.mjs scripts/smoke-test.test.mjs scripts/analytics-context-bundle.test.mjs scripts/check-no-context-workarounds.test.mjs scripts/revalidation-matrix.test.mjs scripts/develop-sites-timing.test.mjs scripts/markdown-accuracy-audit.test.mjs scripts/publish-state.test.mjs"
|
|
110
|
+
"test": "pnpm build && node --test scripts/screaming-frog-audit.test.mjs scripts/production-audit.test.mjs scripts/discovery.test.mjs scripts/smoke-test.test.mjs scripts/analytics-context-bundle.test.mjs scripts/check-no-context-workarounds.test.mjs scripts/check-cms-driven.test.mjs scripts/revalidation-matrix.test.mjs scripts/develop-sites-timing.test.mjs scripts/markdown-accuracy-audit.test.mjs scripts/publish-state.test.mjs"
|
|
109
111
|
}
|
|
110
112
|
}
|