({ name, modes, variableIds })
| 134 | } |
| 135 | |
| 136 | async function processCollection({ name, modes, variableIds }) { |
| 137 | const files = []; |
| 138 | for (const mode of modes) { |
| 139 | const file = { fileName: `${name}.${mode.name}.tokens.json`, body: {} }; |
| 140 | for (const variableId of variableIds) { |
| 141 | const { name, resolvedType, valuesByMode } = |
| 142 | await figma.variables.getVariableByIdAsync(variableId); |
| 143 | const value = valuesByMode[mode.modeId]; |
| 144 | if (value !== undefined && ["COLOR", "FLOAT"].includes(resolvedType)) { |
| 145 | let obj = file.body; |
| 146 | name.split("/").forEach((groupName) => { |
| 147 | obj[groupName] = obj[groupName] || {}; |
| 148 | obj = obj[groupName]; |
| 149 | }); |
| 150 | obj.$type = resolvedType === "COLOR" ? "color" : "number"; |
| 151 | if (value.type === "VARIABLE_ALIAS") { |
| 152 | const currentVar = await figma.variables.getVariableByIdAsync( |
| 153 | value.id |
| 154 | ); |
| 155 | obj.$value = `{${currentVar.name.replace(/\//g, ".")}}`; |
| 156 | } else { |
| 157 | obj.$value = resolvedType === "COLOR" ? rgbToHex(value) : value; |
| 158 | } |
| 159 | } |
| 160 | } |
| 161 | files.push(file); |
| 162 | } |
| 163 | return files; |
| 164 | } |
| 165 | |
| 166 | figma.ui.onmessage = async (e) => { |
| 167 | console.log("code received message", e); |
no test coverage detected