@chenyqthu/tp-mobile-ui-kit 0.0.0-stage → 0.2.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 +214 -2
- package/dist/assets.js +5 -0
- package/dist/catalog.json +12355 -0
- package/dist/chunks/OmadaAppDemo-BO8a6A-m.js +4910 -0
- package/dist/chunks/TPPrompt-DLd32rsN.js +3456 -0
- package/dist/chunks/asset-icons-BIenKvAh.js +7613 -0
- package/dist/chunks/asset-illustrations-YHXzEd7z.js +3086 -0
- package/dist/chunks/asset-logos-DAyGwOLj.js +59 -0
- package/dist/chunks/asset-motion-D7fWh_JS.js +376 -0
- package/dist/core.js +3 -0
- package/dist/index.js +7 -0
- package/dist/libpag.wasm +0 -0
- package/dist/omada.js +7 -0
- package/dist/standalone.js +3438 -0
- package/dist/style.css +2 -0
- package/dist/types/assets-lib/TPBrandLogo.d.ts +15 -0
- package/dist/types/assets-lib/TPIcon.d.ts +19 -0
- package/dist/types/assets-lib/TPIllustration.d.ts +17 -0
- package/dist/types/assets-lib/TPMotion.d.ts +25 -0
- package/dist/types/assets-lib/assetsManifest.d.ts +22 -0
- package/dist/types/assets-lib/iconsManifest.d.ts +14 -0
- package/dist/types/assets-lib/index.d.ts +8 -0
- package/dist/types/assets-lib/motionsManifest.d.ts +12 -0
- package/dist/types/assets-lib/runtimeUrl.d.ts +4 -0
- package/dist/types/core/components/TPActionSheet.d.ts +4 -0
- package/dist/types/core/components/TPAlert.d.ts +4 -0
- package/dist/types/core/components/TPAvatar.d.ts +7 -0
- package/dist/types/core/components/TPBadge.d.ts +7 -0
- package/dist/types/core/components/TPBottomSheet.d.ts +4 -0
- package/dist/types/core/components/TPButton.d.ts +4 -0
- package/dist/types/core/components/TPCheckbox.d.ts +11 -0
- package/dist/types/core/components/TPDatePicker.d.ts +7 -0
- package/dist/types/core/components/TPDaySwitcher.d.ts +7 -0
- package/dist/types/core/components/TPDivider.d.ts +7 -0
- package/dist/types/core/components/TPEmptyState.d.ts +7 -0
- package/dist/types/core/components/TPFixedButtonBar.d.ts +4 -0
- package/dist/types/core/components/TPFixedToast.d.ts +7 -0
- package/dist/types/core/components/TPHeader.d.ts +4 -0
- package/dist/types/core/components/TPIconButton.d.ts +11 -0
- package/dist/types/core/components/TPInput.d.ts +8 -0
- package/dist/types/core/components/TPKeyboard.d.ts +7 -0
- package/dist/types/core/components/TPLast7DaysPicker.d.ts +7 -0
- package/dist/types/core/components/TPLiquidGlass.d.ts +8 -0
- package/dist/types/core/components/TPListButton.d.ts +7 -0
- package/dist/types/core/components/TPListCard.d.ts +7 -0
- package/dist/types/core/components/TPListItem.d.ts +7 -0
- package/dist/types/core/components/TPMenu.d.ts +4 -0
- package/dist/types/core/components/TPMonthPicker.d.ts +7 -0
- package/dist/types/core/components/TPPageControl.d.ts +4 -0
- package/dist/types/core/components/TPPhoneFrame.d.ts +4 -0
- package/dist/types/core/components/TPPinInput.d.ts +7 -0
- package/dist/types/core/components/TPPopup.d.ts +4 -0
- package/dist/types/core/components/TPProgress.d.ts +7 -0
- package/dist/types/core/components/TPPrompt.d.ts +4 -0
- package/dist/types/core/components/TPRadio.d.ts +11 -0
- package/dist/types/core/components/TPSearchBar.d.ts +7 -0
- package/dist/types/core/components/TPSectionHeader.d.ts +7 -0
- package/dist/types/core/components/TPSectionNote.d.ts +7 -0
- package/dist/types/core/components/TPSegment.d.ts +4 -0
- package/dist/types/core/components/TPSkeleton.d.ts +7 -0
- package/dist/types/core/components/TPSlider.d.ts +4 -0
- package/dist/types/core/components/TPStatusBar.d.ts +4 -0
- package/dist/types/core/components/TPStepText.d.ts +7 -0
- package/dist/types/core/components/TPStepper.d.ts +7 -0
- package/dist/types/core/components/TPSwipeRow.d.ts +8 -0
- package/dist/types/core/components/TPSwitch.d.ts +4 -0
- package/dist/types/core/components/TPTabBar.d.ts +4 -0
- package/dist/types/core/components/TPTag.d.ts +7 -0
- package/dist/types/core/components/TPText.d.ts +7 -0
- package/dist/types/core/components/TPTimePicker.d.ts +7 -0
- package/dist/types/core/components/TPToast.d.ts +13 -0
- package/dist/types/core/components/TPTooltip.d.ts +7 -0
- package/dist/types/core/components/TPWheelPicker.d.ts +7 -0
- package/dist/types/core/index.d.ts +50 -0
- package/dist/types/core/types.d.ts +646 -0
- package/dist/types/lib/assets.d.ts +1 -0
- package/dist/types/lib/core.d.ts +2 -0
- package/dist/types/lib/index.d.ts +4 -0
- package/dist/types/lib/omada.d.ts +4 -0
- package/dist/types/lib/standalone.d.ts +8 -0
- package/dist/types/omada/blocks/OmadaDeviceListBlock.d.ts +42 -0
- package/dist/types/omada/blocks/OmadaFirmwareUpdateBlock.d.ts +23 -0
- package/dist/types/omada/blocks/OmadaIncidentsBlock.d.ts +26 -0
- package/dist/types/omada/blocks/OmadaPortPanelBlock.d.ts +31 -0
- package/dist/types/omada/blocks/OmadaScheduleBlock.d.ts +33 -0
- package/dist/types/omada/blocks/OmadaTopologyBlock.d.ts +26 -0
- package/dist/types/omada/blocks/OmadaWirelessNetworkBlock.d.ts +25 -0
- package/dist/types/omada/components/OmadaStandardInput.d.ts +23 -0
- package/dist/types/omada/index.d.ts +18 -0
- package/dist/types/omada/pages/OmadaAppDemo.d.ts +18 -0
- package/dist/types/omada/pages/OmadaControllerListPage.d.ts +26 -0
- package/dist/types/omada/pages/OmadaDeviceDetailPage.d.ts +15 -0
- package/dist/types/omada/pages/OmadaHealthDetailPage.d.ts +17 -0
- package/dist/types/omada/pages/OmadaLaunchLoadingPage.d.ts +24 -0
- package/dist/types/omada/pages/OmadaSiteClientsPage.d.ts +34 -0
- package/dist/types/omada/pages/OmadaSiteDashboardPage.d.ts +28 -0
- package/dist/types/omada/pages/OmadaSiteDevicesPage.d.ts +18 -0
- package/dist/types/omada/pages/OmadaSiteInsightsPage.d.ts +17 -0
- package/dist/types/omada/pages/OmadaSiteSettingsPage.d.ts +22 -0
- package/dist/types/theme/TPThemeProvider.d.ts +33 -0
- package/dist/types/theme/index.d.ts +2 -0
- package/dist/types/theme/tokens.d.ts +80 -0
- package/package.json +88 -4
- package/skills/tp-mobile-ui-kit/SKILL.md +226 -0
- package/skills/tp-mobile-ui-kit/references/catalog.json +12355 -0
- package/skills/tp-mobile-ui-kit/scripts/query-catalog.mjs +289 -0
- package/skills/tp-mobile-ui-kit/scripts/verify-demo.mjs +193 -0
- package/skills/tp-mobile-ui-kit/templates/multi-brand.html +319 -0
- package/skills/tp-mobile-ui-kit/templates/multi-brand.tsx +337 -0
- package/skills/tp-mobile-ui-kit/templates/omada-dashboard.html +138 -0
- package/skills/tp-mobile-ui-kit/templates/omada-dashboard.tsx +119 -0
- package/skills/tp-mobile-ui-kit/templates/omada-device-detail.html +158 -0
- package/skills/tp-mobile-ui-kit/templates/omada-device-detail.tsx +135 -0
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
|
|
6
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
7
|
+
const __dirname = path.dirname(__filename);
|
|
8
|
+
const CATALOG_PATH = path.resolve(__dirname, '../references/catalog.json');
|
|
9
|
+
const TEMPLATES_DIR = path.resolve(__dirname, '../templates');
|
|
10
|
+
|
|
11
|
+
function loadCatalog() {
|
|
12
|
+
if (!fs.existsSync(CATALOG_PATH)) {
|
|
13
|
+
console.error(`Missing catalog.json at ${CATALOG_PATH}. Run "pnpm build:catalog" in the repo root.`);
|
|
14
|
+
process.exit(1);
|
|
15
|
+
}
|
|
16
|
+
return JSON.parse(fs.readFileSync(CATALOG_PATH, 'utf8'));
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function usage() {
|
|
20
|
+
console.log(`TP Mobile UI Kit Catalog Query CLI
|
|
21
|
+
|
|
22
|
+
Usage:
|
|
23
|
+
node query-catalog.mjs info
|
|
24
|
+
node query-catalog.mjs list-components [category]
|
|
25
|
+
node query-catalog.mjs component <Name>
|
|
26
|
+
node query-catalog.mjs brands [brand]
|
|
27
|
+
node query-catalog.mjs search-icons <keyword> [limit=25]
|
|
28
|
+
node query-catalog.mjs search-assets <illustrations|logos|motions> [keyword] [limit=25]
|
|
29
|
+
node query-catalog.mjs templates
|
|
30
|
+
node query-catalog.mjs template <id> [--html|--tsx]
|
|
31
|
+
node query-catalog.mjs recipes [keyword]`);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function cmdInfo(catalog) {
|
|
35
|
+
console.log(`Package: ${catalog.package.name}@${catalog.package.version}`);
|
|
36
|
+
console.log(`CDN CSS: ${catalog.package.cdn.jsdelivrCss}`);
|
|
37
|
+
console.log(`CDN Standalone: ${catalog.package.cdn.jsdelivrStandalone}`);
|
|
38
|
+
console.log(`CDN PAG WASM: ${catalog.package.cdn.jsdelivrWasm}`);
|
|
39
|
+
console.log('Subpaths:', JSON.stringify(catalog.package.entries));
|
|
40
|
+
console.log('Counts:', JSON.stringify(catalog.counts));
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function cmdListComponents(catalog, category) {
|
|
44
|
+
const items = catalog.components.filter((c) => {
|
|
45
|
+
if (!category) return c.kind !== 'data';
|
|
46
|
+
return c.category.toLowerCase() === category.toLowerCase();
|
|
47
|
+
});
|
|
48
|
+
if (items.length === 0) {
|
|
49
|
+
const categories = [...new Set(catalog.components.map((c) => c.category))];
|
|
50
|
+
console.log(`No items matched category "${category}". Available: ${categories.join(', ')}`);
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
const grouped = new Map();
|
|
54
|
+
for (const item of items) {
|
|
55
|
+
if (!grouped.has(item.category)) grouped.set(item.category, []);
|
|
56
|
+
grouped.get(item.category).push(item);
|
|
57
|
+
}
|
|
58
|
+
for (const [cat, list] of grouped) {
|
|
59
|
+
console.log(`\n## ${cat} (${list.length})`);
|
|
60
|
+
for (const c of list) {
|
|
61
|
+
const propCount = c.props ? ` (${c.props.length} props)` : '';
|
|
62
|
+
const desc = c.description ? ` — ${c.description}` : '';
|
|
63
|
+
console.log(`- ${c.name} [${c.kind}]${propCount}${desc}`);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function cmdComponent(catalog, query) {
|
|
69
|
+
if (!query) {
|
|
70
|
+
console.error('Provide a component name, e.g. node query-catalog.mjs component TPButton');
|
|
71
|
+
process.exit(1);
|
|
72
|
+
}
|
|
73
|
+
const lower = query.toLowerCase();
|
|
74
|
+
const exact = catalog.components.find((c) => c.name.toLowerCase() === lower);
|
|
75
|
+
const matches = exact
|
|
76
|
+
? [exact]
|
|
77
|
+
: catalog.components.filter((c) => c.name.toLowerCase().includes(lower)).slice(0, 8);
|
|
78
|
+
|
|
79
|
+
if (matches.length === 0) {
|
|
80
|
+
console.log(`No exported symbol matches "${query}".`);
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
for (const item of matches) {
|
|
84
|
+
console.log(`\n### ${item.name} (${item.category} / ${item.kind})`);
|
|
85
|
+
if (item.description) console.log(item.description);
|
|
86
|
+
console.log(`Import: import { ${item.name} } from '${item.subpath || catalog.package.name}';`);
|
|
87
|
+
if (item.subpath && item.subpath !== catalog.package.name) {
|
|
88
|
+
console.log(`Root: import { ${item.name} } from '${catalog.package.name}';`);
|
|
89
|
+
}
|
|
90
|
+
if (item.sourcePath) console.log(`Source: ${item.sourcePath}`);
|
|
91
|
+
if (item.extends) console.log(`Extends: ${item.extends}`);
|
|
92
|
+
if (item.signature) console.log(`Signature: ${item.signature}`);
|
|
93
|
+
if (item.props && item.props.length > 0) {
|
|
94
|
+
console.log('\nProps:');
|
|
95
|
+
for (const p of item.props) {
|
|
96
|
+
const req = p.optional ? '?' : '';
|
|
97
|
+
const desc = p.description ? ` // ${p.description}` : '';
|
|
98
|
+
console.log(` ${p.name}${req}: ${p.type}${desc}`);
|
|
99
|
+
}
|
|
100
|
+
} else if (item.kind === 'component') {
|
|
101
|
+
console.log('(No dedicated *Props interface extracted.)');
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function cmdBrands(catalog, brandQuery) {
|
|
107
|
+
const brands = catalog.tokens?.brands ?? [];
|
|
108
|
+
const presets = catalog.tokens?.presets ?? {};
|
|
109
|
+
const screenDimensions = catalog.tokens?.screenDimensions ?? {};
|
|
110
|
+
|
|
111
|
+
if (!brandQuery) {
|
|
112
|
+
console.log(`Supported TP-Design Brands (${brands.length} brands × 2 modes = ${brands.length * 2} presets):\n`);
|
|
113
|
+
for (const b of brands) {
|
|
114
|
+
const light = presets[b.id]?.light;
|
|
115
|
+
const dark = presets[b.id]?.dark;
|
|
116
|
+
console.log(`## ${b.id} (${b.label}) — accent ${b.accent}`);
|
|
117
|
+
console.log(` ${b.description}`);
|
|
118
|
+
if (light && dark) {
|
|
119
|
+
console.log(
|
|
120
|
+
` Light: bg=${light.background}, card=${light.card}, text=${light.textPrimary}, btnRadius=${light.radiusButton}px, cardRadius=${light.radiusCard}px, secStroke=${light.buttonSecondaryStroke}px, fontSize=${light.fontSizeMain}px, sliderStroke=${light.sliderStroke}px, tick=${light.sliderTickSize}px`,
|
|
121
|
+
);
|
|
122
|
+
console.log(
|
|
123
|
+
` Dark: bg=${dark.background}, card=${dark.card}, text=${dark.textPrimary}, primaryFill=${dark.buttonPrimaryFill}, secFill=${dark.buttonSecondaryFill}`,
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
if (Object.keys(screenDimensions).length > 0) {
|
|
128
|
+
console.log('\nScreen Dimensions:', JSON.stringify(screenDimensions));
|
|
129
|
+
}
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const lower = brandQuery.toLowerCase();
|
|
134
|
+
const brandMeta = brands.find((b) => b.id.toLowerCase() === lower || b.label.toLowerCase() === lower);
|
|
135
|
+
if (!brandMeta) {
|
|
136
|
+
console.error(`Unknown brand "${brandQuery}". Valid brands: ${brands.map((b) => b.id).join(', ')}`);
|
|
137
|
+
process.exit(1);
|
|
138
|
+
}
|
|
139
|
+
console.log(`=== ${brandMeta.label} (${brandMeta.id}) ===`);
|
|
140
|
+
console.log(brandMeta.description);
|
|
141
|
+
console.log('\nLight Preset:');
|
|
142
|
+
console.log(JSON.stringify(presets[brandMeta.id]?.light ?? {}, null, 2));
|
|
143
|
+
console.log('\nDark Preset:');
|
|
144
|
+
console.log(JSON.stringify(presets[brandMeta.id]?.dark ?? {}, null, 2));
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function cmdSearchIcons(catalog, keyword = '', limitArg = '25') {
|
|
148
|
+
const limit = Math.max(1, Number.parseInt(limitArg, 10) || 25);
|
|
149
|
+
const lower = keyword.toLowerCase();
|
|
150
|
+
const matches = (catalog.assets?.icons ?? []).filter(
|
|
151
|
+
(icon) =>
|
|
152
|
+
!lower ||
|
|
153
|
+
icon.name.toLowerCase().includes(lower) ||
|
|
154
|
+
icon.category.toLowerCase().includes(lower) ||
|
|
155
|
+
icon.pack.toLowerCase().includes(lower) ||
|
|
156
|
+
(icon.title && icon.title.toLowerCase().includes(lower)),
|
|
157
|
+
);
|
|
158
|
+
console.log(
|
|
159
|
+
`Matched ${matches.length} icons${lower ? ` for "${keyword}"` : ''} (showing ${Math.min(limit, matches.length)}):`,
|
|
160
|
+
);
|
|
161
|
+
for (const icon of matches.slice(0, limit)) {
|
|
162
|
+
console.log(`- ${icon.name} [${icon.pack}/${icon.category}, ${icon.width}x${icon.height}, ${icon.format}]`);
|
|
163
|
+
}
|
|
164
|
+
if (matches.length === 0) {
|
|
165
|
+
console.log(`Packs: ${(catalog.assets?.iconPacks ?? []).join(', ')}`);
|
|
166
|
+
console.log(`Categories: ${(catalog.assets?.iconCategories ?? []).join(', ')}`);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function cmdSearchAssets(catalog, group, keyword = '', limitArg = '25') {
|
|
171
|
+
const validGroups = ['illustrations', 'logos', 'motions'];
|
|
172
|
+
if (!validGroups.includes(group)) {
|
|
173
|
+
console.error(`Asset group must be one of: ${validGroups.join(', ')}`);
|
|
174
|
+
process.exit(1);
|
|
175
|
+
}
|
|
176
|
+
const limit = Math.max(1, Number.parseInt(limitArg, 10) || 25);
|
|
177
|
+
const lower = keyword.toLowerCase();
|
|
178
|
+
const list = catalog.assets?.[group] ?? [];
|
|
179
|
+
const matches = list.filter(
|
|
180
|
+
(entry) =>
|
|
181
|
+
!lower ||
|
|
182
|
+
entry.name.toLowerCase().includes(lower) ||
|
|
183
|
+
(entry.category && entry.category.toLowerCase().includes(lower)) ||
|
|
184
|
+
(entry.title && entry.title.toLowerCase().includes(lower)),
|
|
185
|
+
);
|
|
186
|
+
console.log(
|
|
187
|
+
`Matched ${matches.length} ${group}${lower ? ` for "${keyword}"` : ''} (showing ${Math.min(limit, matches.length)}):`,
|
|
188
|
+
);
|
|
189
|
+
for (const item of matches.slice(0, limit)) {
|
|
190
|
+
if (group === 'motions') {
|
|
191
|
+
console.log(
|
|
192
|
+
`- ${item.name} [${item.category}, themes: ${item.themes.join('/')}, ${item.format}, ${item.bytes}B]`,
|
|
193
|
+
);
|
|
194
|
+
} else if (group === 'logos') {
|
|
195
|
+
console.log(`- ${item.name} (${item.title}) [${item.width}x${item.height}, ${item.format}]`);
|
|
196
|
+
} else {
|
|
197
|
+
console.log(
|
|
198
|
+
`- ${item.name} [themes: ${item.themes.join('/')}, ${item.width}x${item.height}, ${item.format}]`,
|
|
199
|
+
);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
function cmdTemplates(catalog) {
|
|
205
|
+
const templates = catalog.templates ?? [];
|
|
206
|
+
console.log(`Available Templates (${templates.length}):`);
|
|
207
|
+
for (const tpl of templates) {
|
|
208
|
+
console.log(`\n## ${tpl.id} — ${tpl.title}`);
|
|
209
|
+
console.log(tpl.summary);
|
|
210
|
+
if (tpl.brands?.length) console.log(`Brands: ${tpl.brands.join(', ')}`);
|
|
211
|
+
if (tpl.pages?.length) console.log(`Pages: ${tpl.pages.join(', ')}`);
|
|
212
|
+
if (tpl.blocks?.length) console.log(`Blocks: ${tpl.blocks.join(', ')}`);
|
|
213
|
+
if (tpl.motions?.length) console.log(`PAG Motions: ${tpl.motions.join(', ')}`);
|
|
214
|
+
console.log(`Components: ${tpl.components.join(', ')}`);
|
|
215
|
+
console.log(`Pull source: node query-catalog.mjs template ${tpl.id} --html | --tsx`);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
function cmdTemplate(catalog, id, formatFlag = '--html') {
|
|
220
|
+
const templates = catalog.templates ?? [];
|
|
221
|
+
const tpl = templates.find((t) => t.id === id);
|
|
222
|
+
if (!tpl) {
|
|
223
|
+
console.error(`Unknown template "${id}". Available: ${templates.map((t) => t.id).join(', ')}`);
|
|
224
|
+
process.exit(1);
|
|
225
|
+
}
|
|
226
|
+
const ext = formatFlag === '--tsx' ? 'tsx' : 'html';
|
|
227
|
+
const filePath = path.join(TEMPLATES_DIR, `${tpl.id}.${ext}`);
|
|
228
|
+
if (!fs.existsSync(filePath)) {
|
|
229
|
+
console.error(`Missing template file: ${filePath}. Run "pnpm build:catalog" first.`);
|
|
230
|
+
process.exit(1);
|
|
231
|
+
}
|
|
232
|
+
process.stdout.write(fs.readFileSync(filePath, 'utf8'));
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
function cmdRecipes(catalog, keyword = '') {
|
|
236
|
+
const lower = keyword.toLowerCase();
|
|
237
|
+
const matches = (catalog.recipes ?? []).filter(
|
|
238
|
+
(r) =>
|
|
239
|
+
!lower ||
|
|
240
|
+
r.id.toLowerCase().includes(lower) ||
|
|
241
|
+
r.title.toLowerCase().includes(lower) ||
|
|
242
|
+
r.summary.toLowerCase().includes(lower),
|
|
243
|
+
);
|
|
244
|
+
for (const r of matches) {
|
|
245
|
+
console.log(`\n## ${r.title} (${r.id})`);
|
|
246
|
+
console.log(r.summary);
|
|
247
|
+
console.log(`Components: ${r.components.join(', ')}`);
|
|
248
|
+
if (r.cdnUrls) {
|
|
249
|
+
console.log(`CDN CSS: ${r.cdnUrls.css}`);
|
|
250
|
+
console.log(`CDN JS: ${r.cdnUrls.js}`);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
const [, , subcmd, ...rest] = process.argv;
|
|
256
|
+
const catalog = loadCatalog();
|
|
257
|
+
|
|
258
|
+
switch (subcmd) {
|
|
259
|
+
case 'info':
|
|
260
|
+
cmdInfo(catalog);
|
|
261
|
+
break;
|
|
262
|
+
case 'list-components':
|
|
263
|
+
cmdListComponents(catalog, rest[0]);
|
|
264
|
+
break;
|
|
265
|
+
case 'component':
|
|
266
|
+
cmdComponent(catalog, rest[0]);
|
|
267
|
+
break;
|
|
268
|
+
case 'brands':
|
|
269
|
+
cmdBrands(catalog, rest[0]);
|
|
270
|
+
break;
|
|
271
|
+
case 'search-icons':
|
|
272
|
+
cmdSearchIcons(catalog, rest[0], rest[1]);
|
|
273
|
+
break;
|
|
274
|
+
case 'search-assets':
|
|
275
|
+
cmdSearchAssets(catalog, rest[0], rest[1], rest[2]);
|
|
276
|
+
break;
|
|
277
|
+
case 'templates':
|
|
278
|
+
cmdTemplates(catalog);
|
|
279
|
+
break;
|
|
280
|
+
case 'template':
|
|
281
|
+
cmdTemplate(catalog, rest[0], rest[1]);
|
|
282
|
+
break;
|
|
283
|
+
case 'recipes':
|
|
284
|
+
cmdRecipes(catalog, rest[0]);
|
|
285
|
+
break;
|
|
286
|
+
default:
|
|
287
|
+
usage();
|
|
288
|
+
if (subcmd) process.exit(1);
|
|
289
|
+
}
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
|
|
6
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
7
|
+
const __dirname = path.dirname(__filename);
|
|
8
|
+
const CATALOG_PATH = path.resolve(__dirname, '../references/catalog.json');
|
|
9
|
+
|
|
10
|
+
function loadCatalog() {
|
|
11
|
+
if (!fs.existsSync(CATALOG_PATH)) {
|
|
12
|
+
console.error(`Missing catalog.json at ${CATALOG_PATH}. Run "pnpm build:catalog" first.`);
|
|
13
|
+
process.exit(1);
|
|
14
|
+
}
|
|
15
|
+
return JSON.parse(fs.readFileSync(CATALOG_PATH, 'utf8'));
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function lineNumberAt(text, index) {
|
|
19
|
+
return text.slice(0, index).split('\n').length;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Finds JSX opening tags `<TagName ...>` handling nested `{...}` expressions and quotes.
|
|
24
|
+
*/
|
|
25
|
+
function findJsxOpeningTags(source, tagName) {
|
|
26
|
+
const results = [];
|
|
27
|
+
const startRegex = new RegExp(`<${tagName}(?=[\\s/>])`, 'g');
|
|
28
|
+
let match;
|
|
29
|
+
while ((match = startRegex.exec(source)) !== null) {
|
|
30
|
+
let idx = match.index + match[0].length;
|
|
31
|
+
let braceDepth = 0;
|
|
32
|
+
let quote = null;
|
|
33
|
+
while (idx < source.length) {
|
|
34
|
+
const ch = source[idx];
|
|
35
|
+
if (quote) {
|
|
36
|
+
if (ch === '\\') {
|
|
37
|
+
idx += 2;
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
if (ch === quote) quote = null;
|
|
41
|
+
} else {
|
|
42
|
+
if (ch === '"' || ch === "'" || ch === '`') {
|
|
43
|
+
quote = ch;
|
|
44
|
+
} else if (ch === '{') {
|
|
45
|
+
braceDepth++;
|
|
46
|
+
} else if (ch === '}') {
|
|
47
|
+
if (braceDepth > 0) braceDepth--;
|
|
48
|
+
} else if (ch === '>' && braceDepth === 0) {
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
idx++;
|
|
53
|
+
}
|
|
54
|
+
const attrs = source.slice(match.index + match[0].length, idx);
|
|
55
|
+
results.push({ index: match.index, attrs });
|
|
56
|
+
}
|
|
57
|
+
return results;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function extractStringLiteralProp(attrs, propName) {
|
|
61
|
+
const patterns = [
|
|
62
|
+
new RegExp(`\\b${propName}\\s*=\\s*(["'])([^"']+)\\1`),
|
|
63
|
+
new RegExp(`\\b${propName}\\s*=\\s*\\{\\s*(["'])([^"']+)\\1\\s*\\}`),
|
|
64
|
+
];
|
|
65
|
+
for (const re of patterns) {
|
|
66
|
+
const m = attrs.match(re);
|
|
67
|
+
if (m) return m[2];
|
|
68
|
+
}
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function main() {
|
|
73
|
+
const targetArg = process.argv[2];
|
|
74
|
+
if (!targetArg) {
|
|
75
|
+
console.error('Usage: node verify-demo.mjs <path-to-demo.html|tsx>');
|
|
76
|
+
process.exit(1);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const targetPath = path.resolve(process.cwd(), targetArg);
|
|
80
|
+
if (!fs.existsSync(targetPath)) {
|
|
81
|
+
console.error(`File not found: ${targetPath}`);
|
|
82
|
+
process.exit(1);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const catalog = loadCatalog();
|
|
86
|
+
const content = fs.readFileSync(targetPath, 'utf8');
|
|
87
|
+
const isHtml = targetPath.toLowerCase().endsWith('.html');
|
|
88
|
+
|
|
89
|
+
const sets = {
|
|
90
|
+
TPIcon: new Set((catalog.assets?.icons ?? []).map((i) => i.name)),
|
|
91
|
+
TPIllustration: new Set((catalog.assets?.illustrations ?? []).map((i) => i.name)),
|
|
92
|
+
TPBrandLogo: new Set((catalog.assets?.logos ?? []).map((l) => l.name)),
|
|
93
|
+
TPMotion: new Set((catalog.assets?.motions ?? []).map((m) => m.name)),
|
|
94
|
+
};
|
|
95
|
+
const validBrands = new Set((catalog.tokens?.brands ?? []).map((b) => b.id));
|
|
96
|
+
|
|
97
|
+
const errors = [];
|
|
98
|
+
const warnings = [];
|
|
99
|
+
let checkedAssetSlugs = 0;
|
|
100
|
+
|
|
101
|
+
// 1. Validate static asset slug literals against catalog.json
|
|
102
|
+
for (const [tag, validSet] of Object.entries(sets)) {
|
|
103
|
+
for (const opening of findJsxOpeningTags(content, tag)) {
|
|
104
|
+
const slug = extractStringLiteralProp(opening.attrs, 'name');
|
|
105
|
+
if (!slug) continue;
|
|
106
|
+
checkedAssetSlugs++;
|
|
107
|
+
if (!validSet.has(slug)) {
|
|
108
|
+
const line = lineNumberAt(content, opening.index);
|
|
109
|
+
errors.push(
|
|
110
|
+
`Line ${line}: Unknown <${tag} name="${slug}">. Query valid slugs with query-catalog.mjs.`,
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// Also check TPEmptyState illustration="..." slug literals
|
|
117
|
+
for (const opening of findJsxOpeningTags(content, 'TPEmptyState')) {
|
|
118
|
+
const slug = extractStringLiteralProp(opening.attrs, 'illustration');
|
|
119
|
+
if (!slug) continue;
|
|
120
|
+
checkedAssetSlugs++;
|
|
121
|
+
if (!sets.TPIllustration.has(slug)) {
|
|
122
|
+
const line = lineNumberAt(content, opening.index);
|
|
123
|
+
errors.push(
|
|
124
|
+
`Line ${line}: Unknown <TPEmptyState illustration="${slug}">. Query valid illustrations with query-catalog.mjs search-assets illustrations.`,
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// 2. Ensure <TPThemeProvider is present in standalone HTML demos
|
|
130
|
+
if (isHtml && !content.includes('<TPThemeProvider')) {
|
|
131
|
+
errors.push(
|
|
132
|
+
'Missing <TPThemeProvider>: Single-file HTML demos must wrap the root UI with <TPThemeProvider>.',
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// Validate TPThemeProvider brand/defaultBrand string literals
|
|
137
|
+
for (const opening of findJsxOpeningTags(content, 'TPThemeProvider')) {
|
|
138
|
+
for (const attr of ['brand', 'defaultBrand']) {
|
|
139
|
+
const val = extractStringLiteralProp(opening.attrs, attr);
|
|
140
|
+
if (val && !validBrands.has(val)) {
|
|
141
|
+
const line = lineNumberAt(content, opening.index);
|
|
142
|
+
errors.push(
|
|
143
|
+
`Line ${line}: Invalid <TPThemeProvider ${attr}="${val}">. Valid brands: ${[...validBrands].join(', ')}.`,
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
if (/\b(themeMode|defaultThemeMode)\s*=/.test(opening.attrs)) {
|
|
148
|
+
const line = lineNumberAt(content, opening.index);
|
|
149
|
+
errors.push(
|
|
150
|
+
`Line ${line}: <TPThemeProvider> uses \`mode=\` / \`defaultMode=\` (not \`themeMode=\` / \`defaultThemeMode=\`).`,
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// 3. Catch <TPButton type=...> mistakes (should be variant= or htmlType=)
|
|
156
|
+
for (const opening of findJsxOpeningTags(content, 'TPButton')) {
|
|
157
|
+
if (/\btype\s*=/.test(opening.attrs)) {
|
|
158
|
+
const line = lineNumberAt(content, opening.index);
|
|
159
|
+
errors.push(
|
|
160
|
+
`Line ${line}: <TPButton> omits \`type=\`; use \`variant="primary" | "secondary" | "text" | "alert" | "tonal" | "in-card"\` or \`htmlType="button" | "submit" | "reset"\`.`,
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// 4. Warn if useTPToast is used without TPToastProvider in standalone HTML
|
|
166
|
+
if (isHtml && content.includes('useTPToast') && !content.includes('<TPToastProvider')) {
|
|
167
|
+
warnings.push(
|
|
168
|
+
'useTPToast() is referenced without <TPToastProvider>; wrap root UI inside <TPToastProvider> so toasts render.',
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// 5. Warn if standalone HTML uses <script type="module"> with standalone.js (breaks file:// CORS)
|
|
173
|
+
if (isHtml && /<script[^>]*type\s*=\s*["']module["'][^>]*>/i.test(content)) {
|
|
174
|
+
warnings.push(
|
|
175
|
+
'Single-file HTML demos should use classic <script> + <script type="text/babel"> (not type="module") so file:// opens without CORS errors.',
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
for (const w of warnings) {
|
|
180
|
+
console.warn(`WARN [${targetArg}]: ${w}`);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
if (errors.length > 0) {
|
|
184
|
+
for (const err of errors) {
|
|
185
|
+
console.error(`ERROR [${targetArg}] ${err}`);
|
|
186
|
+
}
|
|
187
|
+
process.exit(1);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
console.log(`PASS [${targetArg}]: verified ${checkedAssetSlugs} static asset slug(s), 0 TP-Mobile violations.`);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
main();
|