@plasmicapp/cli 0.1.187 → 0.1.188

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.
@@ -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,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plasmicapp/cli",
3
- "version": "0.1.187",
3
+ "version": "0.1.188",
4
4
  "description": "plasmic cli for syncing local code with Plasmic designs",
5
5
  "engines": {
6
6
  "node": ">=12"
@@ -53,7 +53,6 @@
53
53
  "@babel/traverse": "^7.12.1",
54
54
  "@plasmicapp/code-merger": "^0.0.33",
55
55
  "@sentry/node": "^5.19.2",
56
- "@types/socket.io-client": "^1.4.34",
57
56
  "axios": "^0.21.1",
58
57
  "chalk": "^4.1.0",
59
58
  "fast-glob": "^3.2.4",
@@ -69,7 +68,7 @@
69
68
  "path": "^0.12.7",
70
69
  "prettier": "^2.0.5",
71
70
  "semver": "^7.3.2",
72
- "socket.io-client": "^3.0.3",
71
+ "socket.io-client": "^4.1.2",
73
72
  "typescript": "^3.9.6",
74
73
  "upath": "^1.2.0",
75
74
  "update-notifier": "^4.1.0",
@@ -26,6 +26,7 @@ const api: any = jest.genMockFromModule("../api");
26
26
  const PROJECTS: MockProject[] = [];
27
27
  export interface MockProject {
28
28
  projectId: string;
29
+ branchName: string;
29
30
  projectApiToken: string;
30
31
  version: string;
31
32
  projectName: string;
@@ -38,6 +39,7 @@ export interface MockComponent {
38
39
  id: string;
39
40
  name: string;
40
41
  projectId?: string;
42
+ branchName?: string;
41
43
  version?: string;
42
44
  }
43
45
 
@@ -72,6 +74,7 @@ function mockProjectToProjectVersionMeta(
72
74
  */
73
75
  function addMockProject(proj: MockProject) {
74
76
  const projectId = proj.projectId;
77
+ const branchName = proj.branchName;
75
78
  const version = proj.version;
76
79
  // Populate projectId and version into each component
77
80
  // will be useful when reading / writing components to files
@@ -79,11 +82,12 @@ function addMockProject(proj: MockProject) {
79
82
  return {
80
83
  ...c,
81
84
  projectId,
85
+ branchName,
82
86
  version,
83
87
  };
84
88
  });
85
89
 
86
- const existing = getMockProject(projectId, version);
90
+ const existing = getMockProject(projectId, branchName, version);
87
91
  if (!existing) {
88
92
  PROJECTS.push(proj);
89
93
  } else {
@@ -117,10 +121,14 @@ function mockComponentToString(component: MockComponent): string {
117
121
 
118
122
  function getMockProject(
119
123
  projectId: string,
124
+ branchName: string,
120
125
  version: string
121
126
  ): MockProject | undefined {
122
127
  return PROJECTS.find(
123
- (m) => m.projectId === projectId && m.version === version
128
+ (m) =>
129
+ m.projectId === projectId &&
130
+ m.branchName === branchName &&
131
+ m.version === version
124
132
  );
125
133
  }
126
134
 
@@ -128,15 +136,17 @@ function getMockProject(
128
136
  * Only fetch top-level components that match the projectId (optionally also componentIdOrNames + version)
129
137
  * Does not crawl the dependency tree
130
138
  * @param projectId
139
+ * @param branchName
131
140
  * @param componentIdOrNames
132
141
  * @param versionRange
133
142
  */
134
143
  function getMockComponents(
135
144
  projectId: string,
145
+ branchName: string,
136
146
  version: string,
137
147
  componentIdOrNames: readonly string[] | undefined
138
148
  ): MockComponent[] {
139
- const project = getMockProject(projectId, version);
149
+ const project = getMockProject(projectId, branchName, version);
140
150
  return !project
141
151
  ? []
142
152
  : project.components.filter(
@@ -193,7 +203,7 @@ function* getDeps(projects: ProjectVersionMeta[]) {
193
203
  while (queue.length > 0) {
194
204
  const curr = ensure(queue.shift());
195
205
  for (const [projectId, version] of L.toPairs(curr.dependencies)) {
196
- const mockProject = ensure(getMockProject(projectId, version));
206
+ const mockProject = ensure(getMockProject(projectId, "main", version));
197
207
  const projectMeta = mockProjectToProjectVersionMeta(mockProject);
198
208
  yield projectMeta;
199
209
  queue.push(projectMeta);
@@ -215,6 +225,7 @@ class PlasmicApi {
215
225
  async resolveSync(
216
226
  projects: {
217
227
  projectId: string;
228
+ branchName: string;
218
229
  versionRange: string;
219
230
  componentIdOrNames: readonly string[] | undefined;
220
231
  projectApiToken?: string;
@@ -248,7 +259,9 @@ class PlasmicApi {
248
259
  proj.versionRange
249
260
  );
250
261
  if (version) {
251
- const mockProject = ensure(getMockProject(proj.projectId, version));
262
+ const mockProject = ensure(
263
+ getMockProject(proj.projectId, proj.branchName, version)
264
+ );
252
265
  const projectMeta = mockProjectToProjectVersionMeta(
253
266
  mockProject,
254
267
  proj.componentIdOrNames
@@ -272,6 +285,7 @@ class PlasmicApi {
272
285
 
273
286
  async projectComponents(
274
287
  projectId: string,
288
+ branchName: string,
275
289
  opts: {
276
290
  platform: string;
277
291
  newCompScheme: "blackbox" | "direct";
@@ -310,6 +324,7 @@ class PlasmicApi {
310
324
  }
311
325
  const mockComponents = getMockComponents(
312
326
  projectId,
327
+ branchName,
313
328
  version,
314
329
  componentIdOrNames
315
330
  );
@@ -357,11 +372,17 @@ class PlasmicApi {
357
372
  throw new Error("Unimplemented");
358
373
  }
359
374
 
360
- async projectStyleTokens(projectId: string): Promise<StyleTokensMap> {
375
+ async projectStyleTokens(
376
+ projectId: string,
377
+ branchName: string
378
+ ): Promise<StyleTokensMap> {
361
379
  throw new Error("Unimplemented");
362
380
  }
363
381
 
364
- async projectIcons(projectId: string): Promise<ProjectIconsResponse> {
382
+ async projectIcons(
383
+ projectId: string,
384
+ branchName: string
385
+ ): Promise<ProjectIconsResponse> {
365
386
  throw new Error("Unimplemented");
366
387
  }
367
388
 
@@ -145,7 +145,7 @@ describe("Project API tokens", () => {
145
145
  // We sync project1 which got updated, but the dependency is still same version.
146
146
  opts.force = false;
147
147
  removeAuth();
148
- mockApi.getMockProject("projectId1", "1.2.3").version = "1.2.4";
148
+ mockApi.getMockProject("projectId1", "main", "1.2.3").version = "1.2.4";
149
149
  await expect(sync(opts)).resolves.toBeUndefined();
150
150
  });
151
151
 
@@ -196,7 +196,7 @@ describe("Project API tokens", () => {
196
196
  // We sync project1 which got updated, but the dependency is still same version.
197
197
  opts.force = false;
198
198
  removeAuth();
199
- mockApi.getMockProject("projectId1", "1.2.3").version = "1.2.4";
199
+ mockApi.getMockProject("projectId1", "main", "1.2.3").version = "1.2.4";
200
200
  await expect(sync(opts)).resolves.toBeUndefined();
201
201
  });
202
202
 
@@ -54,7 +54,7 @@ describe("versioned-sync", () => {
54
54
  opts.projects = ["projectId1"];
55
55
  await expect(sync(opts)).resolves.toBeUndefined();
56
56
  // Change component name server-side
57
- const mockProject = mockApi.getMockProject("projectId1", "1.2.3");
57
+ const mockProject = mockApi.getMockProject("projectId1", "main", "1.2.3");
58
58
  const buttonData = mockProject.components.find(
59
59
  (c: MockComponent) => c.id === "buttonId"
60
60
  );
@@ -79,7 +79,7 @@ describe("versioned-sync", () => {
79
79
  opts.projects = ["projectId1"];
80
80
  await expect(sync(opts)).resolves.toBeUndefined();
81
81
  // Change component version server-side
82
- const mockProject = mockApi.getMockProject("projectId1", "1.2.3");
82
+ const mockProject = mockApi.getMockProject("projectId1", "main", "1.2.3");
83
83
  mockProject.version = "1.3.4";
84
84
  mockApi.addMockProject(mockProject);
85
85
  // Try syncing again and see if things show up
@@ -97,7 +97,7 @@ describe("versioned-sync", () => {
97
97
  opts.nonRecursive = true;
98
98
  await expect(sync(opts)).resolves.toBeUndefined();
99
99
  // Change component version server-side
100
- const mockProject = mockApi.getMockProject("projectId1", "1.2.3");
100
+ const mockProject = mockApi.getMockProject("projectId1", "main", "1.2.3");
101
101
  mockProject.version = "2.0.0";
102
102
  mockApi.addMockProject(mockProject);
103
103
  // Read in updated plasmic.json post-sync
@@ -125,7 +125,7 @@ describe("versioned-sync", () => {
125
125
  opts.nonRecursive = true;
126
126
  await expect(sync(opts)).resolves.toBeUndefined();
127
127
  // Change component version server-side
128
- const mockProject = mockApi.getMockProject("projectId1", "1.2.3");
128
+ const mockProject = mockApi.getMockProject("projectId1", "main", "1.2.3");
129
129
  mockProject.version = "1.10.1";
130
130
  mockApi.addMockProject(mockProject);
131
131
  // Update plasmic.json to use semver
@@ -18,7 +18,7 @@ export const getProjectApiToken = async (projectId: string, host?: string) => {
18
18
  if (auth) {
19
19
  const api = new PlasmicApi(auth);
20
20
  const versionResolution = await api.resolveSync([
21
- { projectId, componentIdOrNames: undefined },
21
+ { projectId, branchName: "main", componentIdOrNames: undefined },
22
22
  ]);
23
23
  return versionResolution.projects[0]?.projectApiToken;
24
24
  }
@@ -64,7 +64,12 @@ const updateDirectSkeleton = async (
64
64
  compConfig.projectId,
65
65
  makeCachedProjectSyncDataProvider(async (projectId, revision) => {
66
66
  try {
67
- return await context.api.projectSyncMetadata(projectId, revision, true);
67
+ return await context.api.projectSyncMetadata(
68
+ projectId,
69
+ "main",
70
+ revision,
71
+ true
72
+ );
68
73
  } catch (e) {
69
74
  if (
70
75
  e instanceof AppServerError &&
@@ -18,10 +18,11 @@ export async function syncGlobalVariants(
18
18
  projectMeta: ProjectMetaBundle,
19
19
  bundles: GlobalVariantBundle[],
20
20
  checksums: ChecksumBundle,
21
- baseDir: string,
21
+ branchName: string,
22
+ baseDir: string
22
23
  ) {
23
24
  const projectId = projectMeta.projectId;
24
- const projectLock = getOrAddProjectLock(context, projectId);
25
+ const projectLock = getOrAddProjectLock(context, projectId, branchName);
25
26
  const existingVariantConfigs = L.keyBy(
26
27
  context.config.globalVariants.variantGroups.filter(
27
28
  (group) => group.projectId === projectId
@@ -100,7 +101,11 @@ export async function syncGlobalVariants(
100
101
  await writeFileContent(
101
102
  context,
102
103
  variantConfig.contextFilePath,
103
- formatAsLocal(bundle.contextModule, variantConfig.contextFilePath, baseDir),
104
+ formatAsLocal(
105
+ bundle.contextModule,
106
+ variantConfig.contextFilePath,
107
+ baseDir
108
+ ),
104
109
  { force: !isNew }
105
110
  );
106
111
  }
@@ -25,17 +25,18 @@ export interface SyncIconsArgs extends CommonArgs {
25
25
  export async function syncProjectIconAssets(
26
26
  context: PlasmicContext,
27
27
  projectId: string,
28
+ branchName: string,
28
29
  version: string,
29
30
  iconBundles: IconBundle[],
30
31
  checksums: ChecksumBundle,
31
- baseDir: string,
32
+ baseDir: string
32
33
  ) {
33
34
  const project = getOrAddProjectConfig(context, projectId);
34
35
  if (!project.icons) {
35
36
  project.icons = [];
36
37
  }
37
38
 
38
- const projectLock = getOrAddProjectLock(context, projectId);
39
+ const projectLock = getOrAddProjectLock(context, projectId, branchName);
39
40
  const knownIconConfigs = L.keyBy(project.icons, (i) => i.id);
40
41
  const iconFileLocks = L.keyBy(
41
42
  projectLock.fileLocks.filter((fileLock) => fileLock.type === "icon"),
@@ -22,12 +22,13 @@ import { ensure } from "../utils/lang-utils";
22
22
  export async function syncProjectImageAssets(
23
23
  context: PlasmicContext,
24
24
  projectId: string,
25
+ branchName: string,
25
26
  version: string,
26
27
  imageBundles: ImageBundle[],
27
28
  checksums: ChecksumBundle
28
29
  ) {
29
30
  const project = getOrAddProjectConfig(context, projectId);
30
- const projectLock = getOrAddProjectLock(context, projectId);
31
+ const projectLock = getOrAddProjectLock(context, projectId, branchName);
31
32
  const knownImageConfigs = L.keyBy(project.images, (i) => i.id);
32
33
  const imageBundleIds = L.keyBy(imageBundles, (i) => i.id);
33
34
  const imageFileLocks = L.keyBy(
@@ -243,6 +243,7 @@ export async function sync(
243
243
  const [projectId, projectApiToken] = projectIdToken.split(":");
244
244
  return {
245
245
  projectId,
246
+ branchName: projectConfigMap[projectId]?.projectBranchName ?? "main",
246
247
  versionRange:
247
248
  versionRange || projectConfigMap[projectId]?.version || "latest",
248
249
  componentIdOrNames: undefined, // Get all components!
@@ -255,6 +256,7 @@ export async function sync(
255
256
  ? projectWithVersion
256
257
  : context.config.projects.map((p) => ({
257
258
  projectId: p.projectId,
259
+ branchName: p.projectBranchName ?? "main",
258
260
  versionRange: p.version,
259
261
  componentIdOrNames: undefined, // Get all components!
260
262
  projectApiToken: p.projectApiToken,
@@ -341,6 +343,7 @@ export async function sync(
341
343
  opts,
342
344
  projectIdsAndTokens,
343
345
  projectMeta.projectId,
346
+ projectMeta.branchName,
344
347
  projectMeta.componentIds,
345
348
  projectMeta.version,
346
349
  projectMeta.dependencies,
@@ -557,6 +560,7 @@ async function syncProject(
557
560
  opts: SyncArgs,
558
561
  projectIdsAndTokens: ProjectIdAndToken[],
559
562
  projectId: string,
563
+ branchName: string,
560
564
  componentIds: string[],
561
565
  projectVersion: string,
562
566
  dependencies: { [projectId: string]: string },
@@ -591,26 +595,30 @@ async function syncProject(
591
595
  );
592
596
 
593
597
  // Server-side code-gen
594
- const projectBundle = await context.api.projectComponents(projectId, {
595
- platform: context.config.platform,
596
- newCompScheme: newComponentScheme,
597
- existingCompScheme,
598
- componentIdOrNames: componentIds,
599
- version: projectVersion,
600
- imageOpts: context.config.images,
601
- stylesOpts: context.config.style,
602
- checksums: existingChecksums,
603
- codeOpts: context.config.code,
604
- metadata: generateMetadata(
605
- {
606
- ...metadataDefaults,
607
- platform: context.config.platform,
608
- },
609
- opts.metadata
610
- ),
611
- indirect,
612
- wrapPagesWithGlobalContexts: context.config.wrapPagesWithGlobalContexts,
613
- });
598
+ const projectBundle = await context.api.projectComponents(
599
+ projectId,
600
+ branchName,
601
+ {
602
+ platform: context.config.platform,
603
+ newCompScheme: newComponentScheme,
604
+ existingCompScheme,
605
+ componentIdOrNames: componentIds,
606
+ version: projectVersion,
607
+ imageOpts: context.config.images,
608
+ stylesOpts: context.config.style,
609
+ checksums: existingChecksums,
610
+ codeOpts: context.config.code,
611
+ metadata: generateMetadata(
612
+ {
613
+ ...metadataDefaults,
614
+ platform: context.config.platform,
615
+ },
616
+ opts.metadata
617
+ ),
618
+ indirect,
619
+ wrapPagesWithGlobalContexts: context.config.wrapPagesWithGlobalContexts,
620
+ }
621
+ );
614
622
 
615
623
  // Convert from TSX => JSX
616
624
  if (context.config.code.lang === "js") {
@@ -653,6 +661,7 @@ async function syncProject(
653
661
  projectBundle.projectConfig,
654
662
  projectBundle.globalVariants,
655
663
  projectBundle.checksums,
664
+ branchName,
656
665
  opts.baseDir
657
666
  );
658
667
 
@@ -660,6 +669,7 @@ async function syncProject(
660
669
  context,
661
670
  projectBundle.projectConfig,
662
671
  projectApiToken,
672
+ branchName,
663
673
  projectVersion,
664
674
  dependencies,
665
675
  projectBundle.components,
@@ -680,6 +690,7 @@ async function syncProject(
680
690
  await syncProjectIconAssets(
681
691
  context,
682
692
  projectId,
693
+ branchName,
683
694
  projectVersion,
684
695
  projectBundle.iconAssets,
685
696
  projectBundle.checksums,
@@ -688,6 +699,7 @@ async function syncProject(
688
699
  await syncProjectImageAssets(
689
700
  context,
690
701
  projectId,
702
+ branchName,
691
703
  projectVersion,
692
704
  projectBundle.imageAssets,
693
705
  projectBundle.checksums
@@ -720,6 +732,7 @@ async function syncProjectConfig(
720
732
  context: PlasmicContext,
721
733
  projectBundle: ProjectMetaBundle,
722
734
  projectApiToken: string,
735
+ branchName: string,
723
736
  version: string,
724
737
  dependencies: { [projectId: string]: string },
725
738
  componentBundles: ComponentBundle[],
@@ -760,7 +773,11 @@ async function syncProjectConfig(
760
773
  }
761
774
 
762
775
  // plasmic.lock
763
- const projectLock = getOrAddProjectLock(context, projectConfig.projectId);
776
+ const projectLock = getOrAddProjectLock(
777
+ context,
778
+ projectConfig.projectId,
779
+ branchName
780
+ );
764
781
  projectLock.version = version;
765
782
  projectLock.dependencies = dependencies;
766
783
  projectLock.lang = context.config.code.lang;
package/src/api.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { ProjectSyncMetadataModel } from "@plasmicapp/code-merger";
2
2
  import axios, { AxiosError } from "axios";
3
- import socketio from "socket.io-client";
3
+ import socketio, { Socket } from "socket.io-client";
4
4
  import {
5
5
  AuthConfig,
6
6
  CodeConfig,
@@ -75,6 +75,7 @@ export interface ImageBundle {
75
75
 
76
76
  export interface ProjectVersionMeta {
77
77
  projectId: string;
78
+ branchName: string;
78
79
  projectApiToken: string;
79
80
  version: string;
80
81
  projectName: string;
@@ -201,6 +202,7 @@ export class PlasmicApi {
201
202
  async resolveSync(
202
203
  projects: {
203
204
  projectId: string;
205
+ branchName: string;
204
206
  versionRange?: string;
205
207
  componentIdOrNames: readonly string[] | undefined;
206
208
  projectApiToken?: string;
@@ -243,9 +245,10 @@ export class PlasmicApi {
243
245
 
244
246
  /**
245
247
  * Code-gen endpoint.
246
- * This will fetch components at an exact specified version.
248
+ * This will fetch components from a given branch at an exact specified version.
247
249
  * If you don't know what version should be used, call `resolveSync` first.
248
250
  * @param projectId
251
+ * @param branchName
249
252
  * @param cliVersion
250
253
  * @param reactWebVersion
251
254
  * @param newCompScheme
@@ -255,6 +258,7 @@ export class PlasmicApi {
255
258
  */
256
259
  async projectComponents(
257
260
  projectId: string,
261
+ branchName: string,
258
262
  opts: {
259
263
  platform: string;
260
264
  newCompScheme: "blackbox" | "direct";
@@ -272,7 +276,7 @@ export class PlasmicApi {
272
276
  }
273
277
  ): Promise<ProjectBundle> {
274
278
  const result = await this.post(
275
- `${this.codegenHost}/api/v1/projects/${projectId}/code/components`,
279
+ `${this.codegenHost}/api/v1/projects/${projectId}/code/components?branchName=${branchName}`,
276
280
  {
277
281
  ...opts,
278
282
  }
@@ -345,10 +349,11 @@ export class PlasmicApi {
345
349
 
346
350
  async projectStyleTokens(
347
351
  projectId: string,
352
+ branchName: string,
348
353
  versionRange?: string
349
354
  ): Promise<StyleTokensMap> {
350
355
  const result = await this.post(
351
- `${this.codegenHost}/api/v1/projects/${projectId}/code/tokens`,
356
+ `${this.codegenHost}/api/v1/projects/${projectId}/code/tokens?branchName=${branchName}`,
352
357
  { versionRange }
353
358
  );
354
359
  return result.data as StyleTokensMap;
@@ -356,11 +361,12 @@ export class PlasmicApi {
356
361
 
357
362
  async projectIcons(
358
363
  projectId: string,
364
+ branchName: string,
359
365
  versionRange?: string,
360
366
  iconIds?: string[]
361
367
  ): Promise<ProjectIconsResponse> {
362
368
  const result = await this.post(
363
- `${this.codegenHost}/api/v1/projects/${projectId}/code/icons`,
369
+ `${this.codegenHost}/api/v1/projects/${projectId}/code/icons?branchName=${branchName}`,
364
370
  { versionRange, iconIds }
365
371
  );
366
372
  return result.data as ProjectIconsResponse;
@@ -368,19 +374,20 @@ export class PlasmicApi {
368
374
 
369
375
  async projectSyncMetadata(
370
376
  projectId: string,
377
+ branchName: string,
371
378
  revision: number,
372
379
  rethrowAppError: boolean
373
380
  ): Promise<ProjectSyncMetadataModel> {
374
381
  const result = await this.post(
375
- `${this.codegenHost}/api/v1/projects/${projectId}/code/project-sync-metadata`,
382
+ `${this.codegenHost}/api/v1/projects/${projectId}/code/project-sync-metadata?branchName=${branchName}`,
376
383
  { revision },
377
384
  rethrowAppError
378
385
  );
379
386
  return ProjectSyncMetadataModel.fromJson(result.data);
380
387
  }
381
388
 
382
- connectSocket(): SocketIOClient.Socket {
383
- const socket = socketio.connect(this.studioHost, {
389
+ connectSocket(): Socket {
390
+ const socket = socketio(this.studioHost, {
384
391
  path: `/api/v1/socket`,
385
392
  transportOptions: {
386
393
  polling: {
@@ -43,6 +43,7 @@ export function standardTestSetup(includeDep = true) {
43
43
  // Setup server-side mock data
44
44
  const project1: MockProject = {
45
45
  projectId: "projectId1",
46
+ branchName: "main",
46
47
  projectApiToken: "abc",
47
48
  version: "1.2.3",
48
49
  projectName: "project1",
@@ -64,6 +65,7 @@ export function standardTestSetup(includeDep = true) {
64
65
  };
65
66
  const dependency: MockProject = {
66
67
  projectId: "dependencyId1",
68
+ branchName: "main",
67
69
  projectApiToken: "def",
68
70
  version: "2.3.4",
69
71
  projectName: "dependency1",
@@ -128,6 +130,7 @@ export function expectProject1Components() {
128
130
  export const project1Config: ProjectConfig = {
129
131
  projectId: "projectId1",
130
132
  projectName: "Project 1",
133
+ projectBranchName: "main",
131
134
  version: "latest",
132
135
  cssFilePath: "plasmic/PP__demo.css",
133
136
  components: [
@@ -38,7 +38,7 @@ export function authByPolling(
38
38
  host: string,
39
39
  initToken: string
40
40
  ): CancellablePromise<AuthData> {
41
- const socket = socketio.connect(host, {
41
+ const socket = socketio(host, {
42
42
  path: `/api/v1/init-token`,
43
43
  transportOptions: {
44
44
  polling: {
@@ -50,7 +50,7 @@ export function authByPolling(
50
50
  });
51
51
 
52
52
  const promise = new Promise<AuthData>((resolve, reject) => {
53
- socket.on("connect", (reason: string) => {
53
+ socket.on("connect", () => {
54
54
  logger.info("Waiting for token...");
55
55
  });
56
56
 
@@ -219,7 +219,7 @@ export async function getCurrentAuth(authPath?: string) {
219
219
  await api.getCurrentUser();
220
220
  return auth;
221
221
  } catch (e) {
222
- if (e.response?.status === 401) {
222
+ if ((e as any).response?.status === 401) {
223
223
  logger.error(`The current credentials expired or are not valid.`);
224
224
  return undefined;
225
225
  }
@@ -155,6 +155,8 @@ export interface ProjectConfig {
155
155
  projectApiToken?: string;
156
156
  /** Project name synced down from Studio */
157
157
  projectName: string;
158
+ /** Project branch to be synced */
159
+ projectBranchName?: string;
158
160
  /**
159
161
  * A version range for syncing this project. Can be:
160
162
  * * "latest" - always syncs down whatever has been saved in the project.
@@ -317,6 +319,7 @@ export interface FileLock {
317
319
 
318
320
  export interface ProjectLock {
319
321
  projectId: string;
322
+ branchName: string;
320
323
  // The exact version that was last synced
321
324
  version: string;
322
325
  dependencies: {
@@ -550,6 +553,7 @@ export function getOrAddProjectConfig(
550
553
  export function getOrAddProjectLock(
551
554
  context: PlasmicContext,
552
555
  projectId: string,
556
+ branchName: string,
553
557
  base?: ProjectLock // if one doesn't exist, start with this
554
558
  ): ProjectLock {
555
559
  let project = context.lock.projects.find((p) => p.projectId === projectId);
@@ -558,6 +562,7 @@ export function getOrAddProjectLock(
558
562
  ? L.cloneDeep(base)
559
563
  : {
560
564
  projectId,
565
+ branchName,
561
566
  version: "",
562
567
  dependencies: {},
563
568
  lang: context.config.code.lang,