~ knotless Search/
↑↓ move↵ open⇧↵ all results

chadtmiller.com/hud

A remote MCP server that shows atproto records as interactive UI inside MCP Apps hosts

0
0
37 lines · 1.7 KB Raw History
// The workspace's components' layers, atomic design's: atoms, molecules
// built of atoms, organisms of those, and templates laying organisms out. A
// component uses its own layer and those below it, never one above, so
// each layer can be understood, and changed, knowing only what is under it.
// As knotless's harness/layers.mjs, over web/workspace/lib.
//
//   node harness/layers.mjs    `just lint`
//
// Prints each import that reaches up as `file:line: what`, failing if any.

import { readdirSync, readFileSync } from 'node:fs';
import { dirname, join, relative, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';

const root = resolve(dirname(fileURLToPath(import.meta.url)), '..');
const lib = join(root, 'web/workspace/lib');
const layers = ['atoms', 'molecules', 'organisms', 'templates'];

const files = (d) => readdirSync(d, { withFileTypes: true }).flatMap((e) => (e.isDirectory() ? files(join(d, e.name)) : [join(d, e.name)]));

const problems = [];
for (const [rank, layer] of layers.entries()) {
	for (const file of files(join(lib, layer))) {
		const lines = readFileSync(file, 'utf8').split('\n');
		lines.forEach((line, i) => {
			for (const [, path] of line.matchAll(/(?:from|import)\s+['"]([^'"]+)['"]/g)) {
				if (!path.startsWith('.')) continue;
				const used = layers.indexOf(relative(lib, resolve(dirname(file), path)).split('/')[0]);
				if (used > rank) problems.push(`${relative(root, file)}:${i + 1}: ${layer} use only ${layers.slice(0, rank + 1).join(', ')}, not ${layers[used]}`);
			}
		});
	}
}

for (const p of problems) console.log(p);
if (problems.length) process.exit(1);
console.log(`workspace: ${layers.join(' < ')}, each using only its own layer and those below`);