@plasmicapp/cli 0.1.162

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 (162) hide show
  1. package/.eslintrc.js +61 -0
  2. package/.idea/cli.iml +11 -0
  3. package/.idea/misc.xml +6 -0
  4. package/.idea/modules.xml +8 -0
  5. package/.idea/vcs.xml +6 -0
  6. package/README +16 -0
  7. package/README.internal +46 -0
  8. package/README.md +17 -0
  9. package/build.sh +8 -0
  10. package/dist/__mocks__/api.d.ts +16 -0
  11. package/dist/__mocks__/api.js +297 -0
  12. package/dist/__tests__/code-utils-spec.d.ts +1 -0
  13. package/dist/__tests__/code-utils-spec.js +838 -0
  14. package/dist/__tests__/ftue-spec.d.ts +1 -0
  15. package/dist/__tests__/ftue-spec.js +39 -0
  16. package/dist/__tests__/project-api-token-spec.d.ts +1 -0
  17. package/dist/__tests__/project-api-token-spec.js +147 -0
  18. package/dist/__tests__/versioned-sync-spec.d.ts +1 -0
  19. package/dist/__tests__/versioned-sync-spec.js +145 -0
  20. package/dist/actions/auth.d.ts +8 -0
  21. package/dist/actions/auth.js +47 -0
  22. package/dist/actions/fix-imports.d.ts +4 -0
  23. package/dist/actions/fix-imports.js +25 -0
  24. package/dist/actions/init.d.ts +62 -0
  25. package/dist/actions/init.js +460 -0
  26. package/dist/actions/project-token.d.ts +6 -0
  27. package/dist/actions/project-token.js +42 -0
  28. package/dist/actions/sync-components.d.ts +10 -0
  29. package/dist/actions/sync-components.js +242 -0
  30. package/dist/actions/sync-global-variants.d.ts +3 -0
  31. package/dist/actions/sync-global-variants.js +89 -0
  32. package/dist/actions/sync-icons.d.ts +7 -0
  33. package/dist/actions/sync-icons.js +92 -0
  34. package/dist/actions/sync-images.d.ts +6 -0
  35. package/dist/actions/sync-images.js +137 -0
  36. package/dist/actions/sync-styles.d.ts +3 -0
  37. package/dist/actions/sync-styles.js +58 -0
  38. package/dist/actions/sync.d.ts +25 -0
  39. package/dist/actions/sync.js +417 -0
  40. package/dist/actions/upload-bundle.d.ts +15 -0
  41. package/dist/actions/upload-bundle.js +28 -0
  42. package/dist/actions/watch.d.ts +14 -0
  43. package/dist/actions/watch.js +90 -0
  44. package/dist/api.d.ts +182 -0
  45. package/dist/api.js +202 -0
  46. package/dist/deps.d.ts +2 -0
  47. package/dist/deps.js +20 -0
  48. package/dist/index.d.ts +7 -0
  49. package/dist/index.js +247 -0
  50. package/dist/lib.d.ts +10 -0
  51. package/dist/lib.js +23 -0
  52. package/dist/migrations/0.1.110-fileLocks.d.ts +2 -0
  53. package/dist/migrations/0.1.110-fileLocks.js +15 -0
  54. package/dist/migrations/0.1.143-ensureImportModuleType.d.ts +2 -0
  55. package/dist/migrations/0.1.143-ensureImportModuleType.js +12 -0
  56. package/dist/migrations/0.1.146-addReactRuntime.d.ts +2 -0
  57. package/dist/migrations/0.1.146-addReactRuntime.js +10 -0
  58. package/dist/migrations/0.1.27-migrateInit.d.ts +1 -0
  59. package/dist/migrations/0.1.27-migrateInit.js +8 -0
  60. package/dist/migrations/0.1.28-tsToTsx.d.ts +3 -0
  61. package/dist/migrations/0.1.28-tsToTsx.js +33 -0
  62. package/dist/migrations/0.1.31-ensureProjectIcons.d.ts +2 -0
  63. package/dist/migrations/0.1.31-ensureProjectIcons.js +12 -0
  64. package/dist/migrations/0.1.42-ensureVersion.d.ts +2 -0
  65. package/dist/migrations/0.1.42-ensureVersion.js +12 -0
  66. package/dist/migrations/0.1.57-ensureJsBundleThemes.d.ts +2 -0
  67. package/dist/migrations/0.1.57-ensureJsBundleThemes.js +12 -0
  68. package/dist/migrations/0.1.64-imageFiles.d.ts +2 -0
  69. package/dist/migrations/0.1.64-imageFiles.js +17 -0
  70. package/dist/migrations/0.1.95-componentType.d.ts +2 -0
  71. package/dist/migrations/0.1.95-componentType.js +16 -0
  72. package/dist/migrations/migrations.d.ts +10 -0
  73. package/dist/migrations/migrations.js +119 -0
  74. package/dist/plasmic.schema.json +463 -0
  75. package/dist/test-common/fixtures.d.ts +13 -0
  76. package/dist/test-common/fixtures.js +165 -0
  77. package/dist/tsconfig-transform.json +68 -0
  78. package/dist/utils/auth-utils.d.ts +31 -0
  79. package/dist/utils/auth-utils.js +236 -0
  80. package/dist/utils/checksum.d.ts +4 -0
  81. package/dist/utils/checksum.js +63 -0
  82. package/dist/utils/code-utils.d.ts +46 -0
  83. package/dist/utils/code-utils.js +457 -0
  84. package/dist/utils/config-utils.d.ts +271 -0
  85. package/dist/utils/config-utils.js +178 -0
  86. package/dist/utils/envdetect.d.ts +4 -0
  87. package/dist/utils/envdetect.js +42 -0
  88. package/dist/utils/error.d.ts +14 -0
  89. package/dist/utils/error.js +42 -0
  90. package/dist/utils/file-utils.d.ts +71 -0
  91. package/dist/utils/file-utils.js +433 -0
  92. package/dist/utils/get-context.d.ts +40 -0
  93. package/dist/utils/get-context.js +339 -0
  94. package/dist/utils/help.d.ts +2 -0
  95. package/dist/utils/help.js +56 -0
  96. package/dist/utils/lang-utils.d.ts +10 -0
  97. package/dist/utils/lang-utils.js +52 -0
  98. package/dist/utils/npm-utils.d.ts +28 -0
  99. package/dist/utils/npm-utils.js +215 -0
  100. package/dist/utils/prompts.d.ts +6 -0
  101. package/dist/utils/prompts.js +23 -0
  102. package/dist/utils/resolve-utils.d.ts +13 -0
  103. package/dist/utils/resolve-utils.js +198 -0
  104. package/dist/utils/semver.d.ts +34 -0
  105. package/dist/utils/semver.js +61 -0
  106. package/dist/utils/test-utils.d.ts +22 -0
  107. package/dist/utils/test-utils.js +106 -0
  108. package/dist/utils/user-utils.d.ts +7 -0
  109. package/dist/utils/user-utils.js +48 -0
  110. package/jest.config.js +6 -0
  111. package/package.json +80 -0
  112. package/src/__mocks__/api.ts +394 -0
  113. package/src/__tests__/code-utils-spec.ts +881 -0
  114. package/src/__tests__/ftue-spec.ts +43 -0
  115. package/src/__tests__/project-api-token-spec.ts +208 -0
  116. package/src/__tests__/versioned-sync-spec.ts +176 -0
  117. package/src/actions/auth.ts +43 -0
  118. package/src/actions/fix-imports.ts +13 -0
  119. package/src/actions/init.ts +638 -0
  120. package/src/actions/project-token.ts +36 -0
  121. package/src/actions/sync-components.ts +405 -0
  122. package/src/actions/sync-global-variants.ts +129 -0
  123. package/src/actions/sync-icons.ts +135 -0
  124. package/src/actions/sync-images.ts +191 -0
  125. package/src/actions/sync-styles.ts +71 -0
  126. package/src/actions/sync.ts +747 -0
  127. package/src/actions/upload-bundle.ts +38 -0
  128. package/src/actions/watch.ts +95 -0
  129. package/src/api.ts +407 -0
  130. package/src/deps.ts +18 -0
  131. package/src/index.ts +300 -0
  132. package/src/lib.ts +10 -0
  133. package/src/migrations/0.1.110-fileLocks.ts +16 -0
  134. package/src/migrations/0.1.146-addReactRuntime.ts +8 -0
  135. package/src/migrations/0.1.27-migrateInit.ts +4 -0
  136. package/src/migrations/0.1.28-tsToTsx.ts +37 -0
  137. package/src/migrations/0.1.31-ensureProjectIcons.ts +10 -0
  138. package/src/migrations/0.1.42-ensureVersion.ts +10 -0
  139. package/src/migrations/0.1.57-ensureJsBundleThemes.ts +10 -0
  140. package/src/migrations/0.1.64-imageFiles.ts +15 -0
  141. package/src/migrations/0.1.95-componentType.ts +14 -0
  142. package/src/migrations/migrations.ts +147 -0
  143. package/src/test-common/fixtures.ts +178 -0
  144. package/src/utils/auth-utils.ts +276 -0
  145. package/src/utils/checksum.ts +106 -0
  146. package/src/utils/code-utils.ts +656 -0
  147. package/src/utils/config-utils.ts +551 -0
  148. package/src/utils/envdetect.ts +39 -0
  149. package/src/utils/error.ts +36 -0
  150. package/src/utils/file-utils.ts +526 -0
  151. package/src/utils/get-context.ts +451 -0
  152. package/src/utils/help.ts +75 -0
  153. package/src/utils/lang-utils.ts +52 -0
  154. package/src/utils/npm-utils.ts +223 -0
  155. package/src/utils/prompts.ts +22 -0
  156. package/src/utils/resolve-utils.ts +245 -0
  157. package/src/utils/semver.ts +67 -0
  158. package/src/utils/test-utils.ts +116 -0
  159. package/src/utils/user-utils.ts +37 -0
  160. package/testData/fixImports_plasmic.json +66 -0
  161. package/tsconfig-transform.json +68 -0
  162. package/tsconfig.json +67 -0
@@ -0,0 +1,463 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema#",
3
+ "definitions": {
4
+ "CodeComponentConfig": {
5
+ "properties": {
6
+ "componentImportPath": {
7
+ "type": "string"
8
+ },
9
+ "id": {
10
+ "type": "string"
11
+ },
12
+ "name": {
13
+ "type": "string"
14
+ }
15
+ },
16
+ "required": [
17
+ "componentImportPath",
18
+ "id",
19
+ "name"
20
+ ],
21
+ "type": "object"
22
+ },
23
+ "CodeConfig": {
24
+ "properties": {
25
+ "lang": {
26
+ "description": "Language to generate code in",
27
+ "enum": [
28
+ "js",
29
+ "ts"
30
+ ],
31
+ "type": "string"
32
+ },
33
+ "reactRuntime": {
34
+ "enum": [
35
+ "automatic",
36
+ "classic"
37
+ ],
38
+ "type": "string"
39
+ },
40
+ "scheme": {
41
+ "description": "The default code generation scheme. Each component can override the scheme.",
42
+ "enum": [
43
+ "blackbox",
44
+ "direct"
45
+ ],
46
+ "type": "string"
47
+ }
48
+ },
49
+ "required": [
50
+ "lang",
51
+ "reactRuntime",
52
+ "scheme"
53
+ ],
54
+ "type": "object"
55
+ },
56
+ "ComponentConfig": {
57
+ "properties": {
58
+ "componentType": {
59
+ "enum": [
60
+ "component",
61
+ "page"
62
+ ],
63
+ "type": "string"
64
+ },
65
+ "cssFilePath": {
66
+ "description": "The file path for the component css file, relative to srcDir.",
67
+ "type": "string"
68
+ },
69
+ "id": {
70
+ "description": "Component ID",
71
+ "type": "string"
72
+ },
73
+ "importSpec": {
74
+ "$ref": "#/definitions/ImportSpec",
75
+ "description": "How to import this Component from another component file"
76
+ },
77
+ "name": {
78
+ "description": "Javascript name of component",
79
+ "type": "string"
80
+ },
81
+ "plumeType": {
82
+ "description": "Plume type if component is a Plume component",
83
+ "type": "string"
84
+ },
85
+ "projectId": {
86
+ "description": "Plasmic project that this component belongs in",
87
+ "type": "string"
88
+ },
89
+ "renderModuleFilePath": {
90
+ "description": "The file path for the blackbox render module, relative to srcDir.",
91
+ "type": "string"
92
+ },
93
+ "scheme": {
94
+ "description": "Code generation scheme used for this component",
95
+ "enum": [
96
+ "blackbox",
97
+ "direct"
98
+ ],
99
+ "type": "string"
100
+ },
101
+ "type": {
102
+ "description": "Whether this component is managed by Plasmic -- with Plasmic* files generated -- or mapped to an external library",
103
+ "enum": [
104
+ "managed",
105
+ "mapped"
106
+ ],
107
+ "type": "string"
108
+ }
109
+ },
110
+ "required": [
111
+ "componentType",
112
+ "cssFilePath",
113
+ "id",
114
+ "importSpec",
115
+ "name",
116
+ "projectId",
117
+ "renderModuleFilePath",
118
+ "scheme",
119
+ "type"
120
+ ],
121
+ "type": "object"
122
+ },
123
+ "GlobalVariantGroupConfig": {
124
+ "properties": {
125
+ "contextFilePath": {
126
+ "description": "File path for the global variant group React context definition, relative to srcDir",
127
+ "type": "string"
128
+ },
129
+ "id": {
130
+ "description": "ID of the global variant group",
131
+ "type": "string"
132
+ },
133
+ "name": {
134
+ "description": "Javascript name of the global variant group",
135
+ "type": "string"
136
+ },
137
+ "projectId": {
138
+ "description": "Plasmic project this global variant group belongs to",
139
+ "type": "string"
140
+ }
141
+ },
142
+ "required": [
143
+ "contextFilePath",
144
+ "id",
145
+ "name",
146
+ "projectId"
147
+ ],
148
+ "type": "object"
149
+ },
150
+ "GlobalVariantsConfig": {
151
+ "properties": {
152
+ "variantGroups": {
153
+ "items": {
154
+ "$ref": "#/definitions/GlobalVariantGroupConfig"
155
+ },
156
+ "type": "array"
157
+ }
158
+ },
159
+ "required": [
160
+ "variantGroups"
161
+ ],
162
+ "type": "object"
163
+ },
164
+ "IconConfig": {
165
+ "properties": {
166
+ "id": {
167
+ "description": "ID of icon",
168
+ "type": "string"
169
+ },
170
+ "moduleFilePath": {
171
+ "description": "The file path for the React component file for this icon, relative to srcDir.",
172
+ "type": "string"
173
+ },
174
+ "name": {
175
+ "description": "Javascript name of the React component for this icon",
176
+ "type": "string"
177
+ }
178
+ },
179
+ "required": [
180
+ "id",
181
+ "moduleFilePath",
182
+ "name"
183
+ ],
184
+ "type": "object"
185
+ },
186
+ "ImageConfig": {
187
+ "properties": {
188
+ "filePath": {
189
+ "description": "File path for the image file, relative to srcDir",
190
+ "type": "string"
191
+ },
192
+ "id": {
193
+ "description": "ID of image",
194
+ "type": "string"
195
+ },
196
+ "name": {
197
+ "description": "name of image",
198
+ "type": "string"
199
+ }
200
+ },
201
+ "required": [
202
+ "filePath",
203
+ "id",
204
+ "name"
205
+ ],
206
+ "type": "object"
207
+ },
208
+ "ImagesConfig": {
209
+ "properties": {
210
+ "publicDir": {
211
+ "description": "The folder where \"public\" static files are stored. Plasmic-managed image files will be stored as \"plasmic/project-name/image-name\" under this folder. Relative to srcDir; for example, \"../public\"",
212
+ "type": "string"
213
+ },
214
+ "publicUrlPrefix": {
215
+ "description": "The url prefix where \"public\" static files are stored. For example, if publicDir is \"public\", publicUrlPrefix is \"/static\", then a file at public/test.png will be served at /static/test.png.",
216
+ "type": "string"
217
+ },
218
+ "scheme": {
219
+ "description": "How image files should be referenced from generated React components. The choices are:\n* \"files\" - imported as relative files, like \"import img from './image.png'\". Not all bundlers support this.\n* \"public-files\" - images are stored in a public folder, and referenced from some url prefix, like `<img src=\"/static/image.png\"/>`.\n* \"inlined\" - inlined directly into React files and css files as base64-encoded data-URIs.\n* \"cdn\" - images are served from Plasmic's CDN. Allows for dynamic resizing of images for\n serving the optimal file size given browser viewport.",
220
+ "enum": [
221
+ "cdn",
222
+ "files",
223
+ "inlined",
224
+ "public-files"
225
+ ],
226
+ "type": "string"
227
+ }
228
+ },
229
+ "required": [
230
+ "scheme"
231
+ ],
232
+ "type": "object"
233
+ },
234
+ "ImportSpec": {
235
+ "description": "Describes how to import a Component",
236
+ "properties": {
237
+ "exportName": {
238
+ "description": "If the Component is a named export of the module, then this is the name. If the Component\nis the default export, then this is undefined.",
239
+ "type": "string"
240
+ },
241
+ "modulePath": {
242
+ "description": "The import path to use to instantiate this Component. The modulePath can be:\n* An external npm module, like \"antd/lib/button\"\n* A local file, like \"components/Button.tsx\" (path is relative to srcDir, and file extension is fully specified). If local file is specified, then the module is imported via relative path.\n\nFor this to be an external npm module, the ComponentConfig.type must be \"mapped\".",
243
+ "type": "string"
244
+ }
245
+ },
246
+ "required": [
247
+ "modulePath"
248
+ ],
249
+ "type": "object"
250
+ },
251
+ "JsBundleThemeConfig": {
252
+ "properties": {
253
+ "bundleName": {
254
+ "type": "string"
255
+ },
256
+ "themeFilePath": {
257
+ "type": "string"
258
+ }
259
+ },
260
+ "required": [
261
+ "bundleName",
262
+ "themeFilePath"
263
+ ],
264
+ "type": "object"
265
+ },
266
+ "ProjectConfig": {
267
+ "properties": {
268
+ "codeComponents": {
269
+ "items": {
270
+ "$ref": "#/definitions/CodeComponentConfig"
271
+ },
272
+ "type": "array"
273
+ },
274
+ "components": {
275
+ "description": "Metadata for each synced component in this project.",
276
+ "items": {
277
+ "$ref": "#/definitions/ComponentConfig"
278
+ },
279
+ "type": "array"
280
+ },
281
+ "cssFilePath": {
282
+ "description": "File location for the project-wide css styles. Relative to srcDir",
283
+ "type": "string"
284
+ },
285
+ "icons": {
286
+ "description": "Metadata for each synced icon in this project",
287
+ "items": {
288
+ "$ref": "#/definitions/IconConfig"
289
+ },
290
+ "type": "array"
291
+ },
292
+ "images": {
293
+ "description": "Metadata for each synced image in this project",
294
+ "items": {
295
+ "$ref": "#/definitions/ImageConfig"
296
+ },
297
+ "type": "array"
298
+ },
299
+ "jsBundleThemes": {
300
+ "items": {
301
+ "$ref": "#/definitions/JsBundleThemeConfig"
302
+ },
303
+ "type": "array"
304
+ },
305
+ "projectApiToken": {
306
+ "description": "Project API token. Grants read-only sync access to just this specific project and its dependencies.",
307
+ "type": "string"
308
+ },
309
+ "projectId": {
310
+ "description": "Project ID",
311
+ "type": "string"
312
+ },
313
+ "projectName": {
314
+ "description": "Project name synced down from Studio",
315
+ "type": "string"
316
+ },
317
+ "version": {
318
+ "description": "A version range for syncing this project. Can be:\n* \"latest\" - always syncs down whatever has been saved in the project.\n* \">0\" - always syncs down the latest published version of the project.\n* any other semver string you'd like",
319
+ "type": "string"
320
+ }
321
+ },
322
+ "required": [
323
+ "components",
324
+ "cssFilePath",
325
+ "icons",
326
+ "images",
327
+ "projectId",
328
+ "projectName",
329
+ "version"
330
+ ],
331
+ "type": "object"
332
+ },
333
+ "StyleConfig": {
334
+ "properties": {
335
+ "defaultStyleCssFilePath": {
336
+ "description": "File location for global css styles shared by all components. Relative to srcDir",
337
+ "type": "string"
338
+ },
339
+ "scheme": {
340
+ "description": "Styling framework to use",
341
+ "enum": [
342
+ "css",
343
+ "css-modules"
344
+ ],
345
+ "type": "string"
346
+ }
347
+ },
348
+ "required": [
349
+ "defaultStyleCssFilePath",
350
+ "scheme"
351
+ ],
352
+ "type": "object"
353
+ },
354
+ "TokensConfig": {
355
+ "properties": {
356
+ "scheme": {
357
+ "enum": [
358
+ "theo"
359
+ ],
360
+ "type": "string"
361
+ },
362
+ "tokensFilePath": {
363
+ "type": "string"
364
+ }
365
+ },
366
+ "required": [
367
+ "scheme",
368
+ "tokensFilePath"
369
+ ],
370
+ "type": "object"
371
+ }
372
+ },
373
+ "properties": {
374
+ "cliVersion": {
375
+ "description": "The version of cli when this file was written",
376
+ "type": "string"
377
+ },
378
+ "code": {
379
+ "$ref": "#/definitions/CodeConfig",
380
+ "description": "Config for code generation"
381
+ },
382
+ "defaultPlasmicDir": {
383
+ "description": "The default folder where Plasmic-managed files will be stored. These include\nblackbox component files, svg component files, style files, etc. The path\nis relative to the srcDir.",
384
+ "type": "string"
385
+ },
386
+ "gatsbyConfig": {
387
+ "description": "Gatsby-specific config",
388
+ "properties": {
389
+ "pagesDir": {
390
+ "description": "The folder containing page components source files.",
391
+ "type": "string"
392
+ }
393
+ },
394
+ "type": "object"
395
+ },
396
+ "globalVariants": {
397
+ "$ref": "#/definitions/GlobalVariantsConfig",
398
+ "description": "Metadata for global variant groups"
399
+ },
400
+ "images": {
401
+ "$ref": "#/definitions/ImagesConfig",
402
+ "description": "Config for pictures"
403
+ },
404
+ "nextjsConfig": {
405
+ "description": "Next.js specific config",
406
+ "properties": {
407
+ "pagesDir": {
408
+ "description": "The folder containing page components source files.",
409
+ "type": "string"
410
+ }
411
+ },
412
+ "type": "object"
413
+ },
414
+ "platform": {
415
+ "description": "Target platform to generate code for",
416
+ "enum": [
417
+ "gatsby",
418
+ "nextjs",
419
+ "react"
420
+ ],
421
+ "type": "string"
422
+ },
423
+ "postSyncCommands": {
424
+ "description": "Arbitrary command to run after `plasmic sync` has run; useful for linting and code formatting synced files",
425
+ "items": {
426
+ "type": "string"
427
+ },
428
+ "type": "array"
429
+ },
430
+ "projects": {
431
+ "description": "Metadata for each project that has been synced",
432
+ "items": {
433
+ "$ref": "#/definitions/ProjectConfig"
434
+ },
435
+ "type": "array"
436
+ },
437
+ "srcDir": {
438
+ "description": "The folder containing the component source files; this is the default place where\nall files are generated and stored.",
439
+ "type": "string"
440
+ },
441
+ "style": {
442
+ "$ref": "#/definitions/StyleConfig",
443
+ "description": "Config for style generation"
444
+ },
445
+ "tokens": {
446
+ "$ref": "#/definitions/TokensConfig",
447
+ "description": "Config for style tokens"
448
+ }
449
+ },
450
+ "required": [
451
+ "code",
452
+ "defaultPlasmicDir",
453
+ "globalVariants",
454
+ "images",
455
+ "platform",
456
+ "projects",
457
+ "srcDir",
458
+ "style",
459
+ "tokens"
460
+ ],
461
+ "type": "object"
462
+ }
463
+
@@ -0,0 +1,13 @@
1
+ import { SyncArgs } from "../actions/sync";
2
+ import { PlasmicConfig, ProjectConfig } from "../utils/config-utils";
3
+ import { TempRepo } from "../utils/test-utils";
4
+ export declare const mockApi: any;
5
+ export declare let opts: SyncArgs;
6
+ export declare let tmpRepo: TempRepo;
7
+ export declare const defaultPlasmicJson: PlasmicConfig;
8
+ export declare function standardTestSetup(includeDep?: boolean): void;
9
+ export declare function standardTestTeardown(): void;
10
+ export declare function expectProject1Components(): void;
11
+ export declare const project1Config: ProjectConfig;
12
+ export declare function expectProject1PlasmicJson(): void;
13
+ export declare function expectProjectAndDepPlasmicJson(): void;
@@ -0,0 +1,165 @@
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.expectProjectAndDepPlasmicJson = exports.expectProject1PlasmicJson = exports.project1Config = exports.expectProject1Components = exports.standardTestTeardown = exports.standardTestSetup = exports.defaultPlasmicJson = exports.tmpRepo = exports.opts = exports.mockApi = void 0;
7
+ const lodash_1 = __importDefault(require("lodash"));
8
+ const test_utils_1 = require("../utils/test-utils");
9
+ jest.mock("../api");
10
+ exports.mockApi = require("../api");
11
+ exports.defaultPlasmicJson = {
12
+ platform: "react",
13
+ code: {
14
+ lang: "ts",
15
+ scheme: "blackbox",
16
+ reactRuntime: "classic",
17
+ },
18
+ style: {
19
+ scheme: "css",
20
+ defaultStyleCssFilePath: "plasmic/PP__plasmic__default_style.css",
21
+ },
22
+ images: {
23
+ scheme: "inlined",
24
+ },
25
+ tokens: {
26
+ scheme: "theo",
27
+ tokensFilePath: "plasmic-tokens.theo.json",
28
+ },
29
+ srcDir: "src/",
30
+ defaultPlasmicDir: "./plasmic",
31
+ projects: [],
32
+ globalVariants: {
33
+ variantGroups: [],
34
+ },
35
+ cliVersion: "0.1.44",
36
+ };
37
+ function standardTestSetup(includeDep = true) {
38
+ process.env.PLASMIC_DISABLE_AUTH_SEARCH = "1";
39
+ // Setup server-side mock data
40
+ const project1 = {
41
+ projectId: "projectId1",
42
+ projectApiToken: "abc",
43
+ version: "1.2.3",
44
+ projectName: "project1",
45
+ components: [
46
+ {
47
+ id: "buttonId",
48
+ name: "Button",
49
+ },
50
+ {
51
+ id: "containerId",
52
+ name: "Container",
53
+ },
54
+ ],
55
+ dependencies: includeDep
56
+ ? {
57
+ dependencyId1: "2.3.4",
58
+ }
59
+ : {},
60
+ };
61
+ const dependency = {
62
+ projectId: "dependencyId1",
63
+ projectApiToken: "def",
64
+ version: "2.3.4",
65
+ projectName: "dependency1",
66
+ components: [
67
+ {
68
+ id: "depComponentId",
69
+ name: "DepComponent",
70
+ },
71
+ ],
72
+ dependencies: {},
73
+ };
74
+ [project1, dependency].forEach((p) => exports.mockApi.addMockProject(p));
75
+ // Setup client-side directory
76
+ exports.tmpRepo = new test_utils_1.TempRepo();
77
+ exports.tmpRepo.writePlasmicAuth({
78
+ host: "http://localhost:3003",
79
+ user: "yang@plasmic.app",
80
+ token: "faketoken",
81
+ });
82
+ exports.tmpRepo.writePlasmicJson(exports.defaultPlasmicJson);
83
+ // Default opts and config
84
+ exports.opts = {
85
+ projects: [],
86
+ yes: true,
87
+ force: true,
88
+ nonRecursive: false,
89
+ skipUpgradeCheck: true,
90
+ forceOverwrite: true,
91
+ newComponentScheme: "blackbox",
92
+ appendJsxOnMissingBase: false,
93
+ config: exports.tmpRepo.plasmicJsonPath(),
94
+ auth: exports.tmpRepo.plasmicAuthPath(),
95
+ loaderConfig: exports.tmpRepo.plasmicLoaderJsonPath(),
96
+ baseDir: process.cwd(),
97
+ };
98
+ }
99
+ exports.standardTestSetup = standardTestSetup;
100
+ function standardTestTeardown() {
101
+ exports.tmpRepo.destroy();
102
+ exports.mockApi.clear();
103
+ delete process.env["PLASMIC_DISABLE_AUTH_SEARCH"];
104
+ }
105
+ exports.standardTestTeardown = standardTestTeardown;
106
+ function expectProject1Components() {
107
+ // Check correct files exist
108
+ const button = exports.mockApi.stringToMockComponent(exports.tmpRepo.getComponentFileContents("projectId1", "buttonId"));
109
+ const container = exports.mockApi.stringToMockComponent(exports.tmpRepo.getComponentFileContents("projectId1", "containerId"));
110
+ expect(button).toBeTruthy();
111
+ expect(container).toBeTruthy();
112
+ expect(button === null || button === void 0 ? void 0 : button.name).toEqual("Button");
113
+ expect(button === null || button === void 0 ? void 0 : button.version).toEqual("1.2.3");
114
+ expect(container === null || container === void 0 ? void 0 : container.name).toEqual("Container");
115
+ expect(container === null || container === void 0 ? void 0 : container.version).toEqual("1.2.3");
116
+ }
117
+ exports.expectProject1Components = expectProject1Components;
118
+ exports.project1Config = {
119
+ projectId: "projectId1",
120
+ projectName: "Project 1",
121
+ version: "latest",
122
+ cssFilePath: "plasmic/PP__demo.css",
123
+ components: [
124
+ {
125
+ id: "buttonId",
126
+ name: "Button",
127
+ type: "managed",
128
+ projectId: "projectId1",
129
+ renderModuleFilePath: "plasmic/project_id_1/PlasmicButton.tsx",
130
+ importSpec: {
131
+ modulePath: "Button.tsx",
132
+ },
133
+ cssFilePath: "plasmic/PlasmicButton.css",
134
+ scheme: "blackbox",
135
+ componentType: "component",
136
+ },
137
+ ],
138
+ icons: [],
139
+ images: [],
140
+ jsBundleThemes: [],
141
+ };
142
+ function expectProject1PlasmicJson() {
143
+ const plasmicJson = exports.tmpRepo.readPlasmicJson();
144
+ expect(plasmicJson.projects.length).toEqual(1);
145
+ const projectConfig = plasmicJson.projects[0];
146
+ expect(projectConfig.projectApiToken).toBe("abc");
147
+ expect(projectConfig.components.length).toEqual(2);
148
+ const componentNames = projectConfig.components.map((c) => c.name);
149
+ expect(componentNames).toContain("Button");
150
+ expect(componentNames).toContain("Container");
151
+ }
152
+ exports.expectProject1PlasmicJson = expectProject1PlasmicJson;
153
+ function expectProjectAndDepPlasmicJson() {
154
+ const plasmicJson = exports.tmpRepo.readPlasmicJson();
155
+ expect(plasmicJson.projects.length).toEqual(2);
156
+ const projectConfigMap = lodash_1.default.keyBy(plasmicJson.projects, (p) => p.projectId);
157
+ expect(projectConfigMap["projectId1"]).toBeTruthy();
158
+ expect(projectConfigMap["dependencyId1"]).toBeTruthy();
159
+ const projectComponentNames = projectConfigMap["projectId1"].components.map((c) => c.name);
160
+ const depComponentNames = projectConfigMap["dependencyId1"].components.map((c) => c.name);
161
+ expect(projectComponentNames).toContain("Button");
162
+ expect(projectComponentNames).toContain("Container");
163
+ expect(depComponentNames).toContain("DepComponent");
164
+ }
165
+ exports.expectProjectAndDepPlasmicJson = expectProjectAndDepPlasmicJson;