@plasmicapp/cli 0.1.348 → 0.1.350

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.
@@ -394,6 +394,10 @@
394
394
  },
395
395
  "type": "array"
396
396
  },
397
+ "dataTokensFilePath": {
398
+ "description": "File location for the project-wide data tokens provider. Relative to srcDir",
399
+ "type": "string"
400
+ },
397
401
  "globalContextsFilePath": {
398
402
  "description": "File location for the project-wide global contexts. Relative to srcDir",
399
403
  "type": "string"
@@ -458,6 +462,7 @@
458
462
  "required": [
459
463
  "components",
460
464
  "cssFilePath",
465
+ "dataTokensFilePath",
461
466
  "globalContextsFilePath",
462
467
  "icons",
463
468
  "images",
@@ -148,6 +148,8 @@ export interface ProjectConfig {
148
148
  splitsProviderFilePath: string;
149
149
  /** File location for the project-wide style tokens provider. Relative to srcDir */
150
150
  styleTokensProviderFilePath: string;
151
+ /** File location for the project-wide data tokens provider. Relative to srcDir */
152
+ dataTokensFilePath: string;
151
153
  /** File location for the project-wide plasmic.ts file. Relative to srcDir */
152
154
  projectModuleFilePath: string;
153
155
  jsBundleThemes?: JsBundleThemeConfig[];
@@ -266,7 +268,7 @@ export interface GlobalVariantGroupConfig {
266
268
  contextFilePath: string;
267
269
  }
268
270
  export interface FileLock {
269
- type: "renderModule" | "cssRules" | "icon" | "image" | "projectCss" | "globalVariant" | "globalContexts" | "splitsProvider" | "styleTokensProvider" | "projectModule";
271
+ type: "renderModule" | "cssRules" | "icon" | "image" | "projectCss" | "globalVariant" | "globalContexts" | "splitsProvider" | "styleTokensProvider" | "dataTokens" | "projectModule";
270
272
  checksum: string;
271
273
  assetId: string;
272
274
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plasmicapp/cli",
3
- "version": "0.1.348",
3
+ "version": "0.1.350",
4
4
  "description": "plasmic cli for syncing local code with Plasmic designs",
5
5
  "engines": {
6
6
  "node": ">=12"
@@ -82,5 +82,5 @@
82
82
  "wrap-ansi": "^7.0.0",
83
83
  "yargs": "^15.4.1"
84
84
  },
85
- "gitHead": "dff908ba603a5e5385e126fa431de2e96e497960"
85
+ "gitHead": "1e8a75eb4e5dcf4aa0c74b830234d5a0c3e2eabf"
86
86
  }
@@ -181,7 +181,7 @@ function genEmptyStyleTokensMap() {
181
181
  props: [],
182
182
  global: {
183
183
  meta: {
184
- source: "plasmic.app" as "plasmic.app",
184
+ source: "plasmic.app" as const,
185
185
  },
186
186
  },
187
187
  };
@@ -269,7 +269,7 @@ class PlasmicApi {
269
269
  });
270
270
 
271
271
  // Get dependencies
272
- if (!!recursive) {
272
+ if (recursive) {
273
273
  const deps = [...getDeps(results.projects)];
274
274
  results.dependencies.push(...deps);
275
275
  }
@@ -356,6 +356,7 @@ class PlasmicApi {
356
356
  globalContextsChecksum: "",
357
357
  splitsProviderChecksum: "",
358
358
  styleTokensProviderChecksum: "",
359
+ dataTokensChecksum: "",
359
360
  projectModuleChecksum: "",
360
361
  } as ChecksumBundle,
361
362
  usedNpmPackages: [],
@@ -365,25 +366,25 @@ class PlasmicApi {
365
366
  }
366
367
 
367
368
  async uploadBundle(
368
- projectId: string,
369
- bundleName: string,
370
- bundleJs: string,
371
- css: string[],
372
- metaJson: string
369
+ _projectId: string,
370
+ _bundleName: string,
371
+ _bundleJs: string,
372
+ _css: string[],
373
+ _metaJson: string
373
374
  ): Promise<StyleTokensMap> {
374
375
  throw new Error("Unimplemented");
375
376
  }
376
377
 
377
378
  async projectStyleTokens(
378
- projectId: string,
379
- branchName: string
379
+ _projectId: string,
380
+ _branchName: string
380
381
  ): Promise<StyleTokensMap> {
381
382
  throw new Error("Unimplemented");
382
383
  }
383
384
 
384
385
  async projectIcons(
385
- projectId: string,
386
- branchName: string
386
+ _projectId: string,
387
+ _branchName: string
387
388
  ): Promise<ProjectIconsResponse> {
388
389
  throw new Error("Unimplemented");
389
390
  }
@@ -18,6 +18,7 @@ import {
18
18
  } from "../utils/config-utils";
19
19
  import { getContext, getCurrentOrDefaultAuth } from "../utils/get-context";
20
20
  import { tuple } from "../utils/lang-utils";
21
+ import { DEFAULT_DATA_TOKENS_NAME } from "./sync-data-tokens";
21
22
  import { DEFAULT_GLOBAL_CONTEXTS_NAME } from "./sync-global-contexts";
22
23
  import { ensureImageAssetContents } from "./sync-images";
23
24
  import { DEFAULT_PROJECT_MODULE_NAME } from "./sync-project-module";
@@ -212,6 +213,9 @@ export async function exportProjectsCli(opts: ExportArgs): Promise<void> {
212
213
  .styleTokensProviderBundle
213
214
  ? `${projectName}/${DEFAULT_STYLE_TOKENS_PROVIDER_NAME}.${extx}`
214
215
  : "",
216
+ dataTokensFilePath: bundle.projectConfig.dataTokensBundle
217
+ ? `${projectName}/${DEFAULT_DATA_TOKENS_NAME}.${opts.codeLang}`
218
+ : "",
215
219
  projectModuleFilePath: bundle.projectConfig.projectModuleBundle
216
220
  ? `${projectName}/${DEFAULT_PROJECT_MODULE_NAME}.${extx}`
217
221
  : "",
@@ -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-data-tokens";
18
+ export const DEFAULT_DATA_TOKENS_NAME = MODULE_NAME;
19
+
20
+ export async function syncDataTokens(
21
+ context: PlasmicContext,
22
+ projectMeta: ProjectMetaBundle,
23
+ projectConfig: ProjectConfig,
24
+ projectLock: ProjectLock,
25
+ checksums: ChecksumBundle,
26
+ baseDir: string
27
+ ) {
28
+ const resourcePath = getDataTokensResourcePath(context, projectConfig);
29
+ if (checksums.dataTokensChecksum && projectMeta.dataTokensBundle) {
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.dataTokensBundle.module = await formatScript(
37
+ tsxToJsx(projectMeta.dataTokensBundle.module),
38
+ baseDir
39
+ );
40
+ }
41
+ writeFileContent(
42
+ context,
43
+ resourcePath,
44
+ projectMeta.dataTokensBundle.module,
45
+ { force: true }
46
+ );
47
+ projectConfig.dataTokensFilePath = resourcePath;
48
+ const fl = projectLock.fileLocks.find(
49
+ (lock) =>
50
+ lock.assetId === projectConfig.projectId && lock.type === "dataTokens"
51
+ );
52
+ if (fl) {
53
+ fl.checksum = checksums.dataTokensChecksum || "";
54
+ } else {
55
+ projectLock.fileLocks.push({
56
+ assetId: projectConfig.projectId,
57
+ checksum: checksums.dataTokensChecksum || "",
58
+ type: "dataTokens",
59
+ });
60
+ }
61
+ } else if (!checksums.dataTokensChecksum && !projectMeta.dataTokensBundle) {
62
+ // Only try to delete if there was a previously configured path
63
+ if (projectConfig.dataTokensFilePath) {
64
+ if (fileExists(context, projectConfig.dataTokensFilePath)) {
65
+ deleteFile(context, projectConfig.dataTokensFilePath);
66
+ }
67
+ projectConfig.dataTokensFilePath = "";
68
+ }
69
+ L.remove(
70
+ projectLock.fileLocks,
71
+ (fl) => fl.assetId === projectConfig.projectId && fl.type === "dataTokens"
72
+ );
73
+ }
74
+ }
75
+
76
+ export function getDataTokensResourcePath(
77
+ context: PlasmicContext,
78
+ projectConfig: ProjectConfig
79
+ ) {
80
+ if (projectConfig.dataTokensFilePath) {
81
+ return projectConfig.dataTokensFilePath;
82
+ }
83
+ return defaultResourcePath(
84
+ context,
85
+ projectConfig.projectName,
86
+ `${MODULE_NAME}.${context.config.code.lang}`
87
+ );
88
+ }
@@ -52,6 +52,7 @@ import { checkVersionResolution } from "../utils/resolve-utils";
52
52
  import * as semver from "../utils/semver";
53
53
  import { confirmWithUser } from "../utils/user-utils";
54
54
  import { syncProjectComponents } from "./sync-components";
55
+ import { syncDataTokens } from "./sync-data-tokens";
55
56
  import { syncGlobalContexts } from "./sync-global-contexts";
56
57
  import { syncGlobalVariants } from "./sync-global-variants";
57
58
  import { syncProjectIconAssets } from "./sync-icons";
@@ -796,6 +797,15 @@ async function syncProjectConfig(
796
797
  baseDir
797
798
  );
798
799
 
800
+ await syncDataTokens(
801
+ context,
802
+ projectBundle,
803
+ projectConfig,
804
+ projectLock,
805
+ checksums,
806
+ baseDir
807
+ );
808
+
799
809
  // Write out components
800
810
  await syncProjectComponents(
801
811
  context,
package/src/api.ts CHANGED
@@ -71,6 +71,11 @@ export interface StyleTokensProviderBundle {
71
71
  module: string;
72
72
  }
73
73
 
74
+ export interface DataTokensBundle {
75
+ id: string;
76
+ module: string;
77
+ }
78
+
74
79
  export interface ProjectModuleBundle {
75
80
  id: string;
76
81
  module: string;
@@ -90,6 +95,7 @@ export interface ProjectMetaBundle {
90
95
  globalContextBundle?: GlobalContextBundle;
91
96
  splitsProviderBundle?: SplitsProviderBundle;
92
97
  styleTokensProviderBundle?: StyleTokensProviderBundle;
98
+ dataTokensBundle?: DataTokensBundle;
93
99
  projectModuleBundle?: ProjectModuleBundle;
94
100
  // A list of files that are exported from the project and *can* be used by the user
95
101
  reactWebExportedFiles?: Array<{
@@ -204,6 +210,8 @@ export interface ChecksumBundle {
204
210
  splitsProviderChecksum: string;
205
211
  // Checksum of project style tokens provider
206
212
  styleTokensProviderChecksum: string;
213
+ // Checksum of project data tokens provider
214
+ dataTokensChecksum: string;
207
215
  // Checksum of project plasmic.ts
208
216
  projectModuleChecksum: string;
209
217
  }
@@ -153,6 +153,7 @@ export const project1Config: ProjectConfig = {
153
153
  globalContextsFilePath: "",
154
154
  splitsProviderFilePath: "",
155
155
  styleTokensProviderFilePath: "",
156
+ dataTokensFilePath: "",
156
157
  projectModuleFilePath: "",
157
158
  };
158
159
 
@@ -36,6 +36,9 @@ function getFilesByFileLockAssetId(
36
36
  styleTokensProvider: {
37
37
  [projectConfig.projectId]: projectConfig.styleTokensProviderFilePath,
38
38
  },
39
+ dataTokens: {
40
+ [projectConfig.projectId]: projectConfig.dataTokensFilePath,
41
+ },
39
42
  projectModule: {
40
43
  [projectConfig.projectId]: projectConfig.projectModuleFilePath,
41
44
  },
@@ -53,7 +56,7 @@ export function getChecksums(
53
56
  );
54
57
 
55
58
  const projectLock = context.lock.projects.find(
56
- (projectLock) => projectLock.projectId === projectId
59
+ (lock) => lock.projectId === projectId
57
60
  );
58
61
 
59
62
  if (!projectConfig || !projectLock || opts.allFiles) {
@@ -67,6 +70,7 @@ export function getChecksums(
67
70
  globalContextsChecksum: "",
68
71
  splitsProviderChecksum: "",
69
72
  styleTokensProviderChecksum: "",
73
+ dataTokensChecksum: "",
70
74
  projectModuleChecksum: "",
71
75
  };
72
76
  }
@@ -210,6 +214,18 @@ export function getChecksums(
210
214
  ? splitsProviderChecksums[0].checksum
211
215
  : "";
212
216
 
217
+ const dataTokensChecksums = fileLocks
218
+ .filter(
219
+ (fileLock) =>
220
+ fileLock.type === "dataTokens" && fileLock.assetId === projectId
221
+ )
222
+ .filter((fileLock) =>
223
+ checkFile(fileLocations.dataTokens[fileLock.assetId])
224
+ );
225
+ assert(dataTokensChecksums.length < 2);
226
+ const dataTokensChecksum =
227
+ dataTokensChecksums.length > 0 ? dataTokensChecksums[0].checksum : "";
228
+
213
229
  return {
214
230
  imageChecksums,
215
231
  iconChecksums,
@@ -220,6 +236,7 @@ export function getChecksums(
220
236
  globalContextsChecksum,
221
237
  splitsProviderChecksum,
222
238
  styleTokensProviderChecksum,
239
+ dataTokensChecksum,
223
240
  projectModuleChecksum,
224
241
  };
225
242
  }
@@ -8,6 +8,7 @@ import type { Options } from "prettier";
8
8
  import * as Prettier from "prettier";
9
9
  import * as ts from "typescript";
10
10
  import path from "upath";
11
+ import { getDataTokensResourcePath } from "../actions/sync-data-tokens";
11
12
  import { getGlobalContextsResourcePath } from "../actions/sync-global-contexts";
12
13
  import {
13
14
  fixComponentCssReferences,
@@ -180,6 +181,7 @@ type PlasmicImportType =
180
181
  | "customFunction"
181
182
  | "splitsProvider"
182
183
  | "styleTokensProvider"
184
+ | "dataTokens"
183
185
  | "projectModule"
184
186
  | "rscClient"
185
187
  | "rscServer"
@@ -212,7 +214,7 @@ function tryParsePlasmicImportSpec(node: ImportDeclaration) {
212
214
  "plasmic-import:\\s+([",
213
215
  ...validJsIdentifierChars,
214
216
  "\\.",
215
- "]+)(?:\\/(component|css|render|globalVariant|projectcss|defaultcss|icon|picture|jsBundle|codeComponent|globalContext|customFunction|splitsProvider|styleTokensProvider|projectModule|rscClient|rscServer))?",
217
+ "]+)(?:\\/(component|css|render|globalVariant|projectcss|defaultcss|icon|picture|jsBundle|codeComponent|globalContext|customFunction|splitsProvider|styleTokensProvider|dataTokens|projectModule|rscClient|rscServer))?",
216
218
  ].join("")
217
219
  )
218
220
  );
@@ -448,6 +450,17 @@ export async function replaceImports(
448
450
  projectConfig.styleTokensProviderFilePath
449
451
  );
450
452
  stmt.source.value = realPath;
453
+ } else if (type === "dataTokens") {
454
+ const projectConfig = fixImportContext.projects[uuid];
455
+ if (!projectConfig) {
456
+ throwMissingReference(context, "project", uuid, fromPath);
457
+ }
458
+ const realPath = makeImportPath(
459
+ context,
460
+ fromPath,
461
+ projectConfig.dataTokensFilePath
462
+ );
463
+ stmt.source.value = realPath;
451
464
  } else if (type === "projectModule") {
452
465
  const projectConfig = fixImportContext.projects[uuid];
453
466
  if (!projectConfig) {
@@ -718,6 +731,21 @@ export async function fixAllImportStatements(
718
731
  lastError = err;
719
732
  }
720
733
 
734
+ try {
735
+ await fixImportStatements(
736
+ context,
737
+ fixImportContext,
738
+ baseDir,
739
+ "dataTokensFilePath",
740
+ getDataTokensResourcePath
741
+ );
742
+ } catch (err) {
743
+ logger.error(
744
+ `Error encountered while fixing imports for data tokens: ${err}`
745
+ );
746
+ lastError = err;
747
+ }
748
+
721
749
  if (lastError) {
722
750
  throw lastError;
723
751
  }
@@ -196,6 +196,8 @@ export interface ProjectConfig {
196
196
  splitsProviderFilePath: string;
197
197
  /** File location for the project-wide style tokens provider. Relative to srcDir */
198
198
  styleTokensProviderFilePath: string;
199
+ /** File location for the project-wide data tokens provider. Relative to srcDir */
200
+ dataTokensFilePath: string;
199
201
  /** File location for the project-wide plasmic.ts file. Relative to srcDir */
200
202
  projectModuleFilePath: string;
201
203
 
@@ -242,6 +244,7 @@ export function createProjectConfig(base: {
242
244
  globalContextsFilePath: "",
243
245
  splitsProviderFilePath: "",
244
246
  styleTokensProviderFilePath: "",
247
+ dataTokensFilePath: "",
245
248
  projectModuleFilePath: "",
246
249
  };
247
250
  }
@@ -372,6 +375,7 @@ export interface FileLock {
372
375
  | "globalContexts"
373
376
  | "splitsProvider"
374
377
  | "styleTokensProvider"
378
+ | "dataTokens"
375
379
  | "projectModule";
376
380
  // The checksum value for the file
377
381
  checksum: string;
@@ -628,6 +632,7 @@ export function getOrAddProjectConfig(
628
632
  globalContextsFilePath: "",
629
633
  splitsProviderFilePath: "",
630
634
  styleTokensProviderFilePath: "",
635
+ dataTokensFilePath: "",
631
636
  projectModuleFilePath: "",
632
637
  };
633
638
  context.config.projects.push(project);
package/tsconfig.json CHANGED
@@ -63,7 +63,14 @@
63
63
  "skipLibCheck": true,
64
64
 
65
65
  /* Advanced Options */
66
- "forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
66
+ "forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */,
67
+
68
+ "paths": {
69
+ // This package depends on inquirer@7, but we just installed inquirer@12 as a transitive dep.
70
+ // inquirere@12 which ships with .d.ts files, which tsc automatically finds and uses.
71
+ // This tells tsc to use @types/inquirer instead.
72
+ "inquirer": ["../../node_modules/@types/inquirer"]
73
+ }
67
74
  },
68
75
  "include": ["src"]
69
76
  }