@figma/code-connect 1.2.4 → 1.3.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 +5 -8
- package/dist/client/figma_client.d.ts +2 -0
- package/dist/client/figma_client.d.ts.map +1 -1
- package/dist/commands/connect.d.ts +1 -1
- package/dist/commands/connect.d.ts.map +1 -1
- package/dist/commands/connect.js +5 -5
- package/dist/commands/connect.js.map +1 -1
- package/dist/connect/create.d.ts.map +1 -1
- package/dist/connect/create.js +30 -13
- package/dist/connect/create.js.map +1 -1
- package/dist/connect/figma_rest_api.d.ts +6 -2
- package/dist/connect/figma_rest_api.d.ts.map +1 -1
- package/dist/connect/figma_rest_api.js.map +1 -1
- package/dist/connect/helpers.d.ts.map +1 -1
- package/dist/connect/helpers.js +22 -14
- package/dist/connect/helpers.js.map +1 -1
- package/dist/connect/intrinsics.d.ts.map +1 -1
- package/dist/connect/intrinsics.js +11 -0
- package/dist/connect/intrinsics.js.map +1 -1
- package/dist/connect/parser_common.d.ts +1 -1
- package/dist/connect/parser_common.d.ts.map +1 -1
- package/dist/connect/parser_common.js +8 -2
- package/dist/connect/parser_common.js.map +1 -1
- package/dist/connect/parser_executable_types.d.ts +28 -6
- 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 +5 -0
- package/dist/connect/parser_executables.js.map +1 -1
- package/dist/connect/project.d.ts +14 -1
- package/dist/connect/project.d.ts.map +1 -1
- package/dist/connect/project.js +73 -4
- package/dist/connect/project.js.map +1 -1
- package/dist/connect/validation.d.ts +2 -0
- package/dist/connect/validation.d.ts.map +1 -1
- package/dist/connect/validation.js +25 -2
- package/dist/connect/validation.js.map +1 -1
- package/dist/connect/wizard/helpers.d.ts +10 -1
- package/dist/connect/wizard/helpers.d.ts.map +1 -1
- package/dist/connect/wizard/helpers.js +27 -6
- package/dist/connect/wizard/helpers.js.map +1 -1
- package/dist/connect/wizard/run_wizard.d.ts +32 -0
- package/dist/connect/wizard/run_wizard.d.ts.map +1 -1
- package/dist/connect/wizard/run_wizard.js +219 -30
- package/dist/connect/wizard/run_wizard.js.map +1 -1
- package/dist/html/create.d.ts +2 -2
- package/dist/html/create.d.ts.map +1 -1
- package/dist/html/create.js +3 -2
- package/dist/html/create.js.map +1 -1
- package/dist/html/parser.d.ts.map +1 -1
- package/dist/html/parser.js +2 -1
- package/dist/html/parser.js.map +1 -1
- package/dist/react/create.d.ts +3 -3
- package/dist/react/create.d.ts.map +1 -1
- package/dist/react/create.js +64 -36
- package/dist/react/create.js.map +1 -1
- package/dist/react/parser.d.ts.map +1 -1
- package/dist/react/parser.js +1 -1
- package/dist/react/parser.js.map +1 -1
- package/dist/react/parser_template_helpers.d.ts +5 -1
- package/dist/react/parser_template_helpers.d.ts.map +1 -1
- package/dist/react/parser_template_helpers.js +26 -9
- package/dist/react/parser_template_helpers.js.map +1 -1
- package/dist/react/types.d.ts +1 -1
- package/dist/react/types.d.ts.map +1 -1
- package/dist/storybook/convert.d.ts.map +1 -1
- package/dist/storybook/convert.js +63 -5
- package/dist/storybook/convert.js.map +1 -1
- package/dist/storybook/external.d.ts +4 -0
- package/dist/storybook/external.d.ts.map +1 -1
- package/dist/typescript/compiler.d.ts +11 -0
- package/dist/typescript/compiler.d.ts.map +1 -1
- package/dist/typescript/compiler.js +60 -33
- package/dist/typescript/compiler.js.map +1 -1
- package/package.json +9 -8
|
@@ -28,6 +28,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
29
|
exports.maybePrefillWizardQuestionsForTesting = maybePrefillWizardQuestionsForTesting;
|
|
30
30
|
exports.getIncludesGlob = getIncludesGlob;
|
|
31
|
+
exports.createEnvFile = createEnvFile;
|
|
32
|
+
exports.addTokenToEnvFile = addTokenToEnvFile;
|
|
31
33
|
exports.createCodeConnectConfig = createCodeConnectConfig;
|
|
32
34
|
exports.parseFilepathExport = parseFilepathExport;
|
|
33
35
|
exports.getFilepathExport = getFilepathExport;
|
|
@@ -68,15 +70,34 @@ function getIncludesGlob({ dir, componentDirectory, config, }) {
|
|
|
68
70
|
}
|
|
69
71
|
return project_1.DEFAULT_INCLUDE_GLOBS_BY_PARSER[config.parser];
|
|
70
72
|
}
|
|
71
|
-
async function
|
|
73
|
+
async function createEnvFile({ dir, accessToken }) {
|
|
74
|
+
// Create .env file
|
|
75
|
+
const filePath = (0, project_1.getDefaultConfigPath)(dir);
|
|
76
|
+
fs_1.default.writeFileSync((0, project_1.getEnvPath)(dir), `FIGMA_ACCESS_TOKEN="${accessToken}"`);
|
|
77
|
+
logging_1.logger.info((0, logging_1.success)(`Created ${filePath}`));
|
|
78
|
+
}
|
|
79
|
+
function addTokenToEnvFile({ dir, accessToken }) {
|
|
80
|
+
const filePath = (0, project_1.getDefaultConfigPath)(dir);
|
|
81
|
+
fs_1.default.appendFileSync((0, project_1.getEnvPath)(dir), `\nFIGMA_ACCESS_TOKEN="${accessToken}"`);
|
|
82
|
+
logging_1.logger.info((0, logging_1.success)(`Appended access token to ${filePath}`));
|
|
83
|
+
}
|
|
84
|
+
async function createCodeConnectConfig({ dir, componentDirectory, config, figmaUrl, }) {
|
|
85
|
+
const label = project_1.DEFAULT_LABEL_PER_PARSER[config.parser];
|
|
72
86
|
const includesGlob = getIncludesGlob({ dir, componentDirectory, config });
|
|
73
|
-
const configJson =
|
|
74
|
-
{
|
|
87
|
+
const configJson = label
|
|
88
|
+
? `{
|
|
75
89
|
"codeConnect": {
|
|
76
|
-
"include": ["${includesGlob}"]
|
|
77
|
-
|
|
90
|
+
"include": ["${includesGlob}"],
|
|
91
|
+
"label": "${label}",
|
|
92
|
+
"interactiveSetupFigmaFileUrl": "${figmaUrl}",
|
|
78
93
|
}
|
|
79
|
-
|
|
94
|
+
}`
|
|
95
|
+
: `{
|
|
96
|
+
"codeConnect": {
|
|
97
|
+
"include": ["${includesGlob}"],
|
|
98
|
+
"interactiveSetupFigmaFileUrl": "${figmaUrl}",
|
|
99
|
+
}
|
|
100
|
+
}`;
|
|
80
101
|
const formatted = await prettier.format(configJson, {
|
|
81
102
|
parser: 'json',
|
|
82
103
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../../src/connect/wizard/helpers.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../../src/connect/wizard/helpers.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmBA,sFAKC;AAWD,0CAoBC;AAED,sCAKC;AAED,8CAIC;AAED,0DAqCC;AAID,kDAaC;AAED,8CAEC;AAQD,wDAeC;AAQD,kEAgCC;AAED,0CAaC;AA9MD,mDAAoC;AACpC,4CAAmB;AACnB,wCASmB;AACnB,kDAAqE;AACrE,gDAAuB;AACvB,sDAAyC;AAEzC,oDAAqD;AACrD,wCAAyC;AAEzC,SAAgB,qCAAqC;IACnD,IAAI,OAAO,CAAC,GAAG,CAAC,cAAc,IAAI,OAAO,CAAC,GAAG,CAAC,yBAAyB,EAAE,CAAC;QACxE,MAAM,aAAa,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,yBAAyB,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAA;QAC5F,iBAAO,CAAC,MAAM,CAAC,aAAa,CAAC,CAAA;IAC/B,CAAC;AACH,CAAC;AAED;;;;;;;;GAQG;AACH,SAAgB,eAAe,CAAC,EAC9B,GAAG,EACH,kBAAkB,EAClB,MAAM,GAKP;IACC,IAAI,kBAAkB,EAAE,CAAC;QACvB,4CAA4C;QAC5C,MAAM,mBAAmB,GAAG,cAAI,CAAC,QAAQ,CAAC,GAAG,EAAE,kBAAkB,CAAC,CAAC,UAAU,CAA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AkB,CAAC,gBAAgB,CAAC,CAAA;wBAE5D,OAAO,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;4BACtB,OAAO,CAAC,IAAI,CAAC,iBAAiB,CAAC,QAAQ,EAAE,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC,CAAA;wBAC1D,CAAC,CAAC,CAAA;oBACJ,CAAC;oBAAC,OAAO,CAAC,EAAE,CAAC;wBACX,IAAI,GAAG,CAAC,OAAO,EAAE,CAAC;4BAChB,gBAAM,CAAC,IAAI,CAAC,oCAAoC,QAAQ,EAAE,CAAC,CAAA;wBAC7D,CAAC;wBACD,uBAAuB;oBACzB,CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;QACxB,CAAC;QACD,OAAO,OAAO,CAAA;IAChB,CAAC,EAAE,EAAc,CAAC,CAAA;AACpB,CAAC;AAED,SAAgB,eAAe,CAAC,GAAW;IACzC,IAAI,CAAC;QACH,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAA;QACjC,IACE,CAAC,QAAQ,CAAC,QAAQ,CAAC,WAAW,CAAC,EAC/B,CAAC;YACD,OAAO,KAAK,CAAA;QACd,CAAC;QAED,OAAO,CAAC,CAAC,IAAA,sBAAY,EAAC,GAAG,CAAC,CAAA;IAC5B,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,OAAO,KAAK,CAAA;IACd,CAAC;AACH,CAAC"}
|
|
@@ -2,11 +2,43 @@ import { BaseCommand } from '../../commands/connect';
|
|
|
2
2
|
import prompts from 'prompts';
|
|
3
3
|
import { FigmaRestApi } from '../figma_rest_api';
|
|
4
4
|
import { ReactProjectInfo, CodeConnectConfig, ProjectInfo } from '../../connect/project';
|
|
5
|
+
import { CreateRequestPayload, CreateRequestPayloadMulti, PropMapping } from '../parser_executable_types';
|
|
6
|
+
import { ComponentTypeSignature } from '../../react/parser';
|
|
5
7
|
type ConnectedComponentMappings = {
|
|
6
8
|
componentName: string;
|
|
7
9
|
filepathExport: string;
|
|
8
10
|
}[];
|
|
11
|
+
/**
|
|
12
|
+
* enable selection of a subset of components per page
|
|
13
|
+
* @param components to narrow down from
|
|
14
|
+
* @returns components narrowed down to the selected pages
|
|
15
|
+
*/
|
|
16
|
+
export declare function narrowDownComponentsPerPage(components: FigmaRestApi.Component[], pages: Record<string, string>): Promise<FigmaRestApi.Component[]>;
|
|
9
17
|
export declare function getComponentChoicesForPrompt(components: FigmaRestApi.Component[], linkedNodeIdsToFilepathExports: Record<string, string>, connectedComponentsMappings: ConnectedComponentMappings, dir: string): prompts.Choice[];
|
|
18
|
+
interface AddPayloadArgs {
|
|
19
|
+
payloadType: 'MULTI_EXPORT' | 'SINGLE_EXPORT';
|
|
20
|
+
filepath: string;
|
|
21
|
+
sourceExport: string;
|
|
22
|
+
reactTypeSignature?: ComponentTypeSignature;
|
|
23
|
+
propMapping?: PropMapping;
|
|
24
|
+
figmaNodeUrl: string;
|
|
25
|
+
moreComponentProps: FigmaRestApi.Component;
|
|
26
|
+
destinationDir: string;
|
|
27
|
+
sourceFilepath: string;
|
|
28
|
+
normalizedName: string;
|
|
29
|
+
config: CodeConnectConfig;
|
|
30
|
+
}
|
|
31
|
+
export declare function addPayload(payloads: Record<string, CreateRequestPayloadMulti | CreateRequestPayload>, args: AddPayloadArgs): Promise<void>;
|
|
32
|
+
export declare function createCodeConnectFiles({ linkedNodeIdsToFilepathExports, figmaFileUrl, unconnectedComponentsMap, outDir: outDirArg, projectInfo, cmd, accessToken, useAi, }: {
|
|
33
|
+
figmaFileUrl: string;
|
|
34
|
+
linkedNodeIdsToFilepathExports: Record<string, string>;
|
|
35
|
+
unconnectedComponentsMap: Record<string, FigmaRestApi.Component>;
|
|
36
|
+
outDir: string | null;
|
|
37
|
+
projectInfo: ProjectInfo;
|
|
38
|
+
cmd: BaseCommand;
|
|
39
|
+
accessToken: string;
|
|
40
|
+
useAi: boolean;
|
|
41
|
+
}): Promise<boolean>;
|
|
10
42
|
export declare function convertRemoteFileUrlToRelativePath({ remoteFileUrl, gitRootPath, dir, }: {
|
|
11
43
|
remoteFileUrl: string;
|
|
12
44
|
gitRootPath: string;
|
|
@@ -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;AAE3D,OAAO,EACL,gBAAgB,EAKhB,iBAAiB,EACjB,WAAW,
|
|
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;AAE3D,OAAO,EACL,gBAAgB,EAKhB,iBAAiB,EACjB,WAAW,EAGZ,MAAM,uBAAuB,CAAA;AAI9B,OAAO,EACL,oBAAoB,EACpB,yBAAyB,EAGzB,WAAW,EACZ,MAAM,4BAA4B,CAAA;AAuBnC,OAAO,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAA;AAE3D,KAAK,0BAA0B,GAAG;IAAE,aAAa,EAAE,MAAM,CAAC;IAAC,cAAc,EAAE,MAAM,CAAA;CAAE,EAAE,CAAA;AA6FrF;;;;GAIG;AACH,wBAAsB,2BAA2B,CAC/C,UAAU,EAAE,YAAY,CAAC,SAAS,EAAE,EACpC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,qCA0C9B;AA+ED,wBAAgB,4BAA4B,CAC1C,UAAU,EAAE,YAAY,CAAC,SA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W,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;AAsFD,wBAAsB,SAAS,CAAC,GAAG,EAAE,WAAW,iBAyQ/C"}
|
|
@@ -3,7 +3,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.narrowDownComponentsPerPage = narrowDownComponentsPerPage;
|
|
6
7
|
exports.getComponentChoicesForPrompt = getComponentChoicesForPrompt;
|
|
8
|
+
exports.addPayload = addPayload;
|
|
9
|
+
exports.createCodeConnectFiles = createCodeConnectFiles;
|
|
7
10
|
exports.convertRemoteFileUrlToRelativePath = convertRemoteFileUrlToRelativePath;
|
|
8
11
|
exports.getUnconnectedComponentsAndConnectedComponentMappings = getUnconnectedComponentsAndConnectedComponentMappings;
|
|
9
12
|
exports.runWizard = runWizard;
|
|
@@ -30,6 +33,7 @@ const autolinking_1 = require("./autolinking");
|
|
|
30
33
|
const prop_mapping_helpers_1 = require("./prop_mapping_helpers");
|
|
31
34
|
const fetch_1 = require("../../common/fetch");
|
|
32
35
|
const NONE = '(None)';
|
|
36
|
+
const MAX_COMPONENTS_TO_MAP = 40;
|
|
33
37
|
function clearQuestion(prompt, answer) {
|
|
34
38
|
const displayedAnswer = (Array.isArray(prompt.choices) && prompt.choices.find((c) => c.value === answer)?.title) ||
|
|
35
39
|
answer;
|
|
@@ -83,9 +87,51 @@ async function fetchTopLevelComponentsFromFile({ accessToken, figmaUrl, cmd, })
|
|
|
83
87
|
}
|
|
84
88
|
logging_1.logger.debug(JSON.stringify(err.data));
|
|
85
89
|
}
|
|
90
|
+
else {
|
|
91
|
+
logging_1.logger.error(err);
|
|
92
|
+
}
|
|
86
93
|
(0, helpers_1.exitWithFeedbackMessage)(1);
|
|
87
94
|
}
|
|
88
95
|
}
|
|
96
|
+
/**
|
|
97
|
+
* enable selection of a subset of components per page
|
|
98
|
+
* @param components to narrow down from
|
|
99
|
+
* @returns components narrowed down to the selected pages
|
|
100
|
+
*/
|
|
101
|
+
async function narrowDownComponentsPerPage(components, pages) {
|
|
102
|
+
const createTitle = (name, id, pad) => {
|
|
103
|
+
const componentsInPage = components.filter((c) => c.pageId === id);
|
|
104
|
+
let namesPreview = componentsInPage
|
|
105
|
+
.slice(0, 4)
|
|
106
|
+
.map((c) => c.name)
|
|
107
|
+
.join(', ');
|
|
108
|
+
namesPreview = componentsInPage.length > 4 ? `${namesPreview}, ...` : `${namesPreview}`;
|
|
109
|
+
const componentWord = componentsInPage.length === 1 ? 'Component' : 'Components';
|
|
110
|
+
return `${name.padEnd(pad, ' ')} - ${componentsInPage.length} ${componentWord} ${chalk_1.default.dim(`(${namesPreview})`)}`;
|
|
111
|
+
};
|
|
112
|
+
const longestPageName = Math.max(...Object.values(pages).map((name) => name.length));
|
|
113
|
+
let pagesToMap = [];
|
|
114
|
+
console.info('');
|
|
115
|
+
while (true) {
|
|
116
|
+
const { pagesToMap_temp } = await askQuestion({
|
|
117
|
+
type: 'multiselect',
|
|
118
|
+
name: 'pagesToMap_temp',
|
|
119
|
+
message: `Select the pages with the Figma components you'd like to map (Press ${chalk_1.default.green('space')} to select and ${chalk_1.default.green('enter')} to continue)`,
|
|
120
|
+
instructions: false,
|
|
121
|
+
choices: Object.entries(pages).map(([id, name]) => ({
|
|
122
|
+
title: createTitle(name, id, longestPageName),
|
|
123
|
+
value: id,
|
|
124
|
+
})),
|
|
125
|
+
});
|
|
126
|
+
if (!pagesToMap_temp || pagesToMap_temp.length === 0) {
|
|
127
|
+
logging_1.logger.warn('Select at least one page to continue.');
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
pagesToMap = pagesToMap_temp;
|
|
131
|
+
break;
|
|
132
|
+
}
|
|
133
|
+
return components.filter((c) => pagesToMap.includes(c.pageId));
|
|
134
|
+
}
|
|
89
135
|
/**
|
|
90
136
|
* Asks a Prompts question and adds spacing
|
|
91
137
|
* @param question Prompts question
|
|
@@ -142,8 +188,11 @@ async function askQuestionWithExitConfirmation(question) {
|
|
|
142
188
|
}
|
|
143
189
|
}
|
|
144
190
|
function formatComponentTitle(componentName, filepathExport, pad) {
|
|
191
|
+
const fileExport = filepathExport ? (0, helpers_2.parseFilepathExport)(filepathExport) : null;
|
|
145
192
|
const nameLabel = `${chalk_1.default.dim('Figma component:')} ${componentName.padEnd(pad, ' ')}`;
|
|
146
|
-
const
|
|
193
|
+
const filepathLabel = fileExport ? fileExport.filepath : '-';
|
|
194
|
+
const exportNote = fileExport?.exportName ? ` (${fileExport.exportName})` : '';
|
|
195
|
+
const linkedLabel = `↔️ ${chalk_1.default.dim('Code Definition:')} ${filepathLabel}${exportNote}`;
|
|
147
196
|
return `${nameLabel} ${linkedLabel}`;
|
|
148
197
|
}
|
|
149
198
|
function getComponentChoicesForPrompt(components, linkedNodeIdsToFilepathExports, connectedComponentsMappings, dir) {
|
|
@@ -162,7 +211,7 @@ function getComponentChoicesForPrompt(components, linkedNodeIdsToFilepathExports
|
|
|
162
211
|
return {
|
|
163
212
|
title: formatComponentTitle(c.name, filepathExport, longestNameLength),
|
|
164
213
|
value: c.id,
|
|
165
|
-
description: `${chalk_1.default.green('Edit
|
|
214
|
+
description: `${chalk_1.default.green('Edit Match')}`,
|
|
166
215
|
};
|
|
167
216
|
};
|
|
168
217
|
return [
|
|
@@ -188,15 +237,34 @@ function getUnconnectedComponentChoices(componentPaths, dir) {
|
|
|
188
237
|
}),
|
|
189
238
|
];
|
|
190
239
|
}
|
|
240
|
+
const escapeHandler = () => {
|
|
241
|
+
let escPressed = false;
|
|
242
|
+
const keypressListener = (_, key) => {
|
|
243
|
+
if (key.name === 'escape') {
|
|
244
|
+
escPressed = true;
|
|
245
|
+
}
|
|
246
|
+
};
|
|
247
|
+
process.stdin.on('keypress', keypressListener);
|
|
248
|
+
return {
|
|
249
|
+
escPressed: () => escPressed,
|
|
250
|
+
reset: () => {
|
|
251
|
+
escPressed = false;
|
|
252
|
+
},
|
|
253
|
+
destroy: () => {
|
|
254
|
+
process.stdin.removeListener('keypress', keypressListener);
|
|
255
|
+
},
|
|
256
|
+
};
|
|
257
|
+
};
|
|
191
258
|
async function runManualLinking({ unconnectedComponents, linkedNodeIdsToFilepathExports, filepathExports, connectedComponentsMappings, cmd, }) {
|
|
192
259
|
const filesToComponentOptionsMap = (0, helpers_2.getComponentOptionsMap)(filepathExports);
|
|
193
260
|
const dir = (0, connect_1.getDir)(cmd);
|
|
261
|
+
const escHandler = escapeHandler();
|
|
194
262
|
while (true) {
|
|
195
263
|
// Don't show exit confirmation as we're relying on esc behavior
|
|
196
264
|
const { nodeId } = await (0, prompts_1.default)({
|
|
197
265
|
type: 'select',
|
|
198
266
|
name: 'nodeId',
|
|
199
|
-
message: `Select a
|
|
267
|
+
message: `Select a Figma component match you'd like to edit (Press ${chalk_1.default.green('esc')} when you're ready to continue on)`,
|
|
200
268
|
choices: getComponentChoicesForPrompt(unconnectedComponents, linkedNodeIdsToFilepathExports, connectedComponentsMappings, dir),
|
|
201
269
|
warn: 'This component already has a local Code Connect file.',
|
|
202
270
|
hint: ' ',
|
|
@@ -204,7 +272,7 @@ async function runManualLinking({ unconnectedComponents, linkedNodeIdsToFilepath
|
|
|
204
272
|
onSubmit: clearQuestion,
|
|
205
273
|
});
|
|
206
274
|
if (!nodeId) {
|
|
207
|
-
|
|
275
|
+
break;
|
|
208
276
|
}
|
|
209
277
|
const pathChoices = getUnconnectedComponentChoices(Object.keys(filesToComponentOptionsMap), dir);
|
|
210
278
|
const prevSelectedKey = linkedNodeIdsToFilepathExports[nodeId];
|
|
@@ -214,6 +282,7 @@ async function runManualLinking({ unconnectedComponents, linkedNodeIdsToFilepath
|
|
|
214
282
|
filepath: null,
|
|
215
283
|
exportName: null,
|
|
216
284
|
};
|
|
285
|
+
escHandler.reset();
|
|
217
286
|
const { pathToComponent } = await (0, prompts_1.default)({
|
|
218
287
|
type: 'autocomplete',
|
|
219
288
|
name: 'pathToComponent',
|
|
@@ -228,6 +297,9 @@ async function runManualLinking({ unconnectedComponents, linkedNodeIdsToFilepath
|
|
|
228
297
|
}, {
|
|
229
298
|
onSubmit: clearQuestion,
|
|
230
299
|
});
|
|
300
|
+
if (escHandler.escPressed()) {
|
|
301
|
+
continue;
|
|
302
|
+
}
|
|
231
303
|
if (pathToComponent) {
|
|
232
304
|
if (pathToComponent === NONE) {
|
|
233
305
|
delete linkedNodeIdsToFilepathExports[nodeId];
|
|
@@ -239,6 +311,7 @@ async function runManualLinking({ unconnectedComponents, linkedNodeIdsToFilepath
|
|
|
239
311
|
linkedNodeIdsToFilepathExports[nodeId] = pathToComponent;
|
|
240
312
|
}
|
|
241
313
|
else {
|
|
314
|
+
escHandler.reset();
|
|
242
315
|
const { filepathExport } = await (0, prompts_1.default)({
|
|
243
316
|
type: 'autocomplete',
|
|
244
317
|
name: 'filepathExport',
|
|
@@ -253,24 +326,27 @@ async function runManualLinking({ unconnectedComponents, linkedNodeIdsToFilepath
|
|
|
253
326
|
}, {
|
|
254
327
|
onSubmit: clearQuestion,
|
|
255
328
|
});
|
|
329
|
+
if (escHandler.escPressed()) {
|
|
330
|
+
continue;
|
|
331
|
+
}
|
|
256
332
|
linkedNodeIdsToFilepathExports[nodeId] = filepathExport;
|
|
257
333
|
}
|
|
258
334
|
}
|
|
259
335
|
}
|
|
260
336
|
}
|
|
337
|
+
escHandler.destroy();
|
|
261
338
|
}
|
|
262
339
|
async function runManualLinkingWithConfirmation(manualLinkingArgs) {
|
|
263
340
|
let outDir = manualLinkingArgs.cmd.outDir || null;
|
|
264
|
-
let hasAskedOutDirQuestion = false;
|
|
265
341
|
while (true) {
|
|
266
342
|
await runManualLinking(manualLinkingArgs);
|
|
267
|
-
if (!outDir
|
|
343
|
+
if (!outDir) {
|
|
344
|
+
console.info('\nA Code Connect file is created for each Figma component to code definition match.');
|
|
268
345
|
const { outputDirectory } = await askQuestionWithExitConfirmation({
|
|
269
346
|
type: 'text',
|
|
270
347
|
name: 'outputDirectory',
|
|
271
|
-
message: `
|
|
348
|
+
message: `In which directory would you like to store Code Connect files? (Press ${chalk_1.default.green('enter')} to co-locate your files alongside your component files)`,
|
|
272
349
|
});
|
|
273
|
-
hasAskedOutDirQuestion = true;
|
|
274
350
|
outDir = outputDirectory;
|
|
275
351
|
}
|
|
276
352
|
const linkedNodes = Object.keys(manualLinkingArgs.linkedNodeIdsToFilepathExports);
|
|
@@ -310,12 +386,58 @@ async function runManualLinkingWithConfirmation(manualLinkingArgs) {
|
|
|
310
386
|
},
|
|
311
387
|
],
|
|
312
388
|
});
|
|
313
|
-
if (confirmation
|
|
389
|
+
if (confirmation === 'backToEdit') {
|
|
390
|
+
outDir = manualLinkingArgs.cmd.outDir || null;
|
|
391
|
+
}
|
|
392
|
+
else {
|
|
314
393
|
return outDir;
|
|
315
394
|
}
|
|
316
395
|
}
|
|
317
396
|
}
|
|
318
397
|
}
|
|
398
|
+
async function addPayload(payloads, args) {
|
|
399
|
+
const { payloadType, filepath, sourceExport, reactTypeSignature, propMapping, figmaNodeUrl, moreComponentProps, destinationDir, sourceFilepath, normalizedName, config, } = args;
|
|
400
|
+
if (payloadType === 'MULTI_EXPORT') {
|
|
401
|
+
const figmaConnection = {
|
|
402
|
+
sourceExport,
|
|
403
|
+
reactTypeSignature,
|
|
404
|
+
propMapping,
|
|
405
|
+
component: {
|
|
406
|
+
figmaNodeUrl,
|
|
407
|
+
...moreComponentProps,
|
|
408
|
+
},
|
|
409
|
+
};
|
|
410
|
+
if (payloads[filepath]) {
|
|
411
|
+
;
|
|
412
|
+
payloads[filepath].figmaConnections.push(figmaConnection);
|
|
413
|
+
}
|
|
414
|
+
else {
|
|
415
|
+
const payload = {
|
|
416
|
+
mode: 'CREATE',
|
|
417
|
+
destinationDir,
|
|
418
|
+
sourceFilepath,
|
|
419
|
+
normalizedName,
|
|
420
|
+
figmaConnections: [figmaConnection],
|
|
421
|
+
config,
|
|
422
|
+
};
|
|
423
|
+
payloads[filepath] = payload;
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
if (payloadType === 'SINGLE_EXPORT') {
|
|
427
|
+
const payload = {
|
|
428
|
+
mode: 'CREATE',
|
|
429
|
+
destinationDir,
|
|
430
|
+
sourceFilepath,
|
|
431
|
+
component: {
|
|
432
|
+
figmaNodeUrl,
|
|
433
|
+
normalizedName,
|
|
434
|
+
...moreComponentProps,
|
|
435
|
+
},
|
|
436
|
+
config,
|
|
437
|
+
};
|
|
438
|
+
payloads[filepath] = payload;
|
|
439
|
+
}
|
|
440
|
+
}
|
|
319
441
|
async function createCodeConnectFiles({ linkedNodeIdsToFilepathExports, figmaFileUrl, unconnectedComponentsMap, outDir: outDirArg, projectInfo, cmd, accessToken, useAi, }) {
|
|
320
442
|
const filepathExportsToComponents = Object.entries(linkedNodeIdsToFilepathExports).reduce((map, [nodeId, filepathExport]) => {
|
|
321
443
|
map[filepathExport] = unconnectedComponentsMap[nodeId];
|
|
@@ -342,6 +464,7 @@ async function createCodeConnectFiles({ linkedNodeIdsToFilepathExports, figmaFil
|
|
|
342
464
|
embeddingsFetchSpinner.stop();
|
|
343
465
|
}
|
|
344
466
|
let allFilesCreated = true;
|
|
467
|
+
const payloads = {};
|
|
345
468
|
for (const [nodeId, filepathExport] of Object.entries(linkedNodeIdsToFilepathExports)) {
|
|
346
469
|
const urlObj = new URL(figmaFileUrl);
|
|
347
470
|
urlObj.search = '';
|
|
@@ -349,20 +472,25 @@ async function createCodeConnectFiles({ linkedNodeIdsToFilepathExports, figmaFil
|
|
|
349
472
|
const { filepath, exportName } = (0, helpers_2.parseFilepathExport)(filepathExport);
|
|
350
473
|
const { name } = path_1.default.parse(filepath);
|
|
351
474
|
const outDir = outDirArg || path_1.default.dirname(filepath);
|
|
352
|
-
const
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
475
|
+
const payloadType = projectInfo.config.parser === 'react' || projectInfo.config.parser === 'html'
|
|
476
|
+
? 'MULTI_EXPORT'
|
|
477
|
+
: 'SINGLE_EXPORT';
|
|
478
|
+
addPayload(payloads, {
|
|
479
|
+
payloadType,
|
|
480
|
+
filepath,
|
|
481
|
+
sourceExport: exportName || '?',
|
|
357
482
|
reactTypeSignature: propMappingsAndData?.propMappingData[filepathExport]?.signature,
|
|
358
483
|
propMapping: propMappingsAndData?.propMappings[filepathExport],
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
484
|
+
figmaNodeUrl: urlObj.toString(),
|
|
485
|
+
moreComponentProps: unconnectedComponentsMap[nodeId],
|
|
486
|
+
destinationDir: outDir,
|
|
487
|
+
sourceFilepath: filepath,
|
|
488
|
+
normalizedName: (0, create_1.normalizeComponentName)(name),
|
|
364
489
|
config: projectInfo.config,
|
|
365
|
-
};
|
|
490
|
+
});
|
|
491
|
+
}
|
|
492
|
+
for (const payloadKey of Object.keys(payloads)) {
|
|
493
|
+
const payload = payloads[payloadKey];
|
|
366
494
|
let result;
|
|
367
495
|
if (projectInfo.config.parser === 'react') {
|
|
368
496
|
result = await (0, create_2.createReactCodeConnect)(payload);
|
|
@@ -516,10 +644,11 @@ async function runWizard(cmd) {
|
|
|
516
644
|
}));
|
|
517
645
|
const dir = (0, connect_1.getDir)(cmd);
|
|
518
646
|
const { hasConfigFile, config } = await (0, project_1.parseOrDetermineConfig)(dir, cmd.config);
|
|
647
|
+
const { hasEnvFile, envHasFigmaToken } = await (0, project_1.checkForEnvAndToken)(dir);
|
|
519
648
|
// This isn't ideal as you see the intro text followed by an error, but we'll
|
|
520
649
|
// add support for this soon so I think it's OK
|
|
521
650
|
if (config.parser === 'html') {
|
|
522
|
-
(0, logging_1.exitWithError)('HTML projects are currently not supported by Code Connect interactive setup');
|
|
651
|
+
(0, logging_1.exitWithError)('HTML projects are currently not supported by Code Connect interactive setup. Please use the "npx figma connect create" command instead.');
|
|
523
652
|
}
|
|
524
653
|
let accessToken = (0, connect_1.getAccessToken)(cmd);
|
|
525
654
|
if (!accessToken) {
|
|
@@ -533,19 +662,70 @@ async function runWizard(cmd) {
|
|
|
533
662
|
accessToken = accessTokenEntered;
|
|
534
663
|
}
|
|
535
664
|
logging_1.logger.info('');
|
|
665
|
+
if (!hasEnvFile) {
|
|
666
|
+
// If there is no .env file, we should ask the user if they want to create one
|
|
667
|
+
// to store the Figma token.
|
|
668
|
+
const { createConfigFile } = await askQuestionOrExit({
|
|
669
|
+
type: 'select',
|
|
670
|
+
name: 'createConfigFile',
|
|
671
|
+
message: "It looks like you don't have a .env file. Would you like to generate one now to store the Figma access token?",
|
|
672
|
+
choices: [
|
|
673
|
+
{
|
|
674
|
+
title: 'Yes',
|
|
675
|
+
value: 'yes',
|
|
676
|
+
},
|
|
677
|
+
{
|
|
678
|
+
title: 'No',
|
|
679
|
+
value: 'no',
|
|
680
|
+
},
|
|
681
|
+
],
|
|
682
|
+
});
|
|
683
|
+
if (createConfigFile === 'yes') {
|
|
684
|
+
await (0, helpers_2.createEnvFile)({ dir, accessToken });
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
else if (!envHasFigmaToken) {
|
|
688
|
+
// If there is a .env file but no Figma token, we should ask the user if they want to add it.
|
|
689
|
+
const { addFigmaToken } = await askQuestionOrExit({
|
|
690
|
+
type: 'select',
|
|
691
|
+
name: 'addFigmaToken',
|
|
692
|
+
message: 'Would you like to add your Figma access token to your .env file?',
|
|
693
|
+
choices: [
|
|
694
|
+
{
|
|
695
|
+
title: 'Yes',
|
|
696
|
+
value: 'yes',
|
|
697
|
+
},
|
|
698
|
+
{
|
|
699
|
+
title: 'No',
|
|
700
|
+
value: 'no',
|
|
701
|
+
},
|
|
702
|
+
],
|
|
703
|
+
});
|
|
704
|
+
if (addFigmaToken === 'yes') {
|
|
705
|
+
(0, helpers_2.addTokenToEnvFile)({ dir, accessToken });
|
|
706
|
+
}
|
|
707
|
+
}
|
|
536
708
|
const { componentDirectory, projectInfo, filepathExports } = await askForTopLevelDirectoryOrDetermineFromConfig({
|
|
537
709
|
dir,
|
|
538
710
|
hasConfigFile,
|
|
539
711
|
config,
|
|
540
712
|
cmd,
|
|
541
713
|
});
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
714
|
+
let figmaFileUrl;
|
|
715
|
+
if (config.interactiveSetupFigmaFileUrl) {
|
|
716
|
+
logging_1.logger.info(`Using Figma file URL from config: ${config.interactiveSetupFigmaFileUrl}\n`);
|
|
717
|
+
figmaFileUrl = config.interactiveSetupFigmaFileUrl;
|
|
718
|
+
}
|
|
719
|
+
else {
|
|
720
|
+
let { figmaFileUrl: answer } = await askQuestionOrExit({
|
|
721
|
+
type: 'text',
|
|
722
|
+
message: "What is the URL of the Figma file containing design components you'd like to connect?",
|
|
723
|
+
name: 'figmaFileUrl',
|
|
724
|
+
validate: (value) => (0, helpers_2.isValidFigmaUrl)(value) || 'Please enter a valid Figma file URL.',
|
|
725
|
+
});
|
|
726
|
+
figmaFileUrl = answer;
|
|
727
|
+
}
|
|
728
|
+
let componentsFromFile = await fetchTopLevelComponentsFromFile({
|
|
549
729
|
accessToken,
|
|
550
730
|
figmaUrl: figmaFileUrl,
|
|
551
731
|
cmd,
|
|
@@ -570,7 +750,7 @@ async function runWizard(cmd) {
|
|
|
570
750
|
],
|
|
571
751
|
});
|
|
572
752
|
if (createConfigFile === 'yes') {
|
|
573
|
-
await (0, helpers_2.createCodeConnectConfig)({ dir, componentDirectory, config });
|
|
753
|
+
await (0, helpers_2.createCodeConnectConfig)({ dir, componentDirectory, config, figmaUrl: figmaFileUrl });
|
|
574
754
|
}
|
|
575
755
|
}
|
|
576
756
|
let useAi = false;
|
|
@@ -592,6 +772,15 @@ async function runWizard(cmd) {
|
|
|
592
772
|
});
|
|
593
773
|
useAi = useAiSelection === 'yes';
|
|
594
774
|
}
|
|
775
|
+
const pagesFromFile = componentsFromFile.reduce((acc, c) => {
|
|
776
|
+
acc[c.pageId] = c.pageName;
|
|
777
|
+
return acc;
|
|
778
|
+
}, {});
|
|
779
|
+
const pagesFromFileCount = Object.keys(pagesFromFile).length;
|
|
780
|
+
if (componentsFromFile.length > MAX_COMPONENTS_TO_MAP && pagesFromFileCount > 1) {
|
|
781
|
+
logging_1.logger.info(`${componentsFromFile.length} Figma components found in the Figma file across ${pagesFromFileCount} pages.`);
|
|
782
|
+
componentsFromFile = await narrowDownComponentsPerPage(componentsFromFile, pagesFromFile);
|
|
783
|
+
}
|
|
595
784
|
const linkedNodeIdsToFilepathExports = {};
|
|
596
785
|
const { unconnectedComponents, connectedComponentsMappings } = await getUnconnectedComponentsAndConnectedComponentMappings(cmd, figmaFileUrl, componentsFromFile, projectInfo);
|
|
597
786
|
(0, autolinking_1.autoLinkComponents)({
|
|
@@ -599,7 +788,7 @@ async function runWizard(cmd) {
|
|
|
599
788
|
linkedNodeIdsToFilepathExports,
|
|
600
789
|
filepathExports,
|
|
601
790
|
});
|
|
602
|
-
logging_1.logger.info((0, boxen_1.default)(`${chalk_1.default.bold(`Connecting your components`)}\n\n` +
|
|
791
|
+
logging_1.logger.info((0, boxen_1.default)(`${chalk_1.default.bold(`Connecting your Figma components`)}\n\n` +
|
|
603
792
|
`${chalk_1.default.green(`${chalk_1.default.bold(Object.keys(linkedNodeIdsToFilepathExports).length)} ${Object.keys(linkedNodeIdsToFilepathExports).length === 1
|
|
604
793
|
? 'component was automatically matched based on its name'
|
|
605
794
|
: 'components were automatically matched based on their names'}`)}\n` +
|