-
Notifications
You must be signed in to change notification settings - Fork 47
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
feat(bezier-tokens): Implementing composition tokens and removing duplicate CSS #1779
Merged
Merged
Changes from 7 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
c895710
feat(tokens): implement shadow transformer
sungik-choi ad73ab4
feat(tokens): change from $type to type
sungik-choi 6832ebe
feat(tokens): implement custom transition transformer
sungik-choi 2f1f0bf
feat(tokens): enhance font rem transformer to use type of token
sungik-choi 0c6b448
feat(tokens): format composition tokens
sungik-choi 21bc177
feat(tokens): enhance build script
sungik-choi 7bae985
feat(tokens): improve build script to remove duplicate CSS styles
sungik-choi 5b6b145
chore(changeset): add changeset
sungik-choi e835031
refactor(transform): simplify template literal
sungik-choi 204d877
Merge branch 'alpha' into feat/token-css
sungik-choi 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 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,23 +1,18 @@ | ||
import { minimatch } from 'minimatch' | ||
import StyleDictionary, { | ||
type Config, | ||
type Options, | ||
type Platform, | ||
} from 'style-dictionary' | ||
import StyleDictionary, { type Platform } from 'style-dictionary' | ||
|
||
import { | ||
customJsCjs, | ||
customJsEsm, | ||
} from './lib/format' | ||
import { | ||
customCubicBezier, | ||
customFontFamily, | ||
customFontRem, | ||
} from './lib/transform' | ||
import { CSSTransforms } from './lib/transform' | ||
|
||
const CustomTransforms = [...Object.values(CSSTransforms)] | ||
|
||
const TokenBuilder = StyleDictionary.registerTransform(customCubicBezier) | ||
.registerTransform(customFontFamily) | ||
.registerTransform(customFontRem) | ||
const TokenBuilder = CustomTransforms.reduce( | ||
(builder, transform) => builder.registerTransform(transform), | ||
StyleDictionary, | ||
) | ||
.registerFormat(customJsCjs) | ||
.registerFormat(customJsEsm) | ||
|
||
|
@@ -26,9 +21,7 @@ function defineWebPlatform({ options, ...rest }: Platform): Platform { | |
transforms: [ | ||
'attribute/cti', | ||
'name/cti/kebab', | ||
customCubicBezier.name, | ||
customFontFamily.name, | ||
customFontRem.name, | ||
...CustomTransforms.map((transform) => transform.name), | ||
], | ||
basePxFontSize: 10, | ||
options: { | ||
|
@@ -39,93 +32,146 @@ function defineWebPlatform({ options, ...rest }: Platform): Platform { | |
} | ||
} | ||
|
||
interface DefineConfigOptions { | ||
source: string[] | ||
reference?: string[] | ||
destination: string | ||
options?: Options & { | ||
cssSelector: string | ||
} | ||
} | ||
const PATH = { | ||
GLOBAL: 'src/global/*.json', | ||
SEMANTIC_COMMON: 'src/semantic/*.json', | ||
SEMANTIC_LIGHT: 'src/semantic/light-theme/*.json', | ||
SEMANTIC_DARK: 'src/semantic/dark-theme/*.json', | ||
} as const | ||
|
||
function defineConfig({ | ||
source, | ||
reference = [], | ||
destination, | ||
options, | ||
}: DefineConfigOptions): Config { | ||
return { | ||
source: [...source, ...reference], | ||
function main() { | ||
TokenBuilder.extend({ | ||
source: [PATH.GLOBAL, PATH.SEMANTIC_COMMON, PATH.SEMANTIC_LIGHT], | ||
platforms: { | ||
'web/cjs': defineWebPlatform({ | ||
'web/cjs/global': defineWebPlatform({ | ||
buildPath: 'dist/cjs/', | ||
files: [ | ||
{ | ||
destination: 'global.js', | ||
format: customJsCjs.name, | ||
filter: ({ filePath }) => | ||
[PATH.GLOBAL].some((src) => minimatch(filePath, src)), | ||
}, | ||
], | ||
}), | ||
'web/esm/global': defineWebPlatform({ | ||
buildPath: 'dist/esm/', | ||
files: [ | ||
{ | ||
destination: 'global.mjs', | ||
format: customJsEsm.name, | ||
filter: ({ filePath }) => | ||
[PATH.GLOBAL].some((src) => minimatch(filePath, src)), | ||
}, | ||
], | ||
}), | ||
'web/css/global': defineWebPlatform({ | ||
buildPath: 'dist/css/', | ||
files: [ | ||
{ | ||
destination: 'global.css', | ||
format: 'css/variables', | ||
filter: ({ filePath }) => | ||
[PATH.GLOBAL, PATH.SEMANTIC_COMMON].some((src) => | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
minimatch(filePath, src), | ||
), | ||
options: { | ||
selector: ':where(:root, :host)', | ||
outputReferences: true, | ||
}, | ||
}, | ||
], | ||
}), | ||
'web/cjs/light-theme': defineWebPlatform({ | ||
buildPath: 'dist/cjs/', | ||
files: [ | ||
{ | ||
destination: `${destination}.js`, | ||
destination: 'lightTheme.js', | ||
format: customJsCjs.name, | ||
filter: ({ filePath }) => | ||
source.some((src) => minimatch(filePath, src)), | ||
[PATH.SEMANTIC_COMMON, PATH.SEMANTIC_LIGHT].some((src) => | ||
minimatch(filePath, src), | ||
), | ||
}, | ||
], | ||
}), | ||
'web/esm': defineWebPlatform({ | ||
'web/esm/light-theme': defineWebPlatform({ | ||
buildPath: 'dist/esm/', | ||
files: [ | ||
{ | ||
destination: `${destination}.mjs`, | ||
destination: 'lightTheme.mjs', | ||
format: customJsEsm.name, | ||
filter: ({ filePath }) => | ||
source.some((src) => minimatch(filePath, src)), | ||
[PATH.SEMANTIC_COMMON, PATH.SEMANTIC_LIGHT].some((src) => | ||
minimatch(filePath, src), | ||
), | ||
}, | ||
], | ||
}), | ||
'web/css': defineWebPlatform({ | ||
'web/css/light-theme': defineWebPlatform({ | ||
buildPath: 'dist/css/', | ||
files: [ | ||
{ | ||
destination: `${destination}.css`, | ||
destination: 'light-theme.css', | ||
format: 'css/variables', | ||
filter: ({ filePath }) => | ||
source.some((src) => minimatch(filePath, src)), | ||
[PATH.SEMANTIC_LIGHT].some((src) => minimatch(filePath, src)), | ||
options: { | ||
selector: options?.cssSelector, | ||
selector: ':where(:root, :host), [data-bezier-theme="light"]', | ||
outputReferences: true, | ||
}, | ||
}, | ||
], | ||
}), | ||
}, | ||
} | ||
} | ||
}).buildAllPlatforms() | ||
|
||
function main() { | ||
[ | ||
TokenBuilder.extend( | ||
defineConfig({ | ||
source: ['src/global/*.json'], | ||
destination: 'global', | ||
options: { cssSelector: ':where(:root, :host)' }, | ||
TokenBuilder.extend({ | ||
source: [PATH.GLOBAL, PATH.SEMANTIC_COMMON, PATH.SEMANTIC_DARK], | ||
platforms: { | ||
'web/cjs/dark-theme': defineWebPlatform({ | ||
buildPath: 'dist/cjs/', | ||
files: [ | ||
{ | ||
destination: 'darkTheme.js', | ||
format: customJsCjs.name, | ||
filter: ({ filePath }) => | ||
[PATH.SEMANTIC_COMMON, PATH.SEMANTIC_DARK].some((src) => | ||
minimatch(filePath, src), | ||
), | ||
}, | ||
], | ||
}), | ||
), | ||
TokenBuilder.extend( | ||
defineConfig({ | ||
source: ['src/semantic/*.json', 'src/semantic/light-theme/*.json'], | ||
reference: ['src/global/*.json'], | ||
destination: 'lightTheme', | ||
options: { | ||
cssSelector: ':where(:root, :host), [data-bezier-theme="light"]', | ||
}, | ||
'web/esm/dark-theme': defineWebPlatform({ | ||
buildPath: 'dist/esm/', | ||
files: [ | ||
{ | ||
destination: 'darkTheme.mjs', | ||
format: customJsEsm.name, | ||
filter: ({ filePath }) => | ||
[PATH.SEMANTIC_COMMON, PATH.SEMANTIC_DARK].some((src) => | ||
minimatch(filePath, src), | ||
), | ||
}, | ||
], | ||
}), | ||
), | ||
TokenBuilder.extend( | ||
defineConfig({ | ||
source: ['src/semantic/*.json', 'src/semantic/dark-theme/*.json'], | ||
reference: ['src/global/*.json'], | ||
destination: 'darkTheme', | ||
options: { cssSelector: '[data-bezier-theme="dark"]' }, | ||
'web/css/dark-theme': defineWebPlatform({ | ||
buildPath: 'dist/css/', | ||
files: [ | ||
{ | ||
destination: 'darkTheme.css', | ||
format: 'css/variables', | ||
filter: ({ filePath }) => | ||
[PATH.SEMANTIC_DARK].some((src) => minimatch(filePath, src)), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 테마별 CSS에선 JS와 다르게 공통 Semantic token을 필터링하는 로직 |
||
options: { | ||
selector: '[data-bezier-theme="dark"]', | ||
outputReferences: true, | ||
}, | ||
}, | ||
], | ||
}), | ||
), | ||
].forEach((builder) => builder.buildAllPlatforms()) | ||
}, | ||
}).buildAllPlatforms() | ||
} | ||
|
||
main() |
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
custom transformer를 하나의 객체에 담아서 register 과정을 간소화했습니다.