@appdirect/design-system 0.0.0-stage → 0.0.2
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 +12 -2
- package/dist/Buttons/ActionIcon.tsx +37 -0
- package/dist/Buttons/Button.module.css +5 -0
- package/dist/Buttons/Button.tsx +124 -0
- package/dist/Buttons/CloseButton.tsx +83 -0
- package/dist/Buttons/index.ts +20 -0
- package/dist/Combobox/AutocompleteClearable.tsx +128 -0
- package/dist/Combobox/Combobox.tsx +37 -0
- package/dist/Combobox/Multiselect.tsx +158 -0
- package/dist/Combobox/SearchableSelect.tsx +131 -0
- package/dist/Combobox/Select.tsx +154 -0
- package/dist/Combobox/index.ts +20 -0
- package/dist/ComplexComponents/DashboardWidget/DashboardWidget.tsx +313 -0
- package/dist/ComplexComponents/DashboardWidget/index.ts +2 -0
- package/dist/ComplexComponents/DataTable/CustomBottomToolbar/index.tsx +177 -0
- package/dist/ComplexComponents/DataTable/CustomBottomToolbar/utils.ts +35 -0
- package/dist/ComplexComponents/DataTable/CustomToolbarAlertBannerContent/index.tsx +74 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/DateRangeSelectorFilter/index.tsx +358 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/FilterChip.tsx +48 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/FilterSystem/DateRangeFilter.tsx +26 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/FilterSystem/FilterRenderer.tsx +71 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/FilterSystem/FilterSystem.tsx +158 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/FilterSystem/MultiSelectFilter.tsx +79 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/FilterSystem/SingleSelectFilter.tsx +65 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/FilterSystem/index.ts +70 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/FilterSystem/types.ts +140 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/ResultCount/index.tsx +76 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/SearchFilter.tsx +73 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/SelectFilter.tsx +50 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/index.tsx +788 -0
- package/dist/ComplexComponents/DataTable/DataTable.tsx +582 -0
- package/dist/ComplexComponents/DataTable/ErrorOverlay/index.tsx +29 -0
- package/dist/ComplexComponents/DataTable/SortableHeaderCell/index.tsx +57 -0
- package/dist/ComplexComponents/DataTable/index.ts +2 -0
- package/dist/ComplexComponents/DataTable/translations/en.ts +115 -0
- package/dist/ComplexComponents/DataTable/translations/index.ts +23 -0
- package/dist/ComplexComponents/KeyInsight/KeyInsights.tsx +221 -0
- package/dist/ComplexComponents/KeyInsight/index.ts +2 -0
- package/dist/ComplexComponents/NameValue/NameValue.tsx +175 -0
- package/dist/ComplexComponents/NameValue/NameValueItem.tsx +100 -0
- package/dist/ComplexComponents/NameValue/index.ts +4 -0
- package/dist/ComplexComponents/PageContentHeader/DescriptionBlock.tsx +65 -0
- package/dist/ComplexComponents/PageContentHeader/PageContentHeader.tsx +383 -0
- package/dist/ComplexComponents/PageContentHeader/index.ts +4 -0
- package/dist/ComplexComponents/Utilities/CopyButton.tsx +82 -0
- package/dist/ComplexComponents/Utilities/index.ts +2 -0
- package/dist/DataDisplay/Alert.tsx +130 -0
- package/dist/DataDisplay/Avatar.tsx +216 -0
- package/dist/DataDisplay/Badge.tsx +119 -0
- package/dist/DataDisplay/Card.module.css +26 -0
- package/dist/DataDisplay/Card.tsx +163 -0
- package/dist/DataDisplay/Chip.tsx +66 -0
- package/dist/DataDisplay/Indicator.tsx +122 -0
- package/dist/DataDisplay/List.tsx +90 -0
- package/dist/DataDisplay/Pill.tsx +125 -0
- package/dist/DataDisplay/Progress.tsx +77 -0
- package/dist/DataDisplay/Table.tsx +57 -0
- package/dist/DataDisplay/ThemeIcon.tsx +67 -0
- package/dist/DataDisplay/index.ts +41 -0
- package/dist/Inputs/Checkbox.tsx +94 -0
- package/dist/Inputs/ColorInput.tsx +124 -0
- package/dist/Inputs/DropZone.tsx +78 -0
- package/dist/Inputs/FileInput.tsx +120 -0
- package/dist/Inputs/NumberInput.tsx +125 -0
- package/dist/Inputs/Radio.tsx +86 -0
- package/dist/Inputs/RadioGroup.tsx +90 -0
- package/dist/Inputs/SegmentedControl.tsx +64 -0
- package/dist/Inputs/Slider.tsx +69 -0
- package/dist/Inputs/Switch.tsx +67 -0
- package/dist/Inputs/TextArea.tsx +126 -0
- package/dist/Inputs/TextInput.tsx +167 -0
- package/dist/Inputs/index.ts +51 -0
- package/dist/Layout/Box.tsx +82 -0
- package/dist/Layout/Center.tsx +17 -0
- package/dist/Layout/Container.tsx +17 -0
- package/dist/Layout/Flex.tsx +18 -0
- package/dist/Layout/Grid.tsx +31 -0
- package/dist/Layout/Group.tsx +54 -0
- package/dist/Layout/Inline.tsx +86 -0
- package/dist/Layout/SimpleGrid.tsx +50 -0
- package/dist/Layout/Stack.tsx +86 -0
- package/dist/Layout/index.ts +29 -0
- package/dist/Misc/Divider.tsx +27 -0
- package/dist/Misc/Paper.tsx +47 -0
- package/dist/Misc/index.ts +15 -0
- package/dist/Navigation/Breadcrumb.tsx +138 -0
- package/dist/Navigation/NavLink.tsx +37 -0
- package/dist/Navigation/Stepper.tsx +17 -0
- package/dist/Navigation/Tabs.tsx +29 -0
- package/dist/Navigation/index.ts +17 -0
- package/dist/Overlays/Drawer.tsx +123 -0
- package/dist/Overlays/Menu.tsx +192 -0
- package/dist/Overlays/Modal.tsx +159 -0
- package/dist/Overlays/Popover.tsx +319 -0
- package/dist/Overlays/Tooltip.tsx +131 -0
- package/dist/Overlays/index.ts +19 -0
- package/dist/Shell/AppShellLayout.tsx +56 -0
- package/dist/Shell/HeaderBar.tsx +26 -0
- package/dist/Shell/SidebarNav.tsx +47 -0
- package/dist/Shell/SidebarNavLink.tsx +50 -0
- package/dist/Shell/SingleColumnLayout.tsx +22 -0
- package/dist/Shell/TertiaryColumnLayout.tsx +32 -0
- package/dist/Shell/index.ts +17 -0
- package/dist/Typography/Code.tsx +27 -0
- package/dist/Typography/Kbd.tsx +87 -0
- package/dist/Typography/Text.tsx +27 -0
- package/dist/Typography/Title.tsx +34 -0
- package/dist/Typography/index.ts +21 -0
- package/dist/bin/ds-audit.js +521 -0
- package/dist/config.ts +226 -0
- package/dist/contracts/Alert.json +80 -0
- package/dist/contracts/Badge.json +78 -0
- package/dist/contracts/Box.json +52 -0
- package/dist/contracts/Button.json +111 -0
- package/dist/contracts/DataTable.json +68 -0
- package/dist/contracts/Grid.json +35 -0
- package/dist/contracts/Group.json +44 -0
- package/dist/contracts/Inline.json +73 -0
- package/dist/contracts/PageContentHeader.json +107 -0
- package/dist/contracts/Stack.json +62 -0
- package/dist/contracts/ds-component-contract.v1.json +23 -0
- package/dist/contracts/index.json +55 -0
- package/dist/css/foundations.css +703 -0
- package/dist/css/mantine.css +1777 -0
- package/dist/hooks/useTableHandlers.ts +179 -0
- package/dist/hooks/useTableRenderFunctions.tsx +283 -0
- package/dist/hooks/useTableState.ts +81 -0
- package/dist/index.ts +210 -0
- package/dist/types.ts +202 -0
- package/package.json +56 -4
|
@@ -0,0 +1,521 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* ds-audit — read-only DS checker for prototype repos.
|
|
5
|
+
*
|
|
6
|
+
* No LLM. No network. Writes prototype-audit.json.
|
|
7
|
+
*
|
|
8
|
+
* Usage:
|
|
9
|
+
* ds-audit
|
|
10
|
+
* ds-audit --ci
|
|
11
|
+
* node ds-package/bin/ds-audit.js --root /path/to/prototype
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
const fs = require('fs');
|
|
15
|
+
const path = require('path');
|
|
16
|
+
|
|
17
|
+
const SKIP_DIR_NAMES = new Set([
|
|
18
|
+
'node_modules',
|
|
19
|
+
'.next',
|
|
20
|
+
'dist',
|
|
21
|
+
'.git',
|
|
22
|
+
'storybook-static',
|
|
23
|
+
'coverage',
|
|
24
|
+
'DesignSystem',
|
|
25
|
+
]);
|
|
26
|
+
|
|
27
|
+
const SCAN_ROOTS = ['app', path.join('components', 'local')];
|
|
28
|
+
const TS_EXT = new Set(['.ts', '.tsx', '.js', '.jsx']);
|
|
29
|
+
|
|
30
|
+
const FALLBACK_COMPONENTS = [
|
|
31
|
+
'Button',
|
|
32
|
+
'ActionIcon',
|
|
33
|
+
'Alert',
|
|
34
|
+
'Avatar',
|
|
35
|
+
'Badge',
|
|
36
|
+
'Card',
|
|
37
|
+
'Chip',
|
|
38
|
+
'Pill',
|
|
39
|
+
'Table',
|
|
40
|
+
'DataTable',
|
|
41
|
+
'PageContentHeader',
|
|
42
|
+
'Stack',
|
|
43
|
+
'Inline',
|
|
44
|
+
'Group',
|
|
45
|
+
'Grid',
|
|
46
|
+
'Box',
|
|
47
|
+
'TextInput',
|
|
48
|
+
'Select',
|
|
49
|
+
'Text',
|
|
50
|
+
'Title',
|
|
51
|
+
'Breadcrumb',
|
|
52
|
+
'AppShellLayout',
|
|
53
|
+
];
|
|
54
|
+
|
|
55
|
+
function parseArgs(argv) {
|
|
56
|
+
const args = {};
|
|
57
|
+
for (let i = 2; i < argv.length; i++) {
|
|
58
|
+
if (!argv[i].startsWith('--')) continue;
|
|
59
|
+
const key = argv[i].replace(/^--/, '').replace(/-([a-z])/g, (_, c) => c.toUpperCase());
|
|
60
|
+
args[key] = argv[i + 1] && !argv[i + 1].startsWith('--') ? argv[++i] : true;
|
|
61
|
+
}
|
|
62
|
+
return args;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function readJson(filePath) {
|
|
66
|
+
if (!fs.existsSync(filePath)) return null;
|
|
67
|
+
return JSON.parse(fs.readFileSync(filePath, 'utf8'));
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function writeJson(filePath, value) {
|
|
71
|
+
fs.writeFileSync(filePath, JSON.stringify(value, null, 2) + '\n', 'utf8');
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function firstNonEmpty(...values) {
|
|
75
|
+
for (const value of values) {
|
|
76
|
+
if (value !== undefined && value !== null && String(value).length > 0) return value;
|
|
77
|
+
}
|
|
78
|
+
return '';
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function semverFromSpec(spec) {
|
|
82
|
+
if (!spec || typeof spec !== 'string') return '';
|
|
83
|
+
if (spec.includes('__KIT_TARBALL_URL__')) return '';
|
|
84
|
+
const tarball = spec.match(/ds-prototype-kit-v?(\d+\.\d+\.\d+)\.tgz/);
|
|
85
|
+
if (tarball) return tarball[1];
|
|
86
|
+
const tagged = spec.match(/\/download\/v(\d+\.\d+\.\d+)\//);
|
|
87
|
+
if (tagged) return tagged[1];
|
|
88
|
+
if (/^https?:\/\//.test(spec)) return '';
|
|
89
|
+
const matched = spec.match(/(\d+\.\d+\.\d+)/);
|
|
90
|
+
return matched ? matched[1] : '';
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function depSpec(pkg, name) {
|
|
94
|
+
if (!pkg) return '';
|
|
95
|
+
return (pkg.dependencies && pkg.dependencies[name]) || (pkg.devDependencies && pkg.devDependencies[name]) || '';
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function lockfileResolvedVersion(root, name) {
|
|
99
|
+
const lock = readJson(path.join(root, 'package-lock.json'));
|
|
100
|
+
if (!lock) return '';
|
|
101
|
+
if (lock.packages) {
|
|
102
|
+
const entry = lock.packages[`node_modules/${name}`];
|
|
103
|
+
if (entry && entry.version) return entry.version;
|
|
104
|
+
}
|
|
105
|
+
return '';
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function installedVersion(root, name) {
|
|
109
|
+
const parts = name.startsWith('@') ? name.split('/') : [name];
|
|
110
|
+
const pkg = readJson(path.join(root, 'node_modules', ...parts, 'package.json'));
|
|
111
|
+
return (pkg && pkg.version) || '';
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function kitPackage(root) {
|
|
115
|
+
return (
|
|
116
|
+
readJson(path.join(root, 'node_modules', '@appdirect', 'design-system', 'package.json')) ||
|
|
117
|
+
readJson(path.join(root, 'node_modules', '@appdirect', 'ds-prototype-kit', 'package.json')) ||
|
|
118
|
+
readJson(path.join(root, 'ds-package', 'package.json')) ||
|
|
119
|
+
readJson(path.join(__dirname, '..', 'package.json')) ||
|
|
120
|
+
readJson(path.join(__dirname, '..', '..', 'package.json'))
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function resolveVersions(root) {
|
|
125
|
+
const pkg = readJson(path.join(root, 'package.json')) || {};
|
|
126
|
+
const manifest = readJson(path.join(root, 'prototype-manifest.json')) || {};
|
|
127
|
+
const kitPkg = kitPackage(root) || {};
|
|
128
|
+
const previous = manifest.versions || {};
|
|
129
|
+
|
|
130
|
+
const kit = firstNonEmpty(
|
|
131
|
+
installedVersion(root, '@appdirect/design-system'),
|
|
132
|
+
semverFromSpec(depSpec(pkg, '@appdirect/design-system')),
|
|
133
|
+
installedVersion(root, '@appdirect/ds-prototype-kit'),
|
|
134
|
+
semverFromSpec(depSpec(pkg, '@appdirect/ds-prototype-kit')),
|
|
135
|
+
kitPkg.version,
|
|
136
|
+
previous.kit
|
|
137
|
+
);
|
|
138
|
+
const tokensSnapshot = firstNonEmpty(
|
|
139
|
+
semverFromSpec(depSpec(pkg, '@appdirect/ad-design-tokens')),
|
|
140
|
+
kitPkg.tokensSnapshot,
|
|
141
|
+
previous.tokensSnapshot
|
|
142
|
+
);
|
|
143
|
+
const mantine = firstNonEmpty(
|
|
144
|
+
installedVersion(root, '@mantine/core'),
|
|
145
|
+
lockfileResolvedVersion(root, '@mantine/core'),
|
|
146
|
+
semverFromSpec(depSpec(pkg, '@mantine/core')),
|
|
147
|
+
previous.mantine
|
|
148
|
+
);
|
|
149
|
+
const factory = firstNonEmpty(kit, previous.factory);
|
|
150
|
+
const template = (manifest.template && manifest.template.version) || '';
|
|
151
|
+
|
|
152
|
+
return {
|
|
153
|
+
template,
|
|
154
|
+
kit,
|
|
155
|
+
tokensSnapshot,
|
|
156
|
+
factory,
|
|
157
|
+
mantine,
|
|
158
|
+
latestKitKnown: kitPkg.version || kit,
|
|
159
|
+
manifest,
|
|
160
|
+
pkg,
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function collectContractFiles(dir, out = []) {
|
|
165
|
+
if (!fs.existsSync(dir)) return out;
|
|
166
|
+
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
167
|
+
const full = path.join(dir, entry.name);
|
|
168
|
+
if (entry.isDirectory()) collectContractFiles(full, out);
|
|
169
|
+
else if (entry.name.endsWith('.contract.json')) {
|
|
170
|
+
out.push(full);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
return out;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function loadContracts(root) {
|
|
177
|
+
const candidates = [
|
|
178
|
+
path.join(root, 'node_modules', '@appdirect', 'design-system', 'dist', 'contracts'),
|
|
179
|
+
path.join(root, 'node_modules', '@appdirect', 'ds-prototype-kit', 'dist', 'contracts'),
|
|
180
|
+
path.join(root, 'ds-package', 'dist', 'contracts'),
|
|
181
|
+
path.join(__dirname, '..', 'dist', 'contracts'),
|
|
182
|
+
path.join(__dirname, '..', 'contracts'),
|
|
183
|
+
];
|
|
184
|
+
for (const dir of candidates) {
|
|
185
|
+
const index = readJson(path.join(dir, 'index.json'));
|
|
186
|
+
if (index && Array.isArray(index.contracts)) {
|
|
187
|
+
return index.contracts
|
|
188
|
+
.map((item) => readJson(path.join(dir, `${item.id}.json`)))
|
|
189
|
+
.filter(Boolean);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
const source = path.join(root, 'components', 'DesignSystem');
|
|
193
|
+
return collectContractFiles(source).map((file) => readJson(file)).filter(Boolean);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function shouldSkipDir(name) {
|
|
197
|
+
return SKIP_DIR_NAMES.has(name);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
function shouldSkipFile(filePath) {
|
|
201
|
+
const base = path.basename(filePath);
|
|
202
|
+
if (base.endsWith('.stories.tsx') || base.endsWith('.stories.ts')) return true;
|
|
203
|
+
if (base.endsWith('.test.ts') || base.endsWith('.test.tsx') || base.endsWith('.test.mjs')) return true;
|
|
204
|
+
if (base.endsWith('.figma.tsx')) return true;
|
|
205
|
+
if (filePath.includes(`${path.sep}DesignSystem${path.sep}`)) return true;
|
|
206
|
+
return !TS_EXT.has(path.extname(filePath));
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
function walkFiles(dir, out = []) {
|
|
210
|
+
if (!fs.existsSync(dir)) return out;
|
|
211
|
+
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
212
|
+
const full = path.join(dir, entry.name);
|
|
213
|
+
if (entry.isDirectory()) {
|
|
214
|
+
if (!shouldSkipDir(entry.name)) walkFiles(full, out);
|
|
215
|
+
} else if (!shouldSkipFile(full)) {
|
|
216
|
+
out.push(full);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
return out;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
function scanTargets(root) {
|
|
223
|
+
const files = [];
|
|
224
|
+
for (const rel of SCAN_ROOTS) {
|
|
225
|
+
walkFiles(path.join(root, rel), files);
|
|
226
|
+
}
|
|
227
|
+
return files;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
function rel(root, filePath) {
|
|
231
|
+
return path.relative(root, filePath).replace(/\\/g, '/');
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
function parseNamedImports(content, source) {
|
|
235
|
+
const names = [];
|
|
236
|
+
const re = new RegExp(`import\\s+\\{([^}]+)\\}\\s+from\\s+['"]${source}['"]`, 'g');
|
|
237
|
+
let match;
|
|
238
|
+
while ((match = re.exec(content))) {
|
|
239
|
+
for (const part of match[1].split(',')) {
|
|
240
|
+
const name = part.trim().split(/\s+as\s+/)[0].trim();
|
|
241
|
+
if (name && !name.startsWith('type ')) names.push(name);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
return names;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
function countJsx(content, name) {
|
|
248
|
+
const re = new RegExp(`<${name}(\\s|>|/)`, 'g');
|
|
249
|
+
return (content.match(re) || []).length;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
function lineFindings(content, fileRel, test, extra) {
|
|
253
|
+
const findings = [];
|
|
254
|
+
const lines = content.split(/\r?\n/);
|
|
255
|
+
lines.forEach((line, index) => {
|
|
256
|
+
if (test(line)) findings.push({ file: fileRel, line: index + 1, ...extra });
|
|
257
|
+
});
|
|
258
|
+
return findings;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
function styleBlockHas(content, pattern) {
|
|
262
|
+
const blocks = content.match(/style=\{\{[\s\S]*?\}\}/g) || [];
|
|
263
|
+
return blocks.some((block) => pattern.test(block));
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
function isPrototypePage(fileRel) {
|
|
267
|
+
return /^app\/prototype\/.+\/page\.tsx$/.test(fileRel);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
function isPrototypeIndex(fileRel) {
|
|
271
|
+
return fileRel === 'app/prototype/page.tsx';
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
function githubEscape(value) {
|
|
275
|
+
return String(value).replace(/%/g, '%25').replace(/\r/g, '%0D').replace(/\n/g, '%0A');
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
function githubAnnotation(kind, finding, message) {
|
|
279
|
+
const params = [];
|
|
280
|
+
if (finding.file) params.push(`file=${githubEscape(finding.file)}`);
|
|
281
|
+
if (finding.line) params.push(`line=${finding.line}`);
|
|
282
|
+
if (finding.rule || finding.id) params.push(`title=${githubEscape(finding.rule || finding.id)}`);
|
|
283
|
+
const prefix = params.length ? `::${kind} ${params.join(',')}::` : `::${kind} ::`;
|
|
284
|
+
return `${prefix}${githubEscape(message)}`;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
function formatAnnotations(report) {
|
|
288
|
+
const lines = [];
|
|
289
|
+
for (const item of (report.findings && report.findings.restrictedImports) || []) {
|
|
290
|
+
lines.push(
|
|
291
|
+
githubAnnotation(
|
|
292
|
+
'error',
|
|
293
|
+
item,
|
|
294
|
+
'Do not import @mantine/core in prototype app/ or components/local. Use the kit (or @/components/DesignSystem in this repo).'
|
|
295
|
+
)
|
|
296
|
+
);
|
|
297
|
+
}
|
|
298
|
+
for (const item of (report.patterns && report.patterns.unsupported) || []) {
|
|
299
|
+
let message = item.id;
|
|
300
|
+
if (item.id === 'missing-page-content-header') {
|
|
301
|
+
message = 'Prototype page is missing PageContentHeader.';
|
|
302
|
+
} else if (item.id === 'handmade-record-list') {
|
|
303
|
+
message = `Handmade record list; use ${item.insteadOf || 'DataTable or Table'}.`;
|
|
304
|
+
}
|
|
305
|
+
lines.push(githubAnnotation('warning', item, message));
|
|
306
|
+
}
|
|
307
|
+
return lines;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
function shouldAnnotate(args = {}, env = process.env) {
|
|
311
|
+
return Boolean(args.ci) || env.GITHUB_ACTIONS === 'true';
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
function localComponentFiles(root) {
|
|
315
|
+
const dir = path.join(root, 'components', 'local');
|
|
316
|
+
const files = walkFiles(dir).filter((file) => path.basename(file) !== 'index.ts' && path.basename(file) !== 'index.tsx');
|
|
317
|
+
return files.map((file) => rel(root, file));
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
function runAudit(root, options = {}) {
|
|
321
|
+
const now = options.now || new Date().toISOString();
|
|
322
|
+
const versions = resolveVersions(root);
|
|
323
|
+
const contracts = loadContracts(root);
|
|
324
|
+
const contractIds = contracts.map((item) => item.id).filter(Boolean);
|
|
325
|
+
const systemNames = new Set([...FALLBACK_COMPONENTS, ...contractIds]);
|
|
326
|
+
|
|
327
|
+
const restrictedImports = [];
|
|
328
|
+
const deprecatedApi = [];
|
|
329
|
+
const tokenViolations = [];
|
|
330
|
+
const contractViolations = [];
|
|
331
|
+
const unsupported = [];
|
|
332
|
+
const systemComponents = {};
|
|
333
|
+
for (const name of systemNames) systemComponents[name] = 0;
|
|
334
|
+
|
|
335
|
+
const files = scanTargets(root);
|
|
336
|
+
for (const filePath of files) {
|
|
337
|
+
const fileRel = rel(root, filePath);
|
|
338
|
+
const content = fs.readFileSync(filePath, 'utf8');
|
|
339
|
+
|
|
340
|
+
restrictedImports.push(
|
|
341
|
+
...lineFindings(content, fileRel, (line) => /from\s+['"]@mantine\/core['"]/.test(line), {
|
|
342
|
+
rule: 'restricted-import.mantine-core',
|
|
343
|
+
})
|
|
344
|
+
);
|
|
345
|
+
|
|
346
|
+
deprecatedApi.push(
|
|
347
|
+
...lineFindings(content, fileRel, (line) => /<Button\b[^>]*\bcolor=/.test(line), {
|
|
348
|
+
component: 'Button',
|
|
349
|
+
rule: 'api.props.color.deprecated',
|
|
350
|
+
}),
|
|
351
|
+
...lineFindings(content, fileRel, (line) => /variant=["']disabled["']/.test(line), {
|
|
352
|
+
component: 'Button',
|
|
353
|
+
rule: 'api.props.variant.disabled-alias',
|
|
354
|
+
}),
|
|
355
|
+
...lineFindings(content, fileRel, (line) => /<Alert\b[^>]*\btype=/.test(line), {
|
|
356
|
+
component: 'Alert',
|
|
357
|
+
rule: 'api.props.type.deprecated',
|
|
358
|
+
})
|
|
359
|
+
);
|
|
360
|
+
|
|
361
|
+
tokenViolations.push(
|
|
362
|
+
...lineFindings(content, fileRel, (line) => /style=\{\{/.test(line), {
|
|
363
|
+
rule: 'tokens.style-prop',
|
|
364
|
+
})
|
|
365
|
+
);
|
|
366
|
+
if (styleBlockHas(content, /#[0-9A-Fa-f]{3,8}\b/)) {
|
|
367
|
+
tokenViolations.push({ file: fileRel, rule: 'tokens.raw-hex' });
|
|
368
|
+
}
|
|
369
|
+
if (styleBlockHas(content, /\d+px\b/)) {
|
|
370
|
+
tokenViolations.push({ file: fileRel, rule: 'tokens.raw-px' });
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
const imported = [
|
|
374
|
+
...parseNamedImports(content, '@\\/components\\/DesignSystem'),
|
|
375
|
+
...parseNamedImports(content, '@appdirect\\/design-system'),
|
|
376
|
+
...parseNamedImports(content, '@appdirect\\/ds-prototype-kit'),
|
|
377
|
+
];
|
|
378
|
+
for (const name of imported) {
|
|
379
|
+
if (!systemNames.has(name)) continue;
|
|
380
|
+
systemComponents[name] += countJsx(content, name);
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
if (isPrototypePage(fileRel) && !isPrototypeIndex(fileRel)) {
|
|
384
|
+
if (!imported.includes('PageContentHeader') && !/<PageContentHeader[\s>/]/.test(content)) {
|
|
385
|
+
unsupported.push({
|
|
386
|
+
id: 'missing-page-content-header',
|
|
387
|
+
file: fileRel,
|
|
388
|
+
insteadOf: 'PageContentHeader',
|
|
389
|
+
});
|
|
390
|
+
}
|
|
391
|
+
const hasTable = imported.includes('DataTable') || imported.includes('Table') || /<(DataTable|Table)[\s>/]/.test(content);
|
|
392
|
+
const handmade = /\.map\s*\(/.test(content) && /<(Card|Inline)[\s>/]/.test(content);
|
|
393
|
+
if (handmade && !hasTable) {
|
|
394
|
+
unsupported.push({
|
|
395
|
+
id: 'handmade-record-list',
|
|
396
|
+
file: fileRel,
|
|
397
|
+
insteadOf: 'DataTable or Table',
|
|
398
|
+
});
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
const moduleCss = [];
|
|
404
|
+
function walkCss(dir) {
|
|
405
|
+
if (!fs.existsSync(dir)) return;
|
|
406
|
+
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
407
|
+
const full = path.join(dir, entry.name);
|
|
408
|
+
if (entry.isDirectory()) {
|
|
409
|
+
if (!shouldSkipDir(entry.name)) walkCss(full);
|
|
410
|
+
} else if (entry.name.endsWith('.module.css') && !full.includes(`${path.sep}DesignSystem${path.sep}`)) {
|
|
411
|
+
moduleCss.push(rel(root, full));
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
walkCss(path.join(root, 'app'));
|
|
416
|
+
walkCss(path.join(root, 'components', 'local'));
|
|
417
|
+
for (const cssPath of moduleCss) {
|
|
418
|
+
tokenViolations.push({ file: cssPath, rule: 'tokens.consumer-css-module' });
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
const customPaths = localComponentFiles(root);
|
|
422
|
+
const exceptions = Array.isArray(versions.manifest.exceptions) ? versions.manifest.exceptions : [];
|
|
423
|
+
|
|
424
|
+
if (versions.manifest.versions && versions.kit && versions.manifest.versions.kit && versions.manifest.versions.kit !== versions.kit) {
|
|
425
|
+
contractViolations.push({
|
|
426
|
+
component: 'versions',
|
|
427
|
+
rule: 'versions.kit-mismatch',
|
|
428
|
+
file: 'prototype-manifest.json',
|
|
429
|
+
expected: versions.kit,
|
|
430
|
+
actual: versions.manifest.versions.kit,
|
|
431
|
+
});
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
for (const item of deprecatedApi) {
|
|
435
|
+
contractViolations.push({
|
|
436
|
+
component: item.component,
|
|
437
|
+
rule: item.rule,
|
|
438
|
+
file: item.file,
|
|
439
|
+
line: item.line,
|
|
440
|
+
});
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
const auditFail = restrictedImports.length > 0;
|
|
444
|
+
const report = {
|
|
445
|
+
schemaVersion: 1,
|
|
446
|
+
generatedAt: now,
|
|
447
|
+
repo: (versions.pkg && versions.pkg.name) || path.basename(root),
|
|
448
|
+
versions: {
|
|
449
|
+
template: versions.template,
|
|
450
|
+
kit: versions.kit,
|
|
451
|
+
tokensSnapshot: versions.tokensSnapshot,
|
|
452
|
+
factory: versions.factory,
|
|
453
|
+
mantine: versions.mantine,
|
|
454
|
+
latestKitKnown: versions.latestKitKnown,
|
|
455
|
+
},
|
|
456
|
+
health: {
|
|
457
|
+
typecheck: 'skipped',
|
|
458
|
+
lint: 'skipped',
|
|
459
|
+
build: 'skipped',
|
|
460
|
+
audit: auditFail ? 'fail' : 'pass',
|
|
461
|
+
},
|
|
462
|
+
adoption: {
|
|
463
|
+
systemComponents,
|
|
464
|
+
customComponents: { count: customPaths.length, paths: customPaths },
|
|
465
|
+
},
|
|
466
|
+
compliance: {
|
|
467
|
+
restrictedImports: restrictedImports.length,
|
|
468
|
+
deprecatedApi: deprecatedApi.length,
|
|
469
|
+
tokenViolations: tokenViolations.length,
|
|
470
|
+
contractViolations,
|
|
471
|
+
a11y: { violations: 0, tool: 'not-run' },
|
|
472
|
+
},
|
|
473
|
+
patterns: { unsupported },
|
|
474
|
+
exceptions,
|
|
475
|
+
findings: {
|
|
476
|
+
restrictedImports,
|
|
477
|
+
deprecatedApi,
|
|
478
|
+
tokenViolations,
|
|
479
|
+
},
|
|
480
|
+
};
|
|
481
|
+
|
|
482
|
+
const outPath =
|
|
483
|
+
options.out === false
|
|
484
|
+
? null
|
|
485
|
+
: typeof options.out === 'string'
|
|
486
|
+
? options.out
|
|
487
|
+
: path.join(root, 'prototype-audit.json');
|
|
488
|
+
if (outPath) writeJson(outPath, report);
|
|
489
|
+
|
|
490
|
+
return { report, exitCode: auditFail ? 1 : 0, outPath };
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
function main(argv = process.argv, env = process.env) {
|
|
494
|
+
const args = parseArgs(argv);
|
|
495
|
+
if (args.help) {
|
|
496
|
+
console.log('Usage: ds-audit [--root <dir>] [--out <file>] [--ci]');
|
|
497
|
+
return { exitCode: 0 };
|
|
498
|
+
}
|
|
499
|
+
const root = typeof args.root === 'string' ? path.resolve(args.root) : process.cwd();
|
|
500
|
+
const result = runAudit(root, { out: typeof args.out === 'string' ? path.resolve(args.out) : undefined });
|
|
501
|
+
const { report } = result;
|
|
502
|
+
console.log(`ds-audit ${report.health.audit}`);
|
|
503
|
+
console.log(` kit: ${report.versions.kit || '(empty)'}`);
|
|
504
|
+
console.log(` restrictedImports: ${report.compliance.restrictedImports}`);
|
|
505
|
+
console.log(` deprecatedApi: ${report.compliance.deprecatedApi}`);
|
|
506
|
+
console.log(` tokenViolations: ${report.compliance.tokenViolations}`);
|
|
507
|
+
console.log(` unsupported: ${report.patterns.unsupported.length}`);
|
|
508
|
+
console.log(` customComponents: ${report.adoption.customComponents.count}`);
|
|
509
|
+
if (result.outPath) console.log(` wrote: ${result.outPath}`);
|
|
510
|
+
if (shouldAnnotate(args, env)) {
|
|
511
|
+
for (const line of formatAnnotations(report)) console.log(line);
|
|
512
|
+
}
|
|
513
|
+
return result;
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
if (require.main === module) {
|
|
517
|
+
const result = main();
|
|
518
|
+
process.exit(result.exitCode);
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
module.exports = { runAudit, main, parseArgs, formatAnnotations, shouldAnnotate };
|