-
Notifications
You must be signed in to change notification settings - Fork 4
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
fix: apply token and script fixes to sync with design #2142
Merged
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ae1988e
fix: apply token and script fixes to sync with design
booc0mtaco e6dcadf
fix: remove typo
booc0mtaco 974f787
fix(Button): use proper token for border-radius
booc0mtaco 3fa4c28
docs: add scrips command improvements
booc0mtaco 41186ac
chore: update yarn lock file
booc0mtaco cf50066
fix(scripts): address bug for internal tier 2 references w/ tests
booc0mtaco 61382d8
chore: remove errant comment
booc0mtaco 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
#!/usr/bin/env node | ||
|
||
const { identity } = require('lodash'); | ||
|
||
// Script shell | ||
(async function () { | ||
const jsonfile = require('jsonfile'); | ||
|
@@ -118,22 +120,34 @@ | |
response.modeId, | ||
figmaApiReader, | ||
); | ||
let writePath = variable.getTokenPath(); | ||
|
||
// If we have a zombie entry in the variable list, skip it (flag for design) | ||
if (variable.isOrphaned()) { | ||
stats.skipped.push(variable); | ||
spinner.warn( | ||
chalk.bold(variable.name) + | ||
': Skipped with warning (orphaned): please remove usage in figma', | ||
); | ||
|
||
return; | ||
} | ||
|
||
// mesh the token path to a matching path in the local theme file | ||
const found = at(localTheme, writePath).filter( | ||
let writePath = variable.getTokenPath(); | ||
const locationInLocal = at(localTheme, writePath).filter( | ||
(entries) => typeof entries !== 'undefined', | ||
); | ||
|
||
if (found.length) { | ||
// Update the write path to conform to the format used in style-dictionary | ||
if (locationInLocal.length) { | ||
// handle case where we should look for @ in the file, then pluck the value object properly | ||
if (found[0]['@']?.value) { | ||
if (locationInLocal[0]['@']?.value) { | ||
// update the write path to mark the @ and value | ||
writePath = writePath + '[email protected]'; | ||
} | ||
|
||
// handle case where it's just value | ||
if (found[0]?.value) { | ||
if (locationInLocal[0]?.value) { | ||
// update the write path to mark the value | ||
writePath = writePath + '.value'; | ||
} | ||
|
@@ -143,17 +157,28 @@ | |
try { | ||
// error when path suffix is invalid (all should end with .value) | ||
if (!writePath.endsWith('value')) { | ||
isVerbose && console.error(variable); | ||
throw new Error( | ||
`Name format violation. JSON path missing in local theme: ${writePath} (${figmaVariable.resolvedType})`, | ||
); | ||
} | ||
|
||
if ( | ||
FigmaVariable.isAliased(figmaVariable, response.modeId) && | ||
!at(localTheme, variable.valueRef).some(identity) | ||
) { | ||
throw new Error( | ||
`Name format violation. Name missing in local theme: ${writePath} (${figmaVariable.resolvedType})`, | ||
`Value violation. Trying to write a reference value path not in local theme: ${writePath} => {${variable.valueRef}}`, | ||
); | ||
} | ||
|
||
// Write the defined value to the specified location by json path | ||
canWrite && | ||
args.local && | ||
set(localTheme, writePath, variable.valueRef); | ||
set(localTheme, writePath, `{${variable.valueRef}}`); | ||
canWrite && !args.local && set(localTheme, writePath, variable.value); | ||
|
||
// write the value using the calculated path and parsed value | ||
// log if in a loggable mode (verbose / dry-run) | ||
if (isVerbose || !canWrite) { | ||
spinner.succeed( | ||
`Write: ${ | ||
|
@@ -166,7 +191,7 @@ | |
stats.updated.push(variable); | ||
} catch (e) { | ||
// We couldn't parse the resolved value, so skip and add to errors | ||
spinner.fail(chalk.bold(variable.name) + ': Error (' + e + ')'); | ||
spinner.fail(chalk.bold(variable.name) + ': ' + e); | ||
stats.errored.push(variable); | ||
} | ||
} else { | ||
|
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.
Note: a few of these constants will migrate to configuration once we have enough use cases to do so