@finedesign/cli 0.9.0 → 0.11.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/CHANGELOG.md +16 -0
- package/README.md +10 -9
- package/data/1.25.1/catalog.json +1 -0
- package/data/1.25.1/manifest.json +16 -0
- package/data/index.json +5 -1
- package/package.json +1 -1
- package/skills/fine-design/references/component-guide.md +6 -3
- package/skills/fine-design/references/docs-slug-map.md +4 -4
- package/skills/fine-design/references/imports-and-setup.md +4 -7
- package/src/cli.mjs +57 -31
- package/src/core/catalog.mjs +108 -14
- package/src/core/contracts.mjs +5 -0
- package/src/core/figma.mjs +1 -0
- package/src/core/runtime.mjs +21 -10
- package/src/mcp.mjs +1 -0
package/src/core/runtime.mjs
CHANGED
|
@@ -4,31 +4,35 @@ import { exactVersion, readIndex, sha256 } from './data.mjs';
|
|
|
4
4
|
import { ToolError } from './errors.mjs';
|
|
5
5
|
import html from './html.cjs';
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
const defaultRuntimeURL = 'npm';
|
|
8
|
+
const npmRuntime = '@finedesign/runtime';
|
|
8
9
|
const hosted = { fineDesign: ['@fx-ui/fine-design', 'fine-design', 'fine-design.min.js'], fineDesignCss: ['@fx-ui/fine-design', 'fine-design', 'fine-design.min.css'], vanAnalysis: ['@van/analysis', 'van-analysis', 'van-analysis.min.js'], vanAnalysisCss: ['@van/analysis', 'van-analysis', 'van-analysis.min.css'] };
|
|
9
10
|
const requiredResources = ['fineDesignCss', 'react', 'reactDOM', 'fineDesign'];
|
|
10
11
|
const invalid = (message) => { throw new ToolError('RUNTIME_INVALID', message, 1); };
|
|
11
12
|
|
|
12
13
|
export function validateRuntimeManifest(manifest) {
|
|
13
|
-
|
|
14
|
+
const packaged = manifest?.package === npmRuntime;
|
|
15
|
+
const expected = packaged ? [...requiredResources] : ['react', 'reactDOM', ...Object.keys(hosted)];
|
|
16
|
+
if (manifest?.schemaVersion !== 1 || !exactVersion.test(manifest.version) || !manifest.resources || Object.keys(manifest.resources).sort().join(',') !== expected.sort().join(',')) invalid('Invalid current runtime manifest.');
|
|
14
17
|
for (const [key, entry] of Object.entries(manifest.resources)) {
|
|
15
18
|
if (!entry || !exactVersion.test(entry.version) || !/^[a-f0-9]{64}$/.test(entry.sha256) || entry.integrity !== `sha256-${Buffer.from(entry.sha256, 'hex').toString('base64')}` || !Number.isSafeInteger(entry.size) || entry.size <= 0 || entry.type !== (key.endsWith('Css') ? 'style' : 'script')) invalid(`Invalid runtime resource: ${key}`);
|
|
16
19
|
if (hosted[key]) {
|
|
17
20
|
const [pkg, directory, filename] = hosted[key];
|
|
18
|
-
|
|
21
|
+
const expectedPath = packaged ? filename : `${directory}/${entry.version}/${filename}`;
|
|
22
|
+
if (entry.package !== pkg || entry.path !== expectedPath || entry.url) invalid(`Unexpected versioned resource path: ${key}`);
|
|
19
23
|
} else {
|
|
20
24
|
const pkg = key === 'react' ? 'react' : 'react-dom';
|
|
21
25
|
if (entry.package !== pkg || entry.path || entry.url !== `https://cdn.jsdelivr.net/npm/${pkg}@${entry.version}/umd/${pkg}.production.min.js`) invalid(`Unexpected React runtime: ${key}`);
|
|
22
26
|
}
|
|
23
27
|
}
|
|
24
28
|
const r = manifest.resources;
|
|
25
|
-
if (r.fineDesign.version !== manifest.version || r.fineDesignCss.version !== manifest.version || r.react.version !== r.reactDOM.version || r.vanAnalysis.version !== r.vanAnalysisCss.version) invalid('Runtime package versions do not match.');
|
|
29
|
+
if (r.fineDesign.version !== manifest.version || r.fineDesignCss.version !== manifest.version || r.react.version !== r.reactDOM.version || (!packaged && r.vanAnalysis.version !== r.vanAnalysisCss.version)) invalid('Runtime package versions do not match.');
|
|
26
30
|
return manifest;
|
|
27
31
|
}
|
|
28
32
|
|
|
29
|
-
async function readRuntime(value = defaultRuntimeURL) {
|
|
33
|
+
async function readRuntime(value = defaultRuntimeURL, version) {
|
|
30
34
|
let base;
|
|
31
|
-
try { base = new URL(value); } catch { invalid('Invalid runtime URL.'); }
|
|
35
|
+
try { base = new URL(value === 'npm' ? `https://cdn.jsdelivr.net/npm/${npmRuntime}@${version || 'latest'}/` : value); } catch { invalid('Invalid runtime URL.'); }
|
|
32
36
|
if ((base.protocol !== 'https:' && !(base.protocol === 'http:' && ['127.0.0.1', 'localhost', '[::1]'].includes(base.hostname))) || base.username || base.password || base.search || base.hash) invalid('Use an HTTPS runtime URL without credentials, query or fragment; HTTP is allowed on loopback.');
|
|
33
37
|
if (!base.pathname.endsWith('/')) base.pathname += '/';
|
|
34
38
|
const manifestURL = new URL('manifest.json', base);
|
|
@@ -50,7 +54,9 @@ async function readRuntime(value = defaultRuntimeURL) {
|
|
|
50
54
|
suggestions: ['Check access to the manifest from this environment or pass --runtime-url with a verified host.']
|
|
51
55
|
});
|
|
52
56
|
}
|
|
53
|
-
|
|
57
|
+
validateRuntimeManifest(manifest);
|
|
58
|
+
if (value === 'npm' && manifest.package !== npmRuntime) invalid('Expected the public npm runtime manifest.');
|
|
59
|
+
return { runtimeURL: base.href, manifestURL: manifestURL.href, manifest };
|
|
54
60
|
}
|
|
55
61
|
|
|
56
62
|
export async function listRuntimes(runtimeURL) {
|
|
@@ -60,15 +66,20 @@ export async function listRuntimes(runtimeURL) {
|
|
|
60
66
|
|
|
61
67
|
export async function resolveRuntime({ version, runtimeURL }) {
|
|
62
68
|
if (version !== undefined && !exactVersion.test(version)) throw new ToolError('INVALID_ARGUMENT', 'Specify an exact component version.', 2);
|
|
63
|
-
|
|
69
|
+
if (!version && (runtimeURL ?? defaultRuntimeURL) === 'npm') {
|
|
70
|
+
const { versions } = await listRuntimes('npm');
|
|
71
|
+
version = versions[0];
|
|
72
|
+
}
|
|
73
|
+
const current = await readRuntime(runtimeURL, version);
|
|
64
74
|
const targetVersion = version || current.manifest.version;
|
|
65
|
-
if (current.manifest.version !== targetVersion) throw new ToolError('RUNTIME_VERSION_NOT_FOUND', `
|
|
75
|
+
if (current.manifest.version !== targetVersion) throw new ToolError('RUNTIME_VERSION_NOT_FOUND', `The runtime manifest contains Fine Design ${current.manifest.version}; requested ${targetVersion}.`, 3, { availableVersions: [current.manifest.version] });
|
|
66
76
|
const resources = Object.fromEntries(Object.entries(current.manifest.resources).map(([key, entry]) => [key, { ...entry, url: entry.url || new URL(entry.path, current.manifestURL).href }]));
|
|
67
77
|
const tags = requiredResources.map((key) => {
|
|
68
78
|
const entry = resources[key];
|
|
69
79
|
return entry.type === 'style' ? `<link rel="stylesheet" href="${entry.url}" integrity="${entry.integrity}" crossorigin="anonymous">` : `<script src="${entry.url}" integrity="${entry.integrity}" crossorigin="anonymous"></script>`;
|
|
70
80
|
}).join('\n');
|
|
71
|
-
|
|
81
|
+
const example = current.manifest.package === npmRuntime ? {} : { exampleURL: new URL('index.html', current.runtimeURL).href };
|
|
82
|
+
return { version: targetVersion, docsAvailable: Object.hasOwn(readIndex().versions, targetVersion), manifestURL: current.manifestURL, ...example, resources, tags };
|
|
72
83
|
}
|
|
73
84
|
|
|
74
85
|
export async function exportRuntime(runtime, output, dryRun = false) {
|
package/src/mcp.mjs
CHANGED
|
@@ -24,6 +24,7 @@ export async function startMcp() {
|
|
|
24
24
|
search_components: 'Search components, subcomponents and built-in icons. Version is optional and defaults to the project or latest bundled version; use nextOffset to browse subsequent pages.',
|
|
25
25
|
get_component_doc: 'Read component documentation, or pass summary: true to list section headings and example IDs first. Version is optional.',
|
|
26
26
|
get_component_info: 'Show component overview, exports, aliases and API/props table sections. Version is optional.',
|
|
27
|
+
get_generation_context: 'Get a compact API and example index for one to six components. Provide the exact Fine Design version and follow section or example references for details.',
|
|
27
28
|
get_component_tokens: 'Inspect component or global Design Tokens and their default values. Version is optional.',
|
|
28
29
|
diff_catalogs: 'Compare documentation sections, examples and aliases between versions, optionally for one component. Migration guidance is general, not version-specific.',
|
|
29
30
|
lint_files: 'Scan code for Fine Design API traps. Pass an exact version if it cannot be detected from the targets.',
|