-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add json to design token output
- Loading branch information
1 parent
b4ca0c1
commit bf9e03a
Showing
15 changed files
with
99 additions
and
47 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
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 joined 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