@fragments-sdk/mcp 0.8.1 → 0.10.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.
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/rules.ts"],"sourcesContent":["import { join } from 'node:path';\nimport { writeFileSync, mkdirSync, existsSync } from 'node:fs';\nimport type { McpComponent } from '@fragments-sdk/core';\nimport type { DesignSystemData } from './types.js';\nimport { getGuidanceWhen, getGuidanceWhenNot } from './snapshot-helpers.js';\n\nexport type RulesFormat = 'cursor' | 'claude' | 'copilot';\n\nexport interface RulesGeneratorOptions {\n data: DesignSystemData;\n brandName: string;\n outputDir: string;\n formats: RulesFormat[];\n /** Overwrite existing files (default: false — skip and warn) */\n force?: boolean;\n}\n\n/**\n * Generate IDE rules files from design system data.\n * Returns list of files written. Skips existing files unless force is true.\n */\nexport function generateRulesFiles(options: RulesGeneratorOptions): string[] {\n const { data, brandName, outputDir, formats, force = false } = options;\n const content = buildRulesContent(data, brandName);\n const files: string[] = [];\n\n for (const format of formats) {\n let filePath: string;\n let fileContent: string;\n\n switch (format) {\n case 'cursor':\n filePath = join(outputDir, '.cursorrules');\n fileContent = content;\n break;\n case 'claude':\n filePath = join(outputDir, 'CLAUDE.md');\n fileContent = `# CLAUDE.md\\n\\nThis file provides guidance to Claude Code when working with code in this repository.\\n\\n${content}`;\n break;\n case 'copilot': {\n const dir = join(outputDir, '.github');\n if (!existsSync(dir)) mkdirSync(dir, { recursive: true });\n filePath = join(dir, 'copilot-instructions.md');\n fileContent = content;\n break;\n }\n }\n\n if (!force && existsSync(filePath)) {\n console.error(` Skipped ${filePath} (already exists, use --force to overwrite)`);\n continue;\n }\n\n writeFileSync(filePath, fileContent, 'utf-8');\n files.push(filePath);\n }\n\n return files;\n}\n\nfunction buildRulesContent(data: DesignSystemData, brandName: string): string {\n const sections: string[] = [];\n\n // Header\n sections.push(`# ${brandName} Design System Rules\\n`);\n sections.push(`Always use ${brandName} components and design tokens when building UI. Do not use raw HTML elements, Tailwind classes, or hardcoded CSS values when a design system component or token exists.\\n`);\n\n // Component inventory\n const components: McpComponent[] = Object.values(data.components);\n if (components.length > 0) {\n sections.push('## Components\\n');\n const byCategory = new Map<string, string[]>();\n for (const c of components) {\n const cat = c.category || 'uncategorized';\n if (!byCategory.has(cat)) byCategory.set(cat, []);\n byCategory.get(cat)!.push(c.name);\n }\n for (const [cat, names] of byCategory) {\n sections.push(`### ${cat}\\n`);\n sections.push(names.map(n => `- ${n}`).join('\\n'));\n sections.push('');\n }\n }\n\n // Import pattern\n if (data.defaultPackageName) {\n sections.push('## Imports\\n');\n sections.push(`Import components from \\`${data.defaultPackageName}\\`:\\n`);\n sections.push('```typescript');\n const exampleNames = components.slice(0, 3).map(c => c.name);\n sections.push(`import { ${exampleNames.join(', ')} } from '${data.defaultPackageName}';`);\n sections.push('```\\n');\n }\n\n // Tokens\n if (data.tokens && data.tokens.total > 0) {\n sections.push('## Design Tokens\\n');\n sections.push(`Prefix: \\`${data.tokens.prefix}\\`. Use \\`var(--token-name)\\` in CSS/styles.\\n`);\n sections.push('Available categories:');\n for (const [cat, tokens] of Object.entries(data.tokens.categories) as Array<\n [string, typeof data.tokens.categories[string]]\n >) {\n sections.push(`- **${cat}** (${tokens.length} tokens)`);\n }\n sections.push('');\n }\n\n // Usage guidelines (aggregated from all components)\n const allDos: string[] = [];\n const allDonts: string[] = [];\n for (const c of components) {\n allDos.push(...getGuidanceWhen(c).slice(0, 1).map(w => `${c.name}: ${w}`));\n allDonts.push(...getGuidanceWhenNot(c).slice(0, 1).map(w => `${c.name}: ${w}`));\n }\n if (allDos.length > 0 || allDonts.length > 0) {\n sections.push('## Usage Guidelines\\n');\n if (allDos.length > 0) {\n sections.push('**Do:**');\n sections.push(allDos.slice(0, 10).map(d => `- ${d}`).join('\\n'));\n sections.push('');\n }\n if (allDonts.length > 0) {\n sections.push('**Don\\'t:**');\n sections.push(allDonts.slice(0, 10).map(d => `- ${d}`).join('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AmB,CAAC,EAAE,MAAM,GAAG,CAAC,EAAE,IAAI,OAAK,GAAG,EAAE,IAAI,KAAK,CAAC,EAAE,CAAC;AAAA,EAChF;AACA,MAAI,OAAO,SAAS,KAAK,SAAS,SAAS,GAAG;AAC5C,aAAS,KAAK,uBAAuB;AACrC,QAAI,OAAO,SAAS,GAAG;AACrB,eAAS,KAAK,SAAS;AACvB,eAAS,KAAK,OAAO,MAAM,GAAG,EAAE,EAAE,IAAI,OAAK,KAAK,CAAC,EAAE,EAAE,KAAK,IAAI,CAAC;AAC/D,eAAS,KAAK,EAAE;AAAA,IAClB;AACA,QAAI,SAAS,SAAS,GAAG;AACvB,eAAS,KAAK,YAAa;AAC3B,eAAS,KAAK,SAAS,MAAM,GAAG,EAAE,EAAE,IAAI,OAAK,KAAK,CAAC,EAAE,EAAE,KAAK,IAAI,CAAC;AACjE,eAAS,KAAK,EAAE;AAAA,IAClB;AAAA,EACF;AAEA,SAAO,SAAS,KAAK,IAAI;AAC3B;","names":[]}
@@ -1,93 +0,0 @@
1
- // src/snapshot-helpers.ts
2
- function listComponents(snapshot) {
3
- return Object.values(snapshot.components);
4
- }
5
- function componentNames(snapshot) {
6
- return listComponents(snapshot).map((component) => component.name);
7
- }
8
- function listBlocks(snapshot) {
9
- return Object.values(snapshot.blocks ?? {});
10
- }
11
- function findComponentByName(snapshot, name) {
12
- const query = name.toLowerCase();
13
- return listComponents(snapshot).find(
14
- (component) => component.name.toLowerCase() === query
15
- );
16
- }
17
- function normalizeComponentRef(value) {
18
- return value.trim().toLowerCase();
19
- }
20
- function buildCompoundComponent(parent, childName) {
21
- const child = parent.compoundChildren.find(
22
- (entry) => normalizeComponentRef(entry.name) === normalizeComponentRef(childName)
23
- );
24
- if (!child) return void 0;
25
- const fullName = child.name.includes(".") ? child.name : `${parent.name}.${child.name}`;
26
- return {
27
- ...parent,
28
- id: child.componentId ?? `${parent.id}::${fullName}`,
29
- name: fullName,
30
- description: child.description ?? "",
31
- props: {},
32
- propsSummary: [],
33
- examples: [],
34
- relations: [],
35
- compoundChildren: [],
36
- publicRef: child.componentId ?? fullName,
37
- publicSlug: null,
38
- parentComponentId: parent.id,
39
- parentComponentName: parent.name
40
- };
41
- }
42
- function findComponent(snapshot, reference) {
43
- const query = normalizeComponentRef(reference);
44
- const components = listComponents(snapshot);
45
- const exact = components.find((component) => {
46
- return normalizeComponentRef(component.name) === query || normalizeComponentRef(component.id) === query || normalizeComponentRef(component.publicRef ?? "") === query;
47
- });
48
- if (exact) return exact;
49
- if (reference.includes(".")) {
50
- const [parentName, ...childParts] = reference.split(".");
51
- const childName = childParts.join(".");
52
- const parent = components.find((component) => {
53
- return normalizeComponentRef(component.name) === normalizeComponentRef(parentName) || normalizeComponentRef(component.publicRef ?? "") === normalizeComponentRef(parentName) || normalizeComponentRef(component.id) === normalizeComponentRef(parentName);
54
- });
55
- if (parent) {
56
- const child = buildCompoundComponent(parent, childName);
57
- if (child) return child;
58
- }
59
- }
60
- return void 0;
61
- }
62
- function getGuidanceWhen(component) {
63
- if (component.guidance.when.length > 0) {
64
- return component.guidance.when;
65
- }
66
- if (component.guidance.usageGuidance) {
67
- return [component.guidance.usageGuidance];
68
- }
69
- if (component.guidance.dos.length > 0) {
70
- return component.guidance.dos;
71
- }
72
- return [];
73
- }
74
- function getGuidanceWhenNot(component) {
75
- if (component.guidance.whenNot.length > 0) {
76
- return component.guidance.whenNot;
77
- }
78
- if (component.guidance.donts.length > 0) {
79
- return component.guidance.donts;
80
- }
81
- return [];
82
- }
83
-
84
- export {
85
- listComponents,
86
- componentNames,
87
- listBlocks,
88
- findComponentByName,
89
- findComponent,
90
- getGuidanceWhen,
91
- getGuidanceWhenNot
92
- };
93
- //# sourceMappingURL=chunk-YSRGQDEB.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/snapshot-helpers.ts"],"sourcesContent":["import type { McpBlock, McpComponent, McpSnapshot } from '@fragments-sdk/core';\n\nexport type ResolvedMcpComponent = McpComponent & {\n isCanonical?: boolean;\n};\n\nexport function listComponents(\n snapshot: Pick<McpSnapshot, 'components'>,\n): ResolvedMcpComponent[] {\n return Object.values(snapshot.components);\n}\n\nexport function componentNames(snapshot: Pick<McpSnapshot, 'components'>): string[] {\n return listComponents(snapshot).map((component) => component.name);\n}\n\nexport function listBlocks(snapshot: Pick<McpSnapshot, 'blocks'>): McpBlock[] {\n return Object.values(snapshot.blocks ?? {});\n}\n\nexport function findComponentByName(\n snapshot: Pick<McpSnapshot, 'components'>,\n name: string,\n): ResolvedMcpComponent | undefined {\n const query = name.toLowerCase();\n return listComponents(snapshot).find(\n (component) => component.name.toLowerCase() === query,\n );\n}\n\nfunction normalizeComponentRef(value: string): string {\n return value.trim().toLowerCase();\n}\n\nfunction buildCompoundComponent(\n parent: ResolvedMcpComponent,\n childName: string,\n): ResolvedMcpComponent | undefined {\n const child = parent.compoundChildren.find(\n (entry) => normalizeComponentRef(entry.name) === normalizeComponentRef(childName),\n );\n if (!child) return undefined;\n\n const fullName = child.name.includes('.')\n ? child.name\n : `${parent.name}.${child.name}`;\n\n return {\n ...parent,\n id: child.componentId ?? `${parent.id}::${fullName}`,\n name: fullName,\n description: child.description ?? '',\n props: {},\n propsSummary: [],\n examples: [],\n relations: [],\n compoundChildren: [],\n publicRef: child.componentId ?? fullName,\n publicSlug: null,\n parentComponentId: parent.id,\n parentComponentName: parent.name,\n };\n}\n\nexport function findComponent(\n snapshot: Pick<McpSnapshot, 'components'>,\n reference: string,\n): ResolvedMcpComponent | undefined {\n const query = normalizeComponentRef(reference);\n const components = listComponents(snapshot);\n\n const exact = components.find((component) => {\n return (\n normalizeComponentRef(component.name) === query ||\n normalizeComponentRef(component.id) === query ||\n normalizeComponentRef(component.publicRef ?? '') === query\n );\n });\n if (exact) return exact;\n\n if (reference.includes('.')) {\n const [parentName, ...childParts] = reference.split('.');\n const childName = childParts.join('.');\n const parent = components.find((component) => {\n return (\n normalizeComponentRef(component.name) === normalizeComponentRef(parentName) ||\n normalizeComponentRef(component.publicRef ?? '') ===\n normalizeComponentRef(parentName) ||\n normalizeComponentRef(component.id) === normalizeComponentRef(parentName)\n );\n });\n\n if (parent) {\n const child = buildCompoundComponent(parent, childName);\n if (child) return child;\n }\n }\n\n return undefined;\n}\n\nexport function getGuidanceWhen(component: ResolvedMcpComponent): string[] {\n if (component.guidance.when.length > 0) {\n return component.guidance.when;\n }\n if (component.guidance.usageGuidance) {\n return [component.guidance.usageGuidance];\n }\n if (component.guidance.dos.length > 0) {\n return component.guidance.dos;\n }\n return [];\n}\n\nexport function getGuidanceWhenNot(component: ResolvedMcpComponent): string[] {\n if (component.guidance.whenNot.length > 0) {\n return component.guidance.whenNot;\n }\n if (component.guidance.donts.length > 0) {\n return component.guidance.donts;\n }\n return [];\n}\n"],"mappings":";AAMO,SAAS,eACd,UACwB;AACxB,SAAO,OAAO,OAAO,SAAS,UAAU;AAC1C;AAEO,SAAS,eAAe,UAAqD;AAClF,SAAO,eAAe,QAAQ,EAAE,IAAI,CAAC,cAAc,UAAU,IAAI;AACnE;AAEO,SAAS,WAAW,UAAmD;AAC5E,SAAO,OAAO,OAAO,SAAS,UAAU,CAAC,CAAC;AAC5C;AAEO,SAAS,oBACd,UACA,MACkC;AAClC,QAAM,QAAQ,KAAK,YAAY;AAC/B,SAAO,eAAe,QAAQ,EAAE;AAAA,IAC9B,CAAC,cAAc,UAAU,KAAK,YAAY,MAAM;AAAA,EAClD;AACF;AAEA,SAAS,sBAAsB,OAAuB;AACpD,SAAO,MAAM,KAAK,EAAE,YAAY;AAClC;AAEA,SAAS,uBACP,QACA,WACkC;AAClC,QAAM,QAAQ,OAAO,iBAAiB;AAAA,IACpC,CAAC,UAAU,sBAAsB,MAAM,IAAI,MAAM,sBAAsB,SAAS;AAAA,EAClF;AACA,MAAI,CAAC,MAAO,QAAO;AAEnB,QAAM,WAAW,MAAM,KAAK,SAAS,GAAG,IACpC,MAAM,OACN,GAAG,OAAO,IAAI,IAAI,MAAM,IAAI;AAEhC,SAAO;AAAA,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