-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dbda419
commit 3814a64
Showing
3 changed files
with
56 additions
and
73 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,49 @@ | ||
import StyleDictionary from "style-dictionary" | ||
import _ from "lodash" | ||
|
||
import { TokenSet } from "./types" | ||
import * as Utils from "./utils" | ||
|
||
// This name is only used for sorting; we don't use it in output. | ||
const nameForGroupedJson = path => path.join("") | ||
|
||
StyleDictionary.registerTransform({ | ||
name: "fluentui/name/json/grouped", | ||
type: "name", | ||
transformer: prop => nameForGroupedJson(Utils.getTokenExportPath(prop)), | ||
}) | ||
|
||
StyleDictionary.registerTransformGroup({ | ||
name: "fluentui/json/grouped", | ||
transforms: ["fluentui/attribute", "fluentui/name/json/grouped"], | ||
}) | ||
|
||
StyleDictionary.registerFormat({ | ||
name: "fluentui/json/grouped", | ||
formatter: (dictionary, config) => | ||
{ | ||
// Flatten out the token hierarchy and just keep the important bits. | ||
const sortedProps = Utils.sortPropertiesForReadability(dictionary.allProperties) | ||
const tokens: any = {} | ||
let previousProp: any | null = null | ||
let thisOutputObject: any | null = null | ||
for (const thisProp of sortedProps) | ||
{ | ||
if (thisProp.path[0] === "Global" || thisProp.path[0] === "Set") continue | ||
|
||
if (!previousProp || thisProp.path[0] !== previousProp.path[0]) | ||
{ | ||
const controlName = _.camelCase(thisProp.path[0]) | ||
tokens[controlName] = thisOutputObject = tokens[controlName] || {} | ||
} | ||
|
||
const meaningfulPathStart = (thisProp.path.length > 2 && thisProp.path[1] === "Base") ? 2 : 1 | ||
const exportName = _.camelCase(thisProp.path.slice(meaningfulPathStart).join(" ")) | ||
thisOutputObject[exportName] = thisProp.value | ||
|
||
previousProp = thisProp | ||
} | ||
|
||
return JSON.stringify(tokens, /* replacer: */ undefined, /* space: */ "\t") | ||
}, | ||
}) |