Skip to content

Commit

Permalink
Enable platform overrides at last
Browse files Browse the repository at this point in the history
  • Loading branch information
TravisSpomer committed Jan 26, 2021
1 parent 0895442 commit 8ca7fcb
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 8 deletions.
42 changes: 42 additions & 0 deletions src/demo/fluentui-overrides.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"Meta": {
"FluentUITokensVersion": 0
},
"OverrideTests": {
"Base": {
"Fill": {
"Color": {
"aliasOf": "Set.MergeMe.Fill.Color",
"Red": { "value": "red" },
"WrongName": { "value": "blue", "fullName": "OverrideTests-Base-Fill-Color-Blue" },
"Silver": { "fullName": "OverrideTests-Base-Fill-Color-Grey" },
"Magenta": { "platform": { "winui": { "fullName": "OverrideTests-Base-Fill-Color-MagentaSpecialNameForWinUIOnly" } } }
}
},
"Stroke": {
"Color": {
"aliasOf": "Set.PlatformOverrides.Stroke.Color"
}
}
}
},
"Set": {
"MergeMe": {
"Fill": {
"Color": {
"Green": { "value": "green" },
"Silver": { "value": "silver", "fullName": "Set-MergeMe-Fill-Color-SilverSpecialNameForSetOnly" },
"Magenta": { "value": "magenta" }
}
}
},
"PlatformOverrides": {
"Stroke": {
"Color": {
"YellowExceptPurpleInWinUI": { "value": "yellow", "platform": { "winui": { "value": "purple" } } },
"OrangeExceptBlackInWinUI": { "value": "orange", "platform": { "winui": { "value": "black", "fullName": "PlatformOverrides-Stroke-Color-BlackInWinUI" } } }
}
}
}
}
}
16 changes: 8 additions & 8 deletions src/pipeline/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,9 @@ export const buildOutputs = (input: string[] | string, outputPath: string, platf
}
}

let tokens = {}
const tokens = {}
if (typeof input === "string") input = [input]
input.forEach((inputFile) => _.merge(tokens, jsonfile.readFileSync(inputFile)))
tokens = buildColorRamps(tokens)
tokens = resolveAliases(tokens)
tokens = resolveComputedTokens(tokens)

if (!platforms || platforms.includes("debug")) buildOnePlatform(tokens, /* platformOverride: */ null,
{
Expand Down Expand Up @@ -115,13 +112,16 @@ export const buildOutputs = (input: string[] | string, outputPath: string, platf
)
}

const buildOnePlatform = (tokens: any, platformOverride: SupportedPlatform | null, platformConfig: any): void =>
const buildOnePlatform = (tokens: any, platformOverride: SupportedPlatform | null, platformConfig: Record<string, unknown>): void =>
{
tokens = platformOverride ? resolvePlatformOverrides(_.cloneDeep(tokens), platformOverride) : _.cloneDeep(tokens)
tokens = buildColorRamps(tokens)
tokens = resolveAliases(tokens)
tokens = resolveComputedTokens(tokens)

require("style-dictionary").extend(
{
// NYI: The platform overrides feature isn't finished yet, so don't enable it.
// properties: platformOverride ? resolvePlatformOverrides(_.cloneDeep(tokens), platformOverride) : _.cloneDeep(tokens),
properties: _.cloneDeep(tokens),
properties: tokens,
platforms: platformConfig,
}
).buildAllPlatforms()
Expand Down

0 comments on commit 8ca7fcb

Please sign in to comment.