@plasmicapp/cli 0.1.341 → 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.
@@ -434,6 +434,10 @@
434
434
  "description": "Project ID",
435
435
  "type": "string"
436
436
  },
437
+ "projectModuleFilePath": {
438
+ "description": "File location for the project-wide plasmic.ts file. Relative to srcDir",
439
+ "type": "string"
440
+ },
437
441
  "projectName": {
438
442
  "description": "Project name synced down from Studio",
439
443
  "type": "string"
@@ -442,6 +446,10 @@
442
446
  "description": "File location for the project-wide splits provider. Relative to srcDir",
443
447
  "type": "string"
444
448
  },
449
+ "styleTokensProviderFilePath": {
450
+ "description": "File location for the project-wide style tokens provider. Relative to srcDir",
451
+ "type": "string"
452
+ },
445
453
  "version": {
446
454
  "description": "A version range for syncing this project. Can be:\n* \"latest\" - always syncs down whatever has been saved in the project.\n* \">0\" - always syncs down the latest published version of the project.\n* any other semver string you'd like",
447
455
  "type": "string"
@@ -455,8 +463,10 @@
455
463
  "images",
456
464
  "indirect",
457
465
  "projectId",
466
+ "projectModuleFilePath",
458
467
  "projectName",
459
468
  "splitsProviderFilePath",
469
+ "styleTokensProviderFilePath",
460
470
  "version"
461
471
  ],
462
472
  "type": "object"
@@ -144,6 +144,10 @@ export interface ProjectConfig {
144
144
  globalContextsFilePath: string;
145
145
  /** File location for the project-wide splits provider. Relative to srcDir */
146
146
  splitsProviderFilePath: string;
147
+ /** File location for the project-wide style tokens provider. Relative to srcDir */
148
+ styleTokensProviderFilePath: string;
149
+ /** File location for the project-wide plasmic.ts file. Relative to srcDir */
150
+ projectModuleFilePath: string;
147
151
  jsBundleThemes?: JsBundleThemeConfig[];
148
152
  codeComponents?: CodeComponentConfig[];
149
153
  customFunctions?: CustomFunctionConfig[];
@@ -260,7 +264,7 @@ export interface GlobalVariantGroupConfig {
260
264
  contextFilePath: string;
261
265
  }
262
266
  export interface FileLock {
263
- type: "renderModule" | "cssRules" | "icon" | "image" | "projectCss" | "globalVariant" | "globalContexts" | "splitsProvider";
267
+ type: "renderModule" | "cssRules" | "icon" | "image" | "projectCss" | "globalVariant" | "globalContexts" | "splitsProvider" | "styleTokensProvider" | "projectModule";
264
268
  checksum: string;
265
269
  assetId: string;
266
270
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plasmicapp/cli",
3
- "version": "0.1.341",
3
+ "version": "0.1.342",
4
4
  "description": "plasmic cli for syncing local code with Plasmic designs",
5
5
  "engines": {
6
6
  "node": ">=12"
@@ -83,5 +83,5 @@
83
83
  "wrap-ansi": "^7.0.0",
84
84
  "yargs": "^15.4.1"
85
85
  },
86
- "gitHead": "fcc97c73f5bb7a9eddf27528e2769d33a8c4f069"
86
+ "gitHead": "354b30e84489d6a01d96855a04c844aa4fa80f3a"
87
87
  }
@@ -355,6 +355,8 @@ class PlasmicApi {
355
355
  projectCssChecksum: "",
356
356
  globalContextsChecksum: "",
357
357
  splitsProviderChecksum: "",
358
+ styleTokensProviderChecksum: "",
359
+ projectModuleChecksum: "",
358
360
  } as ChecksumBundle,
359
361
  usedNpmPackages: [],
360
362
  externalCssImports: [],
@@ -10,17 +10,19 @@ import {
10
10
  } from "../utils/code-utils";
11
11
  import {
12
12
  CodeConfig,
13
- findConfigFile,
14
13
  I18NConfig,
15
14
  ImagesConfig,
16
15
  PlasmicConfig,
17
16
  StyleConfig,
17
+ findConfigFile,
18
18
  } from "../utils/config-utils";
19
19
  import { getContext, getCurrentOrDefaultAuth } from "../utils/get-context";
20
20
  import { tuple } from "../utils/lang-utils";
21
21
  import { DEFAULT_GLOBAL_CONTEXTS_NAME } from "./sync-global-contexts";
22
22
  import { ensureImageAssetContents } from "./sync-images";
23
+ import { DEFAULT_PROJECT_MODULE_NAME } from "./sync-project-module";
23
24
  import { DEFAULT_SPLITS_PROVIDER_NAME } from "./sync-splits-provider";
25
+ import { DEFAULT_STYLE_TOKENS_PROVIDER_NAME } from "./sync-style-tokens-provider";
24
26
 
25
27
  export interface ExportArgs extends CommonArgs {
26
28
  projects: readonly string[];
@@ -138,6 +140,20 @@ export async function exportProjectsCli(opts: ExportArgs): Promise<void> {
138
140
  );
139
141
  }
140
142
 
143
+ if (bundle.projectConfig.styleTokensProviderBundle) {
144
+ writeFile(
145
+ `${DEFAULT_STYLE_TOKENS_PROVIDER_NAME}.${extx}`,
146
+ bundle.projectConfig.styleTokensProviderBundle.module
147
+ );
148
+ }
149
+
150
+ if (bundle.projectConfig.projectModuleBundle) {
151
+ writeFile(
152
+ `${DEFAULT_PROJECT_MODULE_NAME}.${extx}`,
153
+ bundle.projectConfig.projectModuleBundle.module
154
+ );
155
+ }
156
+
141
157
  if (bundle.projectConfig.reactWebExportedFiles) {
142
158
  for (const file of bundle.projectConfig.reactWebExportedFiles) {
143
159
  writeFile(file.fileName, file.content);
@@ -196,6 +212,13 @@ export async function exportProjectsCli(opts: ExportArgs): Promise<void> {
196
212
  splitsProviderFilePath: bundle.projectConfig.splitsProviderBundle
197
213
  ? `${projectName}/${DEFAULT_SPLITS_PROVIDER_NAME}.${extx}`
198
214
  : "",
215
+ styleTokensProviderFilePath: bundle.projectConfig
216
+ .styleTokensProviderBundle
217
+ ? `${projectName}/${DEFAULT_STYLE_TOKENS_PROVIDER_NAME}.${extx}`
218
+ : "",
219
+ projectModuleFilePath: bundle.projectConfig.projectModuleBundle
220
+ ? `${projectName}/${DEFAULT_PROJECT_MODULE_NAME}.${extx}`
221
+ : "",
199
222
  components: bundle.components.map((comp) => ({
200
223
  id: comp.id,
201
224
  name: comp.componentName,
@@ -351,6 +374,22 @@ async function exportProjects(api: PlasmicApi, opts: ExportOpts) {
351
374
  );
352
375
  proj.projectConfig.splitsProviderBundle.module = res[1];
353
376
  }
377
+ if (proj.projectConfig.styleTokensProviderBundle) {
378
+ const res = maybeConvertTsxToJsx(
379
+ `${DEFAULT_STYLE_TOKENS_PROVIDER_NAME}.tsx`,
380
+ proj.projectConfig.styleTokensProviderBundle.module,
381
+ "."
382
+ );
383
+ proj.projectConfig.styleTokensProviderBundle.module = res[1];
384
+ }
385
+ if (proj.projectConfig.projectModuleBundle) {
386
+ const res = maybeConvertTsxToJsx(
387
+ `${DEFAULT_PROJECT_MODULE_NAME}.tsx`,
388
+ proj.projectConfig.projectModuleBundle.module,
389
+ "."
390
+ );
391
+ proj.projectConfig.projectModuleBundle.module = res[1];
392
+ }
354
393
  }
355
394
  }
356
395
 
@@ -0,0 +1,88 @@
1
+ import L from "lodash";
2
+ import { ChecksumBundle, ProjectMetaBundle } from "../api";
3
+ import { logger } from "../deps";
4
+ import { formatScript, tsxToJsx } from "../utils/code-utils";
5
+ import {
6
+ PlasmicContext,
7
+ ProjectConfig,
8
+ ProjectLock,
9
+ } from "../utils/config-utils";
10
+ import {
11
+ defaultResourcePath,
12
+ deleteFile,
13
+ fileExists,
14
+ writeFileContent,
15
+ } from "../utils/file-utils";
16
+
17
+ const MODULE_NAME = "plasmic";
18
+ export const DEFAULT_PROJECT_MODULE_NAME = MODULE_NAME;
19
+
20
+ export async function syncProjectModule(
21
+ context: PlasmicContext,
22
+ projectMeta: ProjectMetaBundle,
23
+ projectConfig: ProjectConfig,
24
+ projectLock: ProjectLock,
25
+ checksums: ChecksumBundle,
26
+ baseDir: string
27
+ ) {
28
+ const resourcePath = getProjectModuleResourcePath(context, projectConfig);
29
+ if (checksums.projectModuleChecksum && projectMeta.projectModuleBundle) {
30
+ if (context.cliArgs.quiet !== true) {
31
+ logger.info(
32
+ `Syncing module: ${MODULE_NAME}@${projectLock.version}\t['${projectConfig.projectName}' ${projectConfig.projectId} ${projectConfig.version}]`
33
+ );
34
+ }
35
+ if (context.config.code.lang === "js") {
36
+ projectMeta.projectModuleBundle.module = formatScript(
37
+ tsxToJsx(projectMeta.projectModuleBundle.module),
38
+ baseDir
39
+ );
40
+ }
41
+ writeFileContent(
42
+ context,
43
+ resourcePath,
44
+ projectMeta.projectModuleBundle.module,
45
+ { force: true }
46
+ );
47
+ projectConfig.projectModuleFilePath = resourcePath;
48
+ const fl = projectLock.fileLocks.find(
49
+ (fl) =>
50
+ fl.assetId === projectConfig.projectId && fl.type === "projectModule"
51
+ );
52
+ if (fl) {
53
+ fl.checksum = checksums.projectModuleChecksum || "";
54
+ } else {
55
+ projectLock.fileLocks.push({
56
+ assetId: projectConfig.projectId,
57
+ checksum: checksums.projectModuleChecksum || "",
58
+ type: "projectModule",
59
+ });
60
+ }
61
+ } else if (
62
+ !checksums.projectModuleChecksum &&
63
+ !projectMeta.projectModuleBundle
64
+ ) {
65
+ if (fileExists(context, resourcePath)) {
66
+ deleteFile(context, resourcePath);
67
+ }
68
+ projectConfig.projectModuleFilePath = "";
69
+ L.remove(
70
+ projectLock.fileLocks,
71
+ (fl) =>
72
+ fl.assetId === projectConfig.projectId && fl.type === "projectModule"
73
+ );
74
+ }
75
+ }
76
+
77
+ export function getProjectModuleResourcePath(
78
+ context: PlasmicContext,
79
+ projectConfig: ProjectConfig
80
+ ) {
81
+ return projectConfig.projectModuleFilePath !== ""
82
+ ? projectConfig.projectModuleFilePath
83
+ : defaultResourcePath(
84
+ context,
85
+ projectConfig.projectName,
86
+ `${MODULE_NAME}.${context.config.code.lang === "ts" ? "tsx" : "jsx"}`
87
+ );
88
+ }
@@ -0,0 +1,96 @@
1
+ import L from "lodash";
2
+ import { ChecksumBundle, ProjectMetaBundle } from "../api";
3
+ import { logger } from "../deps";
4
+ import { formatScript, tsxToJsx } from "../utils/code-utils";
5
+ import {
6
+ PlasmicContext,
7
+ ProjectConfig,
8
+ ProjectLock,
9
+ } from "../utils/config-utils";
10
+ import {
11
+ defaultResourcePath,
12
+ deleteFile,
13
+ fileExists,
14
+ writeFileContent,
15
+ } from "../utils/file-utils";
16
+
17
+ const MODULE_NAME = "PlasmicStyleTokensProvider";
18
+ export const DEFAULT_STYLE_TOKENS_PROVIDER_NAME = MODULE_NAME;
19
+
20
+ export async function syncStyleTokensProvider(
21
+ context: PlasmicContext,
22
+ projectMeta: ProjectMetaBundle,
23
+ projectConfig: ProjectConfig,
24
+ projectLock: ProjectLock,
25
+ checksums: ChecksumBundle,
26
+ baseDir: string
27
+ ) {
28
+ const resourcePath = getStyleTokensProviderResourcePath(
29
+ context,
30
+ projectConfig
31
+ );
32
+ if (
33
+ checksums.styleTokensProviderChecksum &&
34
+ projectMeta.styleTokensProviderBundle
35
+ ) {
36
+ if (context.cliArgs.quiet !== true) {
37
+ logger.info(
38
+ `Syncing module: ${MODULE_NAME}@${projectLock.version}\t['${projectConfig.projectName}' ${projectConfig.projectId} ${projectConfig.version}]`
39
+ );
40
+ }
41
+ if (context.config.code.lang === "js") {
42
+ projectMeta.styleTokensProviderBundle.module = formatScript(
43
+ tsxToJsx(projectMeta.styleTokensProviderBundle.module),
44
+ baseDir
45
+ );
46
+ }
47
+ writeFileContent(
48
+ context,
49
+ resourcePath,
50
+ projectMeta.styleTokensProviderBundle.module,
51
+ { force: true }
52
+ );
53
+ projectConfig.styleTokensProviderFilePath = resourcePath;
54
+ const fl = projectLock.fileLocks.find(
55
+ (fl) =>
56
+ fl.assetId === projectConfig.projectId &&
57
+ fl.type === "styleTokensProvider"
58
+ );
59
+ if (fl) {
60
+ fl.checksum = checksums.styleTokensProviderChecksum || "";
61
+ } else {
62
+ projectLock.fileLocks.push({
63
+ assetId: projectConfig.projectId,
64
+ checksum: checksums.styleTokensProviderChecksum || "",
65
+ type: "styleTokensProvider",
66
+ });
67
+ }
68
+ } else if (
69
+ !checksums.styleTokensProviderChecksum &&
70
+ !projectMeta.styleTokensProviderBundle
71
+ ) {
72
+ if (fileExists(context, resourcePath)) {
73
+ deleteFile(context, resourcePath);
74
+ }
75
+ projectConfig.styleTokensProviderFilePath = "";
76
+ L.remove(
77
+ projectLock.fileLocks,
78
+ (fl) =>
79
+ fl.assetId === projectConfig.projectId &&
80
+ fl.type === "styleTokensProvider"
81
+ );
82
+ }
83
+ }
84
+
85
+ export function getStyleTokensProviderResourcePath(
86
+ context: PlasmicContext,
87
+ projectConfig: ProjectConfig
88
+ ) {
89
+ return projectConfig.styleTokensProviderFilePath !== ""
90
+ ? projectConfig.styleTokensProviderFilePath
91
+ : defaultResourcePath(
92
+ context,
93
+ projectConfig.projectName,
94
+ `${MODULE_NAME}.${context.config.code.lang === "ts" ? "tsx" : "jsx"}`
95
+ );
96
+ }
@@ -56,7 +56,9 @@ import { syncGlobalContexts } from "./sync-global-contexts";
56
56
  import { syncGlobalVariants } from "./sync-global-variants";
57
57
  import { syncProjectIconAssets } from "./sync-icons";
58
58
  import { syncProjectImageAssets } from "./sync-images";
59
+ import { syncProjectModule } from "./sync-project-module";
59
60
  import { syncSplitsProvider } from "./sync-splits-provider";
61
+ import { syncStyleTokensProvider } from "./sync-style-tokens-provider";
60
62
  import { upsertStyleTokens } from "./sync-styles";
61
63
 
62
64
  export interface SyncArgs extends CommonArgs {
@@ -781,6 +783,24 @@ async function syncProjectConfig(
781
783
  baseDir
782
784
  );
783
785
 
786
+ await syncProjectModule(
787
+ context,
788
+ projectBundle,
789
+ projectConfig,
790
+ projectLock,
791
+ checksums,
792
+ baseDir
793
+ );
794
+
795
+ await syncStyleTokensProvider(
796
+ context,
797
+ projectBundle,
798
+ projectConfig,
799
+ projectLock,
800
+ checksums,
801
+ baseDir
802
+ );
803
+
784
804
  // Write out components
785
805
  await syncProjectComponents(
786
806
  context,
package/src/api.ts CHANGED
@@ -65,6 +65,16 @@ export interface SplitsProviderBundle {
65
65
  module: string;
66
66
  }
67
67
 
68
+ export interface StyleTokensProviderBundle {
69
+ id: string;
70
+ module: string;
71
+ }
72
+
73
+ export interface ProjectModuleBundle {
74
+ id: string;
75
+ module: string;
76
+ }
77
+
68
78
  export interface JsBundleTheme {
69
79
  themeFileName: string;
70
80
  themeModule: string;
@@ -78,6 +88,8 @@ export interface ProjectMetaBundle {
78
88
  cssRules: string;
79
89
  globalContextBundle?: GlobalContextBundle;
80
90
  splitsProviderBundle?: SplitsProviderBundle;
91
+ styleTokensProviderBundle?: StyleTokensProviderBundle;
92
+ projectModuleBundle?: ProjectModuleBundle;
81
93
  // A list of files that are exported from the project and *can* be used by the user
82
94
  reactWebExportedFiles?: Array<{
83
95
  fileName: string;
@@ -189,6 +201,10 @@ export interface ChecksumBundle {
189
201
  globalContextsChecksum: string;
190
202
  // Checksum of project splits provider
191
203
  splitsProviderChecksum: string;
204
+ // Checksum of project style tokens provider
205
+ styleTokensProviderChecksum: string;
206
+ // Checksum of project plasmic.ts
207
+ projectModuleChecksum: string;
192
208
  }
193
209
 
194
210
  export interface CodeComponentMeta {
@@ -151,6 +151,8 @@ export const project1Config: ProjectConfig = {
151
151
  indirect: false,
152
152
  globalContextsFilePath: "",
153
153
  splitsProviderFilePath: "",
154
+ styleTokensProviderFilePath: "",
155
+ projectModuleFilePath: "",
154
156
  };
155
157
 
156
158
  export function expectProject1PlasmicJson(optional?: {
@@ -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
  }