@figma/code-connect 0.1.0
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 +449 -0
- package/bin/figma +5 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +41 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands/connect.d.ts +3 -0
- package/dist/commands/connect.d.ts.map +1 -0
- package/dist/commands/connect.js +214 -0
- package/dist/commands/connect.js.map +1 -0
- package/dist/common/api.d.ts +146 -0
- package/dist/common/api.d.ts.map +1 -0
- package/dist/common/api.js +3 -0
- package/dist/common/api.js.map +1 -0
- package/dist/common/compiler.d.ts +96 -0
- package/dist/common/compiler.d.ts.map +1 -0
- package/dist/common/compiler.js +281 -0
- package/dist/common/compiler.js.map +1 -0
- package/dist/common/external.d.ts +10 -0
- package/dist/common/external.d.ts.map +1 -0
- package/dist/common/external.js +53 -0
- package/dist/common/external.js.map +1 -0
- package/dist/common/figma_connect.d.ts +24 -0
- package/dist/common/figma_connect.d.ts.map +1 -0
- package/dist/common/figma_connect.js +3 -0
- package/dist/common/figma_connect.js.map +1 -0
- package/dist/common/intrinsics.d.ts +61 -0
- package/dist/common/intrinsics.d.ts.map +1 -0
- package/dist/common/intrinsics.js +239 -0
- package/dist/common/intrinsics.js.map +1 -0
- package/dist/common/logging.d.ts +25 -0
- package/dist/common/logging.d.ts.map +1 -0
- package/dist/common/logging.js +47 -0
- package/dist/common/logging.js.map +1 -0
- package/dist/common/parser.d.ts +77 -0
- package/dist/common/parser.d.ts.map +1 -0
- package/dist/common/parser.js +736 -0
- package/dist/common/parser.js.map +1 -0
- package/dist/common/parser_template_helpers.d.ts +2 -0
- package/dist/common/parser_template_helpers.d.ts.map +1 -0
- package/dist/common/parser_template_helpers.js +53 -0
- package/dist/common/parser_template_helpers.js.map +1 -0
- package/dist/common/project.d.ts +79 -0
- package/dist/common/project.d.ts.map +1 -0
- package/dist/common/project.js +171 -0
- package/dist/common/project.js.map +1 -0
- package/dist/connect/create.d.ts +8 -0
- package/dist/connect/create.d.ts.map +1 -0
- package/dist/connect/create.js +162 -0
- package/dist/connect/create.js.map +1 -0
- package/dist/connect/delete_docs.d.ts +11 -0
- package/dist/connect/delete_docs.d.ts.map +1 -0
- package/dist/connect/delete_docs.js +60 -0
- package/dist/connect/delete_docs.js.map +1 -0
- package/dist/connect/figma_rest_api.d.ts +28 -0
- package/dist/connect/figma_rest_api.d.ts.map +1 -0
- package/dist/connect/figma_rest_api.js +19 -0
- package/dist/connect/figma_rest_api.js.map +1 -0
- package/dist/connect/helpers.d.ts +13 -0
- package/dist/connect/helpers.d.ts.map +1 -0
- package/dist/connect/helpers.js +87 -0
- package/dist/connect/helpers.js.map +1 -0
- package/dist/connect/upload.d.ts +8 -0
- package/dist/connect/upload.d.ts.map +1 -0
- package/dist/connect/upload.js +62 -0
- package/dist/connect/upload.js.map +1 -0
- package/dist/connect/validation.d.ts +3 -0
- package/dist/connect/validation.d.ts.map +1 -0
- package/dist/connect/validation.js +241 -0
- package/dist/connect/validation.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +31 -0
- package/dist/index.js.map +1 -0
- package/dist/storybook/convert.d.ts +24 -0
- package/dist/storybook/convert.d.ts.map +1 -0
- package/dist/storybook/convert.js +280 -0
- package/dist/storybook/convert.js.map +1 -0
- package/dist/storybook/external.d.ts +32 -0
- package/dist/storybook/external.d.ts.map +1 -0
- package/dist/storybook/external.js +3 -0
- package/dist/storybook/external.js.map +1 -0
- package/package.json +56 -0
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.convertStorybookFiles = void 0;
|
|
7
|
+
const fs_1 = require("fs");
|
|
8
|
+
const compiler_1 = require("../common/compiler");
|
|
9
|
+
const parser_1 = require("../common/parser");
|
|
10
|
+
const project_1 = require("../common/project");
|
|
11
|
+
const logging_1 = require("../common/logging");
|
|
12
|
+
const typescript_1 = __importDefault(require("typescript"));
|
|
13
|
+
const minimatch_1 = require("minimatch");
|
|
14
|
+
/**
|
|
15
|
+
* Converts all Storyboook files in a directory into Figmadoc objects. If a file
|
|
16
|
+
* cannot be converted (e.g. unsupported syntax), it is ignored and an error is
|
|
17
|
+
* logged.
|
|
18
|
+
*
|
|
19
|
+
* @param args
|
|
20
|
+
* @returns An array of Figmadoc objects
|
|
21
|
+
*/
|
|
22
|
+
async function convertStorybookFiles({ projectInfo, storiesGlob = '**/*.stories.tsx', }) {
|
|
23
|
+
const { remoteUrl, config, files, tsProgram } = projectInfo;
|
|
24
|
+
const storyFiles = files.filter((file) => (0, minimatch_1.minimatch)(file, storiesGlob, { matchBase: true }));
|
|
25
|
+
logging_1.logger.debug(`Story files found:\n${storyFiles.map((f) => `- ${f}`).join('\n')}`);
|
|
26
|
+
return Promise.all(storyFiles.map((path) => convertStorybookFile({ path, tsProgram, config, remoteUrl })))
|
|
27
|
+
.then((f) => f.filter((x) => Boolean(x)))
|
|
28
|
+
.then((f) => f.flat());
|
|
29
|
+
}
|
|
30
|
+
exports.convertStorybookFiles = convertStorybookFiles;
|
|
31
|
+
async function convertStorybookFile({ path, tsProgram, remoteUrl, config, }) {
|
|
32
|
+
const checker = tsProgram.getTypeChecker();
|
|
33
|
+
const sourceFile = tsProgram.getSourceFile(path);
|
|
34
|
+
if (!sourceFile) {
|
|
35
|
+
throw new parser_1.InternalError(`Source file not found: ${path}`);
|
|
36
|
+
}
|
|
37
|
+
const parserContext = {
|
|
38
|
+
checker,
|
|
39
|
+
config,
|
|
40
|
+
sourceFile,
|
|
41
|
+
};
|
|
42
|
+
let source = (0, fs_1.readFileSync)(path).toString();
|
|
43
|
+
// Replace backticks with ' as csf-tools can't parse dynamic titles
|
|
44
|
+
source = source.replace(/title: `(.*)`/g, (match, title) => {
|
|
45
|
+
return `title: '${title}'`;
|
|
46
|
+
});
|
|
47
|
+
logging_1.logger.debug(`Parsing story ${path}`);
|
|
48
|
+
try {
|
|
49
|
+
// We need to get the default export, which contains the story file meta,
|
|
50
|
+
// from the TS Program rather than using `babelNodeToTsSourceFile(csf._metaNode)`,
|
|
51
|
+
// because we need access to the full Program to parse it for prop types etc.
|
|
52
|
+
const storyFileMetaNode = (0, compiler_1.getDefaultExport)(sourceFile);
|
|
53
|
+
if (!storyFileMetaNode) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
const parseResult = parseStoryMetadata(storyFileMetaNode, parserContext);
|
|
57
|
+
if (!parseResult) {
|
|
58
|
+
logging_1.logger.debug(`Could not parse story metadata for ${path}`);
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
const { figmaStoryMetadata, componentDeclaration, propMappings, mappedProps, examples } = parseResult;
|
|
62
|
+
const componentMetadata = await (0, parser_1.parseComponentMetadata)(componentDeclaration, parserContext);
|
|
63
|
+
const figmadocs = [];
|
|
64
|
+
const baseFigmadoc = {
|
|
65
|
+
figmaNode: figmaStoryMetadata.url,
|
|
66
|
+
source: (0, project_1.getRemoteFileUrl)(componentMetadata.source, remoteUrl),
|
|
67
|
+
sourceLocation: { line: componentMetadata.line },
|
|
68
|
+
template: '',
|
|
69
|
+
templateData: {
|
|
70
|
+
props: propMappings,
|
|
71
|
+
imports: [],
|
|
72
|
+
},
|
|
73
|
+
component: componentMetadata.component,
|
|
74
|
+
label: 'Storybook',
|
|
75
|
+
language: 'typescript',
|
|
76
|
+
metadata: {
|
|
77
|
+
cliVersion: require('../../package.json').version,
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
// If there are no examples, just return a default Figmadoc
|
|
81
|
+
if (!examples) {
|
|
82
|
+
figmadocs.push({
|
|
83
|
+
...baseFigmadoc,
|
|
84
|
+
template: (0, parser_1.getDefaultTemplate)(componentMetadata),
|
|
85
|
+
});
|
|
86
|
+
return figmadocs;
|
|
87
|
+
}
|
|
88
|
+
for (const statement of sourceFile.statements) {
|
|
89
|
+
// Find any exported function or variable declarations, which correspond to stories
|
|
90
|
+
if (!(typescript_1.default.isFunctionDeclaration(statement) || typescript_1.default.isVariableStatement(statement))) {
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
const name = typescript_1.default.isFunctionDeclaration(statement)
|
|
94
|
+
? statement.name?.text
|
|
95
|
+
: statement.declarationList.declarations?.[0].name.getText(sourceFile);
|
|
96
|
+
const example = examples?.find((example) => example.example === name);
|
|
97
|
+
// This story is not in the examples array, so skip it
|
|
98
|
+
if (examples && !example) {
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
let statementToParse;
|
|
102
|
+
if (typescript_1.default.isFunctionDeclaration(statement)) {
|
|
103
|
+
statementToParse = statement;
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
const initializer = statement.declarationList.declarations[0].initializer;
|
|
107
|
+
if (initializer && typescript_1.default.isArrowFunction(initializer)) {
|
|
108
|
+
statementToParse = initializer;
|
|
109
|
+
}
|
|
110
|
+
else if (initializer && typescript_1.default.isObjectLiteralExpression(initializer)) {
|
|
111
|
+
// Handle stories like `export const Primary = { render: () => <Button /> }`
|
|
112
|
+
const renderProperty = (0, compiler_1.parsePropertyOfType)({
|
|
113
|
+
objectLiteralNode: initializer,
|
|
114
|
+
propertyName: 'render',
|
|
115
|
+
predicate: typescript_1.default.isArrowFunction,
|
|
116
|
+
parserContext,
|
|
117
|
+
required: true,
|
|
118
|
+
});
|
|
119
|
+
if (renderProperty) {
|
|
120
|
+
statementToParse = renderProperty;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
if (!statementToParse) {
|
|
125
|
+
throw new parser_1.ParserError('Expected function declaration, arrow function or render function in story', {
|
|
126
|
+
sourceFile,
|
|
127
|
+
node: statement,
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
let render = (0, parser_1.parseRenderFunction)(statementToParse, parserContext, propMappings);
|
|
131
|
+
if (!render) {
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
const template = render.code ?? `<${componentMetadata.component} />`;
|
|
135
|
+
// TODO handle JSDoc on stories
|
|
136
|
+
figmadocs.push({
|
|
137
|
+
...baseFigmadoc,
|
|
138
|
+
template,
|
|
139
|
+
variant: example?.variant,
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
return figmadocs;
|
|
143
|
+
}
|
|
144
|
+
catch (e) {
|
|
145
|
+
logging_1.logger.error(`Error parsing story ${path}: ${e}`);
|
|
146
|
+
throw e;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
function isJsxElement(node) {
|
|
150
|
+
return typescript_1.default.isJsxElement(node) || typescript_1.default.isJsxSelfClosingElement(node) || typescript_1.default.isJsxFragment(node);
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Get the TS Node representing the component declaration from the story file
|
|
154
|
+
*
|
|
155
|
+
* @param objectLiteralNode Object literal containing the story file metadata
|
|
156
|
+
* @returns TS Node representing the component declaration or undefined
|
|
157
|
+
*/
|
|
158
|
+
function getComponentDeclaration(objectLiteralNode) {
|
|
159
|
+
for (const property of objectLiteralNode.properties) {
|
|
160
|
+
if (!typescript_1.default.isPropertyAssignment(property))
|
|
161
|
+
continue;
|
|
162
|
+
const propertyName = property.name;
|
|
163
|
+
if (typescript_1.default.isIdentifier(propertyName) && propertyName.text === 'component') {
|
|
164
|
+
return property.initializer;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
return undefined;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Validate and returns Figma metadata from the default export of the storybook
|
|
171
|
+
* file
|
|
172
|
+
*
|
|
173
|
+
* @param storyFileMetaNode TS Node containing the story file metadata, i.e. the
|
|
174
|
+
* default export of the file
|
|
175
|
+
* @param sourceFile TS SourceFile representing a single story
|
|
176
|
+
* @returns Figma metadata
|
|
177
|
+
* @throws Error if no Figma metadata is found
|
|
178
|
+
*/
|
|
179
|
+
function parseStoryMetadata(storyFileMetaNode, parserContext) {
|
|
180
|
+
const { sourceFile, checker } = parserContext;
|
|
181
|
+
// Find the first object expression under tsSourceFile.statements[0],
|
|
182
|
+
// which contains the story file metadata. We do it this way to allow syntax
|
|
183
|
+
// like `export default ({ ... meta ... } as ComponentMeta<...>)`
|
|
184
|
+
const objectLiteralNode = (0, compiler_1.bfsFindNode)(storyFileMetaNode, sourceFile, (node) => typescript_1.default.isObjectLiteralExpression(node));
|
|
185
|
+
if (!objectLiteralNode || !typescript_1.default.isObjectLiteralExpression(objectLiteralNode)) {
|
|
186
|
+
logging_1.logger.debug(`No object literal found in story metadata`);
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
const componentDeclaration = getComponentDeclaration(objectLiteralNode);
|
|
190
|
+
if (!componentDeclaration) {
|
|
191
|
+
logging_1.logger.debug(`No component declaration found in story metadata`);
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
const parametersNode = (0, compiler_1.parsePropertyOfType)({
|
|
195
|
+
objectLiteralNode: objectLiteralNode,
|
|
196
|
+
propertyName: 'parameters',
|
|
197
|
+
predicate: typescript_1.default.isObjectLiteralExpression,
|
|
198
|
+
parserContext,
|
|
199
|
+
required: false,
|
|
200
|
+
});
|
|
201
|
+
// If there's no parameters object, this file shouldn't be imported
|
|
202
|
+
if (!parametersNode) {
|
|
203
|
+
logging_1.logger.debug(`No parameters object found in story metadata`);
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
const designNode = (0, compiler_1.parsePropertyOfType)({
|
|
207
|
+
objectLiteralNode: parametersNode,
|
|
208
|
+
propertyName: 'design',
|
|
209
|
+
predicate: typescript_1.default.isObjectLiteralExpression,
|
|
210
|
+
parserContext,
|
|
211
|
+
required: false,
|
|
212
|
+
});
|
|
213
|
+
// If there's no design object, this file shouldn't be imported
|
|
214
|
+
if (!designNode) {
|
|
215
|
+
logging_1.logger.debug(`No design object found in story metadata`);
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
const typeNode = (0, compiler_1.parsePropertyOfType)({
|
|
219
|
+
objectLiteralNode: designNode,
|
|
220
|
+
propertyName: 'type',
|
|
221
|
+
predicate: typescript_1.default.isStringLiteral,
|
|
222
|
+
parserContext,
|
|
223
|
+
errorMessage: '"type" property not found in "design" object in story metadata',
|
|
224
|
+
required: false,
|
|
225
|
+
});
|
|
226
|
+
// If the design is not a Figma design, this file shouldn't be imported
|
|
227
|
+
if (!typeNode || typeNode.text !== 'figma') {
|
|
228
|
+
logging_1.logger.debug(`Design type is not figma`);
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
const urlNode = (0, compiler_1.parsePropertyOfType)({
|
|
232
|
+
objectLiteralNode: designNode,
|
|
233
|
+
propertyName: 'url',
|
|
234
|
+
predicate: typescript_1.default.isStringLiteral,
|
|
235
|
+
parserContext,
|
|
236
|
+
errorMessage: '"url" property not found in "design" object in story metadata',
|
|
237
|
+
required: true,
|
|
238
|
+
});
|
|
239
|
+
const figmaStoryMetadata = {
|
|
240
|
+
type: typeNode.text,
|
|
241
|
+
url: urlNode.text,
|
|
242
|
+
};
|
|
243
|
+
const propMappingNode = (0, compiler_1.parsePropertyOfType)({
|
|
244
|
+
objectLiteralNode: designNode,
|
|
245
|
+
propertyName: 'props',
|
|
246
|
+
predicate: typescript_1.default.isObjectLiteralExpression,
|
|
247
|
+
parserContext,
|
|
248
|
+
required: false,
|
|
249
|
+
});
|
|
250
|
+
const examplesNode = (0, compiler_1.parsePropertyOfType)({
|
|
251
|
+
objectLiteralNode: designNode,
|
|
252
|
+
propertyName: 'examples',
|
|
253
|
+
predicate: typescript_1.default.isArrayLiteralExpression,
|
|
254
|
+
parserContext,
|
|
255
|
+
required: false,
|
|
256
|
+
});
|
|
257
|
+
let propMappings;
|
|
258
|
+
let mappedProps;
|
|
259
|
+
if (propMappingNode) {
|
|
260
|
+
mappedProps = new Map();
|
|
261
|
+
propMappings = (0, parser_1.parsePropsObject)(propMappingNode, parserContext);
|
|
262
|
+
}
|
|
263
|
+
let examples;
|
|
264
|
+
if (examplesNode) {
|
|
265
|
+
examples = examplesNode.elements.map((exampleNode) => {
|
|
266
|
+
if (typescript_1.default.isStringLiteral(exampleNode) || typescript_1.default.isIdentifier(exampleNode)) {
|
|
267
|
+
return { example: exampleNode.text };
|
|
268
|
+
}
|
|
269
|
+
if (!typescript_1.default.isObjectLiteralExpression(exampleNode)) {
|
|
270
|
+
throw new parser_1.ParserError(`Expected object literal in examples array, got: ${typescript_1.default.SyntaxKind[exampleNode.kind]}`, {
|
|
271
|
+
sourceFile,
|
|
272
|
+
node: exampleNode,
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
return (0, compiler_1.convertObjectLiteralToJs)(exampleNode, sourceFile, checker);
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
return { figmaStoryMetadata, componentDeclaration, propMappings, mappedProps, examples };
|
|
279
|
+
}
|
|
280
|
+
//# sourceMappingURL=convert.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convert.js","sourceRoot":"","sources":["../../src/storybook/convert.ts"],"names":[],"mappings":";;;;;;AAAA,2BAAuC;AACvC,iDAK2B;AAC3B,6CAQyB;AACzB,+CAAqF;AACrF,+CAA0C;AAE1C,4DAA2B;AAE3B,yCAAqC;AAerC;;;;;;;GAOG;AACI,KAAK,UAAU,qBAAqB,CAAC,EAC1C,WAAW,EACX,WAAW,GAAG,kBAAkB,GACN;IAC1B,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,GAAG,WAAW,CAAA;IAE3D,MAAM,UAAU,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAA,qBAAS,EAAC,IAAI,EAAE,WAAW,EAAE,EAAE,SAAS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AC,CAAC,CAAA;IACJ,CAAC;IAED,OAAO,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,YAAY,EAAE,WAAW,EAAE,QAAQ,EAAE,CAAA;AAC1F,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { FigmaConnectMeta } from '../common/api';
|
|
2
|
+
/**
|
|
3
|
+
* Type for the Storybook `parameters` when using Figma Code Connect. This can
|
|
4
|
+
* be used in your Storybook default export like:
|
|
5
|
+
* ```
|
|
6
|
+
* export default {
|
|
7
|
+
* // ...
|
|
8
|
+
* parameters: {
|
|
9
|
+
* // ...
|
|
10
|
+
* } satisfies StoryParameters,
|
|
11
|
+
* }
|
|
12
|
+
*/
|
|
13
|
+
export type StoryParameters<T = {}> = {
|
|
14
|
+
design: {
|
|
15
|
+
type: 'figma';
|
|
16
|
+
/**
|
|
17
|
+
* A link to the node in Figma, for example:`https://www.figma.com/file/123abc/My-Component?node-id=123:456`
|
|
18
|
+
*/
|
|
19
|
+
url: string;
|
|
20
|
+
/**
|
|
21
|
+
* Optional array of examples to show in Figma. If none are specified, Figma
|
|
22
|
+
* will show a default code example.
|
|
23
|
+
*/
|
|
24
|
+
examples?: (FigmaConnectMeta<T>['example'] | string | ExampleObject<T>)[];
|
|
25
|
+
} & Pick<FigmaConnectMeta, 'props' | 'links'>;
|
|
26
|
+
};
|
|
27
|
+
type ExampleObject<T> = FigmaConnectMeta<T, string> & {
|
|
28
|
+
variant?: FigmaConnectMeta['variant'];
|
|
29
|
+
links?: FigmaConnectMeta['links'];
|
|
30
|
+
};
|
|
31
|
+
export {};
|
|
32
|
+
//# sourceMappingURL=external.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"external.d.ts","sourceRoot":"","sources":["../../src/storybook/external.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAA;AAEhD;;;;;;;;;;GAUG;AACH,MAAM,MAAM,eAAe,CAAC,CAAC,GAAG,EAAE,IAAI;IACpC,MAAM,EAAE;QACN,IAAI,EAAE,OAAO,CAAA;QACb;;WAEG;QACH,GAAG,EAAE,MAAM,CAAA;QACX;;;WAGG;QACH,QAAQ,CAAC,EAAE,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,GAAG,MAAM,GAAG,aAAa,CAAC,CAAC,CAAC,CAAC,EAAE,CAAA;KAC1E,GAAG,IAAI,CAAC,gBAAgB,EAAE,OAAO,GAAG,OAAO,CAAC,CAAA;CAC9C,CAAA;AAED,KAAK,aAAa,CAAC,CAAC,IAAI,gBAAgB,CAAC,CAAC,EAAE,MAAM,CAAC,GAAG;IACpD,OAAO,CAAC,EAAE,gBAAgB,CAAC,SAAS,CAAC,CAAA;IACrC,KAAK,CAAC,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAA;CAClC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"external.js","sourceRoot":"","sources":["../../src/storybook/external.ts"],"names":[],"mappings":""}
|
package/package.json
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@figma/code-connect",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Figma Code Connect",
|
|
5
|
+
"keywords": [],
|
|
6
|
+
"author": "Figma",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"main": "./dist/index.js",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+ssh://git@github.com/figma/code-connect.git"
|
|
12
|
+
},
|
|
13
|
+
"homepage": "https://github.com/figma/code-connect#readme",
|
|
14
|
+
"bin": {
|
|
15
|
+
"figma": "bin/figma"
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist/**/*"
|
|
19
|
+
],
|
|
20
|
+
"scripts": {
|
|
21
|
+
"dev": "tsx src/cli.ts",
|
|
22
|
+
"build": "tsc",
|
|
23
|
+
"build:web": "pnpm build",
|
|
24
|
+
"test": "NODE_OPTIONS=--experimental-vm-modules npx jest --coverage",
|
|
25
|
+
"test-ci": "NODE_OPTIONS=--experimental-vm-modules npx jest --coverage --runInBand",
|
|
26
|
+
"bundle": "npm run build && npm pack && mkdir -p bundle && mv figma-code-connect*.tgz bundle",
|
|
27
|
+
"typecheck": "tsc --noEmit"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@types/jest": "^29.5.5",
|
|
31
|
+
"@types/lodash": "^4.17.0",
|
|
32
|
+
"@types/node": "^18.17.1",
|
|
33
|
+
"@types/react": "18.0.26",
|
|
34
|
+
"jest": "^29.7.0",
|
|
35
|
+
"pkg": "^5.8.1",
|
|
36
|
+
"react": "18.2.0",
|
|
37
|
+
"ts-jest": "^29.1.1",
|
|
38
|
+
"tsx": "^4.7.0"
|
|
39
|
+
},
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"@babel/core": "^7.23.6",
|
|
42
|
+
"@babel/generator": "^7.23.6",
|
|
43
|
+
"@babel/parser": "^7.23.6",
|
|
44
|
+
"@babel/types": "^7.23.6",
|
|
45
|
+
"@storybook/csf-tools": "^7.6.7",
|
|
46
|
+
"axios": "^1.6.0",
|
|
47
|
+
"chalk": "^4.1.2",
|
|
48
|
+
"commander": "^11.1.0",
|
|
49
|
+
"dotenv": "^16.3.1",
|
|
50
|
+
"glob": "^10.3.10",
|
|
51
|
+
"lodash": "^4.17.21",
|
|
52
|
+
"minimatch": "^9.0.3",
|
|
53
|
+
"prettier": "^3.2.4",
|
|
54
|
+
"typescript": "5.4.2"
|
|
55
|
+
}
|
|
56
|
+
}
|