@plasmicapp/cli 0.1.340 → 0.1.342

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.
@@ -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
@@ -608,10 +616,11 @@ export function getOrAddProjectConfig(
608
616
  components: [],
609
617
  icons: [],
610
618
  images: [],
611
- jsBundleThemes: [],
612
619
  indirect: false,
613
620
  globalContextsFilePath: "",
614
621
  splitsProviderFilePath: "",
622
+ styleTokensProviderFilePath: "",
623
+ projectModuleFilePath: "",
615
624
  };
616
625
  context.config.projects.push(project);
617
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,12 +247,32 @@ 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
- project.jsBundleThemes = await filterFiles(
249
- project.jsBundleThemes || [],
250
- "themeFilePath"
251
- );
252
276
 
253
277
  // For components, if they decide to recreate in any of the path (css, wrapper, or blackbox component)
254
278
  // we'll delete existing files.
@@ -1,2 +0,0 @@
1
- import { PlasmicConfig } from "../utils/config-utils";
2
- export declare function ensureJsBundleThemes(config: PlasmicConfig): PlasmicConfig;
@@ -1,10 +0,0 @@
1
- import { PlasmicConfig } from "../utils/config-utils";
2
-
3
- export function ensureJsBundleThemes(config: PlasmicConfig) {
4
- for (const proj of config.projects) {
5
- if (!proj.jsBundleThemes) {
6
- proj.jsBundleThemes = [];
7
- }
8
- }
9
- return config;
10
- }