Skip to content

Commit f97f491

Browse files
committed
fix(scripts): add in checks for unknown types
- support better checks for unknown figma variable types - update and fix handling for verbose output - add documentation details for how to handle import files
1 parent d158fa0 commit f97f491

File tree

4 files changed

+44
-19
lines changed

4 files changed

+44
-19
lines changed

.storybook/components/Docs/Guidelines/Theming.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ npx eds-import-from-figma-api file <file_id> --token <personal_access_token>
145145

146146
**NOTE**: when using this method, it requires both the figma file ID (e.g., `figma.com/design/<file_id>/`), and an API token. Instructions from Figma [are here][figma-access-token-docs].
147147

148+
**NOTE**: the figma file ID should refer to the Foundations file which defines the core tokens used by EDS.
149+
148150
[figma-enterprise]: https://www.figma.com/enterprise/
149151
[figma-api-docs]: https://www.figma.com/developers/api
150152
[figma-access-token-docs]: https://help.figma.com/hc/en-us/articles/8085703771159-Manage-personal-access-tokens

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ The Education Design System (EDS) is a repository of building blocks, implementi
88
- [Presentational](https://medium.com/@dan_abramov/smart-and-dumb-components-7ca2f9a7c7d0) components implementing the common controls provided by the EDS toolkit
99
- Guidelines for creating recipes using EDS, composing the above components
1010

11+
## Prerequisites
12+
13+
Currently, EDS supports the following:
14+
15+
* React 18.x
16+
* Tailwind 3.x
17+
1118
## Installation
1219

1320
First, install the package.

bin/_util.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,10 @@ module.exports = {
257257
);
258258
default:
259259
throw new TypeError(
260-
'unknown resolved type: ' + this._figmaVariableData.resolvedType,
260+
'unknown resolved type for ' +
261+
this._figmaVariableData.name +
262+
': ' +
263+
this._figmaVariableData.resolvedType,
261264
);
262265
}
263266
}
@@ -442,7 +445,10 @@ module.exports = {
442445
: this.value;
443446
default:
444447
throw new TypeError(
445-
'unknown resolved type: ' + this._figmaVariableData.resolvedType,
448+
'unknown resolved type for ' +
449+
this._figmaVariableData.name +
450+
': ' +
451+
this._figmaVariableData.resolvedType,
446452
);
447453
}
448454
}

bin/eds-import-from-figma-api.js

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ const { identity } = require('lodash');
4848

4949
// read in the config from config file, package json "eds", etc.
5050
const config = !args.local && (await getConfig());
51-
const isVerbose = args.v;
51+
const isVerbose = args.verbose;
5252
const canWrite = !args.dryRun;
5353

5454
// Get the local variables from the defined file b/c published ones won't contain the modes
@@ -130,36 +130,44 @@ const { identity } = require('lodash');
130130
chalk.bold(variable.name) +
131131
': Skipped with warning (orphaned): please remove usage in figma',
132132
);
133+
isVerbose && console.warn('Variable details:', variable);
133134

134135
return;
135136
}
136137

137138
// mesh the token path to a matching path in the local theme file
138-
let writePath = variable.getTokenPath();
139-
const locationInLocal = at(localTheme, writePath).filter(
140-
(entries) => typeof entries !== 'undefined',
141-
);
139+
// TODO-AH: this blows up when hitting STRING values
140+
let writePath;
141+
try {
142+
writePath = variable.getTokenPath();
143+
const locationInLocal = at(localTheme, writePath).filter(
144+
(entries) => typeof entries !== 'undefined',
145+
);
142146

143-
// Update the write path to conform to the format used in style-dictionary
144-
if (locationInLocal.length) {
145-
// handle case where we should look for @ in the file, then pluck the value object properly
146-
if (locationInLocal[0]['@']?.value) {
147-
// update the write path to mark the @ and value
148-
writePath = writePath + '[email protected]';
149-
}
147+
// Update the write path to conform to the format used in style-dictionary
148+
if (locationInLocal.length) {
149+
// handle case where we should look for @ in the file, then pluck the value object properly
150+
if (locationInLocal[0]['@']?.value) {
151+
// update the write path to mark the @ and value
152+
writePath = writePath + '[email protected]';
153+
}
150154

151-
// handle case where it's just value
152-
if (locationInLocal[0]?.value) {
153-
// update the write path to mark the value
154-
writePath = writePath + '.value';
155+
// handle case where it's just value
156+
if (locationInLocal[0]?.value) {
157+
// update the write path to mark the value
158+
writePath = writePath + '.value';
159+
}
155160
}
161+
} catch (e) {
162+
// We couldn't parse the write path
163+
isVerbose && spinner.fail(chalk.bold(variable.name) + ': ' + e);
164+
isVerbose && console.error('Variable details:', variable);
156165
}
157166

158167
if (writePath) {
159168
try {
160169
// error when path suffix is invalid (all should end with .value)
161170
if (!writePath.endsWith('value')) {
162-
isVerbose && console.error(variable);
163171
throw new Error(
164172
`Name format violation. JSON path missing in local theme: ${writePath} (${figmaVariable.resolvedType})`,
165173
);
@@ -195,6 +203,7 @@ const { identity } = require('lodash');
195203
} catch (e) {
196204
// We couldn't parse the resolved value, so skip and add to errors
197205
spinner.fail(chalk.bold(variable.name) + ': ' + e);
206+
isVerbose && console.error('Variable details:', variable);
198207
stats.errored.push(variable);
199208
}
200209
} else {
@@ -206,6 +215,7 @@ const { identity } = require('lodash');
206215
': Skipped with warning (no write path)',
207216
);
208217
}
218+
isVerbose && console.warn('Variable details:', variable);
209219
stats.skipped.push(variable);
210220
}
211221
});

0 commit comments

Comments
 (0)