@figma/code-connect 1.0.2 → 1.0.4
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 -0
- package/dist/commands/connect.d.ts +1 -0
- package/dist/commands/connect.d.ts.map +1 -1
- package/dist/commands/connect.js +24 -3
- package/dist/commands/connect.js.map +1 -1
- package/dist/common/intrinsics.js +1 -1
- package/dist/common/intrinsics.js.map +1 -1
- package/dist/common/updates.d.ts +5 -1
- package/dist/common/updates.d.ts.map +1 -1
- package/dist/common/updates.js +12 -2
- package/dist/common/updates.js.map +1 -1
- package/dist/connect/parser_executable_types.d.ts +19 -10
- package/dist/connect/parser_executable_types.d.ts.map +1 -1
- package/dist/connect/parser_executable_types.js.map +1 -1
- package/dist/connect/parser_executables.d.ts.map +1 -1
- package/dist/connect/parser_executables.js +25 -5
- package/dist/connect/parser_executables.js.map +1 -1
- package/dist/connect/project.d.ts +4 -0
- package/dist/connect/project.d.ts.map +1 -1
- package/dist/connect/project.js.map +1 -1
- package/dist/connect/upload.d.ts +3 -1
- package/dist/connect/upload.d.ts.map +1 -1
- package/dist/connect/upload.js +77 -5
- package/dist/connect/upload.js.map +1 -1
- package/dist/connect/validation.d.ts +1 -1
- package/dist/connect/validation.d.ts.map +1 -1
- package/dist/connect/validation.js +4 -4
- package/dist/connect/validation.js.map +1 -1
- package/dist/connect/wizard/autolinking.d.ts +26 -0
- package/dist/connect/wizard/autolinking.d.ts.map +1 -0
- package/dist/connect/wizard/autolinking.js +92 -0
- package/dist/connect/wizard/autolinking.js.map +1 -0
- package/dist/connect/wizard/helpers.d.ts +23 -1
- package/dist/connect/wizard/helpers.d.ts.map +1 -1
- package/dist/connect/wizard/helpers.js +70 -1
- package/dist/connect/wizard/helpers.js.map +1 -1
- package/dist/connect/wizard/prop_mapping.d.ts +16 -0
- package/dist/connect/wizard/prop_mapping.d.ts.map +1 -0
- package/dist/connect/wizard/prop_mapping.js +105 -0
- package/dist/connect/wizard/prop_mapping.js.map +1 -0
- package/dist/connect/wizard/run_wizard.d.ts +4 -14
- package/dist/connect/wizard/run_wizard.d.ts.map +1 -1
- package/dist/connect/wizard/run_wizard.js +125 -91
- package/dist/connect/wizard/run_wizard.js.map +1 -1
- package/dist/parser_scripts/compose_errors.d.ts +2 -0
- package/dist/parser_scripts/compose_errors.d.ts.map +1 -0
- package/dist/parser_scripts/compose_errors.js +12 -0
- package/dist/parser_scripts/compose_errors.js.map +1 -0
- package/dist/parser_scripts/get_swift_parser_dir.d.ts.map +1 -1
- package/dist/parser_scripts/get_swift_parser_dir.js +4 -10
- package/dist/parser_scripts/get_swift_parser_dir.js.map +1 -1
- package/dist/react/create.d.ts.map +1 -1
- package/dist/react/create.js +49 -14
- package/dist/react/create.js.map +1 -1
- package/dist/react/parser.d.ts +15 -0
- package/dist/react/parser.d.ts.map +1 -1
- package/dist/react/parser.js +138 -2
- package/dist/react/parser.js.map +1 -1
- package/dist/react/parser_template_helpers.d.ts.map +1 -1
- package/dist/react/parser_template_helpers.js +8 -2
- package/dist/react/parser_template_helpers.js.map +1 -1
- package/package.json +9 -5
|
@@ -0,0 +1,105 @@
|
|
|
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.generatePropMapping = exports.extractSignature = void 0;
|
|
7
|
+
const typescript_1 = __importDefault(require("typescript"));
|
|
8
|
+
const parser_1 = require("../../react/parser");
|
|
9
|
+
const figma_rest_api_1 = require("../figma_rest_api");
|
|
10
|
+
const fast_fuzzy_1 = require("fast-fuzzy");
|
|
11
|
+
const PROP_MINIMUM_MATCH_THRESHOLD = 0.8;
|
|
12
|
+
function extractSignature({ nameToFind, sourceFilePath, projectInfo, }) {
|
|
13
|
+
const { tsProgram } = projectInfo;
|
|
14
|
+
const checker = tsProgram.getTypeChecker();
|
|
15
|
+
// Get source file
|
|
16
|
+
const sourceFile = tsProgram.getSourceFile(sourceFilePath);
|
|
17
|
+
if (!sourceFile) {
|
|
18
|
+
throw new Error(`Could not find source for file: ${sourceFilePath}`);
|
|
19
|
+
}
|
|
20
|
+
for (const statement of sourceFile.statements) {
|
|
21
|
+
if (!(typescript_1.default.isFunctionDeclaration(statement) || typescript_1.default.isVariableStatement(statement))) {
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
if (!(statement.modifiers &&
|
|
25
|
+
statement.modifiers.some((modifier) => modifier.kind === typescript_1.default.SyntaxKind.ExportKeyword))) {
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
const name = typescript_1.default.isFunctionDeclaration(statement)
|
|
29
|
+
? statement.name?.text
|
|
30
|
+
: statement.declarationList.declarations?.[0].name.getText(sourceFile);
|
|
31
|
+
if (name === nameToFind ||
|
|
32
|
+
(nameToFind === 'default' &&
|
|
33
|
+
statement.modifiers.some((modifier) => modifier.kind === typescript_1.default.SyntaxKind.DefaultKeyword))) {
|
|
34
|
+
const symbol = typescript_1.default.isFunctionDeclaration(statement)
|
|
35
|
+
? statement.name && checker.getSymbolAtLocation(statement.name)
|
|
36
|
+
: checker.getSymbolAtLocation(statement.declarationList.declarations[0].name);
|
|
37
|
+
if (!symbol) {
|
|
38
|
+
throw new Error(`Could not find symbol for ${name}`);
|
|
39
|
+
}
|
|
40
|
+
const signature = (0, parser_1.extractComponentTypeSignature)(symbol, checker, sourceFile);
|
|
41
|
+
if (!signature) {
|
|
42
|
+
throw new Error(`Could not find signature for ${name}`);
|
|
43
|
+
}
|
|
44
|
+
return signature;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
throw new Error('No function or variable signatures found');
|
|
48
|
+
}
|
|
49
|
+
exports.extractSignature = extractSignature;
|
|
50
|
+
function getComponentPropertyTypeFromSignature(tsString) {
|
|
51
|
+
if (tsString === 'string') {
|
|
52
|
+
return figma_rest_api_1.FigmaRestApi.ComponentPropertyType.Text;
|
|
53
|
+
}
|
|
54
|
+
if (tsString === 'false | true') {
|
|
55
|
+
return figma_rest_api_1.FigmaRestApi.ComponentPropertyType.Boolean;
|
|
56
|
+
}
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
const DELIMITERS_REGEX = /[\s-_]/g;
|
|
60
|
+
function getMatchableStr(str) {
|
|
61
|
+
return str.replace(DELIMITERS_REGEX, '').toUpperCase();
|
|
62
|
+
}
|
|
63
|
+
function generatePropMapping({ exportName, filepath, projectInfo, component, }) {
|
|
64
|
+
const signature = extractSignature({
|
|
65
|
+
nameToFind: exportName,
|
|
66
|
+
sourceFilePath: filepath,
|
|
67
|
+
projectInfo,
|
|
68
|
+
});
|
|
69
|
+
const matchableCodeProps = Object.keys(signature).reduce((acc, key) => {
|
|
70
|
+
acc[getMatchableStr(key)] = key;
|
|
71
|
+
return acc;
|
|
72
|
+
}, {});
|
|
73
|
+
const matchedPropScores = {};
|
|
74
|
+
function isBestMatchForProp(match) {
|
|
75
|
+
return !matchedPropScores[match.item] || match.score > matchedPropScores[match.item].score;
|
|
76
|
+
}
|
|
77
|
+
const searchSpace = Object.keys(matchableCodeProps);
|
|
78
|
+
const searcher = new fast_fuzzy_1.Searcher(searchSpace);
|
|
79
|
+
Object.entries(component.componentPropertyDefinitions).forEach(([propertyName, componentPropertyDefinition]) => {
|
|
80
|
+
const results = searcher.search(getMatchableStr(propertyName), { returnMatchData: true });
|
|
81
|
+
const bestMatch = results[0];
|
|
82
|
+
const matchingCodeProp = matchableCodeProps[bestMatch?.item];
|
|
83
|
+
if (bestMatch &&
|
|
84
|
+
bestMatch.score > PROP_MINIMUM_MATCH_THRESHOLD &&
|
|
85
|
+
getComponentPropertyTypeFromSignature(signature[matchingCodeProp]) ===
|
|
86
|
+
componentPropertyDefinition.type &&
|
|
87
|
+
isBestMatchForProp(bestMatch)) {
|
|
88
|
+
matchedPropScores[bestMatch.item] = {
|
|
89
|
+
codePropName: matchingCodeProp,
|
|
90
|
+
figmaPropName: propertyName,
|
|
91
|
+
figmaPropType: componentPropertyDefinition.type,
|
|
92
|
+
score: bestMatch.score,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
return Object.entries(matchedPropScores).reduce((acc, [_, { codePropName, figmaPropName, figmaPropType }]) => {
|
|
97
|
+
acc[figmaPropName] = {
|
|
98
|
+
codePropName,
|
|
99
|
+
mapping: figmaPropType,
|
|
100
|
+
};
|
|
101
|
+
return acc;
|
|
102
|
+
}, {});
|
|
103
|
+
}
|
|
104
|
+
exports.generatePropMapping = generatePropMapping;
|
|
105
|
+
//# sourceMappingURL=prop_mapping.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prop_mapping.js","sourceRoot":"","sources":["../../../src/connect/wizard/prop_mapping.ts"],"names":[],"mappings":";;;;;;AAAA,4DAA2B;AAE3B,+CAA0F;AAC1F,sDAAgD;AAEhD,2CAAgD;AAEhD,MAAM,4BAA4B,GAAG,GAAG,CAAA;AAExC,SAAgB,gBAAgB,CAAC,EAC/B,UAAU,EACV,cAAc,EACd,WAAW,GAKZ;IACC,MAAM,EAAE,SAAS,EAAE,GAAG,WAAW,CAAA;IAEjC,MAAM,OAAO,GAAG,SAAS,CAAC,cAAc,EAAE,CAAA;IAE1C,kBAAkB;IAClB,MAAM,UAAU,GAAG,SAAS,CAAC,aAAa,CAAC,cAAc,CAAC,CAAA;IAC1D,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,MAAM,IAAI,KAAK,CAAC,mCAAmC,cAAc,EAAE,CAAC,CAAA;IACtE,CAAC;IAED,KAAK,MAAM,SAAS,IAAI,UAAU,CAAC,UAAU,EAAE,CAAC;QAC9C,IAAI,CAAC,CAAC,oBAAE,CAAC,qBAAqB,CAAC,SAAS,CAAC,IAAI,oBAAE,CAAC,mBAAmB,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC;YAChF,SAAQ;QACV,CAAC;Q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D,EAAiB,CAClB,CAAA;AACH,CAAC;AA/DD,kDA+DC"}
|
|
@@ -1,28 +1,18 @@
|
|
|
1
1
|
import { BaseCommand } from '../../commands/connect';
|
|
2
2
|
import prompts from 'prompts';
|
|
3
3
|
import { FigmaRestApi } from '../figma_rest_api';
|
|
4
|
-
import { ReactProjectInfo } from '../../connect/project';
|
|
4
|
+
import { ReactProjectInfo, CodeConnectConfig, ProjectInfo } from '../../connect/project';
|
|
5
5
|
type ConnectedComponentMappings = {
|
|
6
6
|
componentName: string;
|
|
7
|
-
|
|
7
|
+
filepathExport: string;
|
|
8
8
|
}[];
|
|
9
|
-
export declare function getComponentChoicesForPrompt(components: FigmaRestApi.Component[],
|
|
10
|
-
/**
|
|
11
|
-
* Autolinks components/paths based on fuzzy matching of name and writes mappings to linkedNodeIdsToPaths.
|
|
12
|
-
*
|
|
13
|
-
* Matching is done by fast-fuzzy
|
|
14
|
-
*/
|
|
15
|
-
export declare function autoLinkComponents({ unconnectedComponents, linkedNodeIdsToPaths, componentPaths, }: {
|
|
16
|
-
unconnectedComponents: FigmaRestApi.Component[];
|
|
17
|
-
linkedNodeIdsToPaths: Record<string, string>;
|
|
18
|
-
componentPaths: string[];
|
|
19
|
-
}): void;
|
|
9
|
+
export declare function getComponentChoicesForPrompt(components: FigmaRestApi.Component[], linkedNodeIdsToFilepathExports: Record<string, string>, connectedComponentsMappings: ConnectedComponentMappings, dir: string): prompts.Choice[];
|
|
20
10
|
export declare function convertRemoteFileUrlToRelativePath({ remoteFileUrl, gitRootPath, dir, }: {
|
|
21
11
|
remoteFileUrl: string;
|
|
22
12
|
gitRootPath: string;
|
|
23
13
|
dir: string;
|
|
24
14
|
}): string | null;
|
|
25
|
-
export declare function getUnconnectedComponentsAndConnectedComponentMappings(cmd: BaseCommand, figmaFileUrl: string, componentsFromFile: FigmaRestApi.Component[], projectInfo: ReactProjectInfo): Promise<{
|
|
15
|
+
export declare function getUnconnectedComponentsAndConnectedComponentMappings(cmd: BaseCommand, figmaFileUrl: string, componentsFromFile: FigmaRestApi.Component[], projectInfo: ProjectInfo<CodeConnectConfig> | ReactProjectInfo): Promise<{
|
|
26
16
|
unconnectedComponents: FigmaRestApi.Component[];
|
|
27
17
|
connectedComponentsMappings: ConnectedComponentMappings;
|
|
28
18
|
}>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run_wizard.d.ts","sourceRoot":"","sources":["../../../src/connect/wizard/run_wizard.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAiD,MAAM,wBAAwB,CAAA;AACnG,OAAO,OAAO,MAAM,SAAS,CAAA;AAG7B,OAAO,EAAE,YAAY,EAAa,MAAM,mBAAmB,CAAA;AAG3D,OAAO,EACL,gBAAgB,
|
|
1
|
+
{"version":3,"file":"run_wizard.d.ts","sourceRoot":"","sources":["../../../src/connect/wizard/run_wizard.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAiD,MAAM,wBAAwB,CAAA;AACnG,OAAO,OAAO,MAAM,SAAS,CAAA;AAG7B,OAAO,EAAE,YAAY,EAAa,MAAM,mBAAmB,CAAA;AAG3D,OAAO,EACL,gBAAgB,EAKhB,iBAAiB,EACjB,WAAW,EAEZ,MAAM,uBAAuB,CAAA;AAwB9B,KAAK,0BAA0B,GAAG;IAAE,aAAa,EAAE,MAAM,CAAC;IAAC,cAAc,EAAE,MAAM,CAAA;CAAE,EAAE,CAAA;AA0JrF,wBAAgB,4BAA4B,CAC1C,UAAU,EAAE,YAAY,CAAC,SAAS,EAAE,EACpC,8BAA8B,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EACtD,2BAA2B,EAAE,0BAA0B,EACvD,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,MAAM,EAAE,CA2ClB;AA2QD,wBAAgB,kCAAkC,CAAC,EACjD,aAAa,EACb,WAAW,EACX,GAAG,GACJ,EAAE;IACD,aAAa,EAAE,MAAM,CAAA;IACrB,WAAW,EAAE,MAAM,CAAA;IACnB,GAAG,EAAE,MAAM,CAAA;CACZ,iBAYA;AAED,wBAAsB,qDAAqD,CACzE,GAAG,EAAE,WAAW,EAChB,YAAY,EAAE,MAAM,EACpB,kBAAkB,EAAE,YAAY,CAAC,SAAS,EAAE,EAC5C,WAAW,EAAE,WAAW,CAAC,iBAAiB,CAAC,GAAG,gBAAgB;;;GA8C/D;AAoFD,wBAAsB,SAAS,CAAC,GAAG,EAAE,WAAW,iBAyJ/C"}
|
|
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.runWizard = exports.getUnconnectedComponentsAndConnectedComponentMappings = exports.convertRemoteFileUrlToRelativePath = exports.
|
|
29
|
+
exports.runWizard = exports.getUnconnectedComponentsAndConnectedComponentMappings = exports.convertRemoteFileUrlToRelativePath = exports.getComponentChoicesForPrompt = void 0;
|
|
30
30
|
const connect_1 = require("../../commands/connect");
|
|
31
31
|
const prompts_1 = __importDefault(require("prompts"));
|
|
32
32
|
const fs_1 = __importDefault(require("fs"));
|
|
@@ -38,15 +38,17 @@ const project_1 = require("../../connect/project");
|
|
|
38
38
|
const validation_1 = require("../validation");
|
|
39
39
|
const chalk_1 = __importDefault(require("chalk"));
|
|
40
40
|
const path_1 = __importDefault(require("path"));
|
|
41
|
+
const parser_executable_types_1 = require("../parser_executable_types");
|
|
41
42
|
const create_1 = require("../create");
|
|
42
43
|
const create_2 = require("../../react/create");
|
|
43
44
|
const boxen_1 = __importDefault(require("boxen"));
|
|
44
|
-
const fast_fuzzy_1 = require("fast-fuzzy");
|
|
45
|
-
const parser_1 = require("../../react/parser");
|
|
46
45
|
const helpers_2 = require("./helpers");
|
|
47
46
|
const strip_ansi_1 = __importDefault(require("strip-ansi"));
|
|
48
47
|
const parser_executables_1 = require("../parser_executables");
|
|
49
48
|
const ora_1 = __importDefault(require("ora"));
|
|
49
|
+
const zod_validation_error_1 = require("zod-validation-error");
|
|
50
|
+
const autolinking_1 = require("./autolinking");
|
|
51
|
+
const prop_mapping_1 = require("./prop_mapping");
|
|
50
52
|
const NONE = '(None)';
|
|
51
53
|
const DELIMITERS_REGEX = /[\s-_]/g;
|
|
52
54
|
function clearQuestion(prompt, answer) {
|
|
@@ -57,13 +59,13 @@ function clearQuestion(prompt, answer) {
|
|
|
57
59
|
process.stdout.moveCursor(0, -rowsToRemove);
|
|
58
60
|
process.stdout.clearScreenDown();
|
|
59
61
|
}
|
|
60
|
-
async function fetchTopLevelComponentsFromFile({ accessToken, figmaUrl, }) {
|
|
62
|
+
async function fetchTopLevelComponentsFromFile({ accessToken, figmaUrl, cmd, }) {
|
|
61
63
|
// TODO enter create flow if node-id specified
|
|
62
64
|
const fileKey = (0, helpers_1.parseFileKey)(figmaUrl);
|
|
63
65
|
const apiUrl = (0, figma_rest_api_1.getApiUrl)(figmaUrl ?? '') + `/code_connect/${fileKey}/cli_data`;
|
|
64
66
|
try {
|
|
65
67
|
const spinner = (0, ora_1.default)({
|
|
66
|
-
text:
|
|
68
|
+
text: `Fetching component information from ${cmd.verbose ? `${apiUrl}\n` : 'Figma...'}`,
|
|
67
69
|
color: 'green',
|
|
68
70
|
}).start();
|
|
69
71
|
const response = await (process.env.CODE_CONNECT_MOCK_DOC_RESPONSE
|
|
@@ -77,7 +79,12 @@ async function fetchTopLevelComponentsFromFile({ accessToken, figmaUrl, }) {
|
|
|
77
79
|
'Content-Type': 'application/json',
|
|
78
80
|
},
|
|
79
81
|
})).finally(() => {
|
|
80
|
-
|
|
82
|
+
if (cmd.verbose) {
|
|
83
|
+
spinner.stopAndPersist();
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
spinner.stop();
|
|
87
|
+
}
|
|
81
88
|
});
|
|
82
89
|
if (response.status === 200) {
|
|
83
90
|
return (0, helpers_1.findComponentsInDocument)(response.data.document).filter(({ id }) => id in response.data.componentSets || !response.data.components[id].componentSetId);
|
|
@@ -155,22 +162,26 @@ async function askQuestionWithExitConfirmation(question) {
|
|
|
155
162
|
}
|
|
156
163
|
}
|
|
157
164
|
}
|
|
158
|
-
function formatComponentTitle(componentName,
|
|
165
|
+
function formatComponentTitle(componentName, filepathExport, pad) {
|
|
159
166
|
const nameLabel = `${chalk_1.default.dim('Figma component:')} ${componentName.padEnd(pad, ' ')}`;
|
|
160
|
-
const linkedLabel = `↔️ ${
|
|
167
|
+
const linkedLabel = `↔️ ${filepathExport ? (0, helpers_2.parseFilepathExport)(filepathExport).filepath : '-'}`;
|
|
161
168
|
return `${nameLabel} ${linkedLabel}`;
|
|
162
169
|
}
|
|
163
|
-
function getComponentChoicesForPrompt(components,
|
|
170
|
+
function getComponentChoicesForPrompt(components, linkedNodeIdsToFilepathExports, connectedComponentsMappings, dir) {
|
|
164
171
|
const longestNameLength = [...components, ...connectedComponentsMappings].reduce((longest, component) => Math.max(longest, 'name' in component ? component.name.length : component.componentName.length), 0);
|
|
165
172
|
const nameCompare = (a, b) => a.name.localeCompare(b.name);
|
|
166
|
-
const linkedComponents = components
|
|
167
|
-
|
|
173
|
+
const linkedComponents = components
|
|
174
|
+
.filter((c) => !!linkedNodeIdsToFilepathExports[c.id])
|
|
175
|
+
.sort(nameCompare);
|
|
176
|
+
const unlinkedComponents = components
|
|
177
|
+
.filter((c) => !linkedNodeIdsToFilepathExports[c.id])
|
|
178
|
+
.sort(nameCompare);
|
|
168
179
|
const formatComponentChoice = (c) => {
|
|
169
|
-
const
|
|
170
|
-
? path_1.default.relative(dir,
|
|
180
|
+
const filepathExport = linkedNodeIdsToFilepathExports[c.id]
|
|
181
|
+
? path_1.default.relative(dir, linkedNodeIdsToFilepathExports[c.id])
|
|
171
182
|
: null;
|
|
172
183
|
return {
|
|
173
|
-
title: formatComponentTitle(c.name,
|
|
184
|
+
title: formatComponentTitle(c.name, filepathExport, longestNameLength),
|
|
174
185
|
value: c.id,
|
|
175
186
|
description: `${chalk_1.default.green('Edit link')}`,
|
|
176
187
|
};
|
|
@@ -179,7 +190,7 @@ function getComponentChoicesForPrompt(components, linkedNodeIdsToPaths, connecte
|
|
|
179
190
|
...linkedComponents.map(formatComponentChoice),
|
|
180
191
|
...unlinkedComponents.map(formatComponentChoice),
|
|
181
192
|
...connectedComponentsMappings.map((connectedComponent) => ({
|
|
182
|
-
title: formatComponentTitle(connectedComponent.componentName, connectedComponent.
|
|
193
|
+
title: formatComponentTitle(connectedComponent.componentName, connectedComponent.filepathExport, longestNameLength),
|
|
183
194
|
disabled: true,
|
|
184
195
|
})),
|
|
185
196
|
];
|
|
@@ -199,7 +210,8 @@ function getUnconnectedComponentChoices(componentPaths, dir) {
|
|
|
199
210
|
}),
|
|
200
211
|
];
|
|
201
212
|
}
|
|
202
|
-
async function runManualLinking({ unconnectedComponents,
|
|
213
|
+
async function runManualLinking({ unconnectedComponents, linkedNodeIdsToFilepathExports, filepathExports, connectedComponentsMappings, cmd, }) {
|
|
214
|
+
const filesToComponentOptionsMap = (0, helpers_2.getComponentOptionsMap)(filepathExports);
|
|
203
215
|
const dir = (0, connect_1.getDir)(cmd);
|
|
204
216
|
while (true) {
|
|
205
217
|
// Don't show exit confirmation as we're relying on esc behavior
|
|
@@ -207,7 +219,7 @@ async function runManualLinking({ unconnectedComponents, linkedNodeIdsToPaths, c
|
|
|
207
219
|
type: 'select',
|
|
208
220
|
name: 'nodeId',
|
|
209
221
|
message: `Select a link to edit (Press ${chalk_1.default.green('esc')} when you're ready to continue on)`,
|
|
210
|
-
choices: getComponentChoicesForPrompt(unconnectedComponents,
|
|
222
|
+
choices: getComponentChoicesForPrompt(unconnectedComponents, linkedNodeIdsToFilepathExports, connectedComponentsMappings, dir),
|
|
211
223
|
warn: 'This component already has a local Code Connect file.',
|
|
212
224
|
hint: ' ',
|
|
213
225
|
}, {
|
|
@@ -216,7 +228,14 @@ async function runManualLinking({ unconnectedComponents, linkedNodeIdsToPaths, c
|
|
|
216
228
|
if (!nodeId) {
|
|
217
229
|
return;
|
|
218
230
|
}
|
|
219
|
-
const pathChoices = getUnconnectedComponentChoices(
|
|
231
|
+
const pathChoices = getUnconnectedComponentChoices(Object.keys(filesToComponentOptionsMap), dir);
|
|
232
|
+
const prevSelectedKey = linkedNodeIdsToFilepathExports[nodeId];
|
|
233
|
+
const { filepath: prevSelectedFilepath, exportName: prevSelectedComponent } = prevSelectedKey
|
|
234
|
+
? (0, helpers_2.parseFilepathExport)(prevSelectedKey)
|
|
235
|
+
: {
|
|
236
|
+
filepath: null,
|
|
237
|
+
exportName: null,
|
|
238
|
+
};
|
|
220
239
|
const { pathToComponent } = await (0, prompts_1.default)({
|
|
221
240
|
type: 'autocomplete',
|
|
222
241
|
name: 'pathToComponent',
|
|
@@ -225,18 +244,39 @@ async function runManualLinking({ unconnectedComponents, linkedNodeIdsToPaths, c
|
|
|
225
244
|
// default suggest uses .startsWith(input) which isn't very useful for full paths
|
|
226
245
|
suggest: (input, choices) => Promise.resolve(choices.filter((i) => i.value.toUpperCase().includes(input.toUpperCase()))),
|
|
227
246
|
// preselect if editing an existing choice
|
|
228
|
-
initial:
|
|
229
|
-
? pathChoices.findIndex(({ value }) => value ===
|
|
247
|
+
initial: prevSelectedFilepath
|
|
248
|
+
? pathChoices.findIndex(({ value }) => value === prevSelectedFilepath)
|
|
230
249
|
: 0,
|
|
231
250
|
}, {
|
|
232
251
|
onSubmit: clearQuestion,
|
|
233
252
|
});
|
|
234
253
|
if (pathToComponent) {
|
|
235
254
|
if (pathToComponent === NONE) {
|
|
236
|
-
delete
|
|
255
|
+
delete linkedNodeIdsToFilepathExports[nodeId];
|
|
237
256
|
}
|
|
238
257
|
else {
|
|
239
|
-
|
|
258
|
+
const fileExports = filesToComponentOptionsMap[pathToComponent];
|
|
259
|
+
if (fileExports.length === 0) {
|
|
260
|
+
// Not TS, default to filepath
|
|
261
|
+
linkedNodeIdsToFilepathExports[nodeId] = pathToComponent;
|
|
262
|
+
}
|
|
263
|
+
else {
|
|
264
|
+
const { filepathExport } = await (0, prompts_1.default)({
|
|
265
|
+
type: 'autocomplete',
|
|
266
|
+
name: 'filepathExport',
|
|
267
|
+
message: `Choose an export of ${path_1.default.parse(pathToComponent).base} (type to filter results)`,
|
|
268
|
+
choices: fileExports,
|
|
269
|
+
// default suggest uses .startsWith(input)
|
|
270
|
+
suggest: (input, choices) => Promise.resolve(choices.filter((i) => i.value.toUpperCase().includes(input.toUpperCase()))),
|
|
271
|
+
// preselect if editing an existing choice
|
|
272
|
+
initial: prevSelectedComponent && prevSelectedFilepath === pathToComponent
|
|
273
|
+
? fileExports.findIndex(({ title }) => title === prevSelectedComponent)
|
|
274
|
+
: 0,
|
|
275
|
+
}, {
|
|
276
|
+
onSubmit: clearQuestion,
|
|
277
|
+
});
|
|
278
|
+
linkedNodeIdsToFilepathExports[nodeId] = filepathExport;
|
|
279
|
+
}
|
|
240
280
|
}
|
|
241
281
|
}
|
|
242
282
|
}
|
|
@@ -255,7 +295,7 @@ async function runManualLinkingWithConfirmation(manualLinkingArgs) {
|
|
|
255
295
|
hasAskedOutDirQuestion = true;
|
|
256
296
|
outDir = outputDirectory;
|
|
257
297
|
}
|
|
258
|
-
const linkedNodes = Object.keys(manualLinkingArgs.
|
|
298
|
+
const linkedNodes = Object.keys(manualLinkingArgs.linkedNodeIdsToFilepathExports);
|
|
259
299
|
if (!linkedNodes.length) {
|
|
260
300
|
const { confirmation } = await askQuestionOrExit({
|
|
261
301
|
type: 'select',
|
|
@@ -298,65 +338,58 @@ async function runManualLinkingWithConfirmation(manualLinkingArgs) {
|
|
|
298
338
|
}
|
|
299
339
|
}
|
|
300
340
|
}
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
*
|
|
304
|
-
* Matching is done by fast-fuzzy
|
|
305
|
-
*/
|
|
306
|
-
function autoLinkComponents({ unconnectedComponents, linkedNodeIdsToPaths, componentPaths, }) {
|
|
307
|
-
const matchableNamesToNodeIdsMap = unconnectedComponents.reduce((acc, curr) => {
|
|
308
|
-
const matchableName = curr.name;
|
|
309
|
-
acc[matchableName] = curr.id;
|
|
310
|
-
return acc;
|
|
311
|
-
}, {});
|
|
312
|
-
const searchSpace = Object.keys(matchableNamesToNodeIdsMap);
|
|
313
|
-
const searcher = new fast_fuzzy_1.Searcher(searchSpace);
|
|
314
|
-
componentPaths.forEach((componentPath) => {
|
|
315
|
-
const { name } = path_1.default.parse(componentPath);
|
|
316
|
-
const matchableName = name;
|
|
317
|
-
const results = searcher.search(matchableName, { returnMatchData: true });
|
|
318
|
-
const bestMatch = results[0];
|
|
319
|
-
if (bestMatch && bestMatch.score > 0.9 && bestMatch.item in matchableNamesToNodeIdsMap) {
|
|
320
|
-
linkedNodeIdsToPaths[matchableNamesToNodeIdsMap[bestMatch.item]] = componentPath;
|
|
321
|
-
}
|
|
322
|
-
});
|
|
323
|
-
}
|
|
324
|
-
exports.autoLinkComponents = autoLinkComponents;
|
|
325
|
-
// returns ES-style import path from given system path
|
|
326
|
-
function formatImportPath(systemPath) {
|
|
327
|
-
// use forward slashes for import paths
|
|
328
|
-
let formattedImportPath = systemPath.replaceAll(path_1.default.sep, '/');
|
|
329
|
-
// prefix current dir paths with ./ (node path does not)
|
|
330
|
-
formattedImportPath = formattedImportPath.startsWith('.')
|
|
331
|
-
? formattedImportPath
|
|
332
|
-
: `./${formattedImportPath}`;
|
|
333
|
-
// assume not using ESM imports
|
|
334
|
-
return formattedImportPath.replace(/\.(jsx|tsx)$/, '');
|
|
335
|
-
}
|
|
336
|
-
async function createCodeConnectFiles({ linkedNodeIdsToPaths, figmaFileUrl, unconnectedComponentsMap, outDir: outDirArg, }) {
|
|
337
|
-
for (const [nodeId, filePath] of Object.entries(linkedNodeIdsToPaths)) {
|
|
341
|
+
async function createCodeConnectFiles({ linkedNodeIdsToFilepathExports, figmaFileUrl, unconnectedComponentsMap, outDir: outDirArg, projectInfo, }) {
|
|
342
|
+
for (const [nodeId, filepathExport] of Object.entries(linkedNodeIdsToFilepathExports)) {
|
|
338
343
|
const urlObj = new URL(figmaFileUrl);
|
|
339
344
|
urlObj.search = '';
|
|
340
345
|
urlObj.searchParams.append('node-id', nodeId);
|
|
341
|
-
const {
|
|
342
|
-
const
|
|
343
|
-
const outDir = outDirArg || path_1.default.dirname(
|
|
344
|
-
const outFile = path_1.default.join(outDir, `${name}.figma.tsx`);
|
|
346
|
+
const { filepath, exportName } = (0, helpers_2.parseFilepathExport)(filepathExport);
|
|
347
|
+
const { name } = path_1.default.parse(filepath);
|
|
348
|
+
const outDir = outDirArg || path_1.default.dirname(filepath);
|
|
345
349
|
const payload = {
|
|
346
350
|
mode: 'CREATE',
|
|
347
|
-
destinationDir:
|
|
348
|
-
|
|
351
|
+
destinationDir: outDir,
|
|
352
|
+
sourceFilepath: filepath,
|
|
353
|
+
sourceExport: exportName || undefined,
|
|
354
|
+
propMapping: projectInfo.config.parser === 'react' && filepath && exportName
|
|
355
|
+
? (0, prop_mapping_1.generatePropMapping)({
|
|
356
|
+
filepath,
|
|
357
|
+
exportName,
|
|
358
|
+
projectInfo: projectInfo,
|
|
359
|
+
component: unconnectedComponentsMap[nodeId],
|
|
360
|
+
})
|
|
361
|
+
: undefined,
|
|
349
362
|
component: {
|
|
350
363
|
figmaNodeUrl: urlObj.toString(),
|
|
351
364
|
normalizedName: (0, create_1.normalizeComponentName)(name),
|
|
352
365
|
...unconnectedComponentsMap[nodeId],
|
|
353
366
|
},
|
|
354
|
-
config:
|
|
367
|
+
config: projectInfo.config,
|
|
355
368
|
};
|
|
356
|
-
|
|
369
|
+
let result;
|
|
370
|
+
if (projectInfo.config.parser === 'react') {
|
|
371
|
+
result = await (0, create_2.createReactCodeConnect)(payload);
|
|
372
|
+
}
|
|
373
|
+
else {
|
|
374
|
+
try {
|
|
375
|
+
const stdout = await (0, parser_executables_1.callParser)(
|
|
376
|
+
// We use `as` because the React parser makes the types difficult
|
|
377
|
+
// TODO remove once React is an executable parser
|
|
378
|
+
projectInfo.config, payload, projectInfo.absPath);
|
|
379
|
+
result = parser_executable_types_1.CreateResponsePayload.parse(stdout);
|
|
380
|
+
}
|
|
381
|
+
catch (e) {
|
|
382
|
+
throw (0, zod_validation_error_1.fromError)(e);
|
|
383
|
+
}
|
|
384
|
+
}
|
|
357
385
|
const { hasErrors } = (0, parser_executables_1.handleMessages)(result.messages);
|
|
358
|
-
if (
|
|
359
|
-
|
|
386
|
+
if (hasErrors) {
|
|
387
|
+
(0, logging_1.exitWithError)('Errors encountered calling parser, exiting');
|
|
388
|
+
}
|
|
389
|
+
else {
|
|
390
|
+
result.createdFiles.forEach((file) => {
|
|
391
|
+
logging_1.logger.info((0, logging_1.success)(`Created ${file.filePath}`));
|
|
392
|
+
});
|
|
360
393
|
}
|
|
361
394
|
}
|
|
362
395
|
}
|
|
@@ -377,7 +410,7 @@ async function getUnconnectedComponentsAndConnectedComponentMappings(cmd, figmaF
|
|
|
377
410
|
const fileKey = (0, helpers_1.parseFileKey)(figmaFileUrl);
|
|
378
411
|
const codeConnectObjects = await (0, connect_1.getCodeConnectObjects)(dir, cmd, projectInfo, true);
|
|
379
412
|
const connectedNodeIdsInFileToCodeConnectObjectMap = codeConnectObjects.reduce((map, codeConnectJson) => {
|
|
380
|
-
const parsedNode = (0, validation_1.parseFigmaNode)(cmd, codeConnectJson, true);
|
|
413
|
+
const parsedNode = (0, validation_1.parseFigmaNode)(cmd.verbose, codeConnectJson, true);
|
|
381
414
|
if (parsedNode && parsedNode.fileKey === fileKey) {
|
|
382
415
|
map[parsedNode.nodeId] = codeConnectJson;
|
|
383
416
|
}
|
|
@@ -396,7 +429,7 @@ async function getUnconnectedComponentsAndConnectedComponentMappings(cmd, figmaF
|
|
|
396
429
|
});
|
|
397
430
|
connectedComponentsMappings.push({
|
|
398
431
|
componentName: c.name,
|
|
399
|
-
|
|
432
|
+
filepathExport: relativePath ?? '(Unknown file)',
|
|
400
433
|
});
|
|
401
434
|
}
|
|
402
435
|
else {
|
|
@@ -448,23 +481,26 @@ async function askForTopLevelDirectoryOrDetermineFromConfig({ dir, hasConfigFile
|
|
|
448
481
|
frames: [''],
|
|
449
482
|
},
|
|
450
483
|
}).start();
|
|
451
|
-
|
|
452
|
-
|
|
484
|
+
let projectInfo = await (0, project_1.getProjectInfoFromConfig)(dir, configToUse);
|
|
485
|
+
if (projectInfo.config.parser === 'react') {
|
|
486
|
+
projectInfo = (0, project_1.getReactProjectInfo)(projectInfo);
|
|
487
|
+
}
|
|
488
|
+
const filepathExports = (0, helpers_2.getFilepathExportsFromFiles)(projectInfo);
|
|
453
489
|
spinner.stop();
|
|
454
|
-
if (!
|
|
490
|
+
if (!filepathExports.length) {
|
|
455
491
|
if (hasConfigFile) {
|
|
456
|
-
logging_1.logger.error('No
|
|
492
|
+
logging_1.logger.error('No files found. Please update the include/exclude globs in your config file and try again.');
|
|
457
493
|
(0, helpers_1.exitWithFeedbackMessage)(1);
|
|
458
494
|
}
|
|
459
495
|
else {
|
|
460
|
-
logging_1.logger.error('No
|
|
496
|
+
logging_1.logger.error('No files for your project type could be found in that directory. Please enter a different directory.');
|
|
461
497
|
}
|
|
462
498
|
}
|
|
463
499
|
else {
|
|
464
500
|
return {
|
|
465
501
|
projectInfo,
|
|
466
502
|
componentDirectory,
|
|
467
|
-
|
|
503
|
+
filepathExports,
|
|
468
504
|
};
|
|
469
505
|
}
|
|
470
506
|
}
|
|
@@ -484,10 +520,6 @@ async function runWizard(cmd) {
|
|
|
484
520
|
}));
|
|
485
521
|
const dir = (0, connect_1.getDir)(cmd);
|
|
486
522
|
const { hasConfigFile, config } = await (0, project_1.parseOrDetermineConfig)(dir, cmd.config);
|
|
487
|
-
if (config.parser !== 'react' && config.parser !== '__unit_test__') {
|
|
488
|
-
logging_1.logger.error('This flow currently only supports React projects. Please use one of the other commands.');
|
|
489
|
-
(0, helpers_1.exitWithFeedbackMessage)(1);
|
|
490
|
-
}
|
|
491
523
|
let accessToken = (0, connect_1.getAccessToken)(cmd);
|
|
492
524
|
if (!accessToken) {
|
|
493
525
|
const { accessTokenEntered } = await askQuestionOrExit({
|
|
@@ -500,7 +532,7 @@ async function runWizard(cmd) {
|
|
|
500
532
|
accessToken = accessTokenEntered;
|
|
501
533
|
}
|
|
502
534
|
logging_1.logger.info('');
|
|
503
|
-
const { componentDirectory, projectInfo,
|
|
535
|
+
const { componentDirectory, projectInfo, filepathExports } = await askForTopLevelDirectoryOrDetermineFromConfig({
|
|
504
536
|
dir,
|
|
505
537
|
hasConfigFile,
|
|
506
538
|
config,
|
|
@@ -514,6 +546,7 @@ async function runWizard(cmd) {
|
|
|
514
546
|
const componentsFromFile = await fetchTopLevelComponentsFromFile({
|
|
515
547
|
accessToken,
|
|
516
548
|
figmaUrl: figmaFileUrl,
|
|
549
|
+
cmd,
|
|
517
550
|
});
|
|
518
551
|
if (!componentsFromFile) {
|
|
519
552
|
(0, helpers_1.exitWithFeedbackMessage)(1);
|
|
@@ -538,15 +571,15 @@ async function runWizard(cmd) {
|
|
|
538
571
|
await (0, helpers_2.createCodeConnectConfig)({ dir, componentDirectory, config });
|
|
539
572
|
}
|
|
540
573
|
}
|
|
541
|
-
const
|
|
574
|
+
const linkedNodeIdsToFilepathExports = {};
|
|
542
575
|
const { unconnectedComponents, connectedComponentsMappings } = await getUnconnectedComponentsAndConnectedComponentMappings(cmd, figmaFileUrl, componentsFromFile, projectInfo);
|
|
543
|
-
autoLinkComponents({
|
|
576
|
+
(0, autolinking_1.autoLinkComponents)({
|
|
544
577
|
unconnectedComponents,
|
|
545
|
-
|
|
546
|
-
|
|
578
|
+
linkedNodeIdsToFilepathExports,
|
|
579
|
+
filepathExports,
|
|
547
580
|
});
|
|
548
581
|
logging_1.logger.info((0, boxen_1.default)(`${chalk_1.default.bold(`Connecting your components`)}\n\n` +
|
|
549
|
-
`${chalk_1.default.green(`${chalk_1.default.bold(Object.keys(
|
|
582
|
+
`${chalk_1.default.green(`${chalk_1.default.bold(Object.keys(linkedNodeIdsToFilepathExports).length)} ${Object.keys(linkedNodeIdsToFilepathExports).length === 1
|
|
550
583
|
? 'component was automatically matched based on its name'
|
|
551
584
|
: 'components were automatically matched based on their names'}`)}\n` +
|
|
552
585
|
`${chalk_1.default.yellow(`${chalk_1.default.bold(unconnectedComponents.length)} ${unconnectedComponents.length === 1
|
|
@@ -561,8 +594,8 @@ async function runWizard(cmd) {
|
|
|
561
594
|
const outDir = await runManualLinkingWithConfirmation({
|
|
562
595
|
unconnectedComponents,
|
|
563
596
|
connectedComponentsMappings,
|
|
564
|
-
|
|
565
|
-
|
|
597
|
+
linkedNodeIdsToFilepathExports,
|
|
598
|
+
filepathExports,
|
|
566
599
|
cmd,
|
|
567
600
|
});
|
|
568
601
|
const unconnectedComponentsMap = unconnectedComponents.reduce((map, component) => {
|
|
@@ -570,10 +603,11 @@ async function runWizard(cmd) {
|
|
|
570
603
|
return map;
|
|
571
604
|
}, {});
|
|
572
605
|
await createCodeConnectFiles({
|
|
573
|
-
|
|
606
|
+
linkedNodeIdsToFilepathExports,
|
|
574
607
|
unconnectedComponentsMap,
|
|
575
608
|
figmaFileUrl,
|
|
576
609
|
outDir,
|
|
610
|
+
projectInfo,
|
|
577
611
|
});
|
|
578
612
|
}
|
|
579
613
|
exports.runWizard = runWizard;
|