@echelonos/design 0.0.0 → 0.1.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.
@@ -0,0 +1,124 @@
1
+ import resolveConfig from 'tailwindcss/resolveConfig.js';
2
+
3
+ // A class that restates a value the token scale already names, and the class to write instead.
4
+ const SPACING_UTILITY =
5
+ '(?:p|px|py|pt|pb|pl|pr|ps|pe|m|mx|my|mt|mb|ml|mr|ms|me|gap|gap-x|gap-y|space-x|space-y)';
6
+
7
+ const RETIRED_CLASSES = [
8
+ {
9
+ pattern: /(?<![\w-])duration-(?:\d+|\[[^\]]+\])/g,
10
+ replacement: 'a duration token: duration-instant, -fast, -normal, -slow or -slower',
11
+ },
12
+ {
13
+ pattern: /(?<![\w-])text-\[[\d.]+(?:px|rem|em)\]/g,
14
+ replacement: 'a type size: text-3xs, -2xs, -xs, -sm, -base, -lg, -xl or -2xl',
15
+ },
16
+ {
17
+ pattern: /(?<![\w-])rounded(?:-[trblse]{1,2})?-\[[\d.]+(?:px|rem)\]/g,
18
+ replacement: 'a radius token: rounded-sm, -md, -lg, -xl or -2xl',
19
+ },
20
+ {
21
+ // A drop shadow with a literal color. Inset and ring shadows that draw a border pass.
22
+ pattern: /(?<![\w-])shadow-\[[^\]]*(?:rgba?\(|#[\da-f]{3,8})[^\]]*\]/gi,
23
+ replacement: 'a shadow token: shadow-xs, -sm, -md, -lg, -xl or -2xl',
24
+ },
25
+ {
26
+ pattern: new RegExp(`(?<![\\w.-])-?${SPACING_UTILITY}-\\[[\\d.]+(?:px|rem)\\]`, 'g'),
27
+ replacement: 'a spacing step',
28
+ },
29
+ ];
30
+
31
+ // One-sided horizontal offsets may use these steps to clear an icon, checkbox or close button.
32
+ const OFFSET_STEPS = new Set(['7', '9', '11', '14']);
33
+ const SPACING_STEP = new RegExp(
34
+ `(?<![\\w.\\[-])-?(${SPACING_UTILITY})-(\\d+(?:\\.5)?)(?![\\w.%/-])`,
35
+ 'g',
36
+ );
37
+
38
+ /**
39
+ * @param {string} css Contents of tokens.css.
40
+ * @param {import('tailwindcss').Config} tailwindPreset
41
+ * @returns {string[]} One message per utility that does not resolve to its token.
42
+ */
43
+ export function checkCoreTokens(css, tailwindPreset) {
44
+ // Step 1: Read the light-theme tokens. The first definition is the scale; later ones are
45
+ // overrides such as reduced motion.
46
+ const tokens = {};
47
+ for (const root of css.matchAll(/:root\s*\{([^}]+)\}/g)) {
48
+ for (const declaration of root[1].matchAll(/(--[\w-]+)\s*:\s*([^;]+);/g)) {
49
+ tokens[declaration[1]] ??= declaration[2].trim();
50
+ }
51
+ }
52
+ const { theme } = resolveConfig({ presets: [tailwindPreset], content: [] });
53
+ const errors = [];
54
+ /** @param {string} prefix */
55
+ const tokenNames = (prefix) => Object.keys(tokens).filter((name) => name.startsWith(prefix));
56
+
57
+ // Step 2: A spacing token and the Tailwind step of the same number must be the same length.
58
+ for (const name of tokenNames('--space-')) {
59
+ const step = name.slice('--space-'.length).replace('-', '.');
60
+ const utility = theme.spacing[step] === '0px' ? '0' : theme.spacing[step];
61
+ if (utility !== tokens[name]) {
62
+ errors.push(`${name} is ${tokens[name]} but Tailwind spacing ${step} is ${utility}.`);
63
+ }
64
+ }
65
+
66
+ // Step 3: Type and motion utilities must read their value from the token, not restate it.
67
+ /** @type {(name: string, value: unknown, utility: string) => void} */
68
+ const requireReference = (name, value, utility) => {
69
+ if (value !== `var(${name})`) errors.push(`Tailwind ${utility} must reference var(${name}).`);
70
+ };
71
+ for (const name of tokenNames('--text-')) {
72
+ const size = name.slice('--text-'.length);
73
+ requireReference(name, [theme.fontSize[size]].flat()[0], `text-${size}`);
74
+ }
75
+ for (const name of tokenNames('--duration-')) {
76
+ const duration = name.slice('--duration-'.length);
77
+ requireReference(name, theme.transitionDuration[duration], `duration-${duration}`);
78
+ }
79
+ for (const name of tokenNames('--ease-')) {
80
+ const easing = name.slice('--ease-'.length);
81
+ requireReference(name, theme.transitionTimingFunction[easing], `ease-${easing}`);
82
+ }
83
+ for (const name of tokenNames('--radius-')) {
84
+ const radius = name.slice('--radius-'.length);
85
+ requireReference(name, theme.borderRadius[radius], `rounded-${radius}`);
86
+ }
87
+ requireReference('--radius-sm', theme.borderRadius.DEFAULT, 'rounded');
88
+ for (const name of tokenNames('--shadow-')) {
89
+ const shadow = name.slice('--shadow-'.length);
90
+ requireReference(name, theme.boxShadow[shadow], `shadow-${shadow}`);
91
+ }
92
+ requireReference('--shadow-sm', theme.boxShadow.DEFAULT, 'shadow');
93
+ requireReference('--duration-fast', theme.transitionDuration.DEFAULT, 'transition duration');
94
+ requireReference('--ease-default', theme.transitionTimingFunction.DEFAULT, 'transition easing');
95
+ return errors;
96
+ }
97
+
98
+ /**
99
+ * @param {string} source Contents of one source file.
100
+ * @param {Set<string>} spacingSteps Spacing steps that have a token, such as '1.5'.
101
+ * @param {string[]} [allowed] Classes this file may keep.
102
+ * @returns {{ line: number, text: string, message: string }[]} One finding per class that
103
+ * bypasses the token scale.
104
+ */
105
+ export function checkRetiredClasses(source, spacingSteps, allowed = []) {
106
+ const findings = [];
107
+ /** @type {(match: RegExpMatchArray, replacement: string) => void} */
108
+ const report = (match, replacement) => {
109
+ if (allowed.includes(match[0])) return;
110
+ findings.push({
111
+ line: source.slice(0, match.index).split('\n').length,
112
+ text: match[0],
113
+ message: `${match[0]} bypasses the token scale; use ${replacement}.`,
114
+ });
115
+ };
116
+ for (const { pattern, replacement } of RETIRED_CLASSES) {
117
+ for (const match of source.matchAll(pattern)) report(match, replacement);
118
+ }
119
+ for (const match of source.matchAll(SPACING_STEP)) {
120
+ const isOffset = /^(?:pl|pr|ps|pe|ml|mr|ms|me)$/.test(match[1]) && OFFSET_STEPS.has(match[2]);
121
+ if (!spacingSteps.has(match[2]) && !isOffset) report(match, 'a spacing step with a token');
122
+ }
123
+ return findings;
124
+ }
@@ -0,0 +1,148 @@
1
+ import resolveConfig from 'tailwindcss/resolveConfig.js';
2
+
3
+ // The approved RGB values are independent of the production token definitions.
4
+ export const NEUTRAL_RGB = {
5
+ 50: [249, 250, 251],
6
+ 100: [243, 244, 246],
7
+ 200: [229, 231, 235],
8
+ 300: [209, 213, 219],
9
+ 400: [156, 163, 175],
10
+ 500: [107, 114, 128],
11
+ 600: [75, 85, 99],
12
+ 700: [55, 65, 81],
13
+ 800: [31, 41, 55],
14
+ 900: [17, 24, 39],
15
+ 950: [3, 7, 18],
16
+ };
17
+
18
+ export const NEUTRAL_ROLES = {
19
+ background: 50,
20
+ foreground: 900,
21
+ 'card-foreground': 950,
22
+ 'popover-foreground': 950,
23
+ primary: 900,
24
+ 'primary-foreground': 50,
25
+ secondary: 100,
26
+ 'secondary-foreground': 900,
27
+ muted: 100,
28
+ 'muted-foreground': 500,
29
+ accent: 100,
30
+ 'accent-foreground': 900,
31
+ 'destructive-foreground': 50,
32
+ 'success-foreground': 50,
33
+ 'warning-foreground': 50,
34
+ border: 200,
35
+ input: 200,
36
+ ring: 950,
37
+ 'eval-none': 500,
38
+ 'sidebar-foreground': 600,
39
+ 'sidebar-primary': 900,
40
+ 'sidebar-primary-foreground': 50,
41
+ 'sidebar-accent': 100,
42
+ 'sidebar-accent-foreground': 900,
43
+ 'sidebar-border': 200,
44
+ 'sidebar-ring': 400,
45
+ };
46
+
47
+ function hslToRgb(channels) {
48
+ const match = channels?.match(/^([\d.]+)\s+([\d.]+)%\s+([\d.]+)%$/);
49
+ if (!match) return null;
50
+ const hue = Number(match[1]) / 30;
51
+ const saturation = Number(match[2]) / 100;
52
+ const lightness = Number(match[3]) / 100;
53
+ const amplitude = saturation * Math.min(lightness, 1 - lightness);
54
+ return [0, 8, 4].map((offset) => {
55
+ const position = (offset + hue) % 12;
56
+ return Math.round(
57
+ (lightness - amplitude * Math.max(-1, Math.min(position - 3, 9 - position, 1))) * 255,
58
+ );
59
+ });
60
+ }
61
+
62
+ export function checkNeutralPalette(css, tailwindPreset) {
63
+ // Step 1: Resolve the light theme and reject duplicate definitions of protected tokens.
64
+ const roots = [...css.matchAll(/:root\s*\{([^}]+)\}/g)];
65
+ const errors = [];
66
+ if (!roots.length) return ['Missing :root token definitions.'];
67
+ const declarations = roots.flatMap((root) => [...root[1].matchAll(/(--[\w-]+)\s*:\s*([^;]+);/g)]);
68
+ const tokens = Object.fromEntries(declarations.map((match) => [match[1], match[2].trim()]));
69
+ const requireToken = (name, expected) => {
70
+ if (declarations.filter((match) => match[1] === name).length !== 1) {
71
+ errors.push(`${name} must have exactly one light-theme definition.`);
72
+ }
73
+ if (tokens[name] !== expected) errors.push(`${name} must reference ${expected}.`);
74
+ };
75
+
76
+ // Step 2: Check displayed RGB values and require every semantic neutral to share that source.
77
+ for (const [stop, rgb] of Object.entries(NEUTRAL_RGB)) {
78
+ const name = `--gray-${stop}-hsl`;
79
+ const actual = hslToRgb(tokens[name]);
80
+ if (!actual || actual.some((channel, index) => channel !== rgb[index])) {
81
+ errors.push(`${name} must resolve to rgb(${rgb.join(', ')}).`);
82
+ }
83
+ requireToken(name, tokens[name]);
84
+ requireToken(`--gray-${stop}`, `hsl(var(${name}))`);
85
+ }
86
+ for (const [role, stop] of Object.entries(NEUTRAL_ROLES)) {
87
+ requireToken(`--${role}`, `var(--gray-${stop}-hsl)`);
88
+ }
89
+
90
+ // Step 3: Resolve Tailwind defaults too, so missing aliases cannot expose another gray palette.
91
+ const { colors } = resolveConfig({ presets: [tailwindPreset], content: [] }).theme;
92
+ for (const family of ['gray', 'slate', 'zinc', 'neutral', 'stone']) {
93
+ for (const stop of Object.keys(NEUTRAL_RGB)) {
94
+ const expected = `hsl(var(--gray-${stop}-hsl) / <alpha-value>)`;
95
+ if (colors[family]?.[stop] !== expected) {
96
+ errors.push(`Tailwind ${family}-${stop} must reference ${expected}.`);
97
+ }
98
+ }
99
+ }
100
+ return errors;
101
+ }
102
+
103
+ /**
104
+ * @param {string} source Contents of one source file.
105
+ * @returns {{ line: number, text: string, message: string }[]} One finding per literal color
106
+ * that matches a retired neutral.
107
+ */
108
+ export function checkNeutralLiterals(source) {
109
+ const findings = [];
110
+ const colors =
111
+ /#[\da-f]{6}(?:[\da-f]{2})?\b|(?:rgb|hsl)a?\([^)]*\)|--[\w-]+\s*:\s*[\d.]+(?:deg)?\s+[\d.]+%\s+[\d.]+%/gi;
112
+ for (const match of source.matchAll(colors)) {
113
+ const color = match[0].replaceAll('_', ' ').toLowerCase();
114
+ let rgb;
115
+ if (color.startsWith('--')) {
116
+ rgb = hslToRgb(
117
+ color
118
+ .slice(color.indexOf(':') + 1)
119
+ .trim()
120
+ .replace('deg', ''),
121
+ );
122
+ } else if (color.startsWith('#')) {
123
+ rgb = [1, 3, 5].map((offset) => Number.parseInt(color.slice(offset, offset + 2), 16));
124
+ } else {
125
+ const channels = color
126
+ .slice(color.indexOf('(') + 1, -1)
127
+ .split(/[\s,/]+/)
128
+ .filter(Boolean);
129
+ if (channels.length < 3) continue;
130
+ if (color.startsWith('rgb')) {
131
+ rgb = channels.slice(0, 3).map((channel) => {
132
+ const number = Number.parseFloat(channel);
133
+ return Math.round(channel.endsWith('%') ? (number * 255) / 100 : number);
134
+ });
135
+ } else {
136
+ rgb = hslToRgb(channels.slice(0, 3).join(' ').replace('deg', ''));
137
+ }
138
+ }
139
+ if (rgb?.every((channel) => channel === 128) || rgb?.every((channel) => channel === 250)) {
140
+ findings.push({
141
+ line: source.slice(0, match.index).split('\n').length,
142
+ text: match[0],
143
+ message: `${match[0]} reintroduces a retired neutral; use a semantic color token.`,
144
+ });
145
+ }
146
+ }
147
+ return findings;
148
+ }
package/lint/cli.mjs ADDED
@@ -0,0 +1,103 @@
1
+ #!/usr/bin/env node
2
+ // `echelon-design-lint`: checks that the Tailwind preset reads tokens.css, then scans the
3
+ // configured source directories for classes and colors that bypass the tokens.
4
+ import { readFileSync } from 'node:fs';
5
+ import { dirname, resolve } from 'node:path';
6
+ import { parseArgs } from 'node:util';
7
+ import { checkCoreTokens, checkRetiredClasses } from './check-core-tokens.mjs';
8
+ import { checkNeutralLiterals, checkNeutralPalette } from './check-neutral-palette.mjs';
9
+ import { preset, readSpacingSteps, readTokens, tokensPath } from './design-tokens.mjs';
10
+ import { readSourceFiles } from './source-files.mjs';
11
+
12
+ const USAGE = `Usage: echelon-design-lint [--config design-lint.json] [--json]
13
+
14
+ The config file lists the source directories to scan, as paths or glob patterns relative to it,
15
+ and the classes each file may keep while its legacy debt is paid down:
16
+
17
+ {
18
+ "sources": ["src", "apps/*/src"],
19
+ "allow": { "src/legacy-row.tsx": ["ml-[22px]"] }
20
+ }
21
+
22
+ --json prints every problem as JSON, for reports that count them.`;
23
+
24
+ /**
25
+ * @typedef {{ check: string, file?: string, line?: number, text?: string, message: string }} Problem
26
+ */
27
+
28
+ /**
29
+ * @param {string} configPath Absolute path of the config file.
30
+ * @returns {Problem[]} Every problem the checks find.
31
+ */
32
+ function lint(configPath) {
33
+ const root = dirname(configPath);
34
+ const config = JSON.parse(readFileSync(configPath, 'utf8'));
35
+ /** @type {Record<string, string[]>} */
36
+ const allow = config.allow ?? {};
37
+ const css = readTokens();
38
+ const spacingSteps = readSpacingSteps(css);
39
+
40
+ // Step 1: The preset and tokens.css must agree before any app class is judged against them.
41
+ /** @type {Problem[]} */
42
+ const problems = [
43
+ ...checkCoreTokens(css, preset).map((message) => ({ check: 'core-tokens', message })),
44
+ ...checkNeutralPalette(css, preset).map((message) => ({ check: 'neutral-palette', message })),
45
+ ];
46
+
47
+ // Step 2: Reject classes and literal colors that bypass the tokens, except allowed legacy ones.
48
+ const sources = readSourceFiles(root, config.sources ?? [], new Set([resolve(tokensPath)]));
49
+ for (const { file, source } of sources) {
50
+ const allowed = allow[file] ?? [];
51
+ for (const finding of checkRetiredClasses(source, spacingSteps, allowed)) {
52
+ problems.push({ check: 'core-tokens', file, ...finding });
53
+ }
54
+ for (const finding of checkNeutralLiterals(source)) {
55
+ problems.push({ check: 'neutral-palette', file, ...finding });
56
+ }
57
+ }
58
+
59
+ // Step 3: The allow list may only shrink, so an entry whose class is gone must go too.
60
+ const scanned = new Map(sources.map(({ file, source }) => [file, source]));
61
+ for (const [file, classes] of Object.entries(allow)) {
62
+ for (const text of classes) {
63
+ if (!scanned.get(file)?.includes(text)) {
64
+ const message = `${text} is gone; remove it from "allow" in the design lint config.`;
65
+ problems.push({ check: 'core-tokens', file, text, message });
66
+ }
67
+ }
68
+ }
69
+ return problems;
70
+ }
71
+
72
+ /** @param {Problem} problem */
73
+ function formatProblem({ file, line, message }) {
74
+ if (!file) return `- ${message}`;
75
+ return line ? `- ${file}: Line ${line}: ${message}` : `- ${file}: ${message}`;
76
+ }
77
+
78
+ function main() {
79
+ const { values } = parseArgs({
80
+ options: {
81
+ config: { type: 'string', default: 'design-lint.json' },
82
+ json: { type: 'boolean', default: false },
83
+ help: { type: 'boolean', short: 'h', default: false },
84
+ },
85
+ });
86
+ if (values.help) {
87
+ console.log(USAGE);
88
+ return;
89
+ }
90
+ const problems = lint(resolve(values.config));
91
+ if (values.json) {
92
+ console.log(JSON.stringify({ problems }, null, 2));
93
+ } else if (problems.length) {
94
+ console.error(`Design lint failed:\n${problems.map(formatProblem).join('\n')}`);
95
+ } else {
96
+ console.log(
97
+ 'Design lint passed: the preset reads tokens.css, and no source class or color bypasses it.',
98
+ );
99
+ }
100
+ if (problems.length) process.exitCode = 1;
101
+ }
102
+
103
+ main();
@@ -0,0 +1,27 @@
1
+ import { existsSync, readFileSync } from 'node:fs';
2
+ import { fileURLToPath } from 'node:url';
3
+
4
+ export { default as preset } from '../tailwind-preset.js';
5
+
6
+ // This repository checks the source tokens; the published package holds only the compiled copy.
7
+ const tokenFiles = ['../src/styles/tokens.css', '../dist/styles/tokens.css'].map((path) =>
8
+ fileURLToPath(new URL(path, import.meta.url)),
9
+ );
10
+
11
+ /** The tokens.css the checks compare against. */
12
+ export const tokensPath = tokenFiles.find((path) => existsSync(path)) ?? tokenFiles[1];
13
+
14
+ /** @returns {string} Contents of tokens.css. */
15
+ export function readTokens() {
16
+ return readFileSync(tokensPath, 'utf8');
17
+ }
18
+
19
+ /**
20
+ * @param {string} css Contents of tokens.css.
21
+ * @returns {Set<string>} Spacing steps that have a token, such as '1.5' for `--space-1-5`.
22
+ */
23
+ export function readSpacingSteps(css) {
24
+ return new Set(
25
+ [...css.matchAll(/--space-([\d-]+)\s*:/g)].map((match) => match[1].replace('-', '.')),
26
+ );
27
+ }
@@ -0,0 +1,9 @@
1
+ // UI rules for app code, loaded through oxlint's `jsPlugins` as `@echelonos/design/oxlint-plugin`.
2
+ import { noAdhocBadge } from './no-adhoc-badge.mjs';
3
+
4
+ export default {
5
+ meta: { name: 'echelon-design' },
6
+ rules: {
7
+ 'no-adhoc-badge': noAdhocBadge,
8
+ },
9
+ };
@@ -0,0 +1,66 @@
1
+ // Badges come from `StatusPill` only. A badge is `rounded-full` + horizontal padding + a text size
2
+ // in one className; avatars, dots and rails lack a text size or padding, so they pass.
3
+ const BADGE_ROUNDED = /(?:^|\s)!?rounded-full(?:\s|$)/;
4
+ const BADGE_PADDING = /(?:^|\s)!?px-[\w.[\]/-]+/;
5
+ const BADGE_TEXT_SIZE = /(?:^|\s)!?text-(?:xs|sm|base|\[\d+(?:\.\d+)?px\])(?:\s|$)/;
6
+
7
+ function looksLikeBadge(text) {
8
+ return BADGE_ROUNDED.test(text) && BADGE_PADDING.test(text) && BADGE_TEXT_SIZE.test(text);
9
+ }
10
+
11
+ /** Every string fragment inside a node, so a badge assembled across `cn(...)` args is still seen. */
12
+ function collectStrings(node, fragments) {
13
+ if (!node || typeof node !== 'object') return;
14
+ if (Array.isArray(node)) {
15
+ node.forEach((child) => collectStrings(child, fragments));
16
+ return;
17
+ }
18
+ if (node.type === 'Literal' && typeof node.value === 'string') fragments.push(node.value);
19
+ if (node.type === 'TemplateElement') fragments.push(node.value.raw);
20
+ for (const key of Object.keys(node)) {
21
+ if (key === 'parent') continue;
22
+ const child = node[key];
23
+ if (child && typeof child === 'object') collectStrings(child, fragments);
24
+ }
25
+ }
26
+
27
+ export const noAdhocBadge = {
28
+ meta: {
29
+ type: 'problem',
30
+ docs: {
31
+ description: 'Disallow inline badge/pill class strings outside the StatusPill component',
32
+ },
33
+ schema: [],
34
+ messages: {
35
+ adhocBadge:
36
+ 'Do not define a badge inline. Use `StatusPill` (or `CountBadge`) with a `tone` from ' +
37
+ '@echelonos/design/primitives/status-pill so every badge shares one geometry and the ' +
38
+ 'brand tones (see DESIGN.md 5.2). If this is not a badge, split the class string so it no ' +
39
+ 'longer reads as `rounded-full` + `px-*` + `text-<size>`.',
40
+ },
41
+ },
42
+ create(context) {
43
+ const reported = new Set();
44
+ const report = (node) => {
45
+ if (reported.has(node)) return;
46
+ reported.add(node);
47
+ context.report({ node, messageId: 'adhocBadge' });
48
+ };
49
+ return {
50
+ Literal(node) {
51
+ if (typeof node.value === 'string' && looksLikeBadge(node.value)) report(node);
52
+ },
53
+ TemplateElement(node) {
54
+ if (looksLikeBadge(node.value.raw ?? '')) report(node);
55
+ },
56
+ JSXAttribute(node) {
57
+ if (node.name?.name !== 'className' || !node.value) return;
58
+ const fragments = [];
59
+ collectStrings(node.value, fragments);
60
+ // Any single fragment is already handled above; this catches the split-across-args case.
61
+ if (fragments.some(looksLikeBadge)) return;
62
+ if (looksLikeBadge(fragments.join(' '))) report(node);
63
+ },
64
+ };
65
+ },
66
+ };
@@ -0,0 +1,44 @@
1
+ import { existsSync, globSync, readFileSync, readdirSync } from 'node:fs';
2
+ import { join, relative, resolve } from 'node:path';
3
+
4
+ const SKIPPED_DIRECTORIES = new Set(['generated', '__tests__', '__fixtures__', 'node_modules']);
5
+
6
+ /**
7
+ * Every UI source file under the `patterns` directories, without generated code, tests, fixtures
8
+ * or the files in `skipped`.
9
+ *
10
+ * @param {string} root Directory the patterns and the returned paths are relative to.
11
+ * @param {string[]} patterns Source directories as glob patterns, such as `packages/ui/src`.
12
+ * @param {Set<string>} [skipped] Absolute paths to leave out, such as the tokens file.
13
+ * @returns {{ file: string, source: string }[]} Root-relative path and contents.
14
+ */
15
+ export function readSourceFiles(root, patterns, skipped = new Set()) {
16
+ // Step 1: Expand the patterns into source directories.
17
+ const directories = new Set(
18
+ patterns.flatMap((pattern) => globSync(pattern, { cwd: root }).map((path) => join(root, path))),
19
+ );
20
+
21
+ // Step 2: Read each source file under them.
22
+ const sources = [];
23
+ /** @param {string} directory */
24
+ const scan = (directory) => {
25
+ if (!existsSync(directory)) return;
26
+ for (const entry of readdirSync(directory, { withFileTypes: true })) {
27
+ const path = join(directory, entry.name);
28
+ if (entry.isDirectory()) {
29
+ if (!SKIPPED_DIRECTORIES.has(entry.name)) scan(path);
30
+ } else if (
31
+ entry.isFile() &&
32
+ /\.(?:[cm]?[jt]sx?|css)$/.test(entry.name) &&
33
+ !/\.(?:test|spec)\./.test(entry.name) &&
34
+ !skipped.has(resolve(path))
35
+ ) {
36
+ // Read only regular files discovered under the configured source roots.
37
+ // no-dd-sa:javascript-node-security/detect-non-literal-fs-filename
38
+ sources.push({ file: relative(root, path), source: readFileSync(path, 'utf8') });
39
+ }
40
+ }
41
+ };
42
+ directories.forEach(scan);
43
+ return sources.sort((left, right) => left.file.localeCompare(right.file));
44
+ }
package/package.json CHANGED
@@ -1,15 +1,20 @@
1
1
  {
2
2
  "name": "@echelonos/design",
3
- "version": "0.0.0",
3
+ "version": "0.1.0",
4
4
  "description": "Echelon design system: tokens and components.",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/EchelonOS/design.git",
8
8
  "directory": "packages/design"
9
9
  },
10
+ "bin": {
11
+ "echelon-design-lint": "./lint/cli.mjs"
12
+ },
10
13
  "files": [
11
14
  "dist",
12
- "tailwind-content.js"
15
+ "lint",
16
+ "tailwind-content.js",
17
+ "tailwind-preset.js"
13
18
  ],
14
19
  "type": "module",
15
20
  "imports": {
@@ -25,11 +30,13 @@
25
30
  "./fonts/*": "./dist/fonts/*",
26
31
  "./hooks/*": "./dist/hooks/*.js",
27
32
  "./lib/*": "./dist/lib/*.js",
33
+ "./oxlint-plugin": "./lint/oxlint-plugin/index.mjs",
28
34
  "./primitives/*": "./dist/primitives/*.js",
29
35
  "./theme": "./dist/theme/theme-context.js",
30
36
  "./utils": "./dist/lib/utils.js",
31
37
  "./styles.css": "./dist/styles/tokens.css",
32
- "./tailwind-content": "./tailwind-content.js"
38
+ "./tailwind-content": "./tailwind-content.js",
39
+ "./tailwind-preset": "./tailwind-preset.js"
33
40
  },
34
41
  "publishConfig": {
35
42
  "access": "public"
@@ -37,5 +44,15 @@
37
44
  "scripts": {
38
45
  "build": "tsc -p tsconfig.json && node scripts/copy-assets.mjs",
39
46
  "typecheck": "tsc -p tsconfig.json --noEmit"
47
+ },
48
+ "dependencies": {
49
+ "@tailwindcss/typography": "0.5.19",
50
+ "tailwindcss-animate": "1.0.7"
51
+ },
52
+ "devDependencies": {
53
+ "tailwindcss": "3.4.19"
54
+ },
55
+ "peerDependencies": {
56
+ "tailwindcss": "^3.4.0"
40
57
  }
41
58
  }