Skip to content

Commit

Permalink
Merge pull request #660 from pixiv/mimo/fix-token-cli
Browse files Browse the repository at this point in the history
tokenが参照できない時、warnを出して処理を続けるようにする
  • Loading branch information
mimokmt authored Dec 4, 2024
2 parents e289309 + 2021b22 commit 99245ab
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 12 deletions.
38 changes: 28 additions & 10 deletions packages/token-cli/src/createToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,36 @@ export const createToken = (

if (!v) throw new Error(`can't find variable: ${it}`)

return {
[v.name]: {
value: resolveValue(
variableCollectionMap,
variableMap,
v.resolvedType,
v,
modeId
),
},
try {
const value = resolveValue(
variableCollectionMap,
variableMap,
v.resolvedType,
v,
modeId
)
return {
[v.name]: {
value,
},
}
} catch (e) {
if (e instanceof Error) {
// eslint-disable-next-line no-console
console.warn(`[warn]: ${e.message}`)
}
return undefined
}
})
.filter(
(
it
): it is {
[x: string]: {
value: string
}
} => it !== undefined
)
.reduce((prev, current) => ({
...prev,
...current,
Expand Down
7 changes: 5 additions & 2 deletions packages/token-cli/src/figma/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,16 @@ export const resolveValue = (
// if alias, look at it recursively.
if (typeof value === 'object' && 'type' in value && 'id' in value) {
const v = variableMap.get(value.id)
if (!v) throw new Error(`can't find variable ${value.id}`)
if (!v)
throw new Error(
`can't find variable alias "${variable.name}:${value.id}"`
)

const variableCollection = variableCollectionMap.get(v.variableCollectionId)

if (!variableCollection)
throw new Error(
`can't find variable collection ${v.variableCollectionId}`
`can't find variable collection "${variable.name}:${v.variableCollectionId}"`
)

return `{${variableCollection.name}.${v.name}}`
Expand Down

0 comments on commit 99245ab

Please sign in to comment.