@plasmicapp/cli 0.1.188 → 0.1.190

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.
@@ -6,5 +6,6 @@ export interface LocalizationStringsArgs extends CommonArgs {
6
6
  format: "po" | "json" | "lingui";
7
7
  output: string;
8
8
  forceOverwrite: boolean;
9
+ keyScheme: "content" | "hash";
9
10
  }
10
11
  export declare function localizationStrings(opts: LocalizationStringsArgs): Promise<void>;
@@ -66,7 +66,7 @@ function localizationStrings(opts) {
66
66
  token: "",
67
67
  });
68
68
  deps_1.logger.info(`Generating localization strings for ${chalk_1.default.bold(opts.projects.join(", "))}...`);
69
- const data = yield api.genLocalizationStrings(opts.projects, opts.format, projectIdsAndTokens);
69
+ const data = yield api.genLocalizationStrings(opts.projects, opts.format, opts.keyScheme, projectIdsAndTokens);
70
70
  if (file_utils_1.existsBuffered(output)) {
71
71
  const overwrite = yield user_utils_1.confirmWithUser(`File ${output} already exists. Do you want to overwrite?`, opts.forceOverwrite);
72
72
  if (!overwrite) {
package/dist/api.d.ts CHANGED
@@ -192,7 +192,7 @@ export declare class PlasmicApi {
192
192
  metadata?: Metadata;
193
193
  }): Promise<ProjectBundle>;
194
194
  projectMeta(projectId: string): Promise<ProjectMetaInfo>;
195
- genLocalizationStrings(projects: readonly string[], format: "po" | "json" | "lingui", projectIdsAndTokens: ProjectIdAndToken[]): Promise<string>;
195
+ genLocalizationStrings(projects: readonly string[], format: "po" | "json" | "lingui", keyScheme: "content" | "hash", projectIdsAndTokens: ProjectIdAndToken[]): Promise<string>;
196
196
  uploadBundle(projectId: string, bundleName: string, bundleJs: string, css: string[], metaJson: string, genModulePath: string | undefined, genCssPaths: string[], pkgVersion: string | undefined, extraPropMetaJson: string | undefined, themeProviderWrapper: string | undefined, themeModule: string | undefined): Promise<StyleTokensMap>;
197
197
  projectStyleTokens(projectId: string, branchName: string, versionRange?: string): Promise<StyleTokensMap>;
198
198
  projectIcons(projectId: string, branchName: string, versionRange?: string, iconIds?: string[]): Promise<ProjectIconsResponse>;
package/dist/api.js CHANGED
@@ -100,9 +100,9 @@ class PlasmicApi {
100
100
  return result.data;
101
101
  });
102
102
  }
103
- genLocalizationStrings(projects, format, projectIdsAndTokens) {
103
+ genLocalizationStrings(projects, format, keyScheme, projectIdsAndTokens) {
104
104
  return __awaiter(this, void 0, void 0, function* () {
105
- const result = yield this.get(`${this.codegenHost}/api/v1/localization/gen-texts?format=${format}&preview=true&${projects
105
+ const result = yield this.get(`${this.codegenHost}/api/v1/localization/gen-texts?format=${format}&keyScheme=${keyScheme}&preview=true&${projects
106
106
  .map((p) => `projectId=${p}`)
107
107
  .join("&")}`, undefined, {
108
108
  "x-plasmic-api-project-tokens": projectIdsAndTokens
package/dist/index.js CHANGED
@@ -203,6 +203,12 @@ yargs_1.default
203
203
  type: "string",
204
204
  choices: ["json", "po", "lingui"],
205
205
  default: "json",
206
+ })
207
+ .option("key-scheme", {
208
+ describe: "What value to use as message keys; either the message content itself, or a hash of it",
209
+ type: "string",
210
+ choices: ["content", "hash"],
211
+ default: "content",
206
212
  })
207
213
  .option("output", {
208
214
  alias: "o",
@@ -78,7 +78,8 @@ function checkProjectMeta(meta, root, context, opts) {
78
78
  // If the codegen version on-disk is invalid, we will sync again the project.
79
79
  const checkCodegenVersion = () => __awaiter(this, void 0, void 0, function* () {
80
80
  const projectLock = context.lock.projects.find((p) => p.projectId === projectId);
81
- if (!!(projectLock === null || projectLock === void 0 ? void 0 : projectLock.codegenVersion) && semver.gte(projectLock.codegenVersion, yield context.api.latestCodegenVersion())) {
81
+ if (!!(projectLock === null || projectLock === void 0 ? void 0 : projectLock.codegenVersion) &&
82
+ semver.gte(projectLock.codegenVersion, yield context.api.latestCodegenVersion())) {
82
83
  return false;
83
84
  }
84
85
  return true;
@@ -92,9 +93,10 @@ function checkProjectMeta(meta, root, context, opts) {
92
93
  // Always sync if we haven't seen sync'ed before
93
94
  return true;
94
95
  }
95
- if (semver.isLatest(versionOnDisk) &&
96
- semver.isLatest(newVersion) &&
97
- meta !== root) {
96
+ // If version is a branch name, we want to get the latest of the branch
97
+ const newVersionIsLatest = semver.isLatest(newVersion) || !semver.valid(newVersion);
98
+ const versionOnDiskIsLatest = semver.isLatest(versionOnDisk) || !semver.valid(versionOnDisk);
99
+ if (versionOnDiskIsLatest && newVersionIsLatest && meta !== root) {
98
100
  // If this is a dependency (not root), and we're dealing with latest dep version
99
101
  // just skip, it's confusing
100
102
  if (!isOnDiskCodeInvalid) {
@@ -102,11 +104,11 @@ function checkProjectMeta(meta, root, context, opts) {
102
104
  }
103
105
  return false;
104
106
  }
105
- if (semver.isLatest(newVersion)) {
107
+ if (newVersionIsLatest) {
106
108
  // Always sync when version set to "latest"
107
109
  return true;
108
110
  }
109
- if (semver.isLatest(versionOnDisk)) {
111
+ if (versionOnDiskIsLatest) {
110
112
  // Explicitly allow downgrades from "latest" to published version
111
113
  return true;
112
114
  }
@@ -152,8 +154,10 @@ function checkProjectMeta(meta, root, context, opts) {
152
154
  : deps_1.logger.info(`'${projectName} has never been synced before. Syncing...'`);
153
155
  return true;
154
156
  }
157
+ // If version is a branch name, we want to get the latest of the branch
158
+ const versionRangeIsLatest = semver.isLatest(versionRange) || !semver.valid(versionRange);
155
159
  // If satisfies range in plasmic.json
156
- if (semver.satisfies(newVersion, versionRange)) {
160
+ if (versionRangeIsLatest || semver.satisfies(newVersion, versionRange)) {
157
161
  deps_1.logger.info(`Updating project '${projectName}' to ${newVersion}`);
158
162
  return true;
159
163
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plasmicapp/cli",
3
- "version": "0.1.188",
3
+ "version": "0.1.190",
4
4
  "description": "plasmic cli for syncing local code with Plasmic designs",
5
5
  "engines": {
6
6
  "node": ">=12"
@@ -4,12 +4,8 @@ import { CommonArgs } from "..";
4
4
  import { PlasmicApi, ProjectIdAndToken } from "../api";
5
5
  import { logger } from "../deps";
6
6
  import { HandledError } from "../lib";
7
- import { getCurrentAuth, getOrStartAuth } from "../utils/auth-utils";
8
- import {
9
- DEFAULT_HOST,
10
- findConfigFile,
11
- PlasmicContext,
12
- } from "../utils/config-utils";
7
+ import { getCurrentAuth } from "../utils/auth-utils";
8
+ import { DEFAULT_HOST, findConfigFile } from "../utils/config-utils";
13
9
  import { existsBuffered, writeFileText } from "../utils/file-utils";
14
10
  import { getContext } from "../utils/get-context";
15
11
  import { confirmWithUser } from "../utils/user-utils";
@@ -21,6 +17,7 @@ export interface LocalizationStringsArgs extends CommonArgs {
21
17
  format: "po" | "json" | "lingui";
22
18
  output: string;
23
19
  forceOverwrite: boolean;
20
+ keyScheme: "content" | "hash";
24
21
  }
25
22
 
26
23
  export async function localizationStrings(
@@ -81,6 +78,7 @@ export async function localizationStrings(
81
78
  const data = await api.genLocalizationStrings(
82
79
  opts.projects,
83
80
  opts.format,
81
+ opts.keyScheme,
84
82
  projectIdsAndTokens
85
83
  );
86
84
  if (existsBuffered(output)) {
package/src/api.ts CHANGED
@@ -294,12 +294,13 @@ export class PlasmicApi {
294
294
  async genLocalizationStrings(
295
295
  projects: readonly string[],
296
296
  format: "po" | "json" | "lingui",
297
+ keyScheme: "content" | "hash",
297
298
  projectIdsAndTokens: ProjectIdAndToken[]
298
299
  ) {
299
300
  const result = await this.get(
300
301
  `${
301
302
  this.codegenHost
302
- }/api/v1/localization/gen-texts?format=${format}&preview=true&${projects
303
+ }/api/v1/localization/gen-texts?format=${format}&keyScheme=${keyScheme}&preview=true&${projects
303
304
  .map((p) => `projectId=${p}`)
304
305
  .join("&")}`,
305
306
  undefined,
package/src/index.ts CHANGED
@@ -252,6 +252,13 @@ yargs
252
252
  choices: ["json", "po", "lingui"],
253
253
  default: "json",
254
254
  })
255
+ .option("key-scheme", {
256
+ describe:
257
+ "What value to use as message keys; either the message content itself, or a hash of it",
258
+ type: "string",
259
+ choices: ["content", "hash"],
260
+ default: "content",
261
+ })
255
262
  .option("output", {
256
263
  alias: "o",
257
264
  describe: "Output file",
@@ -1,5 +1,4 @@
1
1
  import L from "lodash";
2
- import { InvalidatedProjectKind } from "typescript";
3
2
  import { SyncArgs } from "../actions/sync";
4
3
  import { ProjectVersionMeta, VersionResolution } from "../api";
5
4
  import { logger } from "../deps";
@@ -74,7 +73,13 @@ async function checkProjectMeta(
74
73
  (p) => p.projectId === projectId
75
74
  );
76
75
 
77
- if (!!projectLock?.codegenVersion && semver.gte(projectLock.codegenVersion, await context.api.latestCodegenVersion())) {
76
+ if (
77
+ !!projectLock?.codegenVersion &&
78
+ semver.gte(
79
+ projectLock.codegenVersion,
80
+ await context.api.latestCodegenVersion()
81
+ )
82
+ ) {
78
83
  return false;
79
84
  }
80
85
 
@@ -95,11 +100,13 @@ async function checkProjectMeta(
95
100
  return true;
96
101
  }
97
102
 
98
- if (
99
- semver.isLatest(versionOnDisk) &&
100
- semver.isLatest(newVersion) &&
101
- meta !== root
102
- ) {
103
+ // If version is a branch name, we want to get the latest of the branch
104
+ const newVersionIsLatest =
105
+ semver.isLatest(newVersion) || !semver.valid(newVersion);
106
+ const versionOnDiskIsLatest =
107
+ semver.isLatest(versionOnDisk) || !semver.valid(versionOnDisk);
108
+
109
+ if (versionOnDiskIsLatest && newVersionIsLatest && meta !== root) {
103
110
  // If this is a dependency (not root), and we're dealing with latest dep version
104
111
  // just skip, it's confusing
105
112
  if (!isOnDiskCodeInvalid) {
@@ -110,12 +117,12 @@ async function checkProjectMeta(
110
117
  return false;
111
118
  }
112
119
 
113
- if (semver.isLatest(newVersion)) {
120
+ if (newVersionIsLatest) {
114
121
  // Always sync when version set to "latest"
115
122
  return true;
116
123
  }
117
124
 
118
- if (semver.isLatest(versionOnDisk)) {
125
+ if (versionOnDiskIsLatest) {
119
126
  // Explicitly allow downgrades from "latest" to published version
120
127
  return true;
121
128
  }
@@ -128,7 +135,7 @@ async function checkProjectMeta(
128
135
  );
129
136
  return true;
130
137
  } else {
131
- if (!isOnDiskCodeInvalid) {
138
+ if (!isOnDiskCodeInvalid) {
132
139
  logger.info(
133
140
  `Project '${projectName}'@${newVersion} is already up to date; skipping. (To force an update, run again with "--force")`
134
141
  );
@@ -186,8 +193,12 @@ async function checkProjectMeta(
186
193
  return true;
187
194
  }
188
195
 
196
+ // If version is a branch name, we want to get the latest of the branch
197
+ const versionRangeIsLatest =
198
+ semver.isLatest(versionRange) || !semver.valid(versionRange);
199
+
189
200
  // If satisfies range in plasmic.json
190
- if (semver.satisfies(newVersion, versionRange)) {
201
+ if (versionRangeIsLatest || semver.satisfies(newVersion, versionRange)) {
191
202
  logger.info(`Updating project '${projectName}' to ${newVersion}`);
192
203
  return true;
193
204
  }
@@ -230,12 +241,12 @@ async function checkProjectMeta(
230
241
  // we should always sync it, even if nothing has changed
231
242
  return true;
232
243
  }
233
- const checkedVersion =
244
+ const checkedVersion =
234
245
  (await checkVersionLock()) &&
235
246
  (await checkVersionRange()) &&
236
247
  (await checkIndirect());
237
248
 
238
- if(!checkedVersion && isOnDiskCodeInvalid) {
249
+ if (!checkedVersion && isOnDiskCodeInvalid) {
239
250
  // sync, but try to keep the current version on disk
240
251
  const projectLock = context.lock.projects.find(
241
252
  (p) => p.projectId === projectId
@@ -244,7 +255,7 @@ async function checkProjectMeta(
244
255
  logger.warn(
245
256
  `Project '${projectName}' was synced by an incompatible version of Plasmic Codegen. Syncing again on the same version ${projectName}@${versionOnDisk}`
246
257
  );
247
-
258
+
248
259
  meta.version = versionOnDisk ?? meta.version;
249
260
  return true;
250
261
  } else if (checkedVersion) {