-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(tokens): adds index-generator (#1204)
* feat: adds index-generator * fix: file namings
- Loading branch information
1 parent
baafea8
commit 09ea9b7
Showing
29 changed files
with
118 additions
and
101 deletions.
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
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export const buildpaths = { | ||
mjs_modules: '../ui-library/src/foundation/_tokens-generated/mjs_modules/', | ||
modul_declarations: '../ui-library/src/foundation/_tokens-generated/module_declarations/', | ||
_tg: '../ui-library/src/foundation/_tokens-generated/', | ||
}; |
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,79 @@ | ||
import fs from 'fs'; | ||
import themes from './themes_generated.cjs'; | ||
import { buildpaths } from './buildpaths.mjs'; | ||
|
||
// # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # | ||
// Template for the generated file | ||
// # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # | ||
|
||
const fileTemplate = `import { makeIterator, joinCss } from '../../utils/css-in-ts/make-token-part-iterator.js'; | ||
{{imports}} | ||
export const componentTokenTree = { | ||
{{componentTree}} | ||
}; | ||
export const semanticTokenTree = { | ||
{{semanticTree}} | ||
}; | ||
export const ComponentThemeIterator = ( | ||
renderFunction: ( | ||
theme: keyof typeof componentTokenTree, | ||
cmp: typeof componentTokenTree.{{firstTheme}}, | ||
css: typeof joinCss, | ||
) => string, | ||
) => { | ||
const it = makeIterator<typeof componentTokenTree>(); | ||
return it(componentTokenTree, renderFunction); | ||
}; | ||
export const SemanticThemeIterator = ( | ||
renderFunction: ( | ||
theme: keyof typeof semanticTokenTree, | ||
sem: typeof semanticTokenTree.{{firstTheme}}, | ||
css: typeof joinCss, | ||
) => string, | ||
) => { | ||
const it = makeIterator<typeof semanticTokenTree>(); | ||
return it(semanticTokenTree, renderFunction); | ||
};`; | ||
|
||
// # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # | ||
// Generate imports, component tree, and semantic tree dynamically. Then fill the template. | ||
// # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # | ||
|
||
const imports = themes.array | ||
.map((theme) => { | ||
const prefix = theme.split('_')[0]; | ||
return `import { tokens as cmp${prefix} } from './mjs_modules/__component-tokens.${theme}.generated.mjs';\nimport { tokens as sem${prefix} } from './mjs_modules/__semantic-tokens.${theme}.generated.mjs';`; | ||
}) | ||
.join('\n'); | ||
|
||
const componentTree = themes.array | ||
.map((theme) => { | ||
const prefix = theme.split('_')[0]; | ||
return ` ${theme}: cmp${prefix}.cmp`; | ||
}) | ||
.join(',\n'); | ||
|
||
const semanticTree = themes.array | ||
.map((theme) => { | ||
const prefix = theme.split('_')[0]; | ||
return ` ${theme}: sem${prefix}.sem`; | ||
}) | ||
.join(',\n'); | ||
|
||
// Fill the template with the generated content | ||
const fileContent = fileTemplate | ||
.replace('{{imports}}', imports) | ||
.replace('{{componentTree}}', componentTree) | ||
.replace('{{semanticTree}}', semanticTree) | ||
.replace(/{{firstTheme}}/g, themes.array[0]); | ||
|
||
// Write the generated content to a new file | ||
fs.writeFileSync(`${buildpaths._tg}/iterator.generated.ts`, fileContent, 'utf-8'); | ||
|
||
console.log('File generated successfully!'); |
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
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
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
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
2 changes: 1 addition & 1 deletion
2
packages/ui-library/src/components/form-caption-group/index.css.ts
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
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
2 changes: 1 addition & 1 deletion
2
packages/ui-library/src/components/input-field-number/index.css.ts
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
2 changes: 1 addition & 1 deletion
2
packages/ui-library/src/components/input-field-text/index.css.ts
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
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
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
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
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
54 changes: 0 additions & 54 deletions
54
packages/ui-library/src/foundation/_tokens-generated/index.pseudo.generated.ts
This file was deleted.
Oops, something went wrong.
2 changes: 2 additions & 0 deletions
2
packages/ui-library/src/foundation/_tokens-generated/index.themes.ts
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,2 @@ | ||
export const Themes = ['Licht_value', 'Dunkel_value'] as const; | ||
export type ThemeType = (typeof Themes)[number]; |
2 changes: 1 addition & 1 deletion
2
packages/ui-library/src/foundation/semantic-tokens/action.css.ts
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