-
Notifications
You must be signed in to change notification settings - Fork 78
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: add json to design token output #8290
Merged
+108
−45
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
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
21 changes: 7 additions & 14 deletions
21
...support/token-transformer/styleDictionary/transformer/attributes/attributePlatformName.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
21 changes: 21 additions & 0 deletions
21
...n-tokens/support/token-transformer/styleDictionary/transformer/name/nameSpacePath.spec.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,21 @@ | ||
import { registerStyleDictionaryTransform } from "../../../../test/utils/registerStyleDictionaryFunction"; | ||
import { TransformedToken } from "../../../../types/styleDictionary/transformedToken"; | ||
import { registerNameSpacePath, transformNamesSpacePath } from "./nameSpacePath"; | ||
|
||
describe("StyleDictionary Transform Name to a spaced path", () => { | ||
describe("register", () => { | ||
it("should call StyleDictionary registerTransform", () => registerStyleDictionaryTransform(registerNameSpacePath)); | ||
}); | ||
|
||
describe("transformer", () => { | ||
it("should transform a token name to a spaced path", () => { | ||
const token = { | ||
name: "some fake name", | ||
path: ["tier", "group", "element", "property", "state"], | ||
} as TransformedToken; | ||
const args = {}; | ||
const transformedName = transformNamesSpacePath(token, args); | ||
expect(transformedName).toBe("Tier Group Element Property State"); | ||
}); | ||
}); | ||
}); |
31 changes: 31 additions & 0 deletions
31
...design-tokens/support/token-transformer/styleDictionary/transformer/name/nameSpacePath.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,31 @@ | ||
import { Core as StyleDictionary } from "style-dictionary"; | ||
import { CalledTransformerFunction, TransformerConfig } from "../utils.js"; | ||
import { parseTokenPath } from "../utils/parseTokenPath.js"; | ||
import { capitalCase } from "change-case"; | ||
|
||
export const transformNamesSpacePath: CalledTransformerFunction<string> = (token, args) => { | ||
const [tokenPath, negNameRef] = parseTokenPath( | ||
[].concat(args.options?.prefix, token.path).filter((p) => p && p !== args?.options?.prefix) | ||
); | ||
let name = capitalCase(tokenPath.join(" ")); | ||
|
||
for (let i = 0; i < negNameRef.length; i++) { | ||
const negName = negNameRef[i]; | ||
const n = negName.slice(1); | ||
name = name.replace(n, negName); | ||
} | ||
|
||
return name; | ||
}; | ||
|
||
export const registerNameSpacePath = (sd: StyleDictionary): void => { | ||
const transformerConfig: TransformerConfig = { | ||
name: nameSpacePath, | ||
transformer: transformNamesSpacePath, | ||
type: "name", | ||
}; | ||
|
||
sd.registerTransform(transformerConfig); | ||
}; | ||
|
||
export const nameSpacePath = "name/calcite/space-path"; |
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
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.
Does this need to be reverted since we're keeping the JS output?
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.
IMO no. It seems like engineers are preferring to use es6 to import specific tokens when necessary. So the es6 format (which is tree-shakable) should be the one imported by default.
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.
Makes sense, but this is now unrelated to this PR and I think falls under breaking change territory.