Per owner decision: MediaEngine (the Media product family's Go backend and SvelteKit frontend, previously its own repo referenced by 7 thin service repos via git submodule) is folded directly into shared/ as media-backend/ and media-webui/, rather than staying separate. media-backend/go.mod's replace directive now points at ../backend (a true sibling within this repo) instead of a vendored ../shared/backend copy, since there's no more nested vendoring - it's the real thing. Also moved MediaEngine's own CI (media-backend-lint.yml, media-backend-tests.yml) and dev tooling scripts (scripts/media/*, audit/lint/enforce scripts for the media-backend+media-webui content), fixing their path assumptions for the new layout, and dropped scripts/media/sync-shared.mjs (confirmed dead code, and now doubly obsolete since there's no more vendored shared/ subfolder for it to check). Added media:* script aliases to package.json for the moved tooling, namespaced to avoid colliding with this repo's own scripts. Also fixed sync-consumers.ps1's workspace-root resolution to walk up until it finds a directory containing both Original/ and Forks/, instead of assuming shared/ is always a direct child of the workspace root - it broke when shared/ moved from Web/shared to Web/Central/shared earlier in this same restructuring. Removed the now-obsolete Original/MediaEngine entry from its consumer list. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
90 lines
2.6 KiB
JavaScript
90 lines
2.6 KiB
JavaScript
import fs from 'node:fs/promises';
|
|
import path from 'node:path';
|
|
|
|
const repoRoot = process.cwd();
|
|
const strict = process.argv.includes('--strict');
|
|
|
|
const includeExt = new Set(['.js', '.ejs', '.html']);
|
|
const skipDirs = new Set(['node_modules', '.git', 'dist', 'release', 'coverage']);
|
|
|
|
const styleDisplayAssign = /style\.display\s*=\s*['"](?:flex|grid)['"]/gi;
|
|
const inlineDisplayStyle = /style\s*=\s*['"][^'"]*display\s*:\s*(?:flex|grid)[^'"]*['"]/gi;
|
|
|
|
async function walk(dir, out = []) {
|
|
const entries = await fs.readdir(dir, { withFileTypes: true });
|
|
for (const entry of entries) {
|
|
const full = path.join(dir, entry.name);
|
|
if (entry.isDirectory()) {
|
|
if (skipDirs.has(entry.name)) continue;
|
|
await walk(full, out);
|
|
continue;
|
|
}
|
|
if (!includeExt.has(path.extname(entry.name))) continue;
|
|
out.push(full);
|
|
}
|
|
return out;
|
|
}
|
|
|
|
function lineNumberAt(content, index) {
|
|
let line = 1;
|
|
for (let i = 0; i < index; i += 1) {
|
|
if (content.charCodeAt(i) === 10) line += 1;
|
|
}
|
|
return line;
|
|
}
|
|
|
|
function collectMatches(content, regex, type) {
|
|
const rows = [];
|
|
regex.lastIndex = 0;
|
|
let match;
|
|
while ((match = regex.exec(content)) !== null) {
|
|
rows.push({
|
|
type,
|
|
line: lineNumberAt(content, match.index),
|
|
snippet: match[0],
|
|
});
|
|
}
|
|
return rows;
|
|
}
|
|
|
|
const allFiles = await walk(repoRoot);
|
|
const violations = [];
|
|
|
|
// After folding media-backend/media-webui directly into the shared repo, this filter targets
|
|
// the frontend directories where inline HTML/CSS layout violations are actually possible
|
|
// (the plain Go backend/ and Go media-backend/ have none; there is no more nested shared/).
|
|
const includedTopLevelDirs = ['media-webui/', 'scripts/media/'];
|
|
|
|
for (const filePath of allFiles) {
|
|
const rel = path.relative(repoRoot, filePath).replaceAll('\\', '/');
|
|
if (!includedTopLevelDirs.some(prefix => rel.startsWith(prefix))) continue;
|
|
const content = await fs.readFile(filePath, 'utf8');
|
|
const hits = [
|
|
...collectMatches(content, styleDisplayAssign, 'js-style-display'),
|
|
...collectMatches(content, inlineDisplayStyle, 'inline-style-display'),
|
|
];
|
|
if (hits.length) {
|
|
violations.push({ file: rel, hits });
|
|
}
|
|
}
|
|
|
|
const total = violations.reduce((sum, row) => sum + row.hits.length, 0);
|
|
|
|
console.log(
|
|
JSON.stringify(
|
|
{
|
|
ok: strict ? total === 0 : true,
|
|
strict,
|
|
files: violations.length,
|
|
violations: total,
|
|
entries: violations,
|
|
},
|
|
null,
|
|
2
|
|
)
|
|
);
|
|
|
|
if (strict && total > 0) {
|
|
process.exitCode = 1;
|
|
}
|