@plasmicapp/cli 0.1.187 → 0.1.189

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 (36) hide show
  1. package/dist/__mocks__/api.d.ts +2 -0
  2. package/dist/__mocks__/api.js +16 -11
  3. package/dist/__tests__/project-api-token-spec.js +2 -2
  4. package/dist/__tests__/versioned-sync-spec.js +4 -4
  5. package/dist/actions/project-token.js +1 -1
  6. package/dist/actions/sync-components.js +1 -1
  7. package/dist/actions/sync-global-variants.d.ts +1 -1
  8. package/dist/actions/sync-global-variants.js +2 -2
  9. package/dist/actions/sync-icons.d.ts +1 -1
  10. package/dist/actions/sync-icons.js +2 -2
  11. package/dist/actions/sync-images.d.ts +1 -1
  12. package/dist/actions/sync-images.js +2 -2
  13. package/dist/actions/sync.js +23 -18
  14. package/dist/api.d.ts +10 -7
  15. package/dist/api.js +11 -10
  16. package/dist/plasmic.schema.json +4 -0
  17. package/dist/test-common/fixtures.js +3 -0
  18. package/dist/utils/auth-utils.js +2 -2
  19. package/dist/utils/config-utils.d.ts +4 -1
  20. package/dist/utils/config-utils.js +2 -1
  21. package/dist/utils/resolve-utils.js +11 -7
  22. package/package.json +2 -3
  23. package/src/__mocks__/api.ts +28 -7
  24. package/src/__tests__/project-api-token-spec.ts +2 -2
  25. package/src/__tests__/versioned-sync-spec.ts +4 -4
  26. package/src/actions/project-token.ts +1 -1
  27. package/src/actions/sync-components.ts +6 -1
  28. package/src/actions/sync-global-variants.ts +8 -3
  29. package/src/actions/sync-icons.ts +3 -2
  30. package/src/actions/sync-images.ts +2 -1
  31. package/src/actions/sync.ts +38 -21
  32. package/src/api.ts +15 -8
  33. package/src/test-common/fixtures.ts +3 -0
  34. package/src/utils/auth-utils.ts +3 -3
  35. package/src/utils/config-utils.ts +5 -0
  36. package/src/utils/resolve-utils.ts +25 -14
@@ -1,5 +1,6 @@
1
1
  export interface MockProject {
2
2
  projectId: string;
3
+ branchName: string;
3
4
  projectApiToken: string;
4
5
  version: string;
5
6
  projectName: string;
@@ -12,5 +13,6 @@ export interface MockComponent {
12
13
  id: string;
13
14
  name: string;
14
15
  projectId?: string;
16
+ branchName?: string;
15
17
  version?: string;
16
18
  }
@@ -59,14 +59,16 @@ function mockProjectToProjectVersionMeta(mock, componentIdOrNames) {
59
59
  */
60
60
  function addMockProject(proj) {
61
61
  const projectId = proj.projectId;
62
+ const branchName = proj.branchName;
62
63
  const version = proj.version;
63
64
  // Populate projectId and version into each component
64
65
  // will be useful when reading / writing components to files
65
66
  proj.components = proj.components.map((c) => {
66
67
  return Object.assign(Object.assign({}, c), { projectId,
68
+ branchName,
67
69
  version });
68
70
  });
69
- const existing = getMockProject(projectId, version);
71
+ const existing = getMockProject(projectId, branchName, version);
70
72
  if (!existing) {
71
73
  PROJECTS.push(proj);
72
74
  }
@@ -96,18 +98,21 @@ function stringToMockComponent(data) {
96
98
  function mockComponentToString(component) {
97
99
  return "// " + JSON.stringify(component);
98
100
  }
99
- function getMockProject(projectId, version) {
100
- return PROJECTS.find((m) => m.projectId === projectId && m.version === version);
101
+ function getMockProject(projectId, branchName, version) {
102
+ return PROJECTS.find((m) => m.projectId === projectId &&
103
+ m.branchName === branchName &&
104
+ m.version === version);
101
105
  }
102
106
  /**
103
107
  * Only fetch top-level components that match the projectId (optionally also componentIdOrNames + version)
104
108
  * Does not crawl the dependency tree
105
109
  * @param projectId
110
+ * @param branchName
106
111
  * @param componentIdOrNames
107
112
  * @param versionRange
108
113
  */
109
- function getMockComponents(projectId, version, componentIdOrNames) {
110
- const project = getMockProject(projectId, version);
114
+ function getMockComponents(projectId, branchName, version, componentIdOrNames) {
115
+ const project = getMockProject(projectId, branchName, version);
111
116
  return !project
112
117
  ? []
113
118
  : project.components.filter((c) => !componentIdOrNames ||
@@ -156,7 +161,7 @@ function* getDeps(projects) {
156
161
  while (queue.length > 0) {
157
162
  const curr = lang_utils_1.ensure(queue.shift());
158
163
  for (const [projectId, version] of lodash_1.default.toPairs(curr.dependencies)) {
159
- const mockProject = lang_utils_1.ensure(getMockProject(projectId, version));
164
+ const mockProject = lang_utils_1.ensure(getMockProject(projectId, "main", version));
160
165
  const projectMeta = mockProjectToProjectVersionMeta(mockProject);
161
166
  yield projectMeta;
162
167
  queue.push(projectMeta);
@@ -194,7 +199,7 @@ class PlasmicApi {
194
199
  const availableVersions = availableProjects.map((p) => p.version);
195
200
  const version = semver.maxSatisfying(availableVersions, proj.versionRange);
196
201
  if (version) {
197
- const mockProject = lang_utils_1.ensure(getMockProject(proj.projectId, version));
202
+ const mockProject = lang_utils_1.ensure(getMockProject(proj.projectId, proj.branchName, version));
198
203
  const projectMeta = mockProjectToProjectVersionMeta(mockProject, proj.componentIdOrNames);
199
204
  results.projects.push(projectMeta);
200
205
  }
@@ -212,7 +217,7 @@ class PlasmicApi {
212
217
  return true;
213
218
  });
214
219
  }
215
- projectComponents(projectId, opts) {
220
+ projectComponents(projectId, branchName, opts) {
216
221
  return __awaiter(this, void 0, void 0, function* () {
217
222
  const { componentIdOrNames, version } = opts;
218
223
  if (PROJECTS.length <= 0) {
@@ -229,7 +234,7 @@ class PlasmicApi {
229
234
  if (!deps.every((dep) => this.lastProjectIdsAndTokens.find((p) => p.projectId === dep.projectId))) {
230
235
  throw new Error("No user+token and project API tokens don't match on a dependency");
231
236
  }
232
- const mockComponents = getMockComponents(projectId, version, componentIdOrNames);
237
+ const mockComponents = getMockComponents(projectId, branchName, version, componentIdOrNames);
233
238
  if (mockComponents.length <= 0) {
234
239
  throw new Error(`Code gen failed: no components match the parameters ${JSON.stringify({ projectId, version, componentIdOrNames }, undefined, 2)}`);
235
240
  }
@@ -262,12 +267,12 @@ class PlasmicApi {
262
267
  throw new Error("Unimplemented");
263
268
  });
264
269
  }
265
- projectStyleTokens(projectId) {
270
+ projectStyleTokens(projectId, branchName) {
266
271
  return __awaiter(this, void 0, void 0, function* () {
267
272
  throw new Error("Unimplemented");
268
273
  });
269
274
  }
270
- projectIcons(projectId) {
275
+ projectIcons(projectId, branchName) {
271
276
  return __awaiter(this, void 0, void 0, function* () {
272
277
  throw new Error("Unimplemented");
273
278
  });
@@ -96,7 +96,7 @@ describe("Project API tokens", () => {
96
96
  // We sync project1 which got updated, but the dependency is still same version.
97
97
  fixtures_1.opts.force = false;
98
98
  removeAuth();
99
- fixtures_1.mockApi.getMockProject("projectId1", "1.2.3").version = "1.2.4";
99
+ fixtures_1.mockApi.getMockProject("projectId1", "main", "1.2.3").version = "1.2.4";
100
100
  yield expect(sync_1.sync(fixtures_1.opts)).resolves.toBeUndefined();
101
101
  }));
102
102
  test("should prompt for auth if you have only irrelevant tokens", () => __awaiter(void 0, void 0, void 0, function* () {
@@ -134,7 +134,7 @@ describe("Project API tokens", () => {
134
134
  // We sync project1 which got updated, but the dependency is still same version.
135
135
  fixtures_1.opts.force = false;
136
136
  removeAuth();
137
- fixtures_1.mockApi.getMockProject("projectId1", "1.2.3").version = "1.2.4";
137
+ fixtures_1.mockApi.getMockProject("projectId1", "main", "1.2.3").version = "1.2.4";
138
138
  yield expect(sync_1.sync(fixtures_1.opts)).resolves.toBeUndefined();
139
139
  }));
140
140
  test("should fail in loader mode if not available", () => __awaiter(void 0, void 0, void 0, function* () {
@@ -45,7 +45,7 @@ describe("versioned-sync", () => {
45
45
  fixtures_1.opts.projects = ["projectId1"];
46
46
  yield expect(sync_1.sync(fixtures_1.opts)).resolves.toBeUndefined();
47
47
  // Change component name server-side
48
- const mockProject = fixtures_1.mockApi.getMockProject("projectId1", "1.2.3");
48
+ const mockProject = fixtures_1.mockApi.getMockProject("projectId1", "main", "1.2.3");
49
49
  const buttonData = mockProject.components.find((c) => c.id === "buttonId");
50
50
  buttonData.name = "NewButton";
51
51
  mockProject.version = "2.0.0";
@@ -64,7 +64,7 @@ describe("versioned-sync", () => {
64
64
  fixtures_1.opts.projects = ["projectId1"];
65
65
  yield expect(sync_1.sync(fixtures_1.opts)).resolves.toBeUndefined();
66
66
  // Change component version server-side
67
- const mockProject = fixtures_1.mockApi.getMockProject("projectId1", "1.2.3");
67
+ const mockProject = fixtures_1.mockApi.getMockProject("projectId1", "main", "1.2.3");
68
68
  mockProject.version = "1.3.4";
69
69
  fixtures_1.mockApi.addMockProject(mockProject);
70
70
  // Try syncing again and see if things show up
@@ -79,7 +79,7 @@ describe("versioned-sync", () => {
79
79
  fixtures_1.opts.nonRecursive = true;
80
80
  yield expect(sync_1.sync(fixtures_1.opts)).resolves.toBeUndefined();
81
81
  // Change component version server-side
82
- const mockProject = fixtures_1.mockApi.getMockProject("projectId1", "1.2.3");
82
+ const mockProject = fixtures_1.mockApi.getMockProject("projectId1", "main", "1.2.3");
83
83
  mockProject.version = "2.0.0";
84
84
  fixtures_1.mockApi.addMockProject(mockProject);
85
85
  // Read in updated plasmic.json post-sync
@@ -104,7 +104,7 @@ describe("versioned-sync", () => {
104
104
  fixtures_1.opts.nonRecursive = true;
105
105
  yield expect(sync_1.sync(fixtures_1.opts)).resolves.toBeUndefined();
106
106
  // Change component version server-side
107
- const mockProject = fixtures_1.mockApi.getMockProject("projectId1", "1.2.3");
107
+ const mockProject = fixtures_1.mockApi.getMockProject("projectId1", "main", "1.2.3");
108
108
  mockProject.version = "1.10.1";
109
109
  fixtures_1.mockApi.addMockProject(mockProject);
110
110
  // Update plasmic.json to use semver
@@ -27,7 +27,7 @@ exports.getProjectApiToken = (projectId, host) => __awaiter(void 0, void 0, void
27
27
  if (auth) {
28
28
  const api = new api_1.PlasmicApi(auth);
29
29
  const versionResolution = yield api.resolveSync([
30
- { projectId, componentIdOrNames: undefined },
30
+ { projectId, branchName: "main", componentIdOrNames: undefined },
31
31
  ]);
32
32
  return (_a = versionResolution.projects[0]) === null || _a === void 0 ? void 0 : _a.projectApiToken;
33
33
  }
@@ -34,7 +34,7 @@ const updateDirectSkeleton = (newFileContent, editedFileContent, context, compCo
34
34
  });
35
35
  const mergedFiles = yield code_merger_1.mergeFiles(componentByUuid, compConfig.projectId, code_merger_1.makeCachedProjectSyncDataProvider((projectId, revision) => __awaiter(void 0, void 0, void 0, function* () {
36
36
  try {
37
- return yield context.api.projectSyncMetadata(projectId, revision, true);
37
+ return yield context.api.projectSyncMetadata(projectId, "main", revision, true);
38
38
  }
39
39
  catch (e) {
40
40
  if (e instanceof api_1.AppServerError &&
@@ -1,3 +1,3 @@
1
1
  import { ChecksumBundle, GlobalVariantBundle, ProjectMetaBundle } from "../api";
2
2
  import { PlasmicContext } from "../utils/config-utils";
3
- export declare function syncGlobalVariants(context: PlasmicContext, projectMeta: ProjectMetaBundle, bundles: GlobalVariantBundle[], checksums: ChecksumBundle, baseDir: string): Promise<void>;
3
+ export declare function syncGlobalVariants(context: PlasmicContext, projectMeta: ProjectMetaBundle, bundles: GlobalVariantBundle[], checksums: ChecksumBundle, branchName: string, baseDir: string): Promise<void>;
@@ -20,10 +20,10 @@ const code_utils_1 = require("../utils/code-utils");
20
20
  const config_utils_1 = require("../utils/config-utils");
21
21
  const file_utils_1 = require("../utils/file-utils");
22
22
  const lang_utils_1 = require("../utils/lang-utils");
23
- function syncGlobalVariants(context, projectMeta, bundles, checksums, baseDir) {
23
+ function syncGlobalVariants(context, projectMeta, bundles, checksums, branchName, baseDir) {
24
24
  return __awaiter(this, void 0, void 0, function* () {
25
25
  const projectId = projectMeta.projectId;
26
- const projectLock = config_utils_1.getOrAddProjectLock(context, projectId);
26
+ const projectLock = config_utils_1.getOrAddProjectLock(context, projectId, branchName);
27
27
  const existingVariantConfigs = lodash_1.default.keyBy(context.config.globalVariants.variantGroups.filter((group) => group.projectId === projectId), (c) => c.id);
28
28
  const globalVariantFileLocks = lodash_1.default.keyBy(projectLock.fileLocks.filter((fileLock) => fileLock.type === "globalVariant"), (fl) => fl.assetId);
29
29
  const id2VariantChecksum = new Map(checksums.globalVariantChecksums);
@@ -4,4 +4,4 @@ import { PlasmicContext } from "../utils/config-utils";
4
4
  export interface SyncIconsArgs extends CommonArgs {
5
5
  projects: readonly string[];
6
6
  }
7
- export declare function syncProjectIconAssets(context: PlasmicContext, projectId: string, version: string, iconBundles: IconBundle[], checksums: ChecksumBundle, baseDir: string): Promise<void>;
7
+ export declare function syncProjectIconAssets(context: PlasmicContext, projectId: string, branchName: string, version: string, iconBundles: IconBundle[], checksums: ChecksumBundle, baseDir: string): Promise<void>;
@@ -20,13 +20,13 @@ const code_utils_1 = require("../utils/code-utils");
20
20
  const config_utils_1 = require("../utils/config-utils");
21
21
  const file_utils_1 = require("../utils/file-utils");
22
22
  const lang_utils_1 = require("../utils/lang-utils");
23
- function syncProjectIconAssets(context, projectId, version, iconBundles, checksums, baseDir) {
23
+ function syncProjectIconAssets(context, projectId, branchName, version, iconBundles, checksums, baseDir) {
24
24
  return __awaiter(this, void 0, void 0, function* () {
25
25
  const project = config_utils_1.getOrAddProjectConfig(context, projectId);
26
26
  if (!project.icons) {
27
27
  project.icons = [];
28
28
  }
29
- const projectLock = config_utils_1.getOrAddProjectLock(context, projectId);
29
+ const projectLock = config_utils_1.getOrAddProjectLock(context, projectId, branchName);
30
30
  const knownIconConfigs = lodash_1.default.keyBy(project.icons, (i) => i.id);
31
31
  const iconFileLocks = lodash_1.default.keyBy(projectLock.fileLocks.filter((fileLock) => fileLock.type === "icon"), (fl) => fl.assetId);
32
32
  const id2IconChecksum = new Map(checksums.iconChecksums);
@@ -1,6 +1,6 @@
1
1
  import { ChecksumBundle, ImageBundle } from "../api";
2
2
  import { FixImportContext } from "../utils/code-utils";
3
3
  import { PlasmicContext } from "../utils/config-utils";
4
- export declare function syncProjectImageAssets(context: PlasmicContext, projectId: string, version: string, imageBundles: ImageBundle[], checksums: ChecksumBundle): Promise<void>;
4
+ export declare function syncProjectImageAssets(context: PlasmicContext, projectId: string, branchName: string, version: string, imageBundles: ImageBundle[], checksums: ChecksumBundle): Promise<void>;
5
5
  export declare function fixComponentCssReferences(context: PlasmicContext, fixImportContext: FixImportContext, cssFilePath: string): Promise<void>;
6
6
  export declare function fixComponentImagesReferences(context: PlasmicContext, fixImportContext: FixImportContext, renderModuleFilePath: string): Promise<boolean>;
@@ -19,10 +19,10 @@ const deps_1 = require("../deps");
19
19
  const config_utils_1 = require("../utils/config-utils");
20
20
  const file_utils_1 = require("../utils/file-utils");
21
21
  const lang_utils_1 = require("../utils/lang-utils");
22
- function syncProjectImageAssets(context, projectId, version, imageBundles, checksums) {
22
+ function syncProjectImageAssets(context, projectId, branchName, version, imageBundles, checksums) {
23
23
  return __awaiter(this, void 0, void 0, function* () {
24
24
  const project = config_utils_1.getOrAddProjectConfig(context, projectId);
25
- const projectLock = config_utils_1.getOrAddProjectLock(context, projectId);
25
+ const projectLock = config_utils_1.getOrAddProjectLock(context, projectId, branchName);
26
26
  const knownImageConfigs = lodash_1.default.keyBy(project.images, (i) => i.id);
27
27
  const imageBundleIds = lodash_1.default.keyBy(imageBundles, (i) => i.id);
28
28
  const imageFileLocks = lodash_1.default.keyBy(projectLock.fileLocks.filter((fileLock) => fileLock.type === "image"), (fl) => fl.assetId);
@@ -150,12 +150,13 @@ function sync(opts, metadataDefaults) {
150
150
  // Resolve what will be synced
151
151
  const projectConfigMap = lodash_1.default.keyBy(context.config.projects, (p) => p.projectId);
152
152
  const projectWithVersion = opts.projects.map((p) => {
153
- var _a;
153
+ var _a, _b, _c;
154
154
  const [projectIdToken, versionRange] = p.split("@");
155
155
  const [projectId, projectApiToken] = projectIdToken.split(":");
156
156
  return {
157
157
  projectId,
158
- versionRange: versionRange || ((_a = projectConfigMap[projectId]) === null || _a === void 0 ? void 0 : _a.version) || "latest",
158
+ branchName: (_b = (_a = projectConfigMap[projectId]) === null || _a === void 0 ? void 0 : _a.projectBranchName) !== null && _b !== void 0 ? _b : "main",
159
+ versionRange: versionRange || ((_c = projectConfigMap[projectId]) === null || _c === void 0 ? void 0 : _c.version) || "latest",
159
160
  componentIdOrNames: undefined,
160
161
  projectApiToken: projectApiToken || projectIdToToken.get(projectId),
161
162
  indirect: false,
@@ -163,13 +164,17 @@ function sync(opts, metadataDefaults) {
163
164
  });
164
165
  const projectSyncParams = projectWithVersion.length
165
166
  ? projectWithVersion
166
- : context.config.projects.map((p) => ({
167
- projectId: p.projectId,
168
- versionRange: p.version,
169
- componentIdOrNames: undefined,
170
- projectApiToken: p.projectApiToken,
171
- indirect: !!p.indirect,
172
- }));
167
+ : context.config.projects.map((p) => {
168
+ var _a;
169
+ return ({
170
+ projectId: p.projectId,
171
+ branchName: (_a = p.projectBranchName) !== null && _a !== void 0 ? _a : "main",
172
+ versionRange: p.version,
173
+ componentIdOrNames: undefined,
174
+ projectApiToken: p.projectApiToken,
175
+ indirect: !!p.indirect,
176
+ });
177
+ });
173
178
  // Short-circuit if nothing to sync
174
179
  if (projectSyncParams.length === 0) {
175
180
  throw new error_1.HandledError("Don't know which projects to sync. Please specify via --projects");
@@ -224,7 +229,7 @@ function sync(opts, metadataDefaults) {
224
229
  // Sync in sequence (no parallelism)
225
230
  // going in reverse to get leaves of the dependency tree first
226
231
  for (const projectMeta of projectsToSync) {
227
- yield syncProject(context, opts, projectIdsAndTokens, projectMeta.projectId, projectMeta.componentIds, projectMeta.version, projectMeta.dependencies, summary, pendingMerge, projectMeta.indirect, externalNpmPackages, externalCssImports, metadataDefaults);
232
+ yield syncProject(context, opts, projectIdsAndTokens, projectMeta.projectId, projectMeta.branchName, projectMeta.componentIds, projectMeta.version, projectMeta.dependencies, summary, pendingMerge, projectMeta.indirect, externalNpmPackages, externalCssImports, metadataDefaults);
228
233
  }
229
234
  // Materialize scheme into each component config.
230
235
  context.config.projects.forEach((p) => p.components.forEach((c) => {
@@ -339,7 +344,7 @@ function fixFileExtension(context) {
339
344
  });
340
345
  });
341
346
  }
342
- function syncProject(context, opts, projectIdsAndTokens, projectId, componentIds, projectVersion, dependencies, summary, pendingMerge, indirect, externalNpmPackages, externalCssImports, metadataDefaults) {
347
+ function syncProject(context, opts, projectIdsAndTokens, projectId, branchName, componentIds, projectVersion, dependencies, summary, pendingMerge, indirect, externalNpmPackages, externalCssImports, metadataDefaults) {
343
348
  var _a;
344
349
  return __awaiter(this, void 0, void 0, function* () {
345
350
  const newComponentScheme = opts.newComponentScheme || context.config.code.scheme;
@@ -348,7 +353,7 @@ function syncProject(context, opts, projectIdsAndTokens, projectId, componentIds
348
353
  const projectApiToken = lang_utils_1.ensure((_a = projectIdsAndTokens.find((p) => p.projectId === projectId)) === null || _a === void 0 ? void 0 : _a.projectApiToken, `Could not find the API token for project ${projectId} in list: ${JSON.stringify(projectIdsAndTokens)}`);
349
354
  const existingChecksums = checksum_1.getChecksums(context, opts, projectId, componentIds);
350
355
  // Server-side code-gen
351
- const projectBundle = yield context.api.projectComponents(projectId, {
356
+ const projectBundle = yield context.api.projectComponents(projectId, branchName, {
352
357
  platform: context.config.platform,
353
358
  newCompScheme: newComponentScheme,
354
359
  existingCompScheme,
@@ -378,12 +383,12 @@ function syncProject(context, opts, projectIdsAndTokens, projectId, componentIds
378
383
  [theme.themeFileName, theme.themeModule] = code_utils_1.maybeConvertTsxToJsx(theme.themeFileName, theme.themeModule, opts.baseDir);
379
384
  });
380
385
  }
381
- yield sync_global_variants_1.syncGlobalVariants(context, projectBundle.projectConfig, projectBundle.globalVariants, projectBundle.checksums, opts.baseDir);
382
- yield syncProjectConfig(context, projectBundle.projectConfig, projectApiToken, projectVersion, dependencies, projectBundle.components, opts.forceOverwrite, !!opts.appendJsxOnMissingBase, summary, pendingMerge, projectBundle.checksums, opts.baseDir, indirect);
386
+ yield sync_global_variants_1.syncGlobalVariants(context, projectBundle.projectConfig, projectBundle.globalVariants, projectBundle.checksums, branchName, opts.baseDir);
387
+ yield syncProjectConfig(context, projectBundle.projectConfig, projectApiToken, branchName, projectVersion, dependencies, projectBundle.components, opts.forceOverwrite, !!opts.appendJsxOnMissingBase, summary, pendingMerge, projectBundle.checksums, opts.baseDir, indirect);
383
388
  syncCodeComponentsMeta(context, projectId, projectBundle.codeComponentMetas);
384
389
  yield sync_styles_1.upsertStyleTokens(context, projectBundle.usedTokens, projectBundle.projectConfig.projectId);
385
- yield sync_icons_1.syncProjectIconAssets(context, projectId, projectVersion, projectBundle.iconAssets, projectBundle.checksums, opts.baseDir);
386
- yield sync_images_1.syncProjectImageAssets(context, projectId, projectVersion, projectBundle.imageAssets, projectBundle.checksums);
390
+ yield sync_icons_1.syncProjectIconAssets(context, projectId, branchName, projectVersion, projectBundle.iconAssets, projectBundle.checksums, opts.baseDir);
391
+ yield sync_images_1.syncProjectImageAssets(context, projectId, branchName, projectVersion, projectBundle.imageAssets, projectBundle.checksums);
387
392
  (projectBundle.usedNpmPackages || []).forEach((pkg) => externalNpmPackages.add(pkg));
388
393
  (projectBundle.externalCssImports || []).forEach((css) => externalCssImports.add(css));
389
394
  });
@@ -398,7 +403,7 @@ function syncStyleConfig(context, response) {
398
403
  });
399
404
  });
400
405
  }
401
- function syncProjectConfig(context, projectBundle, projectApiToken, version, dependencies, componentBundles, forceOverwrite, appendJsxOnMissingBase, summary, pendingMerge, checksums, baseDir, indirect) {
406
+ function syncProjectConfig(context, projectBundle, projectApiToken, branchName, version, dependencies, componentBundles, forceOverwrite, appendJsxOnMissingBase, summary, pendingMerge, checksums, baseDir, indirect) {
402
407
  return __awaiter(this, void 0, void 0, function* () {
403
408
  const defaultCssFilePath = file_utils_1.defaultResourcePath(context, projectBundle.projectName, projectBundle.cssFileName);
404
409
  const isNew = !context.config.projects.find((p) => p.projectId === projectBundle.projectId);
@@ -416,7 +421,7 @@ function syncProjectConfig(context, projectBundle, projectApiToken, version, dep
416
421
  projectConfig.cssFilePath = defaultCssFilePath;
417
422
  }
418
423
  // plasmic.lock
419
- const projectLock = config_utils_1.getOrAddProjectLock(context, projectConfig.projectId);
424
+ const projectLock = config_utils_1.getOrAddProjectLock(context, projectConfig.projectId, branchName);
420
425
  projectLock.version = version;
421
426
  projectLock.dependencies = dependencies;
422
427
  projectLock.lang = context.config.code.lang;
package/dist/api.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- /// <reference types="socket.io-client" />
2
1
  import { ProjectSyncMetadataModel } from "@plasmicapp/code-merger";
2
+ import { Socket } from "socket.io-client";
3
3
  import { AuthConfig, CodeConfig, ImagesConfig, StyleConfig } from "./utils/config-utils";
4
4
  import { Metadata } from "./utils/get-context";
5
5
  export declare class AppServerError extends Error {
@@ -56,6 +56,7 @@ export interface ImageBundle {
56
56
  }
57
57
  export interface ProjectVersionMeta {
58
58
  projectId: string;
59
+ branchName: string;
59
60
  projectApiToken: string;
60
61
  version: string;
61
62
  projectName: string;
@@ -155,6 +156,7 @@ export declare class PlasmicApi {
155
156
  */
156
157
  resolveSync(projects: {
157
158
  projectId: string;
159
+ branchName: string;
158
160
  versionRange?: string;
159
161
  componentIdOrNames: readonly string[] | undefined;
160
162
  projectApiToken?: string;
@@ -164,9 +166,10 @@ export declare class PlasmicApi {
164
166
  latestCodegenVersion(): Promise<string>;
165
167
  /**
166
168
  * Code-gen endpoint.
167
- * This will fetch components at an exact specified version.
169
+ * This will fetch components from a given branch at an exact specified version.
168
170
  * If you don't know what version should be used, call `resolveSync` first.
169
171
  * @param projectId
172
+ * @param branchName
170
173
  * @param cliVersion
171
174
  * @param reactWebVersion
172
175
  * @param newCompScheme
@@ -174,7 +177,7 @@ export declare class PlasmicApi {
174
177
  * @param componentIdOrNames
175
178
  * @param version
176
179
  */
177
- projectComponents(projectId: string, opts: {
180
+ projectComponents(projectId: string, branchName: string, opts: {
178
181
  platform: string;
179
182
  newCompScheme: "blackbox" | "direct";
180
183
  existingCompScheme: Array<[string, "blackbox" | "direct"]>;
@@ -191,10 +194,10 @@ export declare class PlasmicApi {
191
194
  projectMeta(projectId: string): Promise<ProjectMetaInfo>;
192
195
  genLocalizationStrings(projects: readonly string[], format: "po" | "json" | "lingui", projectIdsAndTokens: ProjectIdAndToken[]): Promise<string>;
193
196
  uploadBundle(projectId: string, bundleName: string, bundleJs: string, css: string[], metaJson: string, genModulePath: string | undefined, genCssPaths: string[], pkgVersion: string | undefined, extraPropMetaJson: string | undefined, themeProviderWrapper: string | undefined, themeModule: string | undefined): Promise<StyleTokensMap>;
194
- projectStyleTokens(projectId: string, versionRange?: string): Promise<StyleTokensMap>;
195
- projectIcons(projectId: string, versionRange?: string, iconIds?: string[]): Promise<ProjectIconsResponse>;
196
- projectSyncMetadata(projectId: string, revision: number, rethrowAppError: boolean): Promise<ProjectSyncMetadataModel>;
197
- connectSocket(): SocketIOClient.Socket;
197
+ projectStyleTokens(projectId: string, branchName: string, versionRange?: string): Promise<StyleTokensMap>;
198
+ projectIcons(projectId: string, branchName: string, versionRange?: string, iconIds?: string[]): Promise<ProjectIconsResponse>;
199
+ projectSyncMetadata(projectId: string, branchName: string, revision: number, rethrowAppError: boolean): Promise<ProjectSyncMetadataModel>;
200
+ connectSocket(): Socket;
198
201
  private post;
199
202
  private get;
200
203
  private makeErrorMessage;
package/dist/api.js CHANGED
@@ -77,9 +77,10 @@ class PlasmicApi {
77
77
  }
78
78
  /**
79
79
  * Code-gen endpoint.
80
- * This will fetch components at an exact specified version.
80
+ * This will fetch components from a given branch at an exact specified version.
81
81
  * If you don't know what version should be used, call `resolveSync` first.
82
82
  * @param projectId
83
+ * @param branchName
83
84
  * @param cliVersion
84
85
  * @param reactWebVersion
85
86
  * @param newCompScheme
@@ -87,9 +88,9 @@ class PlasmicApi {
87
88
  * @param componentIdOrNames
88
89
  * @param version
89
90
  */
90
- projectComponents(projectId, opts) {
91
+ projectComponents(projectId, branchName, opts) {
91
92
  return __awaiter(this, void 0, void 0, function* () {
92
- const result = yield this.post(`${this.codegenHost}/api/v1/projects/${projectId}/code/components`, Object.assign({}, opts));
93
+ const result = yield this.post(`${this.codegenHost}/api/v1/projects/${projectId}/code/components?branchName=${branchName}`, Object.assign({}, opts));
93
94
  return result.data;
94
95
  });
95
96
  }
@@ -129,26 +130,26 @@ class PlasmicApi {
129
130
  return result.data;
130
131
  });
131
132
  }
132
- projectStyleTokens(projectId, versionRange) {
133
+ projectStyleTokens(projectId, branchName, versionRange) {
133
134
  return __awaiter(this, void 0, void 0, function* () {
134
- const result = yield this.post(`${this.codegenHost}/api/v1/projects/${projectId}/code/tokens`, { versionRange });
135
+ const result = yield this.post(`${this.codegenHost}/api/v1/projects/${projectId}/code/tokens?branchName=${branchName}`, { versionRange });
135
136
  return result.data;
136
137
  });
137
138
  }
138
- projectIcons(projectId, versionRange, iconIds) {
139
+ projectIcons(projectId, branchName, versionRange, iconIds) {
139
140
  return __awaiter(this, void 0, void 0, function* () {
140
- const result = yield this.post(`${this.codegenHost}/api/v1/projects/${projectId}/code/icons`, { versionRange, iconIds });
141
+ const result = yield this.post(`${this.codegenHost}/api/v1/projects/${projectId}/code/icons?branchName=${branchName}`, { versionRange, iconIds });
141
142
  return result.data;
142
143
  });
143
144
  }
144
- projectSyncMetadata(projectId, revision, rethrowAppError) {
145
+ projectSyncMetadata(projectId, branchName, revision, rethrowAppError) {
145
146
  return __awaiter(this, void 0, void 0, function* () {
146
- const result = yield this.post(`${this.codegenHost}/api/v1/projects/${projectId}/code/project-sync-metadata`, { revision }, rethrowAppError);
147
+ const result = yield this.post(`${this.codegenHost}/api/v1/projects/${projectId}/code/project-sync-metadata?branchName=${branchName}`, { revision }, rethrowAppError);
147
148
  return code_merger_1.ProjectSyncMetadataModel.fromJson(result.data);
148
149
  });
149
150
  }
150
151
  connectSocket() {
151
- const socket = socket_io_client_1.default.connect(this.studioHost, {
152
+ const socket = socket_io_client_1.default(this.studioHost, {
152
153
  path: `/api/v1/socket`,
153
154
  transportOptions: {
154
155
  polling: {
@@ -314,6 +314,10 @@
314
314
  "description": "Project API token. Grants read-only sync access to just this specific project and its dependencies.",
315
315
  "type": "string"
316
316
  },
317
+ "projectBranchName": {
318
+ "description": "Project branch to be synced",
319
+ "type": "string"
320
+ },
317
321
  "projectId": {
318
322
  "description": "Project ID",
319
323
  "type": "string"
@@ -40,6 +40,7 @@ function standardTestSetup(includeDep = true) {
40
40
  // Setup server-side mock data
41
41
  const project1 = {
42
42
  projectId: "projectId1",
43
+ branchName: "main",
43
44
  projectApiToken: "abc",
44
45
  version: "1.2.3",
45
46
  projectName: "project1",
@@ -61,6 +62,7 @@ function standardTestSetup(includeDep = true) {
61
62
  };
62
63
  const dependency = {
63
64
  projectId: "dependencyId1",
65
+ branchName: "main",
64
66
  projectApiToken: "def",
65
67
  version: "2.3.4",
66
68
  projectName: "dependency1",
@@ -119,6 +121,7 @@ exports.expectProject1Components = expectProject1Components;
119
121
  exports.project1Config = {
120
122
  projectId: "projectId1",
121
123
  projectName: "Project 1",
124
+ projectBranchName: "main",
122
125
  version: "latest",
123
126
  cssFilePath: "plasmic/PP__demo.css",
124
127
  components: [
@@ -26,7 +26,7 @@ const error_1 = require("../utils/error");
26
26
  const config_utils_1 = require("./config-utils");
27
27
  const file_utils_1 = require("./file-utils");
28
28
  function authByPolling(host, initToken) {
29
- const socket = socket_io_client_1.default.connect(host, {
29
+ const socket = socket_io_client_1.default(host, {
30
30
  path: `/api/v1/init-token`,
31
31
  transportOptions: {
32
32
  polling: {
@@ -37,7 +37,7 @@ function authByPolling(host, initToken) {
37
37
  },
38
38
  });
39
39
  const promise = new Promise((resolve, reject) => {
40
- socket.on("connect", (reason) => {
40
+ socket.on("connect", () => {
41
41
  deps_1.logger.info("Waiting for token...");
42
42
  });
43
43
  socket.on("token", (data) => {
@@ -112,6 +112,8 @@ export interface ProjectConfig {
112
112
  projectApiToken?: string;
113
113
  /** Project name synced down from Studio */
114
114
  projectName: string;
115
+ /** Project branch to be synced */
116
+ projectBranchName?: string;
115
117
  /**
116
118
  * A version range for syncing this project. Can be:
117
119
  * * "latest" - always syncs down whatever has been saved in the project.
@@ -224,6 +226,7 @@ export interface FileLock {
224
226
  }
225
227
  export interface ProjectLock {
226
228
  projectId: string;
229
+ branchName: string;
227
230
  version: string;
228
231
  dependencies: {
229
232
  [projectId: string]: string;
@@ -279,5 +282,5 @@ export declare function writeConfig(configFile: string, config: PlasmicConfig, b
279
282
  export declare function writeLock(lockFile: string, lock: PlasmicLock, baseDir: string): Promise<void>;
280
283
  export declare function updateConfig(context: PlasmicContext, newConfig: PlasmicConfig, baseDir: string): Promise<void>;
281
284
  export declare function getOrAddProjectConfig(context: PlasmicContext, projectId: string, base?: ProjectConfig): ProjectConfig;
282
- export declare function getOrAddProjectLock(context: PlasmicContext, projectId: string, base?: ProjectLock): ProjectLock;
285
+ export declare function getOrAddProjectLock(context: PlasmicContext, projectId: string, branchName: string, base?: ProjectLock): ProjectLock;
283
286
  export declare function isPageAwarePlatform(platform: string): boolean;
@@ -159,7 +159,7 @@ function getOrAddProjectConfig(context, projectId, base // if one doesn't exist,
159
159
  return project;
160
160
  }
161
161
  exports.getOrAddProjectConfig = getOrAddProjectConfig;
162
- function getOrAddProjectLock(context, projectId, base // if one doesn't exist, start with this
162
+ function getOrAddProjectLock(context, projectId, branchName, base // if one doesn't exist, start with this
163
163
  ) {
164
164
  let project = context.lock.projects.find((p) => p.projectId === projectId);
165
165
  if (!project) {
@@ -167,6 +167,7 @@ function getOrAddProjectLock(context, projectId, base // if one doesn't exist, s
167
167
  ? lodash_1.default.cloneDeep(base)
168
168
  : {
169
169
  projectId,
170
+ branchName,
170
171
  version: "",
171
172
  dependencies: {},
172
173
  lang: context.config.code.lang,
@@ -78,7 +78,8 @@ function checkProjectMeta(meta, root, context, opts) {
78
78
  // If the codegen version on-disk is invalid, we will sync again the project.
79
79
  const checkCodegenVersion = () => __awaiter(this, void 0, void 0, function* () {
80
80
  const projectLock = context.lock.projects.find((p) => p.projectId === projectId);
81
- if (!!(projectLock === null || projectLock === void 0 ? void 0 : projectLock.codegenVersion) && semver.gte(projectLock.codegenVersion, yield context.api.latestCodegenVersion())) {
81
+ if (!!(projectLock === null || projectLock === void 0 ? void 0 : projectLock.codegenVersion) &&
82
+ semver.gte(projectLock.codegenVersion, yield context.api.latestCodegenVersion())) {
82
83
  return false;
83
84
  }
84
85
  return true;
@@ -92,9 +93,10 @@ function checkProjectMeta(meta, root, context, opts) {
92
93
  // Always sync if we haven't seen sync'ed before
93
94
  return true;
94
95
  }
95
- if (semver.isLatest(versionOnDisk) &&
96
- semver.isLatest(newVersion) &&
97
- meta !== root) {
96
+ // If version is a branch name, we want to get the latest of the branch
97
+ const newVersionIsLatest = semver.isLatest(newVersion) || !semver.valid(newVersion);
98
+ const versionOnDiskIsLatest = semver.isLatest(versionOnDisk) || !semver.valid(versionOnDisk);
99
+ if (versionOnDiskIsLatest && newVersionIsLatest && meta !== root) {
98
100
  // If this is a dependency (not root), and we're dealing with latest dep version
99
101
  // just skip, it's confusing
100
102
  if (!isOnDiskCodeInvalid) {
@@ -102,11 +104,11 @@ function checkProjectMeta(meta, root, context, opts) {
102
104
  }
103
105
  return false;
104
106
  }
105
- if (semver.isLatest(newVersion)) {
107
+ if (newVersionIsLatest) {
106
108
  // Always sync when version set to "latest"
107
109
  return true;
108
110
  }
109
- if (semver.isLatest(versionOnDisk)) {
111
+ if (versionOnDiskIsLatest) {
110
112
  // Explicitly allow downgrades from "latest" to published version
111
113
  return true;
112
114
  }
@@ -152,8 +154,10 @@ function checkProjectMeta(meta, root, context, opts) {
152
154
  : deps_1.logger.info(`'${projectName} has never been synced before. Syncing...'`);
153
155
  return true;
154
156
  }
157
+ // If version is a branch name, we want to get the latest of the branch
158
+ const versionRangeIsLatest = semver.isLatest(versionRange) || !semver.valid(versionRange);
155
159
  // If satisfies range in plasmic.json
156
- if (semver.satisfies(newVersion, versionRange)) {
160
+ if (versionRangeIsLatest || semver.satisfies(newVersion, versionRange)) {
157
161
  deps_1.logger.info(`Updating project '${projectName}' to ${newVersion}`);
158
162
  return true;
159
163
  }