@plasmicapp/cli 0.1.186 → 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.
Files changed (42) 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/localization-strings.d.ts +3 -1
  6. package/dist/actions/localization-strings.js +39 -8
  7. package/dist/actions/project-token.js +1 -1
  8. package/dist/actions/sync-components.js +1 -1
  9. package/dist/actions/sync-global-variants.d.ts +1 -1
  10. package/dist/actions/sync-global-variants.js +2 -2
  11. package/dist/actions/sync-icons.d.ts +1 -1
  12. package/dist/actions/sync-icons.js +2 -2
  13. package/dist/actions/sync-images.d.ts +1 -1
  14. package/dist/actions/sync-images.js +2 -2
  15. package/dist/actions/sync-styles.d.ts +1 -1
  16. package/dist/actions/sync-styles.js +14 -1
  17. package/dist/actions/sync.js +24 -19
  18. package/dist/api.d.ts +11 -8
  19. package/dist/api.js +19 -14
  20. package/dist/index.js +5 -0
  21. package/dist/plasmic.schema.json +4 -0
  22. package/dist/test-common/fixtures.js +3 -0
  23. package/dist/utils/auth-utils.js +2 -2
  24. package/dist/utils/config-utils.d.ts +4 -1
  25. package/dist/utils/config-utils.js +2 -1
  26. package/package.json +2 -3
  27. package/src/__mocks__/api.ts +28 -7
  28. package/src/__tests__/project-api-token-spec.ts +2 -2
  29. package/src/__tests__/versioned-sync-spec.ts +4 -4
  30. package/src/actions/localization-strings.ts +60 -12
  31. package/src/actions/project-token.ts +1 -1
  32. package/src/actions/sync-components.ts +6 -1
  33. package/src/actions/sync-global-variants.ts +8 -3
  34. package/src/actions/sync-icons.ts +3 -2
  35. package/src/actions/sync-images.ts +2 -1
  36. package/src/actions/sync-styles.ts +15 -1
  37. package/src/actions/sync.ts +43 -22
  38. package/src/api.ts +29 -12
  39. package/src/index.ts +6 -0
  40. package/src/test-common/fixtures.ts +3 -0
  41. package/src/utils/auth-utils.ts +3 -3
  42. package/src/utils/config-utils.ts +5 -0
package/dist/index.js CHANGED
@@ -213,6 +213,11 @@ yargs_1.default
213
213
  type: "boolean",
214
214
  describe: "Overwrite the output file.",
215
215
  default: false,
216
+ })
217
+ .option("project-tokens", {
218
+ type: "array",
219
+ default: [],
220
+ describe: "(Optional) List of project API tokens to be used for auth, in the format PROJECT_ID:PROJECT_API_TOKEN (the pairs should be separated by comma)",
216
221
  }), (argv) => error_1.handleError(localization_strings_1.localizationStrings(argv)))
217
222
  .demandCommand()
218
223
  .strict()
@@ -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.186",
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
@@ -1,15 +1,23 @@
1
1
  import chalk from "chalk";
2
- import { PlasmicApi } from "../api";
2
+ import { pick } from "lodash";
3
+ import { CommonArgs } from "..";
4
+ import { PlasmicApi, ProjectIdAndToken } from "../api";
3
5
  import { logger } from "../deps";
4
6
  import { HandledError } from "../lib";
5
- import { getOrStartAuth } from "../utils/auth-utils";
6
- import { DEFAULT_HOST } from "../utils/config-utils";
7
+ import { getCurrentAuth, getOrStartAuth } from "../utils/auth-utils";
8
+ import {
9
+ DEFAULT_HOST,
10
+ findConfigFile,
11
+ PlasmicContext,
12
+ } from "../utils/config-utils";
7
13
  import { existsBuffered, writeFileText } from "../utils/file-utils";
14
+ import { getContext } from "../utils/get-context";
8
15
  import { confirmWithUser } from "../utils/user-utils";
9
16
 
10
- export interface LocalizationStringsArgs {
17
+ export interface LocalizationStringsArgs extends CommonArgs {
11
18
  host: string;
12
19
  projects: readonly string[];
20
+ projectTokens?: readonly string[];
13
21
  format: "po" | "json" | "lingui";
14
22
  output: string;
15
23
  forceOverwrite: boolean;
@@ -21,23 +29,60 @@ export async function localizationStrings(
21
29
  if (!opts.projects || opts.projects.length === 0) {
22
30
  throw new HandledError(`Missing projects.`);
23
31
  }
32
+ if (!opts.baseDir) opts.baseDir = process.cwd();
33
+ const parsedProjectTokens: ProjectIdAndToken[] = (
34
+ opts.projectTokens ?? []
35
+ ).map((val) => {
36
+ const [projectId, projectApiToken] = val.split(":");
37
+ if (!projectId || !projectApiToken) {
38
+ throw new Error(
39
+ `Invalid value passed to '--project-tokens': ${val}\nPlease provide the API tokens with the format PROJECT_ID:PROJECT_API_TOKEN`
40
+ );
41
+ }
42
+ return {
43
+ projectId: projectId.trim(),
44
+ projectApiToken: projectApiToken.trim(),
45
+ };
46
+ });
24
47
  const output = !opts.output
25
48
  ? opts.format === "po"
26
49
  ? "data.po"
27
50
  : "data.json"
28
51
  : opts.output;
29
- const auth = await getOrStartAuth({
30
- baseDir: "",
31
- host: opts.host || DEFAULT_HOST,
32
- });
33
- if (auth) {
34
- const api = new PlasmicApi(auth);
52
+ const projectTokensFromConfig: ProjectIdAndToken[] = [];
53
+ const auth = await getCurrentAuth(opts.auth);
54
+ const maybeConfigFile =
55
+ opts.config || findConfigFile(opts.baseDir, { traverseParents: true });
56
+ if (maybeConfigFile) {
57
+ const context = await getContext(opts, { enableSkipAuth: true });
58
+ context.config.projects.forEach((p) => {
59
+ projectTokensFromConfig.push(pick(p, "projectId", "projectApiToken"));
60
+ });
61
+ }
62
+
63
+ const projectIdsAndTokens = [
64
+ ...parsedProjectTokens,
65
+ ...projectTokensFromConfig,
66
+ ].filter((v) => !!v && !!v.projectId && !!v.projectApiToken);
67
+
68
+ if (auth || projectIdsAndTokens.length > 0) {
69
+ const api = new PlasmicApi(
70
+ auth ?? {
71
+ host: DEFAULT_HOST,
72
+ user: "",
73
+ token: "",
74
+ }
75
+ );
35
76
  logger.info(
36
77
  `Generating localization strings for ${chalk.bold(
37
78
  opts.projects.join(", ")
38
79
  )}...`
39
80
  );
40
- const data = await api.genLocalizationStrings(opts.projects, opts.format);
81
+ const data = await api.genLocalizationStrings(
82
+ opts.projects,
83
+ opts.format,
84
+ projectIdsAndTokens
85
+ );
41
86
  if (existsBuffered(output)) {
42
87
  const overwrite = await confirmWithUser(
43
88
  `File ${output} already exists. Do you want to overwrite?`,
@@ -52,6 +97,9 @@ export async function localizationStrings(
52
97
  writeFileText(output, data);
53
98
  logger.info(`Localization strings have been written to ${output}`);
54
99
  } else {
55
- logger.error("Missing auth information");
100
+ logger.error(`Missing auth information. You can follow any of the steps below to fix it:
101
+ - Run 'plasmic auth'
102
+ - Provide the project API token to 'plasmic.json'
103
+ - Or provide the project API token through '--project-tokens' flag`);
56
104
  }
57
105
  }
@@ -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(
@@ -9,7 +9,8 @@ import {
9
9
 
10
10
  export async function upsertStyleTokens(
11
11
  context: PlasmicContext,
12
- newStyleMap: StyleTokensMap
12
+ newStyleMap: StyleTokensMap,
13
+ projectId: string
13
14
  ) {
14
15
  const curStyleMap = await readCurStyleMap(context);
15
16
  for (const prop of newStyleMap.props) {
@@ -22,6 +23,19 @@ export async function upsertStyleTokens(
22
23
  curStyleMap.props.push(prop);
23
24
  }
24
25
  }
26
+ const allNewPropIds = new Set(newStyleMap.props.map((prop) => prop.meta.id));
27
+ curStyleMap.props = curStyleMap.props.filter((prop) => {
28
+ if (prop.meta.projectId !== projectId) {
29
+ // Keep all tokens from other projects
30
+ return true;
31
+ }
32
+ if (allNewPropIds.has(prop.meta.id)) {
33
+ // Keep the current tokens in this project
34
+ return true;
35
+ }
36
+ // Delete the tokens that have been removed from the project
37
+ return false;
38
+ });
25
39
  curStyleMap.props.sort((prop1, prop2) =>
26
40
  prop1.name === prop2.name ? 0 : prop1.name < prop2.name ? -1 : 1
27
41
  );