@figma/code-connect 0.1.2 → 0.2.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.
Files changed (106) hide show
  1. package/README.md +123 -25
  2. package/dist/cli.js +7 -0
  3. package/dist/cli.js.map +1 -1
  4. package/dist/commands/connect.d.ts +15 -0
  5. package/dist/commands/connect.d.ts.map +1 -1
  6. package/dist/commands/connect.js +137 -76
  7. package/dist/commands/connect.js.map +1 -1
  8. package/dist/common/__test__/project.test.d.ts +2 -0
  9. package/dist/common/__test__/project.test.d.ts.map +1 -0
  10. package/dist/common/__test__/project.test.js +14 -0
  11. package/dist/common/__test__/project.test.js.map +1 -0
  12. package/dist/common/api.d.ts +56 -2
  13. package/dist/common/api.d.ts.map +1 -1
  14. package/dist/common/external.d.ts +6 -3
  15. package/dist/common/external.d.ts.map +1 -1
  16. package/dist/common/external.js +13 -1
  17. package/dist/common/external.js.map +1 -1
  18. package/dist/common/figma_connect.d.ts +10 -8
  19. package/dist/common/figma_connect.d.ts.map +1 -1
  20. package/dist/common/intrinsics.d.ts +38 -6
  21. package/dist/common/intrinsics.d.ts.map +1 -1
  22. package/dist/common/intrinsics.js +160 -26
  23. package/dist/common/intrinsics.js.map +1 -1
  24. package/dist/common/logging.d.ts +9 -0
  25. package/dist/common/logging.d.ts.map +1 -1
  26. package/dist/common/logging.js +21 -1
  27. package/dist/common/logging.js.map +1 -1
  28. package/dist/common/updates.d.ts +4 -0
  29. package/dist/common/updates.d.ts.map +1 -0
  30. package/dist/common/updates.js +87 -0
  31. package/dist/common/updates.js.map +1 -0
  32. package/dist/connect/create.d.ts +5 -1
  33. package/dist/connect/create.d.ts.map +1 -1
  34. package/dist/connect/create.js +55 -69
  35. package/dist/connect/create.js.map +1 -1
  36. package/dist/connect/delete_docs.d.ts.map +1 -1
  37. package/dist/connect/delete_docs.js +1 -4
  38. package/dist/connect/delete_docs.js.map +1 -1
  39. package/dist/connect/figma_rest_api.d.ts +5 -0
  40. package/dist/connect/figma_rest_api.d.ts.map +1 -1
  41. package/dist/connect/figma_rest_api.js +10 -1
  42. package/dist/connect/figma_rest_api.js.map +1 -1
  43. package/dist/connect/helpers.d.ts +1 -1
  44. package/dist/connect/helpers.d.ts.map +1 -1
  45. package/dist/connect/helpers.js +6 -5
  46. package/dist/connect/helpers.js.map +1 -1
  47. package/dist/connect/parser_executable_types.d.ts +297 -0
  48. package/dist/connect/parser_executable_types.d.ts.map +1 -0
  49. package/dist/connect/parser_executable_types.js +108 -0
  50. package/dist/connect/parser_executable_types.js.map +1 -0
  51. package/dist/connect/parser_executables.d.ts +8 -0
  52. package/dist/connect/parser_executables.d.ts.map +1 -0
  53. package/dist/connect/parser_executables.js +132 -0
  54. package/dist/connect/parser_executables.js.map +1 -0
  55. package/dist/connect/project.d.ts +137 -0
  56. package/dist/connect/project.d.ts.map +1 -0
  57. package/dist/connect/project.js +411 -0
  58. package/dist/connect/project.js.map +1 -0
  59. package/dist/connect/upload.d.ts.map +1 -1
  60. package/dist/connect/upload.js +1 -4
  61. package/dist/connect/upload.js.map +1 -1
  62. package/dist/connect/validation.d.ts +6 -1
  63. package/dist/connect/validation.d.ts.map +1 -1
  64. package/dist/connect/validation.js +23 -18
  65. package/dist/connect/validation.js.map +1 -1
  66. package/dist/connect/wizard/helpers.d.ts +7 -0
  67. package/dist/connect/wizard/helpers.d.ts.map +1 -0
  68. package/dist/connect/wizard/helpers.js +55 -0
  69. package/dist/connect/wizard/helpers.js.map +1 -0
  70. package/dist/connect/wizard/run_wizard.d.ts +3 -0
  71. package/dist/connect/wizard/run_wizard.d.ts.map +1 -0
  72. package/dist/connect/wizard/run_wizard.js +480 -0
  73. package/dist/connect/wizard/run_wizard.js.map +1 -0
  74. package/dist/parser_scripts/get_file_if_exists.d.ts +2 -0
  75. package/dist/parser_scripts/get_file_if_exists.d.ts.map +1 -0
  76. package/dist/parser_scripts/get_file_if_exists.js +10 -0
  77. package/dist/parser_scripts/get_file_if_exists.js.map +1 -0
  78. package/dist/parser_scripts/get_gradlew_path.d.ts +3 -0
  79. package/dist/parser_scripts/get_gradlew_path.d.ts.map +1 -0
  80. package/dist/parser_scripts/get_gradlew_path.js +24 -0
  81. package/dist/parser_scripts/get_gradlew_path.js.map +1 -0
  82. package/dist/parser_scripts/get_swift_parser_dir.d.ts +2 -0
  83. package/dist/parser_scripts/get_swift_parser_dir.d.ts.map +1 -0
  84. package/dist/parser_scripts/get_swift_parser_dir.js +93 -0
  85. package/dist/parser_scripts/get_swift_parser_dir.js.map +1 -0
  86. package/dist/react/create.d.ts +4 -0
  87. package/dist/react/create.d.ts.map +1 -0
  88. package/dist/react/create.js +132 -0
  89. package/dist/react/create.js.map +1 -0
  90. package/dist/react/parser.d.ts +6 -15
  91. package/dist/react/parser.d.ts.map +1 -1
  92. package/dist/react/parser.js +55 -62
  93. package/dist/react/parser.js.map +1 -1
  94. package/dist/react/parser_template_helpers.d.ts +21 -0
  95. package/dist/react/parser_template_helpers.d.ts.map +1 -1
  96. package/dist/react/parser_template_helpers.js +107 -43
  97. package/dist/react/parser_template_helpers.js.map +1 -1
  98. package/dist/storybook/convert.d.ts +2 -2
  99. package/dist/storybook/convert.d.ts.map +1 -1
  100. package/dist/storybook/convert.js +6 -4
  101. package/dist/storybook/convert.js.map +1 -1
  102. package/package.json +36 -11
  103. package/dist/common/project.d.ts +0 -94
  104. package/dist/common/project.d.ts.map +0 -1
  105. package/dist/common/project.js +0 -198
  106. package/dist/common/project.js.map +0 -1
@@ -0,0 +1,297 @@
1
+ import { z } from 'zod';
2
+ export type ParseRequestPayload = {
3
+ mode: 'PARSE';
4
+ paths: string[];
5
+ config: Record<string, any>;
6
+ };
7
+ export declare const ParserExecutableMessages: z.ZodArray<z.ZodObject<{
8
+ level: z.ZodUnion<[z.ZodLiteral<"DEBUG">, z.ZodLiteral<"INFO">, z.ZodLiteral<"WARN">, z.ZodLiteral<"ERROR">]>;
9
+ type: z.ZodOptional<z.ZodString>;
10
+ message: z.ZodString;
11
+ sourceLocation: z.ZodOptional<z.ZodObject<{
12
+ file: z.ZodString;
13
+ line: z.ZodOptional<z.ZodNumber>;
14
+ }, "strip", z.ZodTypeAny, {
15
+ file: string;
16
+ line?: number | undefined;
17
+ }, {
18
+ file: string;
19
+ line?: number | undefined;
20
+ }>>;
21
+ }, "strip", z.ZodTypeAny, {
22
+ message: string;
23
+ level: "DEBUG" | "INFO" | "WARN" | "ERROR";
24
+ type?: string | undefined;
25
+ sourceLocation?: {
26
+ file: string;
27
+ line?: number | undefined;
28
+ } | undefined;
29
+ }, {
30
+ message: string;
31
+ level: "DEBUG" | "INFO" | "WARN" | "ERROR";
32
+ type?: string | undefined;
33
+ sourceLocation?: {
34
+ file: string;
35
+ line?: number | undefined;
36
+ } | undefined;
37
+ }>, "many">;
38
+ export declare const ParseResponsePayload: z.ZodObject<{
39
+ docs: z.ZodArray<z.ZodObject<{
40
+ figmaNode: z.ZodString;
41
+ component: z.ZodOptional<z.ZodString>;
42
+ variant: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
43
+ source: z.ZodOptional<z.ZodString>;
44
+ sourceLocation: z.ZodOptional<z.ZodObject<{
45
+ line: z.ZodNumber;
46
+ }, "strip", z.ZodTypeAny, {
47
+ line: number;
48
+ }, {
49
+ line: number;
50
+ }>>;
51
+ template: z.ZodString;
52
+ templateData: z.ZodObject<{
53
+ props: z.ZodRecord<z.ZodString, any>;
54
+ imports: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
55
+ nestable: z.ZodOptional<z.ZodBoolean>;
56
+ }, "strip", z.ZodTypeAny, {
57
+ props: Record<string, any>;
58
+ imports?: string[] | undefined;
59
+ nestable?: boolean | undefined;
60
+ }, {
61
+ props: Record<string, any>;
62
+ imports?: string[] | undefined;
63
+ nestable?: boolean | undefined;
64
+ }>;
65
+ language: z.ZodString;
66
+ label: z.ZodString;
67
+ links: z.ZodOptional<z.ZodArray<z.ZodObject<{
68
+ name: z.ZodString;
69
+ url: z.ZodString;
70
+ }, "strip", z.ZodTypeAny, {
71
+ name: string;
72
+ url: string;
73
+ }, {
74
+ name: string;
75
+ url: string;
76
+ }>, "many">>;
77
+ }, "strip", z.ZodTypeAny, {
78
+ figmaNode: string;
79
+ label: string;
80
+ language: string;
81
+ template: string;
82
+ templateData: {
83
+ props: Record<string, any>;
84
+ imports?: string[] | undefined;
85
+ nestable?: boolean | undefined;
86
+ };
87
+ variant?: Record<string, any> | undefined;
88
+ links?: {
89
+ name: string;
90
+ url: string;
91
+ }[] | undefined;
92
+ component?: string | undefined;
93
+ source?: string | undefined;
94
+ sourceLocation?: {
95
+ line: number;
96
+ } | undefined;
97
+ }, {
98
+ figmaNode: string;
99
+ label: string;
100
+ language: string;
101
+ template: string;
102
+ templateData: {
103
+ props: Record<string, any>;
104
+ imports?: string[] | undefined;
105
+ nestable?: boolean | undefined;
106
+ };
107
+ variant?: Record<string, any> | undefined;
108
+ links?: {
109
+ name: string;
110
+ url: string;
111
+ }[] | undefined;
112
+ component?: string | undefined;
113
+ source?: string | undefined;
114
+ sourceLocation?: {
115
+ line: number;
116
+ } | undefined;
117
+ }>, "many">;
118
+ messages: z.ZodArray<z.ZodObject<{
119
+ level: z.ZodUnion<[z.ZodLiteral<"DEBUG">, z.ZodLiteral<"INFO">, z.ZodLiteral<"WARN">, z.ZodLiteral<"ERROR">]>;
120
+ type: z.ZodOptional<z.ZodString>;
121
+ message: z.ZodString;
122
+ sourceLocation: z.ZodOptional<z.ZodObject<{
123
+ file: z.ZodString;
124
+ line: z.ZodOptional<z.ZodNumber>;
125
+ }, "strip", z.ZodTypeAny, {
126
+ file: string;
127
+ line?: number | undefined;
128
+ }, {
129
+ file: string;
130
+ line?: number | undefined;
131
+ }>>;
132
+ }, "strip", z.ZodTypeAny, {
133
+ message: string;
134
+ level: "DEBUG" | "INFO" | "WARN" | "ERROR";
135
+ type?: string | undefined;
136
+ sourceLocation?: {
137
+ file: string;
138
+ line?: number | undefined;
139
+ } | undefined;
140
+ }, {
141
+ message: string;
142
+ level: "DEBUG" | "INFO" | "WARN" | "ERROR";
143
+ type?: string | undefined;
144
+ sourceLocation?: {
145
+ file: string;
146
+ line?: number | undefined;
147
+ } | undefined;
148
+ }>, "many">;
149
+ }, "strip", z.ZodTypeAny, {
150
+ docs: {
151
+ figmaNode: string;
152
+ label: string;
153
+ language: string;
154
+ template: string;
155
+ templateData: {
156
+ props: Record<string, any>;
157
+ imports?: string[] | undefined;
158
+ nestable?: boolean | undefined;
159
+ };
160
+ variant?: Record<string, any> | undefined;
161
+ links?: {
162
+ name: string;
163
+ url: string;
164
+ }[] | undefined;
165
+ component?: string | undefined;
166
+ source?: string | undefined;
167
+ sourceLocation?: {
168
+ line: number;
169
+ } | undefined;
170
+ }[];
171
+ messages: {
172
+ message: string;
173
+ level: "DEBUG" | "INFO" | "WARN" | "ERROR";
174
+ type?: string | undefined;
175
+ sourceLocation?: {
176
+ file: string;
177
+ line?: number | undefined;
178
+ } | undefined;
179
+ }[];
180
+ }, {
181
+ docs: {
182
+ figmaNode: string;
183
+ label: string;
184
+ language: string;
185
+ template: string;
186
+ templateData: {
187
+ props: Record<string, any>;
188
+ imports?: string[] | undefined;
189
+ nestable?: boolean | undefined;
190
+ };
191
+ variant?: Record<string, any> | undefined;
192
+ links?: {
193
+ name: string;
194
+ url: string;
195
+ }[] | undefined;
196
+ component?: string | undefined;
197
+ source?: string | undefined;
198
+ sourceLocation?: {
199
+ line: number;
200
+ } | undefined;
201
+ }[];
202
+ messages: {
203
+ message: string;
204
+ level: "DEBUG" | "INFO" | "WARN" | "ERROR";
205
+ type?: string | undefined;
206
+ sourceLocation?: {
207
+ file: string;
208
+ line?: number | undefined;
209
+ } | undefined;
210
+ }[];
211
+ }>;
212
+ export type CreateRequestPayload = {
213
+ mode: 'CREATE';
214
+ destinationDir: string;
215
+ destinationFile?: string;
216
+ component: {
217
+ figmaNodeUrl: string;
218
+ id: string;
219
+ name: string;
220
+ normalizedName: string;
221
+ type: 'COMPONENT' | 'COMPONENT_SET';
222
+ componentPropertyDefinitions: Record<string, {
223
+ type: 'BOOLEAN' | 'INSTANCE_SWAP' | 'TEXT' | 'VARIANT';
224
+ defaultValue: boolean | string;
225
+ variantOptions?: string[];
226
+ }>;
227
+ };
228
+ config: Record<string, any>;
229
+ };
230
+ export declare const CreateResponsePayload: z.ZodObject<{
231
+ createdFiles: z.ZodArray<z.ZodObject<{
232
+ filePath: z.ZodString;
233
+ }, "strip", z.ZodTypeAny, {
234
+ filePath: string;
235
+ }, {
236
+ filePath: string;
237
+ }>, "many">;
238
+ messages: z.ZodArray<z.ZodObject<{
239
+ level: z.ZodUnion<[z.ZodLiteral<"DEBUG">, z.ZodLiteral<"INFO">, z.ZodLiteral<"WARN">, z.ZodLiteral<"ERROR">]>;
240
+ type: z.ZodOptional<z.ZodString>;
241
+ message: z.ZodString;
242
+ sourceLocation: z.ZodOptional<z.ZodObject<{
243
+ file: z.ZodString;
244
+ line: z.ZodOptional<z.ZodNumber>;
245
+ }, "strip", z.ZodTypeAny, {
246
+ file: string;
247
+ line?: number | undefined;
248
+ }, {
249
+ file: string;
250
+ line?: number | undefined;
251
+ }>>;
252
+ }, "strip", z.ZodTypeAny, {
253
+ message: string;
254
+ level: "DEBUG" | "INFO" | "WARN" | "ERROR";
255
+ type?: string | undefined;
256
+ sourceLocation?: {
257
+ file: string;
258
+ line?: number | undefined;
259
+ } | undefined;
260
+ }, {
261
+ message: string;
262
+ level: "DEBUG" | "INFO" | "WARN" | "ERROR";
263
+ type?: string | undefined;
264
+ sourceLocation?: {
265
+ file: string;
266
+ line?: number | undefined;
267
+ } | undefined;
268
+ }>, "many">;
269
+ }, "strip", z.ZodTypeAny, {
270
+ messages: {
271
+ message: string;
272
+ level: "DEBUG" | "INFO" | "WARN" | "ERROR";
273
+ type?: string | undefined;
274
+ sourceLocation?: {
275
+ file: string;
276
+ line?: number | undefined;
277
+ } | undefined;
278
+ }[];
279
+ createdFiles: {
280
+ filePath: string;
281
+ }[];
282
+ }, {
283
+ messages: {
284
+ message: string;
285
+ level: "DEBUG" | "INFO" | "WARN" | "ERROR";
286
+ type?: string | undefined;
287
+ sourceLocation?: {
288
+ file: string;
289
+ line?: number | undefined;
290
+ } | undefined;
291
+ }[];
292
+ createdFiles: {
293
+ filePath: string;
294
+ }[];
295
+ }>;
296
+ export type ParserRequestPayload = ParseRequestPayload | CreateRequestPayload;
297
+ //# sourceMappingURL=parser_executable_types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parser_executable_types.d.ts","sourceRoot":"","sources":["../../src/connect/parser_executable_types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAGvB,MAAM,MAAM,mBAAmB,GAAG;IAChC,IAAI,EAAE,OAAO,CAAA;IAGb,KAAK,EAAE,MAAM,EAAE,CAAA;IAIf,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;CAC5B,CAAA;AAOD,eAAO,MAAM,wBAAwB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;WAuBpC,CAAA;AASD,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA8D/B,CAAA;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC,IAAI,EAAE,QAAQ,CAAA;IAId,cAAc,EAAE,MAAM,CAAA;IAGtB,eAAe,CAAC,EAAE,MAAM,CAAA;IAIxB,SAAS,EAAE;QAGT,YAAY,EAAE,MAAM,CAAA;QAEpB,EAAE,EAAE,MAAM,CAAA;QAEV,IAAI,EAAE,MAAM,CAAA;QAGZ,cAAc,EAAE,MAAM,CAAA;QAEtB,IAAI,EAAE,WAAW,GAAG,eAAe,CAAA;QAEnC,4BAA4B,EAAE,MAAM,CAClC,MAAM,EACN;YAEE,IAAI,EAAE,SAAS,GAAG,eAAe,GAAG,MAAM,GAAG,SAAS,CAAA;YAEtD,YAAY,EAAE,OAAO,GAAG,MAAM,CAAA;YAE9B,cAAc,CAAC,EAAE,MAAM,EAAE,CAAA;SAC1B,CACF,CAAA;KACF,CAAA;IAID,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;CAC5B,CAAA;AAED,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAUhC,CAAA;AAEF,MAAM,MAAM,oBAAoB,GAAG,mBAAmB,GAAG,oBAAoB,CAAA"}
@@ -0,0 +1,108 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CreateResponsePayload = exports.ParseResponsePayload = exports.ParserExecutableMessages = void 0;
4
+ const zod_1 = require("zod");
5
+ const FigmaConnectLink = zod_1.z.object({
6
+ name: zod_1.z.string(),
7
+ url: zod_1.z.string(),
8
+ });
9
+ exports.ParserExecutableMessages = zod_1.z.array(zod_1.z.object({
10
+ // DEBUG and INFO messages should be output to console by the CLI for the
11
+ // user to read, according to the current log level setting.
12
+ //
13
+ // If any WARNING or ERROR messages are returned, the CLI can determine
14
+ // whether it should proceed with publishing or not based on configuration
15
+ // and the return code should be zero or non-zero as appropriate.
16
+ //
17
+ // There's no need for a "result" field as we can infer this from the
18
+ // messages.
19
+ level: zod_1.z.union([zod_1.z.literal('DEBUG'), zod_1.z.literal('INFO'), zod_1.z.literal('WARN'), zod_1.z.literal('ERROR')]),
20
+ // Optional type of message which can be displayed highlighted in the output
21
+ type: zod_1.z.string().optional(),
22
+ message: zod_1.z.string(),
23
+ // Optional source location which can be displayed in a standardised form
24
+ sourceLocation: zod_1.z
25
+ .object({
26
+ file: zod_1.z.string(),
27
+ line: zod_1.z.number().optional(),
28
+ })
29
+ .optional(),
30
+ }));
31
+ // Zod type modelling the response from a Code Connect parser. Zod allows us to
32
+ // easily validate the response.
33
+ //
34
+ // This type somewhat duplicates the `CodeConnectJSON` type from
35
+ // `figma_connect.ts`, but as Zod doesn't allow us to fully express recursive
36
+ // types such as Intrinsic, we keep this explicit type as well. The `satisfies`
37
+ // should ensure the two types stay in sync.
38
+ exports.ParseResponsePayload = zod_1.z.object({
39
+ // Array of Code Connect docs parsed from the input files
40
+ docs: zod_1.z.array(zod_1.z.object({
41
+ // The Figma node URL the doc links to
42
+ figmaNode: zod_1.z.string(),
43
+ // Optional component name. This is only used for display purposes
44
+ // so can be omitted if it's not relevant to the language/framework
45
+ component: zod_1.z.string().optional(),
46
+ // Variant restrictions keyed by Figma property name e.g. `{ 'With icon': true }`
47
+ variant: zod_1.z.record(zod_1.z.any()).optional(),
48
+ // Optional source path/URL, which can either be a path on disk, which
49
+ // we'll show as a SCM link, or a URL (e.g. for a Storybook parser which
50
+ // wants to link to the story in Storybook rather than the file in Github)
51
+ source: zod_1.z.string().optional(),
52
+ // Optional source location containing line number information.
53
+ sourceLocation: zod_1.z
54
+ .object({
55
+ // Optional line number to link to. This is only used if type === 'PATH',
56
+ // to generate a link to the correct line
57
+ line: zod_1.z.number(),
58
+ })
59
+ .optional(),
60
+ // The JS template function to use for this doc
61
+ template: zod_1.z.string(),
62
+ templateData: zod_1.z.object({
63
+ // Map of information describing the props used by the template. This is
64
+ // used by the CLI to validate props before publishing.
65
+ //
66
+ // TODO this Zod type is a bit loose - couldn't work out how to model it exactly
67
+ //
68
+ // TODO We could look to extract this from the template somehow instead,
69
+ // (e.g. run it with figma.properties.* stubbed to record accesses) to
70
+ // avoid needing this duplication.
71
+ props: zod_1.z.record(zod_1.z.object({ kind: zod_1.z.string(), args: zod_1.z.any() })),
72
+ // Optional array of imports for this component. These are prepended
73
+ // to the example code, but it's useful to keep them separate e.g. if
74
+ // we ever want to auto-insert imports in VS Code. If more control
75
+ // over imports is required, they can be output directly by the template
76
+ // function. Currently they'd have to be output in the code directly, but
77
+ // the original spec does propose templates being able to return import
78
+ // sections separately (not implemented as there's no UI for this)
79
+ //
80
+ // Right now, there's no way to handle gathering imports from children and
81
+ // post-processing them (e.g. combining multiple imports from the same file
82
+ // into a single import). We could consider some way for templates to do this
83
+ // in future.
84
+ imports: zod_1.z.array(zod_1.z.string()).optional(),
85
+ // Whether the example should be rendered inline if it's a nested instance
86
+ nestable: zod_1.z.boolean().optional(),
87
+ }),
88
+ // The language to use for syntax highlighting
89
+ language: zod_1.z.string(),
90
+ // Label to be used for the example in the UI
91
+ label: zod_1.z.string(),
92
+ // Optional array of links to be displayed in the UI.
93
+ // TODO Not implemented in UI yet
94
+ links: zod_1.z.array(FigmaConnectLink).optional(),
95
+ })),
96
+ // Any info, warning or error messages generated during parsing.
97
+ messages: exports.ParserExecutableMessages,
98
+ });
99
+ exports.CreateResponsePayload = zod_1.z.object({
100
+ // A list of files created, which can be output to the console
101
+ createdFiles: zod_1.z.array(zod_1.z.object({
102
+ // The absolute path of the created file
103
+ filePath: zod_1.z.string(),
104
+ })),
105
+ // Any info, warning or error messages generated during creation.
106
+ messages: exports.ParserExecutableMessages,
107
+ });
108
+ //# sourceMappingURL=parser_executable_types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parser_executable_types.js","sourceRoot":"","sources":["../../src/connect/parser_executable_types.ts"],"names":[],"mappings":";;;AAAA,6BAAuB;AAcvB,MAAM,gBAAgB,GAAG,OAAC,CAAC,MAAM,CAAC;IAChC,IAAI,EAAE,OAAC,CAAC,MAAM,EAAE;IAChB,GAAG,EAAE,OAAC,CAAC,MAAM,EAAE;CAChB,CAAC,CAAA;AAEW,QAAA,wBAAwB,GAAG,OAAC,CAAC,KAAK,CAC7C,OAAC,CAAC,MAAM,CAAC;IACP,yEAAyE;IACzE,4DAA4D;IAC5D,EAAE;IACF,uEAAuE;IACvE,0EAA0E;IAC1E,iEAAiE;IACjE,EAAE;IACF,qEAAqE;IACr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AAM,CAAC;QACP,wCAAwC;QACxC,QAAQ,EAAE,OAAC,CAAC,MAAM,EAAE;KACrB,CAAC,CACH;IACD,iEAAiE;IACjE,QAAQ,EAAE,gCAAwB;CACnC,CAAC,CAAA"}
@@ -0,0 +1,8 @@
1
+ import { z } from 'zod';
2
+ import { CodeConnectExecutableParserConfig } from './project';
3
+ import { ParserExecutableMessages, ParserRequestPayload } from './parser_executable_types';
4
+ export declare function callParser(config: CodeConnectExecutableParserConfig, payload: ParserRequestPayload, cwd: string): Promise<object>;
5
+ export declare function handleMessages(messages: z.infer<typeof ParserExecutableMessages>): {
6
+ hasErrors: boolean;
7
+ };
8
+ //# sourceMappingURL=parser_executables.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parser_executables.d.ts","sourceRoot":"","sources":["../../src/connect/parser_executables.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,OAAO,EAAE,iCAAiC,EAA8B,MAAM,WAAW,CAAA;AACzF,OAAO,EAEL,wBAAwB,EACxB,oBAAoB,EACrB,MAAM,2BAA2B,CAAA;AAwDlC,wBAAsB,UAAU,CAC9B,MAAM,EAAE,iCAAiC,EACzC,OAAO,EAAE,oBAAoB,EAC7B,GAAG,EAAE,MAAM,mBAqEZ;AAED,wBAAgB,cAAc,CAAC,QAAQ,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,wBAAwB,CAAC;;EAqBhF"}
@@ -0,0 +1,132 @@
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.handleMessages = exports.callParser = void 0;
7
+ const logging_1 = require("../common/logging");
8
+ const cross_spawn_1 = require("cross-spawn");
9
+ const get_swift_parser_dir_1 = require("../parser_scripts/get_swift_parser_dir");
10
+ const fs_1 = __importDefault(require("fs"));
11
+ const path_1 = __importDefault(require("path"));
12
+ const get_gradlew_path_1 = require("../parser_scripts/get_gradlew_path");
13
+ const temporaryInputFilePath = 'tmp/figma-code-connect-parser-input.json.tmp';
14
+ const FIRST_PARTY_PARSERS = {
15
+ swift: {
16
+ command: async (cwd, config, mode) => {
17
+ return `swift run --package-path ${await (0, get_swift_parser_dir_1.getSwiftParserDir)(cwd, config.xcodeprojPath)} figma-swift`;
18
+ },
19
+ },
20
+ compose: {
21
+ command: async (cwd, config, mode) => {
22
+ const gradlewPath = await (0, get_gradlew_path_1.getGradleWrapperPath)(cwd, config.gradleWrapperPath);
23
+ const gradleExecutableInvocation = (0, get_gradlew_path_1.getGradleWrapperExecutablePath)(gradlewPath);
24
+ if (mode === 'CREATE') {
25
+ return `${gradleExecutableInvocation} -p ${gradlewPath} createCodeConnect -PfilePath=${temporaryInputFilePath} -q`;
26
+ }
27
+ else {
28
+ return `${gradleExecutableInvocation} -p ${gradlewPath} parseCodeConnect -PfilePath=${temporaryInputFilePath} -q`;
29
+ }
30
+ },
31
+ temporaryInputFilePath: temporaryInputFilePath,
32
+ },
33
+ __unit_test__: {
34
+ command: async () => 'node parser/unit_test_parser.js',
35
+ },
36
+ };
37
+ function getParser(config) {
38
+ const parser = FIRST_PARTY_PARSERS[config.parser];
39
+ if (!parser) {
40
+ (0, logging_1.exitWithError)(`Invalid parser specified: "${config.parser}". Valid parsers are: ${Object.keys(FIRST_PARTY_PARSERS).join(', ')}.`);
41
+ }
42
+ return parser;
43
+ }
44
+ async function callParser(config, payload, cwd) {
45
+ return new Promise(async (resolve, reject) => {
46
+ try {
47
+ const parser = getParser(config);
48
+ const command = await parser.command(cwd, config, payload.mode);
49
+ if (parser.temporaryInputFilePath) {
50
+ fs_1.default.mkdirSync(path_1.default.dirname(parser.temporaryInputFilePath), { recursive: true });
51
+ fs_1.default.writeFileSync(temporaryInputFilePath, JSON.stringify(payload));
52
+ }
53
+ logging_1.logger.debug(`Running parser: ${command}`);
54
+ const commandSplit = command.split(' ');
55
+ const child = (0, cross_spawn_1.spawn)(commandSplit[0], commandSplit.slice(1), {
56
+ cwd,
57
+ });
58
+ let stdout = '';
59
+ child.stdout.on('data', (data) => {
60
+ stdout += data.toString();
61
+ });
62
+ // This handles any stderr output from the parser.
63
+ //
64
+ // Parsers should not generally write to stderr, and should instead return
65
+ // an array of messages at the end of execution, but there are cases where
66
+ // you might want to log output immediately rather than at the end of the
67
+ // run - e.g. if the parser can take a while to compile first time, you
68
+ // might want to inform the user immediately that it is compiling.
69
+ //
70
+ // To log output, the parser should write a JSON object to stderr with the
71
+ // same structure as the `messages` response object, e.g. `{ "level":
72
+ // "INFO", "message": "Compiling parser..." }`.
73
+ //
74
+ // Non-JSON output will be logged as debug messages, as this is likely to
75
+ // be e.g. compiler output which the user doesn't need to see ordinarily.
76
+ child.stderr.on('data', (data) => {
77
+ const message = data.toString().trim();
78
+ try {
79
+ const parsed = JSON.parse(message);
80
+ handleMessages([parsed]);
81
+ }
82
+ catch (e) {
83
+ logging_1.logger.debug(message);
84
+ }
85
+ });
86
+ child.on('close', (code) => {
87
+ if (code !== 0) {
88
+ reject(new Error(`Parser exited with code ${code}`));
89
+ }
90
+ else {
91
+ resolve(JSON.parse(stdout));
92
+ }
93
+ if (parser.temporaryInputFilePath) {
94
+ fs_1.default.unlinkSync(parser.temporaryInputFilePath);
95
+ }
96
+ });
97
+ child.on('error', (e) => {
98
+ reject(e);
99
+ });
100
+ if (!parser.temporaryInputFilePath) {
101
+ child.stdin.write(JSON.stringify(payload));
102
+ child.stdin.end();
103
+ }
104
+ }
105
+ catch (e) {
106
+ (0, logging_1.exitWithError)(`Error calling parser: ${e}`);
107
+ }
108
+ });
109
+ }
110
+ exports.callParser = callParser;
111
+ function handleMessages(messages) {
112
+ let hasErrors = false;
113
+ messages.forEach((message) => {
114
+ switch (message.level) {
115
+ case 'DEBUG':
116
+ logging_1.logger.debug(message.message);
117
+ break;
118
+ case 'INFO':
119
+ logging_1.logger.info(message.message);
120
+ break;
121
+ case 'WARN':
122
+ logging_1.logger.warn(message.message);
123
+ break;
124
+ case 'ERROR':
125
+ logging_1.logger.error(message.message);
126
+ break;
127
+ }
128
+ });
129
+ return { hasErrors };
130
+ }
131
+ exports.handleMessages = handleMessages;
132
+ //# sourceMappingURL=parser_executables.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parser_executables.js","sourceRoot":"","sources":["../../src/connect/parser_executables.ts"],"names":[],"mappings":";;;;;;AACA,+CAAyD;AAOzD,6CAAmC;AACnC,iFAA0E;AAC1E,4CAAmB;AACnB,gDAAuB;AACvB,yEAG2C;AAE3C,MAAM,sBAAsB,GAAG,8CAA8C,CAAA;AAW7E,MAAM,mBAAmB,GAAmD;IAC1E,KAAK,EAAE;QACL,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE;YACnC,OAAO,4BAA4B,MAAM,IAAA,wCAAiB,EAAC,GAAG,EAAG,MAAc,CAAC,aAAa,CAAC,cAAc,CAAA;QAC9G,CAAC;KACF;IACD,OAAO,EAAE;QACP,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE;YACnC,MAAM,WAAW,GAAG,MAAM,IAAA,uCAAoB,EAAC,GAAG,EAAG,MAAc,CAAC,iBAAiB,CAAC,CAAA;YACtF,MAAM,0BAA0B,GAAG,IAAA,iDAA8B,EAAC,WAAW,CAAC,CAAA;YAC9E,IAAI,IAAI,KAAK,QAAQ,EAAE,CAAC;gBACtB,OAAO,GAAG,0BAA0B,OAAO,WAAW,iCAAiC,sBAAsB,KAAK,CAAA;YACpH,CAAC;iBAAM,CAAC;gBACN,OAAO,GAAG,0BAA0B,OAAO,WAAW,gCAAgC,sBAAsB,KAAK,CAAA;YACnH,CAAC;QACH,CAAC;QACD,sBAAsB,EAAE,sBAAsB;KAC/C;IACD,aAAa,EAAE;QACb,OAAO,EAAE,KAAK,IAAI,EAAE,CAAC,iCAAiC;KACvD;CACF,CAAA;AAED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