medesign 1.2.0 → 1.6.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/README.md +223 -129
- package/bin/mebolder.js +4 -0
- package/bin/medesign.js +992 -200
- package/bin/melint.js +4 -0
- package/bin/mepolish.js +4 -0
- package/bin/mequiet.js +4 -0
- package/bin/mesearch.js +4 -0
- package/bin/mesnapshot.js +4 -0
- package/examples/cadastral-qaqc-slide.html +577 -0
- package/examples/executive-summary-report.html +597 -0
- package/examples/executive-summary-report.pdf +0 -0
- package/examples/geospatial-banner-1200x630.html +370 -0
- package/examples/geospatial-banner-1200x630.svg +149 -0
- package/examples/linear-issue-board.html +1273 -0
- package/examples/snapshots/cadastral-qaqc-slide-desktop-1440x900.png +0 -0
- package/examples/snapshots/cadastral-qaqc-slide-mobile-390x844.png +0 -0
- package/examples/snapshots/cadastral-qaqc-slide-tablet-820x1180.png +0 -0
- package/examples/snapshots/executive-summary-report-desktop-1440x900.png +0 -0
- package/examples/snapshots/executive-summary-report-mobile-390x844.png +0 -0
- package/examples/snapshots/executive-summary-report-tablet-820x1180.png +0 -0
- package/examples/snapshots/geospatial-banner-1200x630-og-banner-1200x630.png +0 -0
- package/examples/snapshots/linear-issue-board-desktop-1440x900.png +0 -0
- package/examples/snapshots/linear-issue-board-mobile-390x844.png +0 -0
- package/examples/snapshots/linear-issue-board-tablet-820x1180.png +0 -0
- package/examples/snapshots/spotify-web-player-desktop-1440x900.png +0 -0
- package/examples/snapshots/spotify-web-player-mobile-390x844.png +0 -0
- package/examples/snapshots/spotify-web-player-tablet-820x1180.png +0 -0
- package/examples/spotify-web-player.html +1446 -0
- package/package.json +21 -4
- package/presets/metha/guidelines.md +26 -17
- package/presets/metha/preset.json +16 -16
- package/references/ai-tells.md +9 -2
- package/references/brand-design-tokens.md +27 -28
- package/references/brief-intake.md +90 -0
- package/references/catalog.json +1024 -101
- package/references/cli-architecture.md +1 -1
- package/references/compositor-smoothness.md +161 -0
- package/references/design-core.md +11 -4
- package/references/executive-reports.md +234 -0
- package/references/image-mockup-direction.md +53 -53
- package/references/image-to-code.md +46 -46
- package/references/modern-craft-invariants.md +55 -9
- package/references/prompt-templates.md +49 -0
- package/references/quality-gate.md +42 -12
- package/references/typography-thai-latin.md +206 -0
- package/references/view-transitions-engine.md +89 -0
- package/references/web-retrofit-protocol.md +103 -0
- package/scripts/export-tokens.js +419 -403
- package/tests/browser-audit.js +463 -442
- package/tests/linter.js +457 -412
- package/tests/snapshot.js +263 -0
package/bin/medesign.js
CHANGED
|
@@ -1,200 +1,992 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* ME-DESIGN CLI — Autonomous Design Engineering Toolkit & Linter
|
|
5
|
-
*
|
|
6
|
-
* Commands:
|
|
7
|
-
* medesign lint <file> [--format text|json|sarif] [--preset <name>] [--config <path>]
|
|
8
|
-
* medesign audit <file> [--json]
|
|
9
|
-
* medesign
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const
|
|
25
|
-
const
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
const
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
//
|
|
144
|
-
const
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* ME-DESIGN CLI — Autonomous Design Engineering Toolkit & Linter
|
|
5
|
+
*
|
|
6
|
+
* Commands:
|
|
7
|
+
* medesign lint <file> [--format text|json|sarif] [--preset <name>] [--config <path>]
|
|
8
|
+
* medesign audit <file> [--json]
|
|
9
|
+
* medesign search <query> [--json]
|
|
10
|
+
* polish <file>
|
|
11
|
+
* bolder <file>
|
|
12
|
+
* quiet <file>
|
|
13
|
+
* medesign tokens [--preset <name>] [--format tailwind|dtcg|css|all] [--out <dir>]
|
|
14
|
+
* medesign presets [list | get <name>]
|
|
15
|
+
* medesign test [--browser]
|
|
16
|
+
* medesign doctor
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
const fs = require('fs');
|
|
20
|
+
const path = require('path');
|
|
21
|
+
const { spawnSync } = require('child_process');
|
|
22
|
+
const pkg = require('../package.json');
|
|
23
|
+
|
|
24
|
+
const rootDir = path.join(__dirname, '..');
|
|
25
|
+
const rawArgs = process.argv.slice(2);
|
|
26
|
+
const invokedBin = path.basename(process.argv[1] || '', path.extname(process.argv[1] || '')).toLowerCase();
|
|
27
|
+
|
|
28
|
+
let args = rawArgs;
|
|
29
|
+
let command = rawArgs[0] || 'help';
|
|
30
|
+
|
|
31
|
+
const aliasMap = {
|
|
32
|
+
mepolish: 'polish',
|
|
33
|
+
mebolder: 'bolder',
|
|
34
|
+
mequiet: 'quiet',
|
|
35
|
+
melint: 'lint',
|
|
36
|
+
mesearch: 'search',
|
|
37
|
+
mesnapshot: 'snapshot'
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
if (aliasMap[invokedBin] && rawArgs[0] !== aliasMap[invokedBin]) {
|
|
41
|
+
command = aliasMap[invokedBin];
|
|
42
|
+
args = [command, ...rawArgs];
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const ANSI_RESET = '\x1b[0m';
|
|
46
|
+
const ANSI_BOLD = '\x1b[1m';
|
|
47
|
+
const ANSI_CYAN = '\x1b[36m';
|
|
48
|
+
const ANSI_GREEN = '\x1b[32m';
|
|
49
|
+
const ANSI_YELLOW = '\x1b[33m';
|
|
50
|
+
const ANSI_RED = '\x1b[31m';
|
|
51
|
+
const ANSI_GRAY = '\x1b[90m';
|
|
52
|
+
|
|
53
|
+
function printHelp() {
|
|
54
|
+
console.log(`
|
|
55
|
+
${ANSI_BOLD}ME-DESIGN CLI v${pkg.version}${ANSI_RESET}
|
|
56
|
+
Autonomous Design Engineering Toolkit & Automated Linter for AI Coding Assistants
|
|
57
|
+
|
|
58
|
+
${ANSI_BOLD}USAGE:${ANSI_RESET}
|
|
59
|
+
medesign <command> [options]
|
|
60
|
+
|
|
61
|
+
${ANSI_BOLD}COMMANDS:${ANSI_RESET}
|
|
62
|
+
${ANSI_CYAN}search${ANSI_RESET} <query> Search 38 Archetypes & presets with discovery engine
|
|
63
|
+
Options: --json
|
|
64
|
+
|
|
65
|
+
${ANSI_CYAN}polish${ANSI_RESET} <file> Self-healing repair for Hard Invariants (MD005, MD104, em-dash)
|
|
66
|
+
|
|
67
|
+
${ANSI_CYAN}bolder${ANSI_RESET} <file> Boost visual density, font weights, and border contrast
|
|
68
|
+
|
|
69
|
+
${ANSI_CYAN}quiet${ANSI_RESET} <file> Softens visual density, font weights, and border treatments
|
|
70
|
+
|
|
71
|
+
${ANSI_CYAN}lint${ANSI_RESET} <file> Lint HTML/CSS/JSX file with static AST & semantic rules
|
|
72
|
+
Options: --format <text|json|sarif>
|
|
73
|
+
--preset <apple|tesla|metha>
|
|
74
|
+
--config <path>
|
|
75
|
+
|
|
76
|
+
${ANSI_CYAN}audit${ANSI_RESET} <file> Run headless Chrome DevTools Protocol verification matrix
|
|
77
|
+
(Checks computed contrast, tab focus outline, 44px hit-targets across viewports)
|
|
78
|
+
Options: --json
|
|
79
|
+
|
|
80
|
+
${ANSI_CYAN}snapshot${ANSI_RESET} <file> Capture high-DPI rendered screenshots across responsive viewports
|
|
81
|
+
Options: --out <dir>, --og (1200x630 banner), --viewports <list>
|
|
82
|
+
|
|
83
|
+
${ANSI_CYAN}tokens${ANSI_RESET} [export] Export preset design tokens to Tailwind v4 @theme, W3C DTCG, or CSS
|
|
84
|
+
Options: --preset <apple|tesla|metha|all>
|
|
85
|
+
--format <tailwind|dtcg|css|all>
|
|
86
|
+
--out <directory>
|
|
87
|
+
|
|
88
|
+
${ANSI_CYAN}presets${ANSI_RESET} [list|get] Inspect available design system presets
|
|
89
|
+
Usage: medesign presets list
|
|
90
|
+
medesign presets get <preset-name>
|
|
91
|
+
|
|
92
|
+
${ANSI_CYAN}test${ANSI_RESET} [options] Run deterministic test suite across fixtures
|
|
93
|
+
Options: --browser (runs both static AST and headless browser matrix)
|
|
94
|
+
|
|
95
|
+
${ANSI_CYAN}doctor${ANSI_RESET} Verify local environment, Node.js, and Chrome/CDP availability
|
|
96
|
+
|
|
97
|
+
${ANSI_CYAN}help${ANSI_RESET} Display this help message
|
|
98
|
+
`);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
switch (command) {
|
|
102
|
+
case 'search': {
|
|
103
|
+
const isJson = args.includes('--json');
|
|
104
|
+
const isHelp = args.includes('--help') || args.includes('-h');
|
|
105
|
+
const query = args.slice(1).filter(a => !a.startsWith('--') && a !== '-h').join(' ').trim();
|
|
106
|
+
|
|
107
|
+
if (!query || isHelp) {
|
|
108
|
+
if (isJson) {
|
|
109
|
+
console.log(JSON.stringify({ usage: 'medesign search <query> [--json]' }));
|
|
110
|
+
} else {
|
|
111
|
+
console.log(`\n${ANSI_BOLD}ME-DESIGN Search Engine${ANSI_RESET}`);
|
|
112
|
+
console.log(`${ANSI_GRAY}Instant discovery across 38 Archetypes & system presets${ANSI_RESET}\n`);
|
|
113
|
+
console.log(`${ANSI_BOLD}Usage:${ANSI_RESET} medesign search "<query>" [--json]`);
|
|
114
|
+
console.log(` mesearch "<query>" [--json]\n`);
|
|
115
|
+
console.log(`Example: medesign search "cadastre survey"\n`);
|
|
116
|
+
}
|
|
117
|
+
process.exit(isHelp ? 0 : 1);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const catalogPath = path.join(rootDir, 'references', 'catalog.json');
|
|
121
|
+
if (!fs.existsSync(catalogPath)) {
|
|
122
|
+
console.error('Error: references/catalog.json not found.');
|
|
123
|
+
process.exit(1);
|
|
124
|
+
}
|
|
125
|
+
const catalog = JSON.parse(fs.readFileSync(catalogPath, 'utf8'));
|
|
126
|
+
|
|
127
|
+
const presetsDir = path.join(rootDir, 'presets');
|
|
128
|
+
const presetFolders = fs.existsSync(presetsDir)
|
|
129
|
+
? fs.readdirSync(presetsDir, { withFileTypes: true }).filter(d => d.isDirectory()).map(d => d.name)
|
|
130
|
+
: [];
|
|
131
|
+
const presets = [];
|
|
132
|
+
presetFolders.forEach(name => {
|
|
133
|
+
const pPath = path.join(presetsDir, name, 'preset.json');
|
|
134
|
+
if (fs.existsSync(pPath)) {
|
|
135
|
+
try {
|
|
136
|
+
presets.push(JSON.parse(fs.readFileSync(pPath, 'utf8')));
|
|
137
|
+
} catch (e) {}
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
const queryTerms = query.toLowerCase().split(/[\s,+/]+/).filter(Boolean);
|
|
142
|
+
|
|
143
|
+
// Score archetypes based on query relevance
|
|
144
|
+
const scored = catalog.archetypes.map(arch => {
|
|
145
|
+
let score = 0;
|
|
146
|
+
const nameLower = (arch.name || '').toLowerCase();
|
|
147
|
+
const titleLower = (arch.archetypeTitle || '').toLowerCase();
|
|
148
|
+
const groupLower = (arch.group || '').toLowerCase();
|
|
149
|
+
const vibeLower = (arch.vibe || '').toLowerCase();
|
|
150
|
+
const spatialLower = (arch.spatialModel || '').toLowerCase();
|
|
151
|
+
const colorLower = (arch.primaryColor || '').toLowerCase();
|
|
152
|
+
const typoLower = (arch.typography || '').toLowerCase();
|
|
153
|
+
const keywords = (arch.keywords || []).map(k => k.toLowerCase());
|
|
154
|
+
const presetId = (arch.presetId || '').toLowerCase();
|
|
155
|
+
const presetLink = (arch.presetLink || '').toLowerCase();
|
|
156
|
+
|
|
157
|
+
// Check entire query phrase match
|
|
158
|
+
const qLower = query.toLowerCase();
|
|
159
|
+
if (nameLower.includes(qLower) || titleLower.includes(qLower)) {
|
|
160
|
+
score += 40;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
let titleTermsMatched = 0;
|
|
164
|
+
queryTerms.forEach(term => {
|
|
165
|
+
const stem = term.length > 4 ? term.replace(/(?:al|ic|ing|e|s)$/i, '') : term;
|
|
166
|
+
// Name / Title match
|
|
167
|
+
if (nameLower.includes(term) || titleLower.includes(term)) {
|
|
168
|
+
score += 20;
|
|
169
|
+
titleTermsMatched++;
|
|
170
|
+
} else if (stem.length >= 4 && (nameLower.includes(stem) || titleLower.includes(stem))) {
|
|
171
|
+
score += 16;
|
|
172
|
+
titleTermsMatched++;
|
|
173
|
+
}
|
|
174
|
+
// Keywords exact or substring match
|
|
175
|
+
keywords.forEach(kw => {
|
|
176
|
+
if (kw === term) score += 15;
|
|
177
|
+
else if (kw.includes(term) || term.includes(kw)) score += 10;
|
|
178
|
+
else if (stem.length >= 4 && (kw.includes(stem) || stem.includes(kw))) score += 8;
|
|
179
|
+
});
|
|
180
|
+
// Vibe match
|
|
181
|
+
if (vibeLower.includes(term) || (stem.length >= 4 && vibeLower.includes(stem))) score += 6;
|
|
182
|
+
// Spatial / color / typography / group match
|
|
183
|
+
if (spatialLower.includes(term)) score += 5;
|
|
184
|
+
if (colorLower.includes(term)) score += 5;
|
|
185
|
+
if (typoLower.includes(term)) score += 5;
|
|
186
|
+
if (groupLower.includes(term)) score += 4;
|
|
187
|
+
// Preset id / link match
|
|
188
|
+
if (presetId.includes(term) || presetLink.includes(term)) score += 12;
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
// Bonus if multiple query terms directly match the title
|
|
192
|
+
if (titleTermsMatched > 1) {
|
|
193
|
+
score += titleTermsMatched * 15;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// Match against presets definitions
|
|
197
|
+
presets.forEach(p => {
|
|
198
|
+
const pName = (p.name || '').toLowerCase();
|
|
199
|
+
const pDesc = (p.description || '').toLowerCase();
|
|
200
|
+
const pId = (p.id || '').toLowerCase();
|
|
201
|
+
const pArch = (p.archetype || '').toLowerCase();
|
|
202
|
+
let presetMatches = false;
|
|
203
|
+
queryTerms.forEach(term => {
|
|
204
|
+
if (pName.includes(term) || pDesc.includes(term) || pId === term || pArch.includes(term)) {
|
|
205
|
+
presetMatches = true;
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
if (presetMatches && (arch.presetId === p.id || (arch.presetLink && arch.presetLink.includes(p.id)))) {
|
|
209
|
+
score += 25;
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
return { ...arch, score };
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
scored.sort((a, b) => b.score - a.score);
|
|
217
|
+
const best = scored[0] || catalog.archetypes[0];
|
|
218
|
+
|
|
219
|
+
if (isJson) {
|
|
220
|
+
console.log(JSON.stringify({
|
|
221
|
+
query,
|
|
222
|
+
bestMatch: {
|
|
223
|
+
id: best.id,
|
|
224
|
+
number: best.number,
|
|
225
|
+
name: best.name,
|
|
226
|
+
archetypeTitle: best.archetypeTitle,
|
|
227
|
+
group: best.group,
|
|
228
|
+
presetLink: best.presetLink,
|
|
229
|
+
spatialModel: best.spatialModel,
|
|
230
|
+
primaryColor: best.primaryColor,
|
|
231
|
+
secondaryColor: best.secondaryColor,
|
|
232
|
+
surfaceContrast: best.surfaceContrast,
|
|
233
|
+
typography: best.typography,
|
|
234
|
+
motionProfile: best.motionProfile,
|
|
235
|
+
score: best.score
|
|
236
|
+
},
|
|
237
|
+
topMatches: scored.slice(0, 5).map(a => ({
|
|
238
|
+
number: a.number,
|
|
239
|
+
name: a.name,
|
|
240
|
+
score: a.score,
|
|
241
|
+
presetLink: a.presetLink
|
|
242
|
+
}))
|
|
243
|
+
}, null, 2));
|
|
244
|
+
process.exit(0);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
console.log(`
|
|
248
|
+
${ANSI_BOLD}ME-DESIGN Discovery Engine${ANSI_RESET}
|
|
249
|
+
${ANSI_GRAY}────────────────────────────────────────${ANSI_RESET}
|
|
250
|
+
${ANSI_BOLD}Query${ANSI_RESET} "${ANSI_CYAN}${query}${ANSI_RESET}"
|
|
251
|
+
${ANSI_BOLD}Best Match${ANSI_RESET} Archetype ${best.number < 10 ? '0' + best.number : best.number}: ${ANSI_GREEN}${ANSI_BOLD}${best.name}${ANSI_RESET}
|
|
252
|
+
${ANSI_BOLD}Preset Link${ANSI_RESET} ${best.presetLink ? ANSI_CYAN + best.presetLink + ANSI_RESET : ANSI_GRAY + 'Standard Catalog' + ANSI_RESET}
|
|
253
|
+
|
|
254
|
+
${ANSI_BOLD}DESIGN ARCHETYPE RECOMMENDATION${ANSI_RESET}
|
|
255
|
+
${ANSI_BOLD}Archetype${ANSI_RESET} ${best.archetypeTitle || best.name}
|
|
256
|
+
${ANSI_BOLD}Spatial Model${ANSI_RESET} ${best.spatialModel || '16:10 / 100dvh Map-Centric with Split Data Grid'}
|
|
257
|
+
${ANSI_BOLD}Primary Color${ANSI_RESET} ${best.primaryColor || 'Electric Cyan (oklch(0.85 0.18 200))'}
|
|
258
|
+
${ANSI_BOLD}Secondary Color${ANSI_RESET} ${best.secondaryColor || 'Passed Emerald (oklch(0.72 0.18 145))'}
|
|
259
|
+
${ANSI_BOLD}Surface Contrast${ANSI_RESET} ${best.surfaceContrast || 'Ultra-Dark Obsidian (#0a0d14)'}
|
|
260
|
+
${ANSI_BOLD}Typography${ANSI_RESET} ${best.typography || 'JetBrains Mono + IBM Plex Sans Thai'}
|
|
261
|
+
${ANSI_BOLD}Motion Profile${ANSI_RESET} ${best.motionProfile || 'Precision Linear (120ms max)'}
|
|
262
|
+
${ANSI_GRAY}────────────────────────────────────────${ANSI_RESET}
|
|
263
|
+
`);
|
|
264
|
+
break;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
case 'polish': {
|
|
268
|
+
const targetFile = args[1];
|
|
269
|
+
if (!targetFile || targetFile === '--help' || targetFile === '-h') {
|
|
270
|
+
console.log(`
|
|
271
|
+
${ANSI_BOLD}ME-DESIGN Self-Healing Polish & Aesthetic Auto-Compiler${ANSI_RESET}
|
|
272
|
+
${ANSI_GRAY}Autonomous aesthetic compilation and self-healing repair engine${ANSI_RESET}
|
|
273
|
+
|
|
274
|
+
${ANSI_BOLD}Usage:${ANSI_RESET}
|
|
275
|
+
medesign polish <file>
|
|
276
|
+
mepolish <file>
|
|
277
|
+
|
|
278
|
+
${ANSI_BOLD}Repairs & Aesthetic Compilations:${ANSI_RESET}
|
|
279
|
+
- Elevates generic typography to curated Archetypes (Geist / Plus Jakarta Sans / JetBrains Mono)
|
|
280
|
+
- Injects GPU-accelerated spring micro-interactions (160ms cubic-bezier(0.16, 1, 0.3, 1))
|
|
281
|
+
- Injects dynamic Bento proportions & asymmetric visual hierarchy
|
|
282
|
+
- Decouples 44px hit-targets with transparent touch halos & boundary clearance (MD106)
|
|
283
|
+
- Normalizes color gamut to perceptual OKLCH interpolation (MD102)
|
|
284
|
+
- Replaces hit-target crushing scale with controlled proportional scale (MD003)
|
|
285
|
+
- Injects physical :focus-visible outline & forced-colors high contrast (MD005)
|
|
286
|
+
- Replaces raw 100vh with dynamic 100dvh fallback (MD104)
|
|
287
|
+
- Fixes dead buttons with interactive hover/active states (MD004)
|
|
288
|
+
- Injects prefers-reduced-motion accessibility gate (MD002)
|
|
289
|
+
- Cleans HTML entity and unicode em-dashes to hyphens (MD201)
|
|
290
|
+
`);
|
|
291
|
+
process.exit(targetFile === '--help' || targetFile === '-h' ? 0 : 1);
|
|
292
|
+
}
|
|
293
|
+
const resolvedPath = path.resolve(process.cwd(), targetFile);
|
|
294
|
+
if (!fs.existsSync(resolvedPath)) {
|
|
295
|
+
console.error(`${ANSI_RED}Error:${ANSI_RESET} File not found: ${resolvedPath}`);
|
|
296
|
+
process.exit(1);
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
const linterScript = path.join(rootDir, 'tests', 'linter.js');
|
|
300
|
+
let beforeQ = 80.0;
|
|
301
|
+
try {
|
|
302
|
+
const beforeRes = spawnSync(process.execPath, [linterScript, resolvedPath, '--json'], { encoding: 'utf8' });
|
|
303
|
+
const parsed = JSON.parse(beforeRes.stdout);
|
|
304
|
+
beforeQ = parsed.qScore || 80.0;
|
|
305
|
+
} catch (e) {}
|
|
306
|
+
|
|
307
|
+
let content = fs.readFileSync(resolvedPath, 'utf8');
|
|
308
|
+
const fixes = [];
|
|
309
|
+
|
|
310
|
+
const getClean = (src) => src.replace(/\/\*[\s\S]*?\*\//g, '').replace(/<!--[\s\S]*?-->/g, '');
|
|
311
|
+
|
|
312
|
+
const isHtml = /<html|<body|<!DOCTYPE|<\/head>/i.test(content);
|
|
313
|
+
if (isHtml && !/<style\b/i.test(content)) {
|
|
314
|
+
if (content.includes('</head>')) {
|
|
315
|
+
content = content.replace('</head>', ' <style>\n </style>\n</head>');
|
|
316
|
+
} else if (content.includes('<body>')) {
|
|
317
|
+
content = content.replace('<body>', '<head>\n <style>\n </style>\n</head>\n<body>');
|
|
318
|
+
} else {
|
|
319
|
+
content = '<style>\n</style>\n' + content;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
// 1. RULE MD104: Dynamic Viewport Units (Convert raw 100vh to 100dvh fallback)
|
|
324
|
+
let count104 = 0;
|
|
325
|
+
content = content.replace(/min-height\s*:\s*100vh\s*;?(?!\s*min-height\s*:\s*100[ds]vh)/gi, () => {
|
|
326
|
+
count104++;
|
|
327
|
+
return 'min-height: 100vh; min-height: 100dvh;';
|
|
328
|
+
});
|
|
329
|
+
content = content.replace(/(?<!min-)(?<!max-)height\s*:\s*100vh\s*;?(?!\s*(?:min-height|height)\s*:\s*100[ds]vh)/gi, () => {
|
|
330
|
+
count104++;
|
|
331
|
+
return 'min-height: 100vh; min-height: 100dvh;';
|
|
332
|
+
});
|
|
333
|
+
content = content.replace(/max-height\s*:\s*100vh\s*;?(?!\s*max-height\s*:\s*100[ds]vh)/gi, () => {
|
|
334
|
+
count104++;
|
|
335
|
+
return 'max-height: 100vh; max-height: 100dvh;';
|
|
336
|
+
});
|
|
337
|
+
if (count104 > 0) {
|
|
338
|
+
fixes.push(`Replaced ${count104} raw 100vh with 100dvh fallback (MD104)`);
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
// 2. RULE MD005: Focus Ring High Contrast & Physical Outline Visibility
|
|
342
|
+
const focusBlockRegex = /((?:[a-zA-Z0-9_\-\.\#\:\*\,\[\]\="'>\s]+)?:focus(?:-visible)?\s*\{)([^}]+)(\})/gi;
|
|
343
|
+
let md005Applied = false;
|
|
344
|
+
content = content.replace(focusBlockRegex, (match, prefix, body, suffix) => {
|
|
345
|
+
let updatedBody = body;
|
|
346
|
+
if (/outline\s*:\s*(?:none|0px?)\s*(?:;|\})/i.test(updatedBody)) {
|
|
347
|
+
updatedBody = updatedBody.replace(/outline\s*:\s*(?:none|0px?)\s*;?/gi, 'outline: 2px solid Highlight; outline-offset: 2px;');
|
|
348
|
+
md005Applied = true;
|
|
349
|
+
} else if (/box-shadow\s*:/i.test(updatedBody) && !/outline\s*:\s*(?!none|0px?)/i.test(updatedBody)) {
|
|
350
|
+
updatedBody += ' outline: 2px solid Highlight; outline-offset: 2px;';
|
|
351
|
+
md005Applied = true;
|
|
352
|
+
}
|
|
353
|
+
return prefix + updatedBody + suffix;
|
|
354
|
+
});
|
|
355
|
+
|
|
356
|
+
// Ensure forced-colors high contrast outline media query is injected
|
|
357
|
+
if (!/@media\s*\(forced-colors:\s*active\)/i.test(getClean(content))) {
|
|
358
|
+
const forcedColorsRule = `\n @media (forced-colors: active) {\n :focus-visible, button:focus-visible, [class*="btn"]:focus-visible, a:focus-visible, [role="button"]:focus-visible {\n outline: 2px solid CanvasText !important;\n outline-offset: 2px !important;\n }\n }\n`;
|
|
359
|
+
if (content.includes('</style>')) {
|
|
360
|
+
content = content.replace('</style>', `${forcedColorsRule} </style>`);
|
|
361
|
+
md005Applied = true;
|
|
362
|
+
} else if (resolvedPath.endsWith('.css') || !isHtml) {
|
|
363
|
+
content = content.trimEnd() + '\n' + forcedColorsRule;
|
|
364
|
+
md005Applied = true;
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
if (md005Applied) {
|
|
368
|
+
fixes.push('Added physical focus outline & forced-colors high contrast (MD005)');
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
// 3. RULE MD003: Uncontrolled Button Scale / Hit Target Crush
|
|
372
|
+
let count003 = 0;
|
|
373
|
+
if (/active:scale-9[0-5]/.test(content)) {
|
|
374
|
+
content = content.replace(/active:scale-9[0-5]/g, 'active:scale-98');
|
|
375
|
+
count003++;
|
|
376
|
+
}
|
|
377
|
+
if (/:active\s*\{[^}]*transform:\s*scale\(0\.9[0-5]\)/.test(content)) {
|
|
378
|
+
content = content.replace(/(transform\s*:\s*scale\()0\.9[0-5](\))/gi, '$10.98$2');
|
|
379
|
+
count003++;
|
|
380
|
+
}
|
|
381
|
+
if (count003 > 0) {
|
|
382
|
+
fixes.push('Replaced hit-target crushing active scale with safe proportional scale(0.98) (MD003)');
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
// 4. RULE MD004: Interactive State Contract & Micro-Interaction Springs
|
|
386
|
+
const cleanForButtons = getClean(content);
|
|
387
|
+
const hasButtons = /<button/i.test(cleanForButtons) || /class="[^"]*btn[^"]*"/i.test(cleanForButtons) || /\.btn\b/i.test(cleanForButtons) || /role="button"/i.test(cleanForButtons);
|
|
388
|
+
const hasInteractive = /:hover/i.test(cleanForButtons) || /:active/i.test(cleanForButtons);
|
|
389
|
+
if (hasButtons && !hasInteractive) {
|
|
390
|
+
const buttonStates = `\n button, [class*="btn"], .btn, [role="button"] {\n min-height: 44px;\n display: inline-flex;\n align-items: center;\n justify-content: center;\n transition: transform 160ms cubic-bezier(0.16, 1, 0.3, 1), box-shadow 160ms cubic-bezier(0.16, 1, 0.3, 1), filter 160ms cubic-bezier(0.16, 1, 0.3, 1);\n }\n button:hover, [class*="btn"]:hover, .btn:hover, [role="button"]:hover {\n filter: brightness(1.1);\n transform: translateY(-1px);\n }\n button:active, [class*="btn"]:active, .btn:active, [role="button"]:active {\n transform: scale(0.98);\n }\n button:focus-visible, [class*="btn"]:focus-visible, .btn:focus-visible, [role="button"]:focus-visible {\n outline: 2px solid Highlight;\n outline-offset: 2px;\n }\n`;
|
|
391
|
+
if (content.includes('</style>')) {
|
|
392
|
+
content = content.replace('</style>', `${buttonStates} </style>`);
|
|
393
|
+
fixes.push('Injected hover and active interactive states for buttons (MD004)');
|
|
394
|
+
} else if (resolvedPath.endsWith('.css') || !isHtml) {
|
|
395
|
+
content = content.trimEnd() + '\n' + buttonStates;
|
|
396
|
+
fixes.push('Injected hover and active interactive states for buttons (MD004)');
|
|
397
|
+
}
|
|
398
|
+
} else if (hasButtons && !content.includes('min-height: 44px')) {
|
|
399
|
+
const hitTargetFix = `\n /* 44px Touch Target Standard (Apple HIG / WCAG) */\n button, [class*="btn"], .btn, [role="button"] { min-height: 44px; }\n`;
|
|
400
|
+
if (content.includes('</style>')) {
|
|
401
|
+
content = content.replace('</style>', `${hitTargetFix} </style>`);
|
|
402
|
+
fixes.push('Enforced 44px minimum touch hit-target standard on buttons');
|
|
403
|
+
} else if (resolvedPath.endsWith('.css') || !isHtml) {
|
|
404
|
+
content = content.trimEnd() + '\n' + hitTargetFix;
|
|
405
|
+
fixes.push('Enforced 44px minimum touch hit-target standard on buttons');
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
// Micro-Interaction Springs (GPU-accelerated 160ms cubic-bezier transitions)
|
|
410
|
+
if (!content.includes('cubic-bezier(0.16, 1, 0.3, 1)')) {
|
|
411
|
+
const springBlock = `\n /* Micro-Interaction Springs (160ms cubic-bezier) */\n button, [class*="btn"], .btn, [role="button"], .card, [class*="card"], .interactive-surface {\n transition: transform 160ms cubic-bezier(0.16, 1, 0.3, 1), box-shadow 160ms cubic-bezier(0.16, 1, 0.3, 1), filter 160ms cubic-bezier(0.16, 1, 0.3, 1);\n }\n .card:hover, [class*="card"]:hover {\n transform: translateY(-2px);\n box-shadow: 0 12px 30px -10px rgba(0, 0, 0, 0.3);\n }\n`;
|
|
412
|
+
if (content.includes('</style>')) {
|
|
413
|
+
content = content.replace('</style>', `${springBlock} </style>`);
|
|
414
|
+
fixes.push('Injected GPU-accelerated spring micro-interactions (160ms cubic-bezier(0.16, 1, 0.3, 1))');
|
|
415
|
+
} else if (resolvedPath.endsWith('.css') || !isHtml) {
|
|
416
|
+
content = content.trimEnd() + '\n' + springBlock;
|
|
417
|
+
fixes.push('Injected GPU-accelerated spring micro-interactions (160ms cubic-bezier(0.16, 1, 0.3, 1))');
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
// 5. RULE MD002: Reduced Motion Compliance
|
|
422
|
+
const cleanForMotion = getClean(content);
|
|
423
|
+
const hasAnimations = /animation:|transition:/i.test(cleanForMotion) && !/transition:\s*none/i.test(cleanForMotion);
|
|
424
|
+
const hasReducedMotion = /prefers-reduced-motion/i.test(cleanForMotion);
|
|
425
|
+
if (hasAnimations && !hasReducedMotion) {
|
|
426
|
+
const reducedMotionBlock = `\n @media (prefers-reduced-motion: reduce) {\n *, *::before, *::after {\n animation-duration: 0.01ms !important;\n animation-iteration-count: 1 !important;\n transition-duration: 0.01ms !important;\n }\n }\n`;
|
|
427
|
+
if (content.includes('</style>')) {
|
|
428
|
+
content = content.replace('</style>', `${reducedMotionBlock} </style>`);
|
|
429
|
+
fixes.push('Added prefers-reduced-motion accessibility gate (MD002)');
|
|
430
|
+
} else if (resolvedPath.endsWith('.css') || !isHtml) {
|
|
431
|
+
content = content.trimEnd() + '\n' + reducedMotionBlock;
|
|
432
|
+
fixes.push('Added prefers-reduced-motion accessibility gate (MD002)');
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
// 6. Anti-AI Tells: Em-Dash / En-Dash & HTML Entities Cleanup (MD201)
|
|
437
|
+
const emDashRegex = /\s*(?:[—–]|—|–|—|–|—|–)\s*/g;
|
|
438
|
+
const emDashMatches = content.match(emDashRegex);
|
|
439
|
+
if (emDashMatches && emDashMatches.length > 0) {
|
|
440
|
+
const count = emDashMatches.length;
|
|
441
|
+
content = content.replace(emDashRegex, ' - ');
|
|
442
|
+
fixes.push(`Cleaned ${count} AI-tell em-dash punctuation & entities`);
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
// 7. Typography Elevation (Generic Fonts -> Curated Archetype Pairings: Geist / Plus Jakarta Sans / JetBrains Mono)
|
|
446
|
+
let countTypo = 0;
|
|
447
|
+
const genericSansRegex = /font-family\s*:\s*(?:['"]?(?:Inter|Arial|Helvetica Neue|Helvetica|Roboto|Open Sans)['"]?|system-ui|-apple-system|BlinkMacSystemFont|['"]?Segoe UI['"]?)(?:\s*,\s*(?:sans-serif|system-ui|-apple-system|BlinkMacSystemFont|['"]?(?:Segoe UI|Roboto|Oxygen|Ubuntu|Cantarell|Open Sans|Helvetica Neue|Helvetica|Arial)['"]?|['"][^'"]+['"]|sans-serif))*\s*;?/gi;
|
|
448
|
+
if (genericSansRegex.test(content)) {
|
|
449
|
+
content = content.replace(genericSansRegex, () => {
|
|
450
|
+
countTypo++;
|
|
451
|
+
return "font-family: 'Geist', 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;";
|
|
452
|
+
});
|
|
453
|
+
}
|
|
454
|
+
const varSansRegex = /(--font-sans\s*:\s*)(?:['"]?(?:Inter|Arial|Helvetica Neue|Helvetica|Roboto|Open Sans)['"]?|system-ui|-apple-system|BlinkMacSystemFont|['"]?Segoe UI['"]?)[^;]*;/gi;
|
|
455
|
+
if (varSansRegex.test(content)) {
|
|
456
|
+
content = content.replace(varSansRegex, () => {
|
|
457
|
+
countTypo++;
|
|
458
|
+
return "--font-sans: 'Geist', 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;";
|
|
459
|
+
});
|
|
460
|
+
}
|
|
461
|
+
const genericMonoRegex = /font-family\s*:\s*(?:['"]?(?:Courier New|Courier|Consolas|Menlo|Monaco)['"]?|monospace|ui-monospace|SFMono-Regular)(?:\s*,\s*[^;}]*)*\s*;?/gi;
|
|
462
|
+
if (genericMonoRegex.test(content)) {
|
|
463
|
+
content = content.replace(genericMonoRegex, () => {
|
|
464
|
+
countTypo++;
|
|
465
|
+
return "font-family: 'JetBrains Mono', 'Geist Mono', ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;";
|
|
466
|
+
});
|
|
467
|
+
}
|
|
468
|
+
const varMonoRegex = /(--font-mono\s*:\s*)(?:['"]?(?:Courier New|Courier|Consolas|Menlo|Monaco)['"]?|monospace|ui-monospace|SFMono-Regular)[^;]*;/gi;
|
|
469
|
+
if (varMonoRegex.test(content)) {
|
|
470
|
+
content = content.replace(varMonoRegex, () => {
|
|
471
|
+
countTypo++;
|
|
472
|
+
return "--font-mono: 'JetBrains Mono', 'Geist Mono', ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;";
|
|
473
|
+
});
|
|
474
|
+
}
|
|
475
|
+
if (countTypo > 0) {
|
|
476
|
+
if (content.includes('</head>') && !content.includes('fonts.googleapis.com/css2?family=Geist')) {
|
|
477
|
+
const fontPreconnect = ` <link rel="preconnect" href="https://fonts.googleapis.com">\n <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>\n <link href="https://fonts.googleapis.com/css2?family=Geist+Mono:wght@400;500;600&family=Geist:wght@300;400;500;600;700&family=Plus+Jakarta+Sans:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500;600&display=swap" rel="stylesheet">\n `;
|
|
478
|
+
content = content.replace('</head>', `${fontPreconnect}</head>`);
|
|
479
|
+
} else if ((resolvedPath.endsWith('.css') || !isHtml) && !content.includes('fonts.googleapis.com')) {
|
|
480
|
+
const fontImport = `@import url('https://fonts.googleapis.com/css2?family=Geist+Mono:wght@400;500;600&family=Geist:wght@300;400;500;600;700&family=Plus+Jakarta+Sans:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500;600&display=swap');\n`;
|
|
481
|
+
content = fontImport + content;
|
|
482
|
+
}
|
|
483
|
+
fixes.push('Elevated generic typography to curated Archetype pairings (Geist / Plus Jakarta Sans / JetBrains Mono)');
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
// 8. Dynamic Bento Proportions (Asymmetric Visual Hierarchy)
|
|
487
|
+
let countBento = 0;
|
|
488
|
+
const gridContainerRegex = /(<(?:div|section|main|ul)\s+[^>]*\b(?:grid\b|bento-grid\b)[^>]*>[\s\S]*?)(<(?:div|article|section|li)\s+class=")([^"]*\bcard\b[^"]*)(")/i;
|
|
489
|
+
if (gridContainerRegex.test(content) && !/\bcol-span-/i.test(content)) {
|
|
490
|
+
content = content.replace(gridContainerRegex, (match, beforeCard, cardOpen, classNames, cardClose) => {
|
|
491
|
+
if (!classNames.includes('bento-featured') && !classNames.includes('col-span-')) {
|
|
492
|
+
countBento++;
|
|
493
|
+
return `${beforeCard}${cardOpen}${classNames} col-span-2 md:col-span-2 bento-featured${cardClose}`;
|
|
494
|
+
}
|
|
495
|
+
return match;
|
|
496
|
+
});
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
const hasBentoCss = /\.bento-featured\b|\.bento-grid\b/.test(getClean(content)) && content.includes('grid-column: span 2');
|
|
500
|
+
if (!hasBentoCss) {
|
|
501
|
+
const bentoCss = `\n /* Dynamic Bento Asymmetric Grid Proportions */\n @media (min-width: 768px) {\n .bento-grid > :first-child, .grid > .bento-featured, [class*="grid"] > .bento-featured { grid-column: span 2; }\n }\n`;
|
|
502
|
+
if (content.includes('</style>')) {
|
|
503
|
+
content = content.replace('</style>', `${bentoCss} </style>`);
|
|
504
|
+
countBento++;
|
|
505
|
+
} else if (resolvedPath.endsWith('.css') || !isHtml) {
|
|
506
|
+
content = content.trimEnd() + '\n' + bentoCss;
|
|
507
|
+
countBento++;
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
if (countBento > 0) {
|
|
511
|
+
fixes.push('Injected dynamic Bento grid proportions (asymmetric visual hierarchy & featured spans)');
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
// 9. RULE MD106: Container Optical Padding & Slider Boundary Clearance
|
|
515
|
+
let count106 = 0;
|
|
516
|
+
const sliderBlockRegex = /((?:[a-zA-Z0-9_\-\.\#\:\*\,\[\]\="'>\s]+)?(?:slider|progress|scrubber|pill-track)\s*\{)([^}]+)(\})/gi;
|
|
517
|
+
content = content.replace(sliderBlockRegex, (match, prefix, body, suffix) => {
|
|
518
|
+
const hasPillRadius = /border-radius\s*:\s*(?:var\(--radius-full\)|9999px|50%|[1-9]\d{1,}px)/i.test(body);
|
|
519
|
+
const hasVisibleBg = /background(?:-color)?\s*:\s*(?!none|transparent\b|rgba\(\s*0\s*,\s*0\s*,\s*0\s*,\s*0\s*\))/i.test(body);
|
|
520
|
+
const hasMinHeight = /(?:min-)?height\s*:\s*(?:[3-9]\dpx|44px)/i.test(body);
|
|
521
|
+
const hasPadding = /padding(?:-inline|-left|-right)?\s*:\s*(?:[^;}]*?(?:[8-9]px|[1-9]\d+px|var\(--padding))/i.test(body);
|
|
522
|
+
if (hasPillRadius && hasVisibleBg && hasMinHeight && !hasPadding) {
|
|
523
|
+
count106++;
|
|
524
|
+
const updatedBody = body.trimEnd() + ' padding: 0 12px;';
|
|
525
|
+
return prefix + updatedBody + ' ' + suffix;
|
|
526
|
+
}
|
|
527
|
+
return match;
|
|
528
|
+
});
|
|
529
|
+
|
|
530
|
+
// Decouple 44px hit-target with transparent touch halo helper
|
|
531
|
+
if (!content.includes('.touch-halo') && !content.includes('.hit-target-decoupled')) {
|
|
532
|
+
const haloCss = `\n /* MD106 Decoupled Touch Halo */\n .touch-halo {\n min-height: 44px;\n min-width: 44px;\n display: inline-flex;\n align-items: center;\n justify-content: center;\n background: transparent !important;\n padding: 0 12px;\n }\n`;
|
|
533
|
+
if (content.includes('</style>')) {
|
|
534
|
+
content = content.replace('</style>', `${haloCss} </style>`);
|
|
535
|
+
count106++;
|
|
536
|
+
} else if (resolvedPath.endsWith('.css') || !isHtml) {
|
|
537
|
+
content = content.trimEnd() + '\n' + haloCss;
|
|
538
|
+
count106++;
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
if (count106 > 0) {
|
|
542
|
+
fixes.push('Decoupled 44px touch hit-target with transparent halo and >=12px boundary clearance (MD106)');
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
// 10. RULE MD102: Perceptual Color Gamut Normalizer (linear-gradient in oklch)
|
|
546
|
+
let count102 = 0;
|
|
547
|
+
const gradientDirectionRegex = /linear-gradient\(\s*(?!in\s+(?:oklch|oklab)\b)(?:(-?\d+(?:\.\d+)?(?:deg|turn|rad|grad)|to\s+[a-zA-Z\s]+),)?\s*/gi;
|
|
548
|
+
content = content.replace(gradientDirectionRegex, (m, direction) => {
|
|
549
|
+
count102++;
|
|
550
|
+
if (direction) {
|
|
551
|
+
return `linear-gradient(in oklch ${direction.trim()}, `;
|
|
552
|
+
}
|
|
553
|
+
return 'linear-gradient(in oklch, ';
|
|
554
|
+
});
|
|
555
|
+
content = content.replace(/radial-gradient\(\s*(?!in\s+(?:oklch|oklab)\b)/gi, () => {
|
|
556
|
+
count102++;
|
|
557
|
+
return 'radial-gradient(in oklch, ';
|
|
558
|
+
});
|
|
559
|
+
content = content.replace(/conic-gradient\(\s*(?!in\s+(?:oklch|oklab)\b)/gi, () => {
|
|
560
|
+
count102++;
|
|
561
|
+
return 'conic-gradient(in oklch, ';
|
|
562
|
+
});
|
|
563
|
+
if (count102 > 0) {
|
|
564
|
+
fixes.push('Normalized color gamut to perceptual OKLCH interpolation space (MD102)');
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
// 11. RULE MD103: Concentric Radius Math Helper
|
|
568
|
+
let count103 = 0;
|
|
569
|
+
const hasOuterRadius = /border-radius:\s*\d+px/i.test(content);
|
|
570
|
+
const hasInnerConcentric = /max\(\s*0px/i.test(content) || /calc\(infinity/i.test(content) || /--corner-r/i.test(content);
|
|
571
|
+
if (hasOuterRadius && !hasInnerConcentric) {
|
|
572
|
+
const concentricRule = `\n /* MD103 Safe Concentric Radius Formula */\n :root { --radius-inner: max(0px, var(--radius-outer, 16px) - 1px - 8px); }\n`;
|
|
573
|
+
if (content.includes('</style>')) {
|
|
574
|
+
content = content.replace('</style>', `${concentricRule} </style>`);
|
|
575
|
+
count103++;
|
|
576
|
+
} else if (resolvedPath.endsWith('.css') || !isHtml) {
|
|
577
|
+
content = content.trimEnd() + '\n' + concentricRule;
|
|
578
|
+
count103++;
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
if (count103 > 0) {
|
|
582
|
+
fixes.push('Injected safe concentric radius formula max(0px, r_outer - border_w - pad) (MD103)');
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
fs.writeFileSync(resolvedPath, content, 'utf8');
|
|
586
|
+
|
|
587
|
+
let afterQ = beforeQ;
|
|
588
|
+
let isPassed = true;
|
|
589
|
+
try {
|
|
590
|
+
const afterRes = spawnSync(process.execPath, [linterScript, resolvedPath, '--json'], { encoding: 'utf8' });
|
|
591
|
+
const parsed = JSON.parse(afterRes.stdout);
|
|
592
|
+
afterQ = parsed.qScore !== undefined ? parsed.qScore : beforeQ;
|
|
593
|
+
isPassed = parsed.passed !== undefined ? parsed.passed : (afterQ >= 75);
|
|
594
|
+
} catch (e) {}
|
|
595
|
+
|
|
596
|
+
console.log(`\n${ANSI_GREEN}${ANSI_BOLD}[POLISH COMPLETED]${ANSI_RESET} ${fixes.length} issues automatically repaired in ${ANSI_CYAN}${path.basename(resolvedPath)}${ANSI_RESET}`);
|
|
597
|
+
fixes.forEach(f => console.log(` ${ANSI_GREEN}Fixed:${ANSI_RESET} ${f}`));
|
|
598
|
+
console.log(`${ANSI_BOLD}Q-Score:${ANSI_RESET} ${beforeQ.toFixed(1)} -> ${ANSI_GREEN}${ANSI_BOLD}${afterQ.toFixed(1)}${ANSI_RESET} [${isPassed ? ANSI_GREEN + 'PASS' + ANSI_RESET : ANSI_YELLOW + 'WARNING' + ANSI_RESET}]\n`);
|
|
599
|
+
process.exit(0);
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
case 'bolder': {
|
|
603
|
+
const targetFile = args[1];
|
|
604
|
+
if (!targetFile || targetFile === '--help' || targetFile === '-h') {
|
|
605
|
+
console.log(`
|
|
606
|
+
${ANSI_BOLD}ME-DESIGN Bolder Modifier${ANSI_RESET}
|
|
607
|
+
${ANSI_GRAY}Elevate visual density, typography weights, and color saturation${ANSI_RESET}
|
|
608
|
+
|
|
609
|
+
${ANSI_BOLD}Usage:${ANSI_RESET}
|
|
610
|
+
medesign bolder <file>
|
|
611
|
+
mebolder <file>
|
|
612
|
+
|
|
613
|
+
${ANSI_BOLD}Modifications:${ANSI_RESET}
|
|
614
|
+
- Elevates font weights: normal/400 -> 600, medium/500 -> 700
|
|
615
|
+
- Deepens subtle translucent borders (border-white/10 -> border-white/20)
|
|
616
|
+
- Boosts OKLCH chroma by ~25%
|
|
617
|
+
`);
|
|
618
|
+
process.exit(targetFile === '--help' || targetFile === '-h' ? 0 : 1);
|
|
619
|
+
}
|
|
620
|
+
const resolvedPath = path.resolve(process.cwd(), targetFile);
|
|
621
|
+
if (!fs.existsSync(resolvedPath)) {
|
|
622
|
+
console.error(`${ANSI_RED}Error:${ANSI_RESET} File not found: ${resolvedPath}`);
|
|
623
|
+
process.exit(1);
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
let content = fs.readFileSync(resolvedPath, 'utf8');
|
|
627
|
+
let fontCount = 0;
|
|
628
|
+
let borderCount = 0;
|
|
629
|
+
let accentCount = 0;
|
|
630
|
+
|
|
631
|
+
// 1. Single-pass atomic elevation of font weights (prevents cascading replacement)
|
|
632
|
+
const bolderFontMap = {
|
|
633
|
+
'font-normal': 'font-medium',
|
|
634
|
+
'font-medium': 'font-semibold',
|
|
635
|
+
'font-semibold': 'font-bold'
|
|
636
|
+
};
|
|
637
|
+
content = content.replace(/\b(font-normal|font-medium|font-semibold)\b/g, (m) => {
|
|
638
|
+
fontCount++;
|
|
639
|
+
return bolderFontMap[m] || m;
|
|
640
|
+
});
|
|
641
|
+
|
|
642
|
+
content = content.replace(/font-weight\s*:\s*(400|500|normal)\b/gi, (match, val) => {
|
|
643
|
+
fontCount++;
|
|
644
|
+
if (val === '400' || val.toLowerCase() === 'normal') return 'font-weight: 600';
|
|
645
|
+
if (val === '500') return 'font-weight: 700';
|
|
646
|
+
return match;
|
|
647
|
+
});
|
|
648
|
+
|
|
649
|
+
// 2. Deepen border contrast & opacity (single pass)
|
|
650
|
+
const bolderBorderMap = {
|
|
651
|
+
'border-white/10': 'border-white/20',
|
|
652
|
+
'border-white/5': 'border-white/15',
|
|
653
|
+
'border-neutral-200': 'border-neutral-400',
|
|
654
|
+
'border-gray-200': 'border-gray-400'
|
|
655
|
+
};
|
|
656
|
+
content = content.replace(/\b(border-white\/10|border-white\/5|border-neutral-200|border-gray-200)\b/g, (m) => {
|
|
657
|
+
borderCount++;
|
|
658
|
+
return bolderBorderMap[m] || m;
|
|
659
|
+
});
|
|
660
|
+
|
|
661
|
+
content = content.replace(/rgba\(\s*255\s*,\s*255\s*,\s*255\s*,\s*0\.0[5-8]\s*\)/gi, () => { borderCount++; return 'rgba(255, 255, 255, 0.18)'; });
|
|
662
|
+
content = content.replace(/rgba\(\s*0\s*,\s*0\s*,\s*0\s*,\s*0\.0[5-8]\s*\)/gi, () => { borderCount++; return 'rgba(0, 0, 0, 0.18)'; });
|
|
663
|
+
|
|
664
|
+
// 3. Boost Accent Saturation & Vibrancy
|
|
665
|
+
// OKLCH chroma boost (increase C by ~25% for chromatic colors C >= 0.04)
|
|
666
|
+
content = content.replace(/oklch\(\s*([\d\.]+)\s+([\d\.]+)(\s+[\d\.]+(?:\s*(?:\/|\s)\s*[\d\.\%]+)?)\s*\)/gi, (match, l, c, rest) => {
|
|
667
|
+
const cVal = parseFloat(c);
|
|
668
|
+
if (cVal >= 0.04) {
|
|
669
|
+
accentCount++;
|
|
670
|
+
const boostedC = Math.min(0.35, parseFloat((cVal * 1.25).toFixed(3)));
|
|
671
|
+
return `oklch(${l} ${boostedC}${rest})`;
|
|
672
|
+
}
|
|
673
|
+
return match;
|
|
674
|
+
});
|
|
675
|
+
|
|
676
|
+
// HSL saturation boost (+15% saturation)
|
|
677
|
+
content = content.replace(/hsl\(\s*([\d\.]+)\s*,\s*([\d\.]+)%\s*,\s*([\d\.]+)%\s*\)/gi, (match, h, s, l) => {
|
|
678
|
+
const sVal = parseFloat(s);
|
|
679
|
+
if (sVal > 0 && sVal <= 85) {
|
|
680
|
+
accentCount++;
|
|
681
|
+
const boostedS = Math.min(100, Math.round(sVal + 15));
|
|
682
|
+
return `hsl(${h}, ${boostedS}%, ${l}%)`;
|
|
683
|
+
}
|
|
684
|
+
return match;
|
|
685
|
+
});
|
|
686
|
+
|
|
687
|
+
// Tailwind accent vibrancy elevation
|
|
688
|
+
const bolderTailwindMap = {
|
|
689
|
+
'saturate-50': 'saturate-100',
|
|
690
|
+
'saturate-100': 'saturate-150'
|
|
691
|
+
};
|
|
692
|
+
content = content.replace(/\b(saturate-50|saturate-100)\b/g, (m) => {
|
|
693
|
+
accentCount++;
|
|
694
|
+
return bolderTailwindMap[m] || m;
|
|
695
|
+
});
|
|
696
|
+
content = content.replace(/\b(bg|text|border)-(blue|cyan|indigo|emerald|sky|violet|amber|rose|teal)-500\b/g, (match, prop, col) => {
|
|
697
|
+
accentCount++;
|
|
698
|
+
return `${prop}-${col}-600`;
|
|
699
|
+
});
|
|
700
|
+
|
|
701
|
+
fs.writeFileSync(resolvedPath, content, 'utf8');
|
|
702
|
+
|
|
703
|
+
console.log(`\n${ANSI_GREEN}${ANSI_BOLD}[BOLDER APPLIED]${ANSI_RESET} Visual density boosted in ${ANSI_CYAN}${path.basename(resolvedPath)}${ANSI_RESET}`);
|
|
704
|
+
console.log(` ${ANSI_BOLD}Font Weights:${ANSI_RESET} ${fontCount} font weight declarations elevated`);
|
|
705
|
+
console.log(` ${ANSI_BOLD}Border Contrast:${ANSI_RESET} ${borderCount} border treatments deepened`);
|
|
706
|
+
console.log(` ${ANSI_BOLD}Accents:${ANSI_RESET} ${accentCount} accent saturation & vibrancy rules boosted\n`);
|
|
707
|
+
process.exit(0);
|
|
708
|
+
}
|
|
709
|
+
|
|
710
|
+
case 'quiet': {
|
|
711
|
+
const targetFile = args[1];
|
|
712
|
+
if (!targetFile || targetFile === '--help' || targetFile === '-h') {
|
|
713
|
+
console.log(`
|
|
714
|
+
${ANSI_BOLD}ME-DESIGN Quiet Modifier${ANSI_RESET}
|
|
715
|
+
${ANSI_GRAY}Soften visual density, typography weights, and border contrast${ANSI_RESET}
|
|
716
|
+
|
|
717
|
+
${ANSI_BOLD}Usage:${ANSI_RESET}
|
|
718
|
+
medesign quiet <file>
|
|
719
|
+
mequiet <file>
|
|
720
|
+
|
|
721
|
+
${ANSI_BOLD}Modifications:${ANSI_RESET}
|
|
722
|
+
- Softens font weights: bold/700 -> 500, semibold/600 -> 500
|
|
723
|
+
- Reduces borders to hairline borders
|
|
724
|
+
- Softens OKLCH chroma by ~30%
|
|
725
|
+
`);
|
|
726
|
+
process.exit(targetFile === '--help' || targetFile === '-h' ? 0 : 1);
|
|
727
|
+
}
|
|
728
|
+
const resolvedPath = path.resolve(process.cwd(), targetFile);
|
|
729
|
+
if (!fs.existsSync(resolvedPath)) {
|
|
730
|
+
console.error(`${ANSI_RED}Error:${ANSI_RESET} File not found: ${resolvedPath}`);
|
|
731
|
+
process.exit(1);
|
|
732
|
+
}
|
|
733
|
+
|
|
734
|
+
let content = fs.readFileSync(resolvedPath, 'utf8');
|
|
735
|
+
let fontCount = 0;
|
|
736
|
+
let borderCount = 0;
|
|
737
|
+
let toneCount = 0;
|
|
738
|
+
|
|
739
|
+
// 1. Single-pass atomic softening of font weights (prevents cascading replacement)
|
|
740
|
+
const quietFontMap = {
|
|
741
|
+
'font-extrabold': 'font-bold',
|
|
742
|
+
'font-bold': 'font-semibold',
|
|
743
|
+
'font-semibold': 'font-medium',
|
|
744
|
+
'font-medium': 'font-normal'
|
|
745
|
+
};
|
|
746
|
+
content = content.replace(/\b(font-extrabold|font-bold|font-semibold|font-medium)\b/g, (m) => {
|
|
747
|
+
fontCount++;
|
|
748
|
+
return quietFontMap[m] || m;
|
|
749
|
+
});
|
|
750
|
+
|
|
751
|
+
content = content.replace(/font-weight\s*:\s*(700|600|bold)\b/gi, (match, val) => {
|
|
752
|
+
fontCount++;
|
|
753
|
+
if (val === '700' || val.toLowerCase() === 'bold') return 'font-weight: 500';
|
|
754
|
+
if (val === '600') return 'font-weight: 400';
|
|
755
|
+
return match;
|
|
756
|
+
});
|
|
757
|
+
|
|
758
|
+
// 2. Soften borders to minimalist hairlines (single pass)
|
|
759
|
+
const quietBorderMap = {
|
|
760
|
+
'border-2': 'border',
|
|
761
|
+
'border-white/20': 'border-white/10',
|
|
762
|
+
'border-white/15': 'border-white/8',
|
|
763
|
+
'border-neutral-400': 'border-neutral-200',
|
|
764
|
+
'border-gray-400': 'border-gray-200'
|
|
765
|
+
};
|
|
766
|
+
content = content.replace(/\b(border-2|border-white\/20|border-white\/15|border-neutral-400|border-gray-400)\b/g, (m) => {
|
|
767
|
+
borderCount++;
|
|
768
|
+
return quietBorderMap[m] || m;
|
|
769
|
+
});
|
|
770
|
+
|
|
771
|
+
content = content.replace(/rgba\(\s*255\s*,\s*255\s*,\s*255\s*,\s*0\.1[5-8]\s*\)/gi, () => { borderCount++; return 'rgba(255, 255, 255, 0.08)'; });
|
|
772
|
+
content = content.replace(/rgba\(\s*0\s*,\s*0\s*,\s*0\s*,\s*0\.1[5-8]\s*\)/gi, () => { borderCount++; return 'rgba(0, 0, 0, 0.08)'; });
|
|
773
|
+
|
|
774
|
+
// 3. Shift Tone to Minimalist (Mute chroma & saturation)
|
|
775
|
+
// OKLCH chroma reduction (decrease C by ~30% for chromatic colors C >= 0.04)
|
|
776
|
+
content = content.replace(/oklch\(\s*([\d\.]+)\s+([\d\.]+)(\s+[\d\.]+(?:\s*(?:\/|\s)\s*[\d\.\%]+)?)\s*\)/gi, (match, l, c, rest) => {
|
|
777
|
+
const cVal = parseFloat(c);
|
|
778
|
+
if (cVal >= 0.04) {
|
|
779
|
+
toneCount++;
|
|
780
|
+
const softenedC = Math.max(0.01, parseFloat((cVal * 0.70).toFixed(3)));
|
|
781
|
+
return `oklch(${l} ${softenedC}${rest})`;
|
|
782
|
+
}
|
|
783
|
+
return match;
|
|
784
|
+
});
|
|
785
|
+
|
|
786
|
+
// HSL saturation reduction (-25% saturation)
|
|
787
|
+
content = content.replace(/hsl\(\s*([\d\.]+)\s*,\s*([\d\.]+)%\s*,\s*([\d\.]+)%\s*\)/gi, (match, h, s, l) => {
|
|
788
|
+
const sVal = parseFloat(s);
|
|
789
|
+
if (sVal > 15) {
|
|
790
|
+
toneCount++;
|
|
791
|
+
const softenedS = Math.max(10, Math.round(sVal - 25));
|
|
792
|
+
return `hsl(${h}, ${softenedS}%, ${l}%)`;
|
|
793
|
+
}
|
|
794
|
+
return match;
|
|
795
|
+
});
|
|
796
|
+
|
|
797
|
+
// Tailwind accent softening
|
|
798
|
+
const quietTailwindMap = {
|
|
799
|
+
'saturate-150': 'saturate-100',
|
|
800
|
+
'saturate-100': 'saturate-50'
|
|
801
|
+
};
|
|
802
|
+
content = content.replace(/\b(saturate-150|saturate-100)\b/g, (m) => {
|
|
803
|
+
toneCount++;
|
|
804
|
+
return quietTailwindMap[m] || m;
|
|
805
|
+
});
|
|
806
|
+
content = content.replace(/\b(bg|text|border)-(blue|cyan|indigo|emerald|sky|violet|amber|rose|teal)-600\b/g, (match, prop, col) => {
|
|
807
|
+
toneCount++;
|
|
808
|
+
return `${prop}-${col}-500`;
|
|
809
|
+
});
|
|
810
|
+
|
|
811
|
+
fs.writeFileSync(resolvedPath, content, 'utf8');
|
|
812
|
+
|
|
813
|
+
console.log(`\n${ANSI_GREEN}${ANSI_BOLD}[QUIET APPLIED]${ANSI_RESET} Visual density softened in ${ANSI_CYAN}${path.basename(resolvedPath)}${ANSI_RESET}`);
|
|
814
|
+
console.log(` ${ANSI_BOLD}Font Weights:${ANSI_RESET} ${fontCount} font weight declarations softened`);
|
|
815
|
+
console.log(` ${ANSI_BOLD}Borders:${ANSI_RESET} ${borderCount} border treatments converted to minimalist hairlines`);
|
|
816
|
+
console.log(` ${ANSI_BOLD}Tone:${ANSI_RESET} ${toneCount} color tone declarations softened to minimalist palette\n`);
|
|
817
|
+
process.exit(0);
|
|
818
|
+
}
|
|
819
|
+
|
|
820
|
+
case 'lint': {
|
|
821
|
+
const linterScript = path.join(rootDir, 'tests', 'linter.js');
|
|
822
|
+
const child = spawnSync(process.execPath, [linterScript, ...args.slice(1)], {
|
|
823
|
+
stdio: 'inherit',
|
|
824
|
+
cwd: process.cwd()
|
|
825
|
+
});
|
|
826
|
+
process.exit(child.status ?? 0);
|
|
827
|
+
}
|
|
828
|
+
|
|
829
|
+
case 'audit': {
|
|
830
|
+
const auditScript = path.join(rootDir, 'tests', 'browser-audit.js');
|
|
831
|
+
const child = spawnSync(process.execPath, [auditScript, ...args.slice(1)], {
|
|
832
|
+
stdio: 'inherit',
|
|
833
|
+
cwd: process.cwd()
|
|
834
|
+
});
|
|
835
|
+
process.exit(child.status ?? 0);
|
|
836
|
+
}
|
|
837
|
+
|
|
838
|
+
case 'snapshot': {
|
|
839
|
+
const snapshotScript = path.join(rootDir, 'tests', 'snapshot.js');
|
|
840
|
+
const child = spawnSync(process.execPath, [snapshotScript, ...args.slice(1)], {
|
|
841
|
+
stdio: 'inherit',
|
|
842
|
+
cwd: process.cwd()
|
|
843
|
+
});
|
|
844
|
+
process.exit(child.status ?? 0);
|
|
845
|
+
}
|
|
846
|
+
|
|
847
|
+
case 'tokens': {
|
|
848
|
+
const exportScript = path.join(rootDir, 'scripts', 'export-tokens.js');
|
|
849
|
+
const exportArgs = args.slice(1).filter(a => a !== 'export');
|
|
850
|
+
const child = spawnSync(process.execPath, [exportScript, ...exportArgs], {
|
|
851
|
+
stdio: 'inherit',
|
|
852
|
+
cwd: process.cwd()
|
|
853
|
+
});
|
|
854
|
+
process.exit(child.status ?? 0);
|
|
855
|
+
}
|
|
856
|
+
|
|
857
|
+
case 'presets': {
|
|
858
|
+
const sub = args[1] || 'list';
|
|
859
|
+
if (sub === '--help' || sub === '-h' || sub === 'help') {
|
|
860
|
+
console.log(`
|
|
861
|
+
${ANSI_BOLD}ME-DESIGN Presets Inspector${ANSI_RESET}
|
|
862
|
+
${ANSI_GRAY}Inspect available design system presets${ANSI_RESET}
|
|
863
|
+
|
|
864
|
+
${ANSI_BOLD}Usage:${ANSI_RESET}
|
|
865
|
+
medesign presets list
|
|
866
|
+
medesign presets get <preset-name>
|
|
867
|
+
`);
|
|
868
|
+
process.exit(0);
|
|
869
|
+
}
|
|
870
|
+
const presetsDir = path.join(rootDir, 'presets');
|
|
871
|
+
if (sub === 'list') {
|
|
872
|
+
console.log(`\n${ANSI_BOLD}AVAILABLE ME-DESIGN PRESETS:${ANSI_RESET}\n`);
|
|
873
|
+
const folders = fs.readdirSync(presetsDir, { withFileTypes: true })
|
|
874
|
+
.filter(d => d.isDirectory())
|
|
875
|
+
.map(d => d.name);
|
|
876
|
+
folders.forEach(f => {
|
|
877
|
+
const pJson = path.join(presetsDir, f, 'preset.json');
|
|
878
|
+
if (fs.existsSync(pJson)) {
|
|
879
|
+
const data = JSON.parse(fs.readFileSync(pJson, 'utf8'));
|
|
880
|
+
console.log(` ${ANSI_CYAN}${data.id.padEnd(10)}${ANSI_RESET} ${data.name}`);
|
|
881
|
+
console.log(` ${ANSI_GRAY}${data.archetype}${ANSI_RESET}`);
|
|
882
|
+
}
|
|
883
|
+
});
|
|
884
|
+
console.log('');
|
|
885
|
+
} else if (sub === 'get') {
|
|
886
|
+
const name = args[2];
|
|
887
|
+
if (!name) {
|
|
888
|
+
console.error('Error: Please specify preset name (e.g. medesign presets get apple)');
|
|
889
|
+
process.exit(1);
|
|
890
|
+
}
|
|
891
|
+
const pJson = path.join(presetsDir, name.toLowerCase(), 'preset.json');
|
|
892
|
+
if (!fs.existsSync(pJson)) {
|
|
893
|
+
console.error(`Error: Preset '${name}' not found.`);
|
|
894
|
+
process.exit(1);
|
|
895
|
+
}
|
|
896
|
+
console.log(fs.readFileSync(pJson, 'utf8'));
|
|
897
|
+
}
|
|
898
|
+
break;
|
|
899
|
+
}
|
|
900
|
+
|
|
901
|
+
case 'test': {
|
|
902
|
+
if (args[1] === '--help' || args[1] === '-h') {
|
|
903
|
+
console.log(`
|
|
904
|
+
${ANSI_BOLD}ME-DESIGN Test Runner${ANSI_RESET}
|
|
905
|
+
${ANSI_GRAY}Run deterministic AST & semantic rule test suites${ANSI_RESET}
|
|
906
|
+
|
|
907
|
+
${ANSI_BOLD}Usage:${ANSI_RESET}
|
|
908
|
+
medesign test
|
|
909
|
+
medesign test --browser
|
|
910
|
+
`);
|
|
911
|
+
process.exit(0);
|
|
912
|
+
}
|
|
913
|
+
const runnerScript = path.join(rootDir, 'tests', 'runner.js');
|
|
914
|
+
const child = spawnSync(process.execPath, [runnerScript, ...args.slice(1)], {
|
|
915
|
+
stdio: 'inherit',
|
|
916
|
+
cwd: process.cwd()
|
|
917
|
+
});
|
|
918
|
+
process.exit(child.status ?? 0);
|
|
919
|
+
}
|
|
920
|
+
|
|
921
|
+
case 'doctor': {
|
|
922
|
+
if (args[1] === '--help' || args[1] === '-h') {
|
|
923
|
+
console.log(`
|
|
924
|
+
${ANSI_BOLD}ME-DESIGN Environment Doctor${ANSI_RESET}
|
|
925
|
+
${ANSI_GRAY}Verify local environment, Node.js, and Chrome/CDP availability${ANSI_RESET}
|
|
926
|
+
|
|
927
|
+
${ANSI_BOLD}Usage:${ANSI_RESET}
|
|
928
|
+
medesign doctor
|
|
929
|
+
`);
|
|
930
|
+
process.exit(0);
|
|
931
|
+
}
|
|
932
|
+
console.log(`\n${ANSI_BOLD}ME-DESIGN System Health & Environment Doctor${ANSI_RESET}`);
|
|
933
|
+
console.log(`${ANSI_GRAY}────────────────────────────────────────${ANSI_RESET}\n`);
|
|
934
|
+
|
|
935
|
+
// 1. Node.js Version Check
|
|
936
|
+
const nodeVer = process.version;
|
|
937
|
+
const major = parseInt(nodeVer.slice(1).split('.')[0], 10);
|
|
938
|
+
const nodeOk = major >= 18;
|
|
939
|
+
console.log(`Node.js Runtime: ${nodeOk ? ANSI_GREEN + nodeVer + ' (Supported)' : ANSI_RED + nodeVer + ' (Requires >= 18.0.0)'}${ANSI_RESET}`);
|
|
940
|
+
|
|
941
|
+
const chromeCandidates = [
|
|
942
|
+
process.env.CHROME_PATH,
|
|
943
|
+
process.env.CHROME_BIN,
|
|
944
|
+
'C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe',
|
|
945
|
+
'C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe',
|
|
946
|
+
'C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe',
|
|
947
|
+
path.join(process.env.LOCALAPPDATA || '', 'ms-playwright', 'chromium-1248', 'chrome-win64', 'chrome.exe'),
|
|
948
|
+
'/usr/bin/google-chrome',
|
|
949
|
+
'/usr/bin/google-chrome-stable',
|
|
950
|
+
'/usr/bin/chromium',
|
|
951
|
+
'/usr/bin/chromium-browser',
|
|
952
|
+
'/snap/bin/chromium',
|
|
953
|
+
'/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
|
|
954
|
+
'/Applications/Chromium.app/Contents/MacOS/Chromium'
|
|
955
|
+
].filter(Boolean);
|
|
956
|
+
|
|
957
|
+
let foundChrome = null;
|
|
958
|
+
for (const c of chromeCandidates) {
|
|
959
|
+
if (fs.existsSync(c)) {
|
|
960
|
+
foundChrome = c;
|
|
961
|
+
break;
|
|
962
|
+
}
|
|
963
|
+
}
|
|
964
|
+
console.log(`Headless Browser: ${foundChrome ? ANSI_GREEN + 'Found (' + path.basename(foundChrome) + ')' : ANSI_YELLOW + 'Not found in default paths'}${ANSI_RESET}`);
|
|
965
|
+
if (foundChrome) {
|
|
966
|
+
console.log(` ${ANSI_GRAY}${foundChrome}${ANSI_RESET}`);
|
|
967
|
+
}
|
|
968
|
+
|
|
969
|
+
// 3. Presets Check
|
|
970
|
+
const presetsDir = path.join(rootDir, 'presets');
|
|
971
|
+
const presets = fs.readdirSync(presetsDir, { withFileTypes: true })
|
|
972
|
+
.filter(d => d.isDirectory() && fs.existsSync(path.join(presetsDir, d.name, 'preset.json')));
|
|
973
|
+
console.log(`Installed Presets: ${ANSI_GREEN}${presets.length} valid presets (${presets.map(p => p.name).join(', ')})${ANSI_RESET}`);
|
|
974
|
+
|
|
975
|
+
// 4. Test Suite Fixtures
|
|
976
|
+
const fixturesDir = path.join(rootDir, 'tests', 'fixtures');
|
|
977
|
+
const validCount = fs.existsSync(path.join(fixturesDir, 'valid')) ? fs.readdirSync(path.join(fixturesDir, 'valid')).length : 0;
|
|
978
|
+
const invalidCount = fs.existsSync(path.join(fixturesDir, 'invalid')) ? fs.readdirSync(path.join(fixturesDir, 'invalid')).length : 0;
|
|
979
|
+
console.log(`Test Fixtures: ${ANSI_GREEN}${validCount} valid, ${invalidCount} invalid test fixtures${ANSI_RESET}\n`);
|
|
980
|
+
|
|
981
|
+
console.log(`${ANSI_GRAY}────────────────────────────────────────${ANSI_RESET}`);
|
|
982
|
+
console.log(`${ANSI_GREEN}${ANSI_BOLD}STATUS: ALL SYSTEMS OPERATIONAL${ANSI_RESET}\n`);
|
|
983
|
+
break;
|
|
984
|
+
}
|
|
985
|
+
|
|
986
|
+
case 'help':
|
|
987
|
+
case '--help':
|
|
988
|
+
case '-h':
|
|
989
|
+
default:
|
|
990
|
+
printHelp();
|
|
991
|
+
break;
|
|
992
|
+
}
|