2026-08-31 22:06:29 +02:00
|
|
|
#!/usr/bin/env node
|
|
|
|
|
/**
|
|
|
|
|
* Enforce design-system CSS constraints for shared theme files.
|
|
|
|
|
*
|
|
|
|
|
* Rules enforced:
|
|
|
|
|
* - Theme CSS must not contain project/service-coupled selector tokens.
|
|
|
|
|
* - Theme CSS must not contain route-coupled panel IDs in selectors.
|
|
|
|
|
*
|
2026-09-04 15:02:16 +02:00
|
|
|
* TODO(shared extraction): the original monorepo version of this script also asserted that
|
2026-08-31 22:06:29 +02:00
|
|
|
* MediaShared/public/css/index.css and MediaDesktop/public/index.css stayed byte-for-byte synced.
|
2026-09-04 15:02:16 +02:00
|
|
|
* That check is no longer possible from inside this repo: MediaDesktop is now a fully separate
|
2026-08-31 22:06:29 +02:00
|
|
|
* repo (Original/MediaDesktop) and isn't checked out alongside this one, so there is nothing here
|
|
|
|
|
* to diff it against. The desktop-vs-shared theme sync check has been dropped rather than pointed
|
|
|
|
|
* at a nonexistent path; if that guarantee still matters, it belongs in MediaDesktop's own CI
|
|
|
|
|
* (comparing its vendored shared/ copy's theme file against its own), not here.
|
|
|
|
|
*/
|
|
|
|
|
import fs from 'node:fs';
|
|
|
|
|
import path from 'node:path';
|
|
|
|
|
import { fileURLToPath } from 'node:url';
|
|
|
|
|
|
|
|
|
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
|
|
|
const repoRoot = path.resolve(__dirname, '..', '..');
|
|
|
|
|
|
2026-09-04 15:02:16 +02:00
|
|
|
// MediaShared/public/css/index.css became packages/legacy-assets/public/css/index.css once
|
|
|
|
|
// media-backend/webui were folded directly into the shared repo (no more vendored copy).
|
2026-08-31 22:06:29 +02:00
|
|
|
const sharedThemePath = path.join(
|
|
|
|
|
repoRoot,
|
|
|
|
|
'packages',
|
2026-09-04 15:02:16 +02:00
|
|
|
'legacy-assets',
|
2026-08-31 22:06:29 +02:00
|
|
|
'public',
|
|
|
|
|
'css',
|
|
|
|
|
'index.css'
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const bannedSelectorRules = [
|
|
|
|
|
{
|
|
|
|
|
name: 'project-coupled service token',
|
2026-09-06 22:50:38 +02:00
|
|
|
regex: /\b(?:kiosk|viewer|moderator|generator|library|contentscanner|downloader|carriernode)-page\b/i,
|
2026-08-31 22:06:29 +02:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: 'project-coupled state class token',
|
|
|
|
|
regex:
|
2026-09-06 22:50:38 +02:00
|
|
|
/\b(?:viewer|kiosk|moderator|generator|library|contentscanner|downloader|carriernode)-(?:home|page|stage|mode|active|panel)\b/i,
|
2026-08-31 22:06:29 +02:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: 'project-prefixed keyframe name',
|
|
|
|
|
regex:
|
2026-09-06 22:50:38 +02:00
|
|
|
/@keyframes\s+nc-(?:viewer|kiosk|moderator|generator|library|contentscanner|downloader|carriernode)/i,
|
2026-08-31 22:06:29 +02:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: 'project-coupled data attribute',
|
|
|
|
|
regex:
|
2026-09-06 22:50:38 +02:00
|
|
|
/\[data-(?:kiosk|viewer|moderator|generator|library|contentscanner|downloader|carriernode)[^\]]*\]/i,
|
2026-08-31 22:06:29 +02:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: 'route-coupled panel selector',
|
|
|
|
|
regex: /#panel-[a-z0-9_-]+/i,
|
|
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
function readUtf8(filePath) {
|
|
|
|
|
return fs.readFileSync(filePath, 'utf8');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function stripCssComments(text) {
|
|
|
|
|
return text.replace(/\/\*[\s\S]*?\*\//g, '');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function findViolations(filePath, content) {
|
|
|
|
|
const cleaned = stripCssComments(content);
|
|
|
|
|
const lines = cleaned.split(/\r?\n/);
|
|
|
|
|
const violations = [];
|
|
|
|
|
|
|
|
|
|
for (let i = 0; i < lines.length; i += 1) {
|
|
|
|
|
const line = lines[i];
|
|
|
|
|
for (const rule of bannedSelectorRules) {
|
|
|
|
|
if (rule.regex.test(line)) {
|
|
|
|
|
violations.push({
|
|
|
|
|
filePath,
|
|
|
|
|
line: i + 1,
|
|
|
|
|
rule: rule.name,
|
|
|
|
|
snippet: line.trim(),
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return violations;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function main() {
|
|
|
|
|
if (!fs.existsSync(sharedThemePath)) {
|
|
|
|
|
console.error('[enforce-design-system-css] Missing expected theme file:');
|
|
|
|
|
console.error(` - ${path.relative(repoRoot, sharedThemePath)}`);
|
|
|
|
|
process.exit(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const sharedTheme = readUtf8(sharedThemePath);
|
|
|
|
|
|
|
|
|
|
const allViolations = findViolations(sharedThemePath, sharedTheme);
|
|
|
|
|
|
|
|
|
|
if (allViolations.length > 0) {
|
|
|
|
|
console.error('[enforce-design-system-css] Design-system CSS violations found:');
|
|
|
|
|
for (const v of allViolations) {
|
|
|
|
|
const rel = path.isAbsolute(v.filePath) ? path.relative(repoRoot, v.filePath) : v.filePath;
|
|
|
|
|
console.error(` - ${rel}:${v.line} [${v.rule}] ${v.snippet}`);
|
|
|
|
|
}
|
|
|
|
|
console.error('[enforce-design-system-css] Fix violations before running lint/test.');
|
|
|
|
|
process.exit(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
console.log(
|
|
|
|
|
'[enforce-design-system-css] OK: shared theme is free of project-coupled selectors.'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
main();
|