@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,43 @@
1
+ jest.mock("../api");
2
+ import { sync } from "../actions/sync";
3
+ import {
4
+ expectProject1Components,
5
+ expectProject1PlasmicJson,
6
+ opts,
7
+ standardTestSetup,
8
+ standardTestTeardown,
9
+ tmpRepo,
10
+ } from "../test-common/fixtures";
11
+
12
+ // Reset the test project directory
13
+ beforeEach(() => {
14
+ standardTestSetup(false);
15
+ });
16
+
17
+ afterEach(() => {
18
+ standardTestTeardown();
19
+ });
20
+
21
+ describe("first-time-user-experience", () => {
22
+ test("missing auth", async () => {
23
+ // Trying to sync is going to fail without a valid auth file
24
+ tmpRepo.deletePlasmicAuth();
25
+ await expect(sync(opts)).rejects.toThrow();
26
+ });
27
+
28
+ test("no args", async () => {
29
+ // No projects or components specified
30
+ await expect(sync(opts)).rejects.toThrow();
31
+ });
32
+
33
+ test("specify project", async () => {
34
+ opts.projects = ["projectId1"];
35
+ await expect(sync(opts)).resolves.toBeUndefined();
36
+
37
+ expectProject1Components();
38
+
39
+ expect(tmpRepo.checkFile("./src/DepComponent.tsx")).toBeFalsy();
40
+
41
+ expectProject1PlasmicJson();
42
+ });
43
+ });
@@ -0,0 +1,208 @@
1
+ import { sync } from "../actions/sync";
2
+ import {
3
+ defaultPlasmicJson,
4
+ expectProject1Components,
5
+ expectProject1PlasmicJson,
6
+ expectProjectAndDepPlasmicJson,
7
+ mockApi,
8
+ opts,
9
+ project1Config,
10
+ standardTestSetup,
11
+ standardTestTeardown,
12
+ tmpRepo,
13
+ } from "../test-common/fixtures";
14
+
15
+ jest.mock("../api");
16
+
17
+ // Reset the test project directory
18
+ beforeEach(() => {
19
+ standardTestSetup(false);
20
+ });
21
+
22
+ afterEach(() => {
23
+ standardTestTeardown();
24
+ });
25
+
26
+ function removeAuth() {
27
+ opts.auth = undefined;
28
+ // Don't need to remove this file, we just do for good measure.
29
+ tmpRepo.deletePlasmicAuth();
30
+ }
31
+
32
+ describe("Project API tokens", () => {
33
+ test("is filled in by auth'd user so that a second run does not need auth", async () => {
34
+ opts.projects = ["projectId1"];
35
+ await expect(sync(opts)).resolves.toBeUndefined();
36
+
37
+ expectProject1Components();
38
+
39
+ expectProject1PlasmicJson();
40
+
41
+ // Re-run, this time with no auth.
42
+ removeAuth();
43
+ await expect(sync(opts)).resolves.toBeUndefined();
44
+ });
45
+
46
+ test("can be passed in from command-line args", async () => {
47
+ removeAuth();
48
+
49
+ // Without specifying version.
50
+ opts.projects = ["projectId1:abc"];
51
+ await expect(sync(opts)).resolves.toBeUndefined();
52
+
53
+ // Specifying version.
54
+ opts.projects = ["projectId1:abc@1.2.3"];
55
+ await expect(sync(opts)).resolves.toBeUndefined();
56
+
57
+ // Wrong token (should fail).
58
+ opts.projects = ["projectId1:123"];
59
+ await expect(sync(opts)).rejects.toThrow(
60
+ "No user+token, and project API tokens don't match"
61
+ );
62
+ });
63
+
64
+ test("is corrected by auth'd user if token was initially incorrect", async () => {
65
+ opts.projects = ["projectId1"];
66
+ tmpRepo.writePlasmicJson({
67
+ ...defaultPlasmicJson,
68
+ projects: [{ ...project1Config, projectApiToken: "blah" }],
69
+ });
70
+ await expect(sync(opts)).resolves.toBeUndefined();
71
+
72
+ expectProject1Components();
73
+
74
+ expectProject1PlasmicJson();
75
+
76
+ // Re-run, this time with no auth.
77
+ removeAuth();
78
+ await expect(sync(opts)).resolves.toBeUndefined();
79
+ });
80
+
81
+ test("is filled in by auth'd user if project exists but token was initially missing", async () => {
82
+ opts.projects = ["projectId1"];
83
+ tmpRepo.writePlasmicJson({
84
+ ...defaultPlasmicJson,
85
+ projects: [project1Config],
86
+ });
87
+ await expect(sync(opts)).resolves.toBeUndefined();
88
+
89
+ expectProject1Components();
90
+
91
+ expectProject1PlasmicJson();
92
+
93
+ // Re-run, this time with no auth.
94
+ removeAuth();
95
+ await expect(sync(opts)).resolves.toBeUndefined();
96
+ });
97
+
98
+ test("when not available, should prompt for auth", async () => {
99
+ opts.projects = ["projectId1"];
100
+ removeAuth();
101
+ await expect(sync(opts)).rejects.toThrow("Unable to authenticate");
102
+ });
103
+
104
+ // TODO: Would be nice to eventually make this not fail outright but to prompt for auth.
105
+ test("when incorrect, should fail", async () => {
106
+ opts.projects = ["projectId1"];
107
+ removeAuth();
108
+ tmpRepo.writePlasmicJson({
109
+ ...defaultPlasmicJson,
110
+ projects: [{ ...project1Config, projectApiToken: "blah" }],
111
+ });
112
+ await expect(sync(opts)).rejects.toThrow(
113
+ "No user+token, and project API tokens don't match"
114
+ );
115
+ });
116
+
117
+ test("works even if you have tokens for base but not deps", async () => {
118
+ // Make project1 have a dependency.
119
+ standardTestSetup();
120
+
121
+ opts.projects = ["projectId1"];
122
+ removeAuth();
123
+ tmpRepo.writePlasmicJson({
124
+ ...defaultPlasmicJson,
125
+ projects: [{ ...project1Config, projectApiToken: "abc" }],
126
+ });
127
+ await expect(sync(opts)).resolves.toBeUndefined();
128
+
129
+ expectProject1Components();
130
+
131
+ expectProjectAndDepPlasmicJson();
132
+ });
133
+
134
+ test("works even if dependency was determined to not need an update", async () => {
135
+ // Make project1 have a dependency.
136
+ standardTestSetup();
137
+
138
+ opts.projects = ["projectId1"];
139
+ await expect(sync(opts)).resolves.toBeUndefined();
140
+
141
+ // We sync project1 which got updated, but the dependency is still same version.
142
+ opts.force = false;
143
+ removeAuth();
144
+ mockApi.getMockProject("projectId1", "1.2.3").version = "1.2.4";
145
+ await expect(sync(opts)).resolves.toBeUndefined();
146
+ });
147
+
148
+ test("should prompt for auth if you have only irrelevant tokens", async () => {
149
+ opts.projects = ["dependencyId1"];
150
+ removeAuth();
151
+ tmpRepo.writePlasmicJson({
152
+ ...defaultPlasmicJson,
153
+ projects: [{ ...project1Config, projectApiToken: "abc" }],
154
+ });
155
+ await expect(sync(opts)).rejects.toThrow("Unable to authenticate");
156
+ });
157
+
158
+ test("should use plasmic-loader.json for API tokens in loader mode", async () => {
159
+ process.env.PLASMIC_LOADER = "1";
160
+
161
+ opts.projects = ["projectId1"];
162
+ await expect(sync(opts)).resolves.toBeUndefined();
163
+
164
+ const loaderConfig = tmpRepo.readPlasmicLoaderJson();
165
+ expect(loaderConfig).toEqual({
166
+ projects: [
167
+ {
168
+ projectId: "projectId1",
169
+ projectApiToken: "abc",
170
+ },
171
+ ],
172
+ });
173
+
174
+ // Re-run, this time with no auth and no tokens in plasmic.json, only in plasmic-loader.json.
175
+ removeAuth();
176
+ tmpRepo.writePlasmicJson(defaultPlasmicJson);
177
+ await expect(sync(opts)).resolves.toBeUndefined();
178
+
179
+ delete process.env["PLASMIC_LOADER"];
180
+ });
181
+
182
+ test("works in PlasmicLoader mode even if root project was determined to not need an update", async () => {
183
+ process.env.PLASMIC_LOADER = "1";
184
+
185
+ // Make project1 have a dependency.
186
+ standardTestSetup();
187
+
188
+ // Explicitly sync both - we had a bug writing back the plasmic-loader.json in this case.
189
+ opts.projects = ["projectId1", "dependencyId1"];
190
+ await expect(sync(opts)).resolves.toBeUndefined();
191
+
192
+ // We sync project1 which got updated, but the dependency is still same version.
193
+ opts.force = false;
194
+ removeAuth();
195
+ mockApi.getMockProject("projectId1", "1.2.3").version = "1.2.4";
196
+ await expect(sync(opts)).resolves.toBeUndefined();
197
+ });
198
+
199
+ test("should fail in loader mode if not available", async () => {
200
+ process.env.PLASMIC_LOADER = "1";
201
+
202
+ opts.projects = ["projectId1"];
203
+ removeAuth();
204
+ await expect(sync(opts)).rejects.toThrow();
205
+
206
+ delete process.env["PLASMIC_LOADER"];
207
+ });
208
+ });
@@ -0,0 +1,176 @@
1
+ import { sync } from "../actions/sync";
2
+ import {
3
+ expectProject1Components,
4
+ expectProject1PlasmicJson,
5
+ expectProjectAndDepPlasmicJson,
6
+ mockApi,
7
+ opts,
8
+ project1Config,
9
+ standardTestSetup,
10
+ standardTestTeardown,
11
+ tmpRepo,
12
+ } from "../test-common/fixtures";
13
+ import { MockComponent } from "../__mocks__/api";
14
+
15
+ jest.mock("../api");
16
+
17
+ // Reset the test project directory
18
+ beforeEach(() => {
19
+ standardTestSetup();
20
+ });
21
+
22
+ afterEach(() => {
23
+ // Remove the temporary directory
24
+ // TODO: Comment out to keep files for debugging
25
+ standardTestTeardown();
26
+ });
27
+
28
+ describe("versioned-sync", () => {
29
+ test("syncs non-recursive case", async () => {
30
+ opts.projects = ["projectId1"];
31
+ opts.nonRecursive = true;
32
+ await expect(sync(opts)).resolves.toBeUndefined();
33
+
34
+ expectProject1Components();
35
+
36
+ expect(tmpRepo.checkFile("./src/DepComponent.tsx")).toBeFalsy();
37
+
38
+ // Check plasmic.json
39
+ expectProject1PlasmicJson();
40
+ });
41
+
42
+ test("syncs missing components", async () => {
43
+ opts.projects = ["projectId1"];
44
+ opts.nonRecursive = true;
45
+ // Simulates user deleting files by accident, since the project exists in plasmic.json,
46
+ // but not in the project directory
47
+ const plasmicJson = tmpRepo.readPlasmicJson();
48
+ plasmicJson.projects.push(project1Config);
49
+ tmpRepo.writePlasmicJson(plasmicJson);
50
+ await expect(sync(opts)).resolves.toBeUndefined();
51
+ });
52
+
53
+ test("syncs down new names", async () => {
54
+ opts.projects = ["projectId1"];
55
+ await expect(sync(opts)).resolves.toBeUndefined();
56
+ // Change component name server-side
57
+ const mockProject = mockApi.getMockProject("projectId1", "1.2.3");
58
+ const buttonData = mockProject.components.find(
59
+ (c: MockComponent) => c.id === "buttonId"
60
+ );
61
+ buttonData.name = "NewButton";
62
+ mockProject.version = "2.0.0";
63
+ mockApi.addMockProject(mockProject);
64
+ // Try syncing again and see if things show up
65
+ await expect(sync(opts)).resolves.toBeUndefined();
66
+
67
+ const plasmicJson = tmpRepo.readPlasmicJson();
68
+ const projectInConfig = plasmicJson.projects.find(
69
+ (p) => p.projectId === "projectId1"
70
+ );
71
+ const componentInConfig = !!projectInConfig
72
+ ? projectInConfig.components.find((c) => c.id === buttonData.id)
73
+ : undefined;
74
+ expect(componentInConfig).toBeTruthy();
75
+ expect(componentInConfig?.name).toEqual(buttonData.name);
76
+ });
77
+
78
+ test("syncs latest", async () => {
79
+ opts.projects = ["projectId1"];
80
+ await expect(sync(opts)).resolves.toBeUndefined();
81
+ // Change component version server-side
82
+ const mockProject = mockApi.getMockProject("projectId1", "1.2.3");
83
+ mockProject.version = "1.3.4";
84
+ mockApi.addMockProject(mockProject);
85
+ // Try syncing again and see if things show up
86
+ await expect(sync(opts)).resolves.toBeUndefined();
87
+ const button = mockApi.stringToMockComponent(
88
+ tmpRepo.getComponentFileContents("projectId1", "buttonId")
89
+ );
90
+ expect(button).toBeTruthy();
91
+ expect(button?.name).toEqual("Button");
92
+ expect(button?.version).toEqual("1.3.4");
93
+ });
94
+
95
+ test("syncs exact version", async () => {
96
+ opts.projects = ["projectId1"];
97
+ opts.nonRecursive = true;
98
+ await expect(sync(opts)).resolves.toBeUndefined();
99
+ // Change component version server-side
100
+ const mockProject = mockApi.getMockProject("projectId1", "1.2.3");
101
+ mockProject.version = "2.0.0";
102
+ mockApi.addMockProject(mockProject);
103
+ // Read in updated plasmic.json post-sync
104
+ const plasmicJson = tmpRepo.readPlasmicJson();
105
+ expect(plasmicJson.projects.length).toEqual(1); // projectId1
106
+ expect(plasmicJson.projects[0].components.length).toEqual(2); // Container+Button
107
+ // Try syncing non-existent version
108
+ plasmicJson.projects[0].version = "1.2.10"; // Doesn't exist
109
+ tmpRepo.writePlasmicJson(plasmicJson);
110
+ await expect(sync(opts)).rejects.toThrow();
111
+ // Try syncing existing version
112
+ plasmicJson.projects[0].version = "2.0.0"; // Doesn't exist
113
+ tmpRepo.writePlasmicJson(plasmicJson);
114
+ await expect(sync(opts)).resolves.toBeUndefined();
115
+ const button = mockApi.stringToMockComponent(
116
+ tmpRepo.getComponentFileContents("projectId1", "buttonId")
117
+ );
118
+ expect(button).toBeTruthy();
119
+ expect(button?.name).toEqual("Button");
120
+ expect(button?.version).toEqual("2.0.0");
121
+ });
122
+
123
+ test("syncs according to semver", async () => {
124
+ opts.projects = ["projectId1"];
125
+ opts.nonRecursive = true;
126
+ await expect(sync(opts)).resolves.toBeUndefined();
127
+ // Change component version server-side
128
+ const mockProject = mockApi.getMockProject("projectId1", "1.2.3");
129
+ mockProject.version = "1.10.1";
130
+ mockApi.addMockProject(mockProject);
131
+ // Update plasmic.json to use semver
132
+ const plasmicJson = tmpRepo.readPlasmicJson();
133
+ expect(plasmicJson.projects.length).toEqual(1);
134
+ expect(plasmicJson.projects[0].components.length).toEqual(2);
135
+ plasmicJson.projects[0].version = "^1.2.3";
136
+ // Try syncing again and see if things show up
137
+ await expect(sync(opts)).resolves.toBeUndefined();
138
+ const button = mockApi.stringToMockComponent(
139
+ tmpRepo.getComponentFileContents("projectId1", "buttonId")
140
+ );
141
+ expect(button).toBeTruthy();
142
+ expect(button?.name).toEqual("Button");
143
+ expect(button?.version).toEqual("1.10.1");
144
+ });
145
+ });
146
+
147
+ describe("recursive-sync", () => {
148
+ test("non-recursive base case", async () => {
149
+ // Should sync both Button+Container because of the dependency
150
+ opts.projects = ["projectId1"];
151
+ opts.nonRecursive = true;
152
+ await expect(sync(opts)).resolves.toBeUndefined();
153
+
154
+ expectProject1Components();
155
+
156
+ expect(tmpRepo.checkFile("./src/DepComponent.tsx")).toBeFalsy();
157
+
158
+ expectProject1PlasmicJson();
159
+ });
160
+
161
+ test("dependencies base case", async () => {
162
+ opts.projects = ["projectId1"];
163
+ await expect(sync(opts)).resolves.toBeUndefined();
164
+ expect(tmpRepo.checkFile("./src/Button.tsx")).toBeTruthy();
165
+ expect(tmpRepo.checkFile("./src/Container.tsx")).toBeTruthy();
166
+ const depComponent = mockApi.stringToMockComponent(
167
+ tmpRepo.getComponentFileContents("dependencyId1", "depComponentId")
168
+ );
169
+ expect(depComponent).toBeTruthy();
170
+ expect(depComponent?.name).toEqual("DepComponent");
171
+ expect(depComponent?.version).toEqual("2.3.4");
172
+
173
+ // Check plasmic.json
174
+ expectProjectAndDepPlasmicJson();
175
+ });
176
+ });
@@ -0,0 +1,43 @@
1
+ import { logger } from "../deps";
2
+ import { getCurrentAuth, startAuth } from "../utils/auth-utils";
3
+ import { HandledError } from "../utils/error";
4
+
5
+ export type AuthArgs = {
6
+ host: string;
7
+ baseDir?: string;
8
+ check?: boolean;
9
+ email?: boolean;
10
+ };
11
+
12
+ export async function checkCredentials() {
13
+ if (await getCurrentAuth()) {
14
+ logger.info("Plasmic credentials are ok.");
15
+ return;
16
+ }
17
+ throw new HandledError(
18
+ "The authentication credentials are missing or invalid."
19
+ );
20
+ }
21
+
22
+ async function getEmail() {
23
+ const authCreds = await getCurrentAuth();
24
+ if (authCreds) {
25
+ logger.info(authCreds.user);
26
+ return authCreds.user;
27
+ }
28
+ throw new HandledError(
29
+ "The authentication credentials are missing or invalid."
30
+ );
31
+ }
32
+
33
+ export async function auth(args: AuthArgs) {
34
+ if (args.check) {
35
+ return checkCredentials();
36
+ }
37
+
38
+ if (args.email) {
39
+ return getEmail();
40
+ }
41
+
42
+ return startAuth(args);
43
+ }
@@ -0,0 +1,13 @@
1
+ import { CommonArgs } from "..";
2
+ import { fixAllImportStatements } from "../utils/code-utils";
3
+ import { fixAllFilePaths } from "../utils/file-utils";
4
+ import { getContext } from "../utils/get-context";
5
+
6
+ export interface FixImportsArgs extends CommonArgs {}
7
+ export async function fixImports(opts: FixImportsArgs) {
8
+ if (!opts.baseDir) opts.baseDir = process.cwd();
9
+ const context = await getContext(opts, { enableSkipAuth: true });
10
+
11
+ await fixAllFilePaths(context, opts.baseDir);
12
+ await fixAllImportStatements(context, opts.baseDir);
13
+ }