@plasmicapp/cli 0.1.341 → 0.1.343

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.
@@ -33,6 +33,12 @@ function getFilesByFileLockAssetId(
33
33
  splitsProvider: {
34
34
  [projectConfig.projectId]: projectConfig.splitsProviderFilePath,
35
35
  },
36
+ styleTokensProvider: {
37
+ [projectConfig.projectId]: projectConfig.styleTokensProviderFilePath,
38
+ },
39
+ projectModule: {
40
+ [projectConfig.projectId]: projectConfig.projectModuleFilePath,
41
+ },
36
42
  } as const;
37
43
  }
38
44
 
@@ -60,6 +66,8 @@ export function getChecksums(
60
66
  projectCssChecksum: "",
61
67
  globalContextsChecksum: "",
62
68
  splitsProviderChecksum: "",
69
+ styleTokensProviderChecksum: "",
70
+ projectModuleChecksum: "",
63
71
  };
64
72
  }
65
73
 
@@ -161,6 +169,33 @@ export function getChecksums(
161
169
  ? globalContextsChecksums[0].checksum
162
170
  : "";
163
171
 
172
+ const styleTokensProviderChecksums = fileLocks
173
+ .filter(
174
+ (fileLock) =>
175
+ fileLock.type === "styleTokensProvider" &&
176
+ fileLock.assetId === projectId
177
+ )
178
+ .filter((fileLock) =>
179
+ checkFile(fileLocations.styleTokensProvider[fileLock.assetId])
180
+ );
181
+ assert(styleTokensProviderChecksums.length < 2);
182
+ const styleTokensProviderChecksum =
183
+ styleTokensProviderChecksums.length > 0
184
+ ? styleTokensProviderChecksums[0].checksum
185
+ : "";
186
+
187
+ const projectModuleChecksums = fileLocks
188
+ .filter(
189
+ (fileLock) =>
190
+ fileLock.type === "projectModule" && fileLock.assetId === projectId
191
+ )
192
+ .filter((fileLock) =>
193
+ checkFile(fileLocations.projectModule[fileLock.assetId])
194
+ );
195
+ assert(projectModuleChecksums.length < 2);
196
+ const projectModuleChecksum =
197
+ projectModuleChecksums.length > 0 ? projectModuleChecksums[0].checksum : "";
198
+
164
199
  const splitsProviderChecksums = fileLocks
165
200
  .filter(
166
201
  (fileLock) =>
@@ -184,5 +219,7 @@ export function getChecksums(
184
219
  projectCssChecksum,
185
220
  globalContextsChecksum,
186
221
  splitsProviderChecksum,
222
+ styleTokensProviderChecksum,
223
+ projectModuleChecksum,
187
224
  };
188
225
  }
@@ -13,7 +13,9 @@ import {
13
13
  fixComponentCssReferences,
14
14
  fixComponentImagesReferences,
15
15
  } from "../actions/sync-images";
16
+ import { getProjectModuleResourcePath } from "../actions/sync-project-module";
16
17
  import { getSplitsProviderResourcePath } from "../actions/sync-splits-provider";
18
+ import { getStyleTokensProviderResourcePath } from "../actions/sync-style-tokens-provider";
17
19
  import { logger } from "../deps";
18
20
  import { GLOBAL_SETTINGS } from "../globals";
19
21
  import { HandledError } from "../utils/error";
@@ -173,6 +175,8 @@ type PlasmicImportType =
173
175
  | "globalContext"
174
176
  | "customFunction"
175
177
  | "splitsProvider"
178
+ | "styleTokensProvider"
179
+ | "projectModule"
176
180
  | "rscClient"
177
181
  | "rscServer"
178
182
  | undefined;
@@ -203,7 +207,7 @@ function tryParsePlasmicImportSpec(node: ImportDeclaration) {
203
207
  "plasmic-import:\\s+([",
204
208
  ...validJsIdentifierChars,
205
209
  "\\.",
206
- "]+)(?:\\/(component|css|render|globalVariant|projectcss|defaultcss|icon|picture|jsBundle|codeComponent|globalContext|customFunction|splitsProvider|rscClient|rscServer))?",
210
+ "]+)(?:\\/(component|css|render|globalVariant|projectcss|defaultcss|icon|picture|jsBundle|codeComponent|globalContext|customFunction|splitsProvider|styleTokensProvider|projectModule|rscClient|rscServer))?",
207
211
  ].join("")
208
212
  )
209
213
  );
@@ -441,6 +445,30 @@ export function replaceImports(
441
445
  true
442
446
  );
443
447
  stmt.source.value = realPath;
448
+ } else if (type === "styleTokensProvider") {
449
+ const projectConfig = fixImportContext.projects[uuid];
450
+ if (!projectConfig) {
451
+ throwMissingReference(context, "project", uuid, fromPath);
452
+ }
453
+ const realPath = makeImportPath(
454
+ context,
455
+ fromPath,
456
+ projectConfig.styleTokensProviderFilePath,
457
+ true
458
+ );
459
+ stmt.source.value = realPath;
460
+ } else if (type === "projectModule") {
461
+ const projectConfig = fixImportContext.projects[uuid];
462
+ if (!projectConfig) {
463
+ throwMissingReference(context, "project", uuid, fromPath);
464
+ }
465
+ const realPath = makeImportPath(
466
+ context,
467
+ fromPath,
468
+ projectConfig.projectModuleFilePath,
469
+ true
470
+ );
471
+ stmt.source.value = realPath;
444
472
  } else if (type === "rscClient") {
445
473
  const compConfig = fixImportContext.components[uuid];
446
474
  if (!compConfig) {
@@ -668,7 +696,13 @@ export async function fixAllImportStatements(
668
696
  }
669
697
 
670
698
  try {
671
- fixSplitsProviderImportStatements(context, fixImportContext, baseDir);
699
+ fixImportStatements(
700
+ context,
701
+ fixImportContext,
702
+ baseDir,
703
+ "splitsProviderFilePath",
704
+ getSplitsProviderResourcePath
705
+ );
672
706
  } catch (err) {
673
707
  logger.error(
674
708
  `Error encountered while fixing imports for splits provider: ${err}`
@@ -676,6 +710,36 @@ export async function fixAllImportStatements(
676
710
  lastError = err;
677
711
  }
678
712
 
713
+ try {
714
+ fixImportStatements(
715
+ context,
716
+ fixImportContext,
717
+ baseDir,
718
+ "projectModuleFilePath",
719
+ getProjectModuleResourcePath
720
+ );
721
+ } catch (err) {
722
+ logger.error(
723
+ `Error encountered while fixing imports for project module bundle: ${err}`
724
+ );
725
+ lastError = err;
726
+ }
727
+
728
+ try {
729
+ fixImportStatements(
730
+ context,
731
+ fixImportContext,
732
+ baseDir,
733
+ "styleTokensProviderFilePath",
734
+ getStyleTokensProviderResourcePath
735
+ );
736
+ } catch (err) {
737
+ logger.error(
738
+ `Error encountered while fixing imports for style tokens provider: ${err}`
739
+ );
740
+ lastError = err;
741
+ }
742
+
679
743
  if (lastError) {
680
744
  throw lastError;
681
745
  }
@@ -901,14 +965,17 @@ async function fixGlobalContextImportStatements(
901
965
  }
902
966
  }
903
967
 
904
- async function fixSplitsProviderImportStatements(
968
+ async function fixImportStatements(
905
969
  context: PlasmicContext,
906
970
  fixImportContext: FixImportContext,
907
- baseDir: string
971
+ baseDir: string,
972
+ configKey: keyof ProjectConfig,
973
+ getResourcePath: (context: PlasmicContext, project: ProjectConfig) => string
908
974
  ) {
909
975
  for (const project of context.config.projects) {
910
- if (!project.splitsProviderFilePath) continue;
911
- const resourcePath = getSplitsProviderResourcePath(context, project);
976
+ if (!project[configKey]) continue;
977
+
978
+ const resourcePath = getResourcePath(context, project);
912
979
 
913
980
  let prevContent: string;
914
981
  try {
@@ -191,6 +191,10 @@ export interface ProjectConfig {
191
191
  globalContextsFilePath: string;
192
192
  /** File location for the project-wide splits provider. Relative to srcDir */
193
193
  splitsProviderFilePath: string;
194
+ /** File location for the project-wide style tokens provider. Relative to srcDir */
195
+ styleTokensProviderFilePath: string;
196
+ /** File location for the project-wide plasmic.ts file. Relative to srcDir */
197
+ projectModuleFilePath: string;
194
198
 
195
199
  // Code-component-related fields can be treated as optional not to be shown
196
200
  // to the users nor appear to be missing in the documentation.
@@ -234,6 +238,8 @@ export function createProjectConfig(base: {
234
238
  indirect: base.indirect,
235
239
  globalContextsFilePath: "",
236
240
  splitsProviderFilePath: "",
241
+ styleTokensProviderFilePath: "",
242
+ projectModuleFilePath: "",
237
243
  };
238
244
  }
239
245
 
@@ -361,7 +367,9 @@ export interface FileLock {
361
367
  | "projectCss"
362
368
  | "globalVariant"
363
369
  | "globalContexts"
364
- | "splitsProvider";
370
+ | "splitsProvider"
371
+ | "styleTokensProvider"
372
+ | "projectModule";
365
373
  // The checksum value for the file
366
374
  checksum: string;
367
375
  // The component id, or the image asset id
@@ -611,6 +619,8 @@ export function getOrAddProjectConfig(
611
619
  indirect: false,
612
620
  globalContextsFilePath: "",
613
621
  splitsProviderFilePath: "",
622
+ styleTokensProviderFilePath: "",
623
+ projectModuleFilePath: "",
614
624
  };
615
625
  context.config.projects.push(project);
616
626
  }
@@ -101,6 +101,10 @@ function removeMissingFilesFromLock(
101
101
  return knownProjects[project.projectId].globalContextsFilePath;
102
102
  case "splitsProvider":
103
103
  return knownProjects[project.projectId].splitsProviderFilePath;
104
+ case "projectModule":
105
+ return knownProjects[project.projectId].projectModuleFilePath;
106
+ case "styleTokensProvider":
107
+ return knownProjects[project.projectId].styleTokensProviderFilePath;
104
108
  }
105
109
  });
106
110
 
@@ -243,6 +247,30 @@ async function resolveMissingFilesInConfig(
243
247
  baseNameToFiles
244
248
  )) || project.splitsProviderFilePath;
245
249
 
250
+ if (!project.styleTokensProviderFilePath) {
251
+ project.styleTokensProviderFilePath = "";
252
+ }
253
+
254
+ // Try to find the file, otherwise recreate at either the specified path or default path (if both are falsey)
255
+ project.styleTokensProviderFilePath =
256
+ (await attemptToRestoreFilePath(
257
+ context,
258
+ project.styleTokensProviderFilePath,
259
+ baseNameToFiles
260
+ )) || project.styleTokensProviderFilePath;
261
+
262
+ if (!project.projectModuleFilePath) {
263
+ project.projectModuleFilePath = "";
264
+ }
265
+
266
+ // Try to find the file, otherwise recreate at either the specified path or default path (if both are falsey)
267
+ project.projectModuleFilePath =
268
+ (await attemptToRestoreFilePath(
269
+ context,
270
+ project.projectModuleFilePath,
271
+ baseNameToFiles
272
+ )) || project.projectModuleFilePath;
273
+
246
274
  project.images = await filterFiles(project.images, "filePath");
247
275
  project.icons = await filterFiles(project.icons, "moduleFilePath");
248
276
 
@@ -2,8 +2,8 @@ import fs from "fs";
2
2
  import * as path from "path";
3
3
  import * as tmp from "tmp";
4
4
  import {
5
- AuthConfig,
6
5
  AUTH_FILE_NAME,
6
+ AuthConfig,
7
7
  CONFIG_FILE_NAME,
8
8
  PlasmicConfig,
9
9
  } from "../utils/config-utils";