Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: automate system tokens in manifests (#1003)
- Loading branch information
1 parent
40bb42f
commit fca7437
Showing
3 changed files
with
42 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
"@patternfly/elements": patch | ||
--- | ||
Updated design system token metadata in custom elements manifest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { readFile, writeFile } from 'node:fs/promises'; | ||
import { tokens } from '@rhds/tokens/meta.js'; | ||
|
||
/** token type names to css syntax data types */ | ||
const syntaxes = new Map(Object.entries({ | ||
color: '<color>', | ||
dimension: '<length>', | ||
fontFamily: '<custom-ident>|string+', | ||
fontWeight: '<integer>', | ||
shadow: '<shadow>', | ||
})); | ||
|
||
/** @return {decl is import('custom-elements-manifest').CustomElementDeclaration} */ | ||
const isCustomElementDeclaration = decl => decl.customElement; | ||
|
||
/** file to modify */ | ||
const url = new URL('../custom-elements.json', import.meta.url); | ||
|
||
/** @type{import('custom-elements-manifest').Package} */ | ||
const manifest = JSON.parse(await readFile(url, 'utf8')); | ||
|
||
for (const mod of manifest.modules) { | ||
for (const decl of mod.declarations) { | ||
if (isCustomElementDeclaration(decl)) { | ||
for (const prop of decl?.cssProperties ?? []) { | ||
const token = tokens.get(prop.name); | ||
if (token) { | ||
prop.description = token.$description; | ||
prop.syntax = syntaxes.get(token.$type) ?? token.$type; | ||
prop.default = token.$value.toString(); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
await writeFile(url, JSON.stringify(manifest, null, 2), 'utf8'); |