-
Notifications
You must be signed in to change notification settings - Fork 2.9k
chore(react-theme): Generate theme tokens using token pipeline #22457
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
miroslavstastny
merged 9 commits into
microsoft:master
from
miroslavstastny:chore/token-pipeline-script
May 5, 2022
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
229f7e9
chore(react-theme): Generate theme tokens using token pipeline
miroslavstastny ed60124
update type
miroslavstastny 04443a2
Merge remote-tracking branch 'upstream/master' into chore/token-pipel…
miroslavstastny fd98616
Address PR comments
miroslavstastny abbf1c2
Merge remote-tracking branch 'upstream/master' into chore/token-pipel…
miroslavstastny 999df2f
Do not register the script as just task
miroslavstastny 80a73ed
Merge remote-tracking branch 'upstream/master' into chore/token-pipel…
miroslavstastny 3522b70
Update paths to reflect the new location of react-theme
miroslavstastny e86df5e
Change file
miroslavstastny File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
7 changes: 7 additions & 0 deletions
7
change/@fluentui-react-theme-d0c1d611-9a7f-4ebe-a610-7a585d38212f.json
This file contains hidden or 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,7 @@ | ||
| { | ||
| "type": "none", | ||
| "comment": "Generate theme tokens using token pipeline", | ||
| "packageName": "@fluentui/react-theme", | ||
| "email": "[email protected]", | ||
| "dependentChangeType": "none" | ||
| } |
This file contains hidden or 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 hidden or 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,58 @@ | ||
| import path from 'path'; | ||
| import * as fs from 'fs-extra'; | ||
| import * as _ from 'lodash'; | ||
|
|
||
| import { findGitRoot } from './monorepo'; | ||
| import execSync from './exec-sync'; | ||
| import { createTempDir } from './projects-test'; | ||
|
|
||
| const themes = ['light', 'dark', 'teamsDark', 'highContrast'] as const; | ||
| const repoRoot = findGitRoot(); | ||
|
|
||
| function getGeneratedFiles(tmpDir: string) { | ||
| return [ | ||
| { | ||
| src: path.join(tmpDir, 'light/react/global-colors.ts'), // the same global colors are generated for all theme, just use light | ||
| dest: path.join(repoRoot, 'packages/react-components/react-theme/src/global/colors.ts'), | ||
| }, | ||
| ...themes.map(theme => ({ | ||
| src: path.join(tmpDir, `${theme}/react/alias-colors.ts`), | ||
| dest: path.join(repoRoot, `packages/react-components/react-theme/src/alias/${theme}Color.ts`), | ||
| })), | ||
| ]; | ||
| } | ||
|
|
||
| function runPipeline(theme: typeof themes[number], pipelineDir: string, outDir: string) { | ||
| console.log(`Running pipeline for ${theme} theme`); | ||
|
|
||
| // https://github.com/microsoft/fluentui-token-pipeline | ||
| execSync( | ||
| `npx transform-tokens --in src/global.json --in src/${_.kebabCase(theme)}.json --out ${outDir}/${theme}`, | ||
| `Generate tokens for theme:${theme}`, | ||
| pipelineDir, | ||
| ); | ||
| } | ||
|
|
||
| export const tokenPipeline = () => { | ||
| const tmpDir = createTempDir('theme'); | ||
|
|
||
| execSync( | ||
| 'git clone --depth 1 https://github.com/microsoft/fluentui-design-tokens.git', | ||
| 'Clone design tokens repo', | ||
| tmpDir, | ||
| ); | ||
| execSync('npm install', 'Install dependencies', path.join(tmpDir, 'fluentui-design-tokens')); | ||
|
|
||
| themes.forEach(theme => { | ||
| runPipeline(theme, path.join(tmpDir, 'fluentui-design-tokens'), tmpDir); | ||
| }); | ||
|
|
||
| getGeneratedFiles(tmpDir).forEach(file => { | ||
| console.log(`Copying generated file ${file.src} -> ${file.dest}`); | ||
| fs.copySync(file.src, file.dest, { overwrite: true }); | ||
| }); | ||
|
|
||
| execSync(`npx prettier --write ${path.join(repoRoot, 'packages/react-components/react-theme/src')}`, 'Prettier'); | ||
| }; | ||
|
|
||
| tokenPipeline(); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.