Skip to content

Commit 3f2bd36

Browse files
committed
chore(internals): generate custom data references
Signed-off-by: John Yanarella <jyanarella@nvidia.com>
1 parent 9a874bd commit 3f2bd36

3 files changed

Lines changed: 32 additions & 5 deletions

File tree

‎projects/internals/eslint/src/configs/typescript.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ const config = {
159159
reflect: {name: false},
160160
command: {name: true},
161161
entrypoint: {name: true},
162+
documentation: {name: true},
162163
tags: {name: true},
163164
aria: {name: true},
164165
experimental: {name: true},

‎projects/internals/vite/src/plugins/cem.config.mjs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ function metadataPlugin() {
4141
'since',
4242
'axe',
4343
'entrypoint',
44-
'example'
44+
'example',
45+
'documentation'
4546
];
4647

4748
switch(node.kind){

‎projects/internals/vite/src/plugins/cem.js‎

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,31 @@ import { generateVsCodeCustomElementData } from 'custom-element-vs-code-integrat
55

66
constresolve=rel=>path.join(process.cwd(),rel);
77

8+
functionnormalizeURL(value){
9+
if(typeofvalue!=='string'){
10+
returnnull;
11+
}
12+
13+
try{
14+
consturl=newURL(value);
15+
returnurl.protocol==='https:' ? url.href : null;
16+
}catch{
17+
returnnull;
18+
}
19+
}
20+
21+
constreferenceNameByMetadataName={
22+
aria: 'WAI-ARIA Reference',
23+
documentation: 'Documentation'
24+
};
25+
26+
functiongenerateVsCodeCustomElementDataReference(manifestMetadataName,manifestMetadataValue){
27+
constname=referenceNameByMetadataName[manifestMetadataName];
28+
consturl=normalizeURL(manifestMetadataValue);
29+
30+
returnname&&url ? { name, url } : null;
31+
}
32+
833
/**
934
* Generates a Custom Elements Manifest on initial build
1035
*/
@@ -41,10 +66,10 @@ export function cem() {
4166
constdeclaration=vsCodeManifest.modules
4267
.flatMap(module=>module.declarations)
4368
.find(d=>d.tagName===tag);
44-
constreferences=Object.keys(declaration.metadata??{})
45-
.map(name=>({name,url: declaration.metadata[name]}))
46-
.filter(ref=>ref.url?.includes&&ref.url.includes('http'));
47-
returnreferences;
69+
returnObject.entries(declaration?.metadata??{}).flatMap(([name,value])=>{
70+
constreference=generateVsCodeCustomElementDataReference(name,value);
71+
returnreference ? [reference] : [];
72+
});
4873
}
4974
});
5075
}

0 commit comments

Comments
 (0)