@figma/code-connect 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -14
- package/dist/commands/connect.js +15 -15
- package/dist/commands/connect.js.map +1 -1
- package/dist/common/api.d.ts +6 -0
- package/dist/common/api.d.ts.map +1 -1
- package/dist/common/figma_connect.d.ts +1 -1
- package/dist/common/figma_connect.d.ts.map +1 -1
- package/dist/common/intrinsics.d.ts.map +1 -1
- package/dist/common/intrinsics.js +3 -1
- package/dist/common/intrinsics.js.map +1 -1
- package/dist/common/parser.d.ts +7 -7
- package/dist/common/parser.d.ts.map +1 -1
- package/dist/common/parser.js +88 -42
- package/dist/common/parser.js.map +1 -1
- package/dist/common/parser_template_helpers.d.ts.map +1 -1
- package/dist/common/parser_template_helpers.js +6 -1
- package/dist/common/parser_template_helpers.js.map +1 -1
- package/dist/common/project.d.ts +26 -21
- package/dist/common/project.d.ts.map +1 -1
- package/dist/common/project.js +10 -2
- package/dist/common/project.js.map +1 -1
- package/dist/connect/create.d.ts +1 -1
- package/dist/connect/create.d.ts.map +1 -1
- package/dist/connect/create.js +6 -5
- package/dist/connect/create.js.map +1 -1
- package/dist/connect/helpers.d.ts.map +1 -1
- package/dist/connect/helpers.js +11 -6
- package/dist/connect/helpers.js.map +1 -1
- package/dist/connect/upload.d.ts +2 -2
- package/dist/connect/upload.d.ts.map +1 -1
- package/dist/connect/upload.js +2 -2
- package/dist/connect/upload.js.map +1 -1
- package/dist/connect/validation.d.ts +2 -2
- package/dist/connect/validation.d.ts.map +1 -1
- package/dist/connect/validation.js +3 -3
- package/dist/connect/validation.js.map +1 -1
- package/dist/storybook/convert.d.ts +4 -4
- package/dist/storybook/convert.d.ts.map +1 -1
- package/dist/storybook/convert.js +11 -11
- package/dist/storybook/convert.js.map +1 -1
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -14,20 +14,20 @@ npm install @figma/code-connect
|
|
|
14
14
|
|
|
15
15
|
## Basic setup
|
|
16
16
|
|
|
17
|
-
To connect your first component go to Dev Mode in Figma and right-click on the component you want to connect, then choose `Copy link to selection` from the menu. Make sure you are copying the link to a main component and not an instance of the component. The main component will typically be located in a centralized design system library file. Using this link, run `figma connect create`.
|
|
17
|
+
To connect your first component go to Dev Mode in Figma and right-click on the component you want to connect, then choose `Copy link to selection` from the menu. Make sure you are copying the link to a main component and not an instance of the component. The main component will typically be located in a centralized design system library file. Using this link, run `figma connect create`. Note that depending on what terminal software you're using, you might need to wrap the URL in quotes.
|
|
18
18
|
|
|
19
19
|
```sh
|
|
20
|
-
npx figma connect create https://... --token <auth token>
|
|
20
|
+
npx figma connect create "https://..." --token <auth token>
|
|
21
21
|
```
|
|
22
22
|
|
|
23
23
|
This will create a Code Connect file with some basic scaffolding for the component you want to connect. By default this file will be called `<component-name>.figma.tsx` based on the name of the component in Figma. However, you may rename this file as you see fit. The scaffolding that is generated is based on the interface of the component in Figma. Depending on how closely this matches your code component you'll need to make some edits to this file before you publish it.
|
|
24
24
|
|
|
25
|
-
Some CLI commands, like `create`, require a valid [authentication token](https://help.figma.com/hc/en-us/articles/8085703771159-Manage-personal-access-tokens) with write permission for the Code Connect scope. You can either pass this via the `--token` flag, or set the `FIGMA_ACCESS_TOKEN` environment variable
|
|
25
|
+
Some CLI commands, like `create`, require a valid [authentication token](https://help.figma.com/hc/en-us/articles/8085703771159-Manage-personal-access-tokens) with write permission for the Code Connect scope. You can either pass this via the `--token` flag, or set the `FIGMA_ACCESS_TOKEN` environment variable. The Figma CLI reads this from a `.env` file in the same folder, if it exists.
|
|
26
26
|
|
|
27
27
|
To keep things simple, we're going to start by replacing the contents of the generated file with the most basic Code Connect configuration possible to make sure everything is set up and working as expected. Replace the contents of the file with the following, replacing the `Button` reference with a reference to whatever component you are trying to connect. The object called by `figma.connect` is your Code Connect doc.
|
|
28
28
|
|
|
29
29
|
```tsx
|
|
30
|
-
import
|
|
30
|
+
import figma from '@figma/code-connect'
|
|
31
31
|
import { Button } from 'src/components'
|
|
32
32
|
|
|
33
33
|
figma.connect(Button, 'https://...', {
|
|
@@ -109,14 +109,14 @@ In addition to the [general configuration](../README.md) for the CLI there is Re
|
|
|
109
109
|
"exclude": ["test/**", "docs/**", "build/**"],
|
|
110
110
|
|
|
111
111
|
"react": {
|
|
112
|
-
importPaths: {
|
|
112
|
+
"importPaths": {
|
|
113
113
|
"src/components/*": "@ui/components"
|
|
114
114
|
},
|
|
115
115
|
|
|
116
|
-
paths: {
|
|
116
|
+
"paths": {
|
|
117
117
|
"@ui/components/*": ["src/components/*"]
|
|
118
|
-
}
|
|
119
|
-
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
120
|
}
|
|
121
121
|
}
|
|
122
122
|
```
|
|
@@ -138,9 +138,15 @@ You can use `importPaths` by specifying where `Button` lives in your repo and ma
|
|
|
138
138
|
consider the full absolute path of the source file `Button.tsx`.
|
|
139
139
|
|
|
140
140
|
```
|
|
141
|
-
|
|
142
|
-
"
|
|
143
|
-
|
|
141
|
+
{
|
|
142
|
+
"codeConnect": {
|
|
143
|
+
"react": {
|
|
144
|
+
"importPaths": {
|
|
145
|
+
"src/components/*": "@ui/components"
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
144
150
|
```
|
|
145
151
|
|
|
146
152
|
Which will end up changing your connected code snippet in Figma to
|
|
@@ -162,7 +168,7 @@ To ensure the connected code snippet accurately reflects the design, we need to
|
|
|
162
168
|
Here is a simple example for a button with a `label`, `disabled`, and `type` property.
|
|
163
169
|
|
|
164
170
|
```tsx
|
|
165
|
-
import
|
|
171
|
+
import figma from '@figma/code-connect'
|
|
166
172
|
|
|
167
173
|
figma.connect(Button, 'https://...', {
|
|
168
174
|
props: {
|
|
@@ -186,7 +192,7 @@ figma.connect(Button, 'https://...', {
|
|
|
186
192
|
And this is how we would achieve the same thing using the Storybook integration. Notice how this works well with existing `args` configuration you may already be using in Storybook.
|
|
187
193
|
|
|
188
194
|
```tsx
|
|
189
|
-
import
|
|
195
|
+
import figma from "@figma/code-connect"
|
|
190
196
|
|
|
191
197
|
export default {
|
|
192
198
|
component: Button,
|
|
@@ -436,7 +442,7 @@ jobs:
|
|
|
436
442
|
By default Code Connect creates a new file which lives alongside the components you want to connect to Figma. However, Code Connect may also be co-located with the component it is connecting in code. To do this, simply move the contents of the `<component-name>.figma.tsx` file into your component definition file.
|
|
437
443
|
|
|
438
444
|
```tsx
|
|
439
|
-
import
|
|
445
|
+
import figma from "@figma/code-connect"
|
|
440
446
|
|
|
441
447
|
interface ButtonProps { ... }
|
|
442
448
|
export function Button(props: ButtonProps) { ... }
|
package/dist/commands/connect.js
CHANGED
|
@@ -53,8 +53,8 @@ function setupHandler(cmd) {
|
|
|
53
53
|
logging_1.logger.setLogLevel(logging_1.LogLevel.Debug);
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
|
-
async function
|
|
57
|
-
const
|
|
56
|
+
async function getCodeConnectObjects(dir, cmd, projectInfo) {
|
|
57
|
+
const codeConnectObjects = [];
|
|
58
58
|
const { files, remoteUrl, config, tsProgram } = projectInfo;
|
|
59
59
|
const figmaNodeToFile = new Map();
|
|
60
60
|
for (const file of files.filter((f) => (0, parser_1.isFigmaConnectFile)(tsProgram, f))) {
|
|
@@ -63,7 +63,7 @@ async function getFigmadocs(dir, cmd, projectInfo) {
|
|
|
63
63
|
for (const doc of docs) {
|
|
64
64
|
figmaNodeToFile.set(doc.figmaNode, file);
|
|
65
65
|
}
|
|
66
|
-
|
|
66
|
+
codeConnectObjects.push(...docs);
|
|
67
67
|
logging_1.logger.info((0, logging_1.success)(file));
|
|
68
68
|
}
|
|
69
69
|
catch (e) {
|
|
@@ -86,7 +86,7 @@ async function getFigmadocs(dir, cmd, projectInfo) {
|
|
|
86
86
|
}
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
|
-
return
|
|
89
|
+
return codeConnectObjects;
|
|
90
90
|
}
|
|
91
91
|
async function handlePublish(cmd) {
|
|
92
92
|
setupHandler(cmd);
|
|
@@ -95,11 +95,11 @@ async function handlePublish(cmd) {
|
|
|
95
95
|
if (cmd.dryRun) {
|
|
96
96
|
logging_1.logger.info(`Files that would be published:`);
|
|
97
97
|
}
|
|
98
|
-
const
|
|
99
|
-
const
|
|
98
|
+
const codeConnectObjects = await getCodeConnectObjects(dir, cmd, projectInfo);
|
|
99
|
+
const storybookCodeConnectObjects = await (0, convert_1.convertStorybookFiles)({
|
|
100
100
|
projectInfo,
|
|
101
101
|
});
|
|
102
|
-
const allCodeConnectFiles =
|
|
102
|
+
const allCodeConnectFiles = codeConnectObjects.concat(storybookCodeConnectObjects);
|
|
103
103
|
if (allCodeConnectFiles.length === 0) {
|
|
104
104
|
logging_1.logger.warn(`No Code Connect files found in ${dir} - Make sure you have configured \`include\` and \`exclude\` in your figma.config.json file correctly, or that you are running in a directory that contains Code Connect files.`);
|
|
105
105
|
process.exit(0);
|
|
@@ -146,11 +146,11 @@ async function handleUnpublish(cmd) {
|
|
|
146
146
|
}
|
|
147
147
|
else {
|
|
148
148
|
const projectInfo = (0, project_1.getProjectInfo)(dir, cmd.config);
|
|
149
|
-
const
|
|
150
|
-
const
|
|
149
|
+
const codeConnectObjects = await getCodeConnectObjects(dir, cmd, projectInfo);
|
|
150
|
+
const storybookCodeConnectObjects = await (0, convert_1.convertStorybookFiles)({
|
|
151
151
|
projectInfo,
|
|
152
152
|
});
|
|
153
|
-
const allCodeConnectFiles =
|
|
153
|
+
const allCodeConnectFiles = codeConnectObjects.concat(storybookCodeConnectObjects);
|
|
154
154
|
nodesToDeleteRelevantInfo = allCodeConnectFiles.map((doc) => ({
|
|
155
155
|
figmaNode: doc.figmaNode,
|
|
156
156
|
label: doc.label,
|
|
@@ -174,17 +174,17 @@ async function handleParse(cmd) {
|
|
|
174
174
|
}
|
|
175
175
|
let dir = cmd.dir ?? process.cwd();
|
|
176
176
|
const projectInfo = (0, project_1.getProjectInfo)(dir, cmd.config);
|
|
177
|
-
const
|
|
178
|
-
const
|
|
177
|
+
const codeConnectObjects = await getCodeConnectObjects(dir, cmd, projectInfo);
|
|
178
|
+
const storybookCodeConnectObjects = await (0, convert_1.convertStorybookFiles)({
|
|
179
179
|
projectInfo,
|
|
180
180
|
});
|
|
181
|
-
const allCodeConnectFiles =
|
|
181
|
+
const allCodeConnectFiles = codeConnectObjects.concat(storybookCodeConnectObjects);
|
|
182
182
|
if (cmd.dryRun) {
|
|
183
183
|
logging_1.logger.info(`Dry run complete`);
|
|
184
184
|
process.exit(0);
|
|
185
185
|
}
|
|
186
186
|
if (cmd.outfile) {
|
|
187
|
-
fs_1.default.writeFileSync(cmd.outfile, JSON.stringify(
|
|
187
|
+
fs_1.default.writeFileSync(cmd.outfile, JSON.stringify(codeConnectObjects, null, 2));
|
|
188
188
|
logging_1.logger.info(`Wrote Code Connect JSON to ${(0, logging_1.highlight)(cmd.outfile)}`);
|
|
189
189
|
}
|
|
190
190
|
else {
|
|
@@ -202,7 +202,7 @@ function handleCreate(nodeUrl, cmd) {
|
|
|
202
202
|
logging_1.logger.error(`Couldn't find a Figma access token. Please provide one with \`--token <access_token>\` or set the FIGMA_ACCESS_TOKEN environment variable`);
|
|
203
203
|
process.exit(1);
|
|
204
204
|
}
|
|
205
|
-
return (0, create_1.
|
|
205
|
+
return (0, create_1.createCodeConnectFromUrl)({
|
|
206
206
|
accessToken,
|
|
207
207
|
// We remove \s to allow users to paste URLs inside quotes - the terminal
|
|
208
208
|
// paste will add backslashes, which the quotes preserve, but expected user
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connect.js","sourceRoot":"","sources":["../../src/commands/connect.ts"],"names":[],"mappings":";;;;;;AACA,6CAAwF;AACxF,4CAAmB;AACnB,8CAA0C;AAC1C,sDAAoD;AACpD,
|
|
1
|
+
{"version":3,"file":"connect.js","sourceRoot":"","sources":["../../src/commands/connect.ts"],"names":[],"mappings":";;;;;;AACA,6CAAwF;AACxF,4CAAmB;AACnB,8CAA0C;AAC1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E,CAAC,CAAC,CAAC,CAAA;IAChE,CAAC;AACH,CAAC;AAED,SAAS,YAAY,CAAC,OAAe,EAAE,GAAgB;IACrD,YAAY,CAAC,GAAG,CAAC,CAAA;IAEjB,IAAI,GAAG,CAAC,MAAM,EAAE,CAAC;QACf,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;IACjB,CAAC;IAED,MAAM,WAAW,GAAG,cAAc,CAAC,GAAG,CAAC,CAAA;IACvC,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,gBAAM,CAAC,KAAK,CACV,2IAA2I,CAC5I,CAAA;QACD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;IACjB,CAAC;IAED,OAAO,IAAA,iCAAwB,EAAC;QAC9B,WAAW;QACX,yEAAyE;QACzE,2EAA2E;QAC3E,yCAAyC;QACzC,YAAY,EAAE,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC;QACxC,OAAO,EAAE,GAAG,CAAC,OAAO;KACrB,CAAC,CAAA;AACJ,CAAC"}
|
package/dist/common/api.d.ts
CHANGED
|
@@ -138,6 +138,12 @@ export interface FigmaConnectMeta<T = {}, ExtraExampleT = never> {
|
|
|
138
138
|
* @returns
|
|
139
139
|
*/
|
|
140
140
|
example?: ((props: T) => React.Component | JSX.Element) | ExtraExampleT;
|
|
141
|
+
/**
|
|
142
|
+
* A list of import statements that will render in the Code Snippet in Figma.
|
|
143
|
+
* This overrides the auto-generated imports for the component. When this is specified,
|
|
144
|
+
* the `importPaths` option in the config file is also ignored.
|
|
145
|
+
*/
|
|
146
|
+
imports?: string[];
|
|
141
147
|
/**
|
|
142
148
|
* A list of links that will display in Figma along with the examples
|
|
143
149
|
*/
|
package/dist/common/api.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../src/common/api.ts"],"names":[],"mappings":";AAAA,MAAM,WAAW,eAAe;IAC9B;;;;;;;;OAQG;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,CAAC,KAAK,EAAE,CAAC,KAAK,KAAK,CAAC,SAAS,GAAG,GAAG,CAAC,OAAO,CAAC,GAAG,aAAa,CAAA;IAEvE;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,EAAE,CAAA;IAElB;;OAEG;IACH,KAAK,CAAC,EAAE,gBAAgB,EAAE,CAAA;CAC3B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"figma_connect.d.ts","sourceRoot":"","sources":["../../src/common/figma_connect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,OAAO,CAAA;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAExC,MAAM,WAAW,
|
|
1
|
+
{"version":3,"file":"figma_connect.d.ts","sourceRoot":"","sources":["../../src/common/figma_connect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,OAAO,CAAA;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAExC,MAAM,WAAW,eAAe;IAC9B,SAAS,EAAE,MAAM,CAAA;IACjB,SAAS,EAAE,MAAM,CAAA;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAC7B,MAAM,EAAE,MAAM,CAAA;IACd,cAAc,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAA;IAChC,QAAQ,EAAE,MAAM,CAAA;IAChB,YAAY,EAAE;QACZ,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,SAAS,CAAA;QAC5C,OAAO,CAAC,EAAE,MAAM,EAAE,CAAA;QAClB,QAAQ,CAAC,EAAE,OAAO,CAAA;KACnB,CAAA;IACD,QAAQ,EAAE,YAAY,CAAA;IACtB,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,CAAC,EAAE,gBAAgB,EAAE,CAAA;IAC1B,QAAQ,EAAE;QACR,UAAU,EAAE,MAAM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AC,IAAI,CAAA;IACxB,IAAI,EAAE;QACJ,aAAa,EAAE,MAAM,CAAA;QACrB,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAA;KAC/C,CAAA;CACF;AAED,MAAM,WAAW,WAAY,SAAQ,aAAa;IAChD,IAAI,EAAE,aAAa,CAAC,MAAM,CAAA;IAC1B,IAAI,EAAE;QACJ,aAAa,EAAE,MAAM,CAAA;KACtB,CAAA;CACF;AAED,MAAM,WAAW,aAAc,SAAQ,aAAa;IAClD,IAAI,EAAE,aAAa,CAAC,QAAQ,CAAA;IAC5B,IAAI,EAAE;QACJ,aAAa,EAAE,MAAM,CAAA;KACtB,CAAA;CACF;AAED,MAAM,WAAW,aAAc,SAAQ,aAAa;IAClD,IAAI,EAAE,aAAa,CAAC,QAAQ,CAAA;IAC5B,IAAI,EAAE;QACJ,MAAM,EAAE,MAAM,EAAE,CAAA;KACjB,CAAA;CACF;AAED,MAAM,MAAM,SAAS,GAAG,YAAY,GAAG,SAAS,GAAG,WAAW,GAAG,aAAa,GAAG,aAAa,CAAA;AA+K9F;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,EAAE,CAAC,cAAc,EAAE,aAAa,EAAE,aAAa,GAAG,SAAS,CAW9F;AAED,wBAAgB,oBAAoB,CAAC,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,GAAG,MAAM,CAmB3F;AAED,wBAAgB,iBAAiB,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,SAAS,GAAG,MAAM,CA+BnE"}
|
|
@@ -53,7 +53,9 @@ const Intrinsics = {};
|
|
|
53
53
|
function makeIntrinsic(intrinsicName, obj) {
|
|
54
54
|
const name = `${exports.API_PREFIX}.${intrinsicName}`;
|
|
55
55
|
Intrinsics[name] = {
|
|
56
|
-
match: (exp) =>
|
|
56
|
+
match: (exp) => {
|
|
57
|
+
return ts.isCallExpression(exp) && exp.getText().startsWith(name);
|
|
58
|
+
},
|
|
57
59
|
...obj(name),
|
|
58
60
|
};
|
|
59
61
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"intrinsics.js","sourceRoot":"","sources":["../../src/common/intrinsics.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAAgC;AAChC,qCAAoE;AACpE,yCAA+D;AAC/D,yCAAqD;AACrD,yCAA4D;AAG/C,QAAA,UAAU,GAAG,OAAO,CAAA;AACpB,QAAA,kBAAkB,GAAG,GAAG,kBAAU,UAAU,CAAA;AAEzD,IAAY,aAMX;AAND,WAAY,aAAa;IACvB,8BAAa,CAAA;IACb,kCAAiB,CAAA;IACjB,oCAAmB,CAAA;IACnB,sCAAqB,CAAA;IACrB,sCAAqB,CAAA;AACvB,CAAC,EANW,aAAa,6BAAb,aAAa,QAMxB;AAgDD,MAAM,UAAU,GAKZ,EAAE,CAAA;AAEN;;;;;;;;;GASG;AACH,SAAS,aAAa,CACpB,aAAgB,EAChB,GAA0B;IAE1B,MAAM,IAAI,GAAG,GAAG,kBAAU,IAAI,aAAa,EAAE,CAAA;IAC7C,UAAU,CAAC,IAAI,CAAC,GAAG;QACjB,KAAK,EAAE,CAAC,GAAsB,EAAE,EAAE,
|
|
1
|
+
{"version":3,"file":"intrinsics.js","sourceRoot":"","sources":["../../src/common/intrinsics.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAAgC;AAChC,qCAAoE;AACpE,yCAA+D;AAC/D,yCAAqD;AACrD,yCAA4D;AAG/C,QAAA,UAAU,GAAG,OAAO,CAAA;AACpB,QAAA,kBAAkB,GAAG,GAAG,kBAAU,UAAU,CAAA;AAEzD,IAAY,aAMX;AAND,WAAY,aAAa;IACvB,8BAAa,CAAA;IACb,kCAAiB,CAAA;IACjB,oCAAmB,CAAA;IACnB,sCAAqB,CAAA;IACrB,sCAAqB,CAAA;AACvB,CAAC,EANW,aAAa,6BAAb,aAAa,QAM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,CAAC;YACD,OAAO,6BAA6B,IAAI,CAAC,aAAa,IAAI,CAAA;QAC5D,CAAC;QACD,KAAK,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC;YACxB,MAAM,aAAa,GAAG,oBAAoB,CAAC,IAAI,CAAC,YAAY,CAAC,CAAA;YAE7D,uGAAuG;YACvG,OAAO,0BAA0B,IAAI,CAAC,aAAa,MAAM,aAAa,GAAG,CAAA;QAC3E,CAAC;QACD,KAAK,aAAa,CAAC,QAAQ,CAAC,CAAC,CAAC;YAC5B,gFAAgF;YAChF,OAAO,8BAA8B,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,IAAI,SAAS,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAA;QACrG,CAAC;QACD;YACE,MAAM,IAAI,sBAAa,CAAC,sBAAsB,IAAI,EAAE,CAAC,CAAA;IACzD,CAAC;AACH,CAAC;AA/BD,8CA+BC"}
|
package/dist/common/parser.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import ts from 'typescript';
|
|
2
|
-
import {
|
|
2
|
+
import { CodeConnectConfig } from './project';
|
|
3
3
|
import { Intrinsic } from './intrinsics';
|
|
4
4
|
interface ParserErrorContext {
|
|
5
5
|
sourceFile: ts.SourceFile;
|
|
@@ -18,10 +18,10 @@ export declare class InternalError extends ParserError {
|
|
|
18
18
|
export interface ParserContext {
|
|
19
19
|
checker: ts.TypeChecker;
|
|
20
20
|
sourceFile: ts.SourceFile;
|
|
21
|
-
config:
|
|
21
|
+
config: CodeConnectConfig | undefined;
|
|
22
22
|
}
|
|
23
23
|
/**
|
|
24
|
-
* Parsers the `props` field of a `
|
|
24
|
+
* Parsers the `props` field of a `figma.connect()` call, returning a mapping of
|
|
25
25
|
* prop names to their respective intrinsic types
|
|
26
26
|
*
|
|
27
27
|
* @param objectLiteral An object literal expression
|
|
@@ -32,7 +32,7 @@ export declare function parsePropsObject(objectLiteral: ts.ObjectLiteralExpressi
|
|
|
32
32
|
export type PropMappings = Record<string, Intrinsic>;
|
|
33
33
|
/**
|
|
34
34
|
* Extract metadata about the referenced React component. Used by both the
|
|
35
|
-
*
|
|
35
|
+
* Code Connect and Storybook commands.
|
|
36
36
|
*
|
|
37
37
|
* @param parserContext Parser context
|
|
38
38
|
* @param componentSymbol The ts.Symbol from the metadata referencing the
|
|
@@ -46,7 +46,7 @@ export declare function parseComponentMetadata(node: ts.PropertyAccessExpression
|
|
|
46
46
|
component: string;
|
|
47
47
|
}>;
|
|
48
48
|
/**
|
|
49
|
-
* Checks if a file contains
|
|
49
|
+
* Checks if a file contains Code Connect by looking for the `figma.connect()` function call
|
|
50
50
|
*
|
|
51
51
|
* @param program
|
|
52
52
|
* @param file
|
|
@@ -54,7 +54,7 @@ export declare function parseComponentMetadata(node: ts.PropertyAccessExpression
|
|
|
54
54
|
*/
|
|
55
55
|
export declare function isFigmaConnectFile(program: ts.Program, file: string): boolean;
|
|
56
56
|
/**
|
|
57
|
-
* Parses the render function passed to `
|
|
57
|
+
* Parses the render function passed to `figma.connect()`, extracting the code and
|
|
58
58
|
* any import statements matching the JSX elements used in the function body
|
|
59
59
|
*
|
|
60
60
|
* @param exp A function or arrow function expression
|
|
@@ -72,6 +72,6 @@ export declare function parseRenderFunction(exp: ts.ArrowFunction | ts.FunctionE
|
|
|
72
72
|
nestable: boolean;
|
|
73
73
|
};
|
|
74
74
|
export declare function getDefaultTemplate(componentMetadata: Awaited<ReturnType<typeof parseComponentMetadata>>): string;
|
|
75
|
-
export declare function parse(program: ts.Program, file: string, repoUrl?: string, config?:
|
|
75
|
+
export declare function parse(program: ts.Program, file: string, repoUrl?: string, config?: CodeConnectConfig, debug?: boolean): Promise<any[]>;
|
|
76
76
|
export {};
|
|
77
77
|
//# sourceMappingURL=parser.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../../src/common/parser.ts"],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;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,EAAE,IAAI,EAAE,MAAM,WAmBnE;AAkFD;;;;;;;;;GASG;AACH,wBAAgB,mBAAmB,CACjC,GAAG,EAAE,EAAE,CAAC,aAAa,GAAG,EAAE,CAAC,kBAAkB,GAAG,EAAE,CAAC,mBAAmB,EACtE,aAAa,EAAE,aAAa,EAC5B,YAAY,CAAC,EAAE,YAAY;;;;;;;EAwO5B;AAiKD,wBAAgB,kBAAkB,CAChC,iBAAiB,EAAE,OAAO,CAAC,UAAU,CAAC,OAAO,sBAAsB,CAAC,CAAC,UAItE;AAoGD,wBAAsB,KAAK,CACzB,OAAO,EAAE,EAAE,CAAC,OAAO,EACnB,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,MAAM,EAChB,MAAM,CAAC,EAAE,iBAAiB,EAC1B,KAAK,CAAC,EAAE,OAAO,GACd,OAAO,CAAC,GAAG,EAAE,CAAC,CAkChB"}
|
package/dist/common/parser.js
CHANGED
|
@@ -153,7 +153,7 @@ function getImportsForIdentifiers({ sourceFile }, _identifiers) {
|
|
|
153
153
|
return imports;
|
|
154
154
|
}
|
|
155
155
|
/**
|
|
156
|
-
* Parsers the `props` field of a `
|
|
156
|
+
* Parsers the `props` field of a `figma.connect()` call, returning a mapping of
|
|
157
157
|
* prop names to their respective intrinsic types
|
|
158
158
|
*
|
|
159
159
|
* @param objectLiteral An object literal expression
|
|
@@ -171,7 +171,7 @@ function parsePropsObject(objectLiteral, parserContext) {
|
|
|
171
171
|
exports.parsePropsObject = parsePropsObject;
|
|
172
172
|
/**
|
|
173
173
|
* Extract metadata about the referenced React component. Used by both the
|
|
174
|
-
*
|
|
174
|
+
* Code Connect and Storybook commands.
|
|
175
175
|
*
|
|
176
176
|
* @param parserContext Parser context
|
|
177
177
|
* @param componentSymbol The ts.Symbol from the metadata referencing the
|
|
@@ -263,24 +263,24 @@ async function parseComponentMetadata(node, { checker, sourceFile }) {
|
|
|
263
263
|
}
|
|
264
264
|
exports.parseComponentMetadata = parseComponentMetadata;
|
|
265
265
|
/**
|
|
266
|
-
* Checks if an AST node is a `
|
|
266
|
+
* Checks if an AST node is a `figma.connect()` call
|
|
267
267
|
*
|
|
268
268
|
* @param node AST node
|
|
269
269
|
* @param sourceFile Source file
|
|
270
|
-
* @returns True if the node is a `
|
|
270
|
+
* @returns True if the node is a `figma.connect()` call
|
|
271
271
|
*/
|
|
272
272
|
function isFigmaConnectCall(node, sourceFile) {
|
|
273
273
|
return (typescript_1.default.isCallExpression(node) && node.expression.getText(sourceFile).includes(intrinsics_1.FIGMA_CONNECT_CALL));
|
|
274
274
|
}
|
|
275
275
|
/**
|
|
276
|
-
* Checks if a file contains
|
|
276
|
+
* Checks if a file contains Code Connect by looking for the `figma.connect()` function call
|
|
277
277
|
*
|
|
278
278
|
* @param program
|
|
279
279
|
* @param file
|
|
280
280
|
* @returns
|
|
281
281
|
*/
|
|
282
282
|
function isFigmaConnectFile(program, file) {
|
|
283
|
-
// We don't support
|
|
283
|
+
// We don't support Code Connect in JSX and this throws an error if we let it proceed
|
|
284
284
|
if (!file.endsWith('.tsx')) {
|
|
285
285
|
return false;
|
|
286
286
|
}
|
|
@@ -297,7 +297,7 @@ function isFigmaConnectFile(program, file) {
|
|
|
297
297
|
}
|
|
298
298
|
exports.isFigmaConnectFile = isFigmaConnectFile;
|
|
299
299
|
/**
|
|
300
|
-
* Parses the `links` field of a `
|
|
300
|
+
* Parses the `links` field of a `figma.connect()` call
|
|
301
301
|
*
|
|
302
302
|
* @param linksArray an ArrayLiteralExpression
|
|
303
303
|
* @param parserContext Parser context
|
|
@@ -345,7 +345,23 @@ function parseVariant(variantMap, sourceFile, checker) {
|
|
|
345
345
|
});
|
|
346
346
|
}
|
|
347
347
|
/**
|
|
348
|
-
* Parses the
|
|
348
|
+
* Parses the `imports` field of a `figma.connect()` call
|
|
349
|
+
*
|
|
350
|
+
* @param importsArray an ArrayLiteralExpression
|
|
351
|
+
* @param parserContext Parser context
|
|
352
|
+
* @returns An array of link objects
|
|
353
|
+
*/
|
|
354
|
+
function parseImports(importsArray, parserContext) {
|
|
355
|
+
const { sourceFile } = parserContext;
|
|
356
|
+
const imports = [];
|
|
357
|
+
for (const element of importsArray.elements) {
|
|
358
|
+
(0, compiler_1.assertIsStringLiteral)(element, sourceFile, `'imports' must be an array literal with strings`);
|
|
359
|
+
imports.push((0, compiler_1.stripQuotes)(element));
|
|
360
|
+
}
|
|
361
|
+
return imports;
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* Parses the render function passed to `figma.connect()`, extracting the code and
|
|
349
365
|
* any import statements matching the JSX elements used in the function body
|
|
350
366
|
*
|
|
351
367
|
* @param exp A function or arrow function expression
|
|
@@ -423,9 +439,22 @@ function parseRenderFunction(exp, parserContext, propMappings) {
|
|
|
423
439
|
// <Button prop1={__PROP__("prop1")} prop2={__PROP__("prop2")} />.
|
|
424
440
|
if (typescript_1.default.isJsxSpreadAttribute(node) &&
|
|
425
441
|
typescript_1.default.isIdentifier(node.expression) &&
|
|
426
|
-
|
|
442
|
+
// example: (props) => (...)
|
|
443
|
+
(node.expression.getText() === propsParameter.name.getText() ||
|
|
444
|
+
// example: ({ prop1, prop2 ...props }) => (...)
|
|
445
|
+
(typescript_1.default.isObjectBindingPattern(propsParameter.name) &&
|
|
446
|
+
propsParameter.name.elements.find((el) => el.dotDotDotToken && el.name.getText() === node.expression?.getText())))) {
|
|
447
|
+
// if we have an object binding pattern ({ prop1, prop2 ...props }),
|
|
448
|
+
// exclude the props that are already destructured (prop1, prop2)
|
|
449
|
+
const propsToExclude = typescript_1.default.isObjectBindingPattern(propsParameter.name)
|
|
450
|
+
? propsParameter.name.elements
|
|
451
|
+
.filter((el) => !el.dotDotDotToken)
|
|
452
|
+
.map((el) => el.name.getText())
|
|
453
|
+
: [];
|
|
427
454
|
const props = propMappings
|
|
428
|
-
? Object.keys(propMappings)
|
|
455
|
+
? Object.keys(propMappings)
|
|
456
|
+
.filter((prop) => !propsToExclude.includes(prop))
|
|
457
|
+
.map((prop) => {
|
|
429
458
|
return typescript_1.default.factory.createJsxAttribute(typescript_1.default.factory.createIdentifier(prop), createPropPlaceholder(prop, node, true));
|
|
430
459
|
})
|
|
431
460
|
: [];
|
|
@@ -514,7 +543,7 @@ function parseRenderFunction(exp, parserContext, propMappings) {
|
|
|
514
543
|
exports.parseRenderFunction = parseRenderFunction;
|
|
515
544
|
/**
|
|
516
545
|
* This wrapper function ensures that property names are type checked in case
|
|
517
|
-
* we make changes to the `
|
|
546
|
+
* we make changes to the `figma.connect()` interface.
|
|
518
547
|
*/
|
|
519
548
|
function makeConfigPropertyParser({ key, predicate, errorMessage, }) {
|
|
520
549
|
return (configArg, parserContext) => {
|
|
@@ -618,6 +647,14 @@ function makeArgParser() {
|
|
|
618
647
|
links: [
|
|
619
648
|
{ name: 'Storybook', url: 'https://storybook.com' }
|
|
620
649
|
]
|
|
650
|
+
})\``,
|
|
651
|
+
}),
|
|
652
|
+
parseImports: makeConfigPropertyParser({
|
|
653
|
+
key: 'imports',
|
|
654
|
+
predicate: typescript_1.default.isArrayLiteralExpression,
|
|
655
|
+
errorMessage: `The 'imports' property must be an array literal. Example usage:
|
|
656
|
+
\`${intrinsics_1.FIGMA_CONNECT_CALL}(Button, 'https://www.figma.com/file/123?node-id=1-1', {
|
|
657
|
+
imports: ['import { Button } from "./Button"']
|
|
621
658
|
})\``,
|
|
622
659
|
}),
|
|
623
660
|
};
|
|
@@ -629,7 +666,7 @@ function getDefaultTemplate(componentMetadata) {
|
|
|
629
666
|
exports.getDefaultTemplate = getDefaultTemplate;
|
|
630
667
|
async function parseDoc(node, parserContext, repoUrl) {
|
|
631
668
|
const { checker, sourceFile, config } = parserContext;
|
|
632
|
-
// Parse the arguments to the `
|
|
669
|
+
// Parse the arguments to the `figma.connect()` call
|
|
633
670
|
const args = makeArgParser();
|
|
634
671
|
// The ones with ! are definitely defined because their parser fn has required: true,
|
|
635
672
|
// but I couldn't work out how to model that in TypeScript
|
|
@@ -640,6 +677,7 @@ async function parseDoc(node, parserContext, repoUrl) {
|
|
|
640
677
|
const exampleArg = configObjArg && args.parseExample(configObjArg, parserContext);
|
|
641
678
|
const variantArg = configObjArg && args.parseVariant(configObjArg, parserContext);
|
|
642
679
|
const linksArg = configObjArg && args.parseLinks(configObjArg, parserContext);
|
|
680
|
+
const importsArg = configObjArg && args.parseImports(configObjArg, parserContext);
|
|
643
681
|
let figmaNode = (0, compiler_1.stripQuotes)(figmaNodeUrlArg);
|
|
644
682
|
if (config?.documentUrlSubstitutions) {
|
|
645
683
|
Object.entries(config.documentUrlSubstitutions).forEach(([from, to]) => {
|
|
@@ -651,34 +689,42 @@ async function parseDoc(node, parserContext, repoUrl) {
|
|
|
651
689
|
const render = exampleArg ? parseRenderFunction(exampleArg, parserContext, props) : undefined;
|
|
652
690
|
const variant = variantArg ? parseVariant(variantArg, sourceFile, checker) : undefined;
|
|
653
691
|
const links = linksArg ? parseLinks(linksArg, parserContext) : undefined;
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
const template = render?.code ?? getDefaultTemplate(metadata);
|
|
658
|
-
if (imports.length === 0) {
|
|
659
|
-
// If no imports were found, it might mean that the component is not imported, or
|
|
660
|
-
// that the `figma.connect` call is in the same file as the component. In the latter
|
|
661
|
-
// case - we'll want to generate one
|
|
662
|
-
const fileName = metadata.source.split('/').pop()?.split('.')[0];
|
|
663
|
-
imports = [
|
|
664
|
-
{
|
|
665
|
-
statement: `import { ${metadata.component} } from './${fileName}'`,
|
|
666
|
-
file: sourceFile.fileName,
|
|
667
|
-
},
|
|
668
|
-
];
|
|
692
|
+
let resolvedImports;
|
|
693
|
+
if (importsArg) {
|
|
694
|
+
resolvedImports = parseImports(importsArg, parserContext);
|
|
669
695
|
}
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
696
|
+
else {
|
|
697
|
+
// Use auto-generated imports
|
|
698
|
+
// If no template function was provided, construct one and add the import
|
|
699
|
+
// statement for the component
|
|
700
|
+
let imports = render?.imports ?? getImportsForIdentifiers(parserContext, [metadata.component]);
|
|
701
|
+
if (imports.length === 0) {
|
|
702
|
+
// If no imports were found, it might mean that the component is not imported, or
|
|
703
|
+
// that the `figma.connect` call is in the same file as the component. In the latter
|
|
704
|
+
// case - we'll want to generate one
|
|
705
|
+
const fileName = metadata.source.split('/').pop()?.split('.')[0];
|
|
706
|
+
imports = [
|
|
707
|
+
{
|
|
708
|
+
statement: `import { ${metadata.component} } from './${fileName}'`,
|
|
709
|
+
file: sourceFile.fileName,
|
|
710
|
+
},
|
|
711
|
+
];
|
|
712
|
+
}
|
|
713
|
+
resolvedImports =
|
|
714
|
+
imports.map((imp) => {
|
|
715
|
+
if (config) {
|
|
716
|
+
const resolvedPath = (0, project_1.resolveImportPath)(imp.file, config);
|
|
717
|
+
if (resolvedPath) {
|
|
718
|
+
return imp.statement.replace(/['"]([\.\/a-zA-Z0-9]*)['"]/, `'${resolvedPath}'`);
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
return imp.statement;
|
|
722
|
+
}) ?? [];
|
|
723
|
+
if (resolvedImports.length === 0) {
|
|
724
|
+
logging_1.logger.warn(`The import statement for ${metadata.component} could not be automatically resolved, make sure the component is imported (if not colocating) and that the path mappings are correct in your figma.config.json`);
|
|
676
725
|
}
|
|
677
|
-
return imp.statement;
|
|
678
|
-
}) ?? [];
|
|
679
|
-
if (resolvedImports.length === 0) {
|
|
680
|
-
logging_1.logger.warn(`The import statement for ${metadata.component} could not be automatically resolved, make sure the component is imported (if not colocating) and that the path mappings are correct in your figma.config.json`);
|
|
681
726
|
}
|
|
727
|
+
const template = render?.code ?? getDefaultTemplate(metadata);
|
|
682
728
|
return {
|
|
683
729
|
figmaNode,
|
|
684
730
|
label: 'React',
|
|
@@ -712,25 +758,25 @@ async function parse(program, file, repoUrl, config, debug) {
|
|
|
712
758
|
sourceFile,
|
|
713
759
|
config,
|
|
714
760
|
};
|
|
715
|
-
const
|
|
761
|
+
const codeConnectObjects = [];
|
|
716
762
|
const nodes = [parserContext.sourceFile];
|
|
717
763
|
while (nodes.length > 0) {
|
|
718
764
|
const node = nodes.shift();
|
|
719
765
|
if (isFigmaConnectCall(node, parserContext.sourceFile)) {
|
|
720
766
|
const doc = await parseDoc(node, parserContext, repoUrl);
|
|
721
767
|
if (doc) {
|
|
722
|
-
|
|
768
|
+
codeConnectObjects.push(doc);
|
|
723
769
|
}
|
|
724
770
|
}
|
|
725
771
|
nodes.push(...node.getChildren(parserContext.sourceFile));
|
|
726
772
|
}
|
|
727
|
-
if (
|
|
728
|
-
throw new ParserError(`Didn't find any calls to
|
|
773
|
+
if (codeConnectObjects.length === 0) {
|
|
774
|
+
throw new ParserError(`Didn't find any calls to figma.connect()`, {
|
|
729
775
|
sourceFile: parserContext.sourceFile,
|
|
730
776
|
node: parserContext.sourceFile,
|
|
731
777
|
});
|
|
732
778
|
}
|
|
733
|
-
return
|
|
779
|
+
return codeConnectObjects;
|
|
734
780
|
}
|
|
735
781
|
exports.parse = parse;
|
|
736
782
|
//# sourceMappingURL=parser.js.map
|