@plasmicapp/cli 0.1.291 → 0.1.293

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,6 +6,8 @@ export interface LocalizationStringsArgs extends CommonArgs {
6
6
  format: "po" | "json" | "lingui";
7
7
  output: string;
8
8
  forceOverwrite: boolean;
9
- keyScheme: "content" | "hash" | undefined;
9
+ keyScheme: "content" | "hash" | "path" | undefined;
10
+ tagPrefix: string | undefined;
11
+ excludeDeps: boolean | undefined;
10
12
  }
11
13
  export declare function localizationStrings(opts: LocalizationStringsArgs): Promise<void>;
@@ -24,7 +24,7 @@ const file_utils_1 = require("../utils/file-utils");
24
24
  const get_context_1 = require("../utils/get-context");
25
25
  const user_utils_1 = require("../utils/user-utils");
26
26
  function localizationStrings(opts) {
27
- var _a, _b;
27
+ var _a, _b, _c;
28
28
  return __awaiter(this, void 0, void 0, function* () {
29
29
  if (!opts.projects || opts.projects.length === 0) {
30
30
  throw new lib_1.HandledError(`Missing projects.`);
@@ -47,6 +47,7 @@ function localizationStrings(opts) {
47
47
  : "data.json"
48
48
  : opts.output;
49
49
  let keyScheme = opts.keyScheme;
50
+ let tagPrefix = opts.tagPrefix;
50
51
  const projectTokensFromConfig = [];
51
52
  const auth = yield auth_utils_1.getCurrentAuth(opts.auth);
52
53
  const maybeConfigFile = opts.config || config_utils_1.findConfigFile(opts.baseDir, { traverseParents: true });
@@ -58,6 +59,9 @@ function localizationStrings(opts) {
58
59
  if (!keyScheme) {
59
60
  keyScheme = (_b = context.config.i18n) === null || _b === void 0 ? void 0 : _b.keyScheme;
60
61
  }
62
+ if (!tagPrefix) {
63
+ tagPrefix = (_c = context.config.i18n) === null || _c === void 0 ? void 0 : _c.tagPrefix;
64
+ }
61
65
  }
62
66
  const projectIdsAndTokens = [
63
67
  ...parsedProjectTokens,
@@ -70,7 +74,7 @@ function localizationStrings(opts) {
70
74
  token: "",
71
75
  });
72
76
  deps_1.logger.info(`Generating localization strings for ${chalk_1.default.bold(opts.projects.join(", "))}...`);
73
- const data = yield api.genLocalizationStrings(opts.projects, opts.format, keyScheme !== null && keyScheme !== void 0 ? keyScheme : "content", projectIdsAndTokens);
77
+ const data = yield api.genLocalizationStrings(opts.projects, opts.format, keyScheme !== null && keyScheme !== void 0 ? keyScheme : "content", tagPrefix, projectIdsAndTokens, opts.excludeDeps);
74
78
  if (file_utils_1.existsBuffered(output)) {
75
79
  const overwrite = yield user_utils_1.confirmWithUser(`File ${output} already exists. Do you want to overwrite?`, opts.forceOverwrite);
76
80
  if (!overwrite) {
package/dist/api.d.ts CHANGED
@@ -200,7 +200,7 @@ export declare class PlasmicApi {
200
200
  metadata?: Metadata;
201
201
  }): Promise<ProjectBundle>;
202
202
  projectMeta(projectId: string): Promise<ProjectMetaInfo>;
203
- genLocalizationStrings(projects: readonly string[], format: "po" | "json" | "lingui", keyScheme: "content" | "hash", projectIdsAndTokens: ProjectIdAndToken[]): Promise<string>;
203
+ genLocalizationStrings(projects: readonly string[], format: "po" | "json" | "lingui", keyScheme: "content" | "hash" | "path", tagPrefix: string | undefined, projectIdsAndTokens: ProjectIdAndToken[], excludeDeps: boolean | undefined): Promise<string>;
204
204
  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>;
205
205
  projectStyleTokens(projectId: string, branchName: string, versionRange?: string): Promise<StyleTokensMap>;
206
206
  projectIcons(projectId: string, branchName: string, versionRange?: string, iconIds?: string[]): Promise<ProjectIconsResponse>;
package/dist/api.js CHANGED
@@ -99,11 +99,17 @@ class PlasmicApi {
99
99
  return result.data;
100
100
  });
101
101
  }
102
- genLocalizationStrings(projects, format, keyScheme, projectIdsAndTokens) {
102
+ genLocalizationStrings(projects, format, keyScheme, tagPrefix, projectIdsAndTokens, excludeDeps) {
103
103
  return __awaiter(this, void 0, void 0, function* () {
104
- const result = yield this.get(`${this.codegenHost}/api/v1/localization/gen-texts?format=${format}&keyScheme=${keyScheme}&preview=true&${projects
105
- .map((p) => `projectId=${p}`)
106
- .join("&")}`, undefined, {
104
+ const params = new URLSearchParams([
105
+ ["format", format],
106
+ ["keyScheme", keyScheme],
107
+ ["preview", "true"],
108
+ ...projects.map((p) => ["projectId", p]),
109
+ tagPrefix ? ["tagPrefix", tagPrefix] : undefined,
110
+ excludeDeps ? ["excludeDeps", "true"] : undefined,
111
+ ].filter((x) => !!x));
112
+ const result = yield this.get(`${this.codegenHost}/api/v1/localization/gen-texts?${params.toString()}`, undefined, {
107
113
  "x-plasmic-api-project-tokens": projectIdsAndTokens
108
114
  .map(({ projectId, projectApiToken }) => `${projectId}:${projectApiToken}`)
109
115
  .join(","),
package/dist/index.js CHANGED
@@ -205,9 +205,18 @@ yargs_1.default
205
205
  default: "json",
206
206
  })
207
207
  .option("key-scheme", {
208
- describe: "What value to use as message keys; either the message content itself, or a hash of it. Defaults to whatever is specified in plasmic.json, or `content`",
208
+ describe: "What value to use as message keys; `content` uses the message content itself, `hash` uses a hash of the content, and `path` uses a a hierarchical string containing the project id, component name, element name, and related variants, and does not encode the text content in the key. Defaults to whatever is specified in plasmic.json, or `content`",
209
209
  type: "string",
210
- choices: ["content", "hash"],
210
+ choices: ["content", "hash", "path"],
211
+ })
212
+ .option("tag-prefix", {
213
+ describe: "By default, rich text with markup tags look like '<0>hello</0>'. If your localization framework requires num-numeric tags, then specify a prefix; for example a prefix of 'n' turns it into '<n0>hello</n0>'.",
214
+ type: "string",
215
+ })
216
+ .option("exclude-deps", {
217
+ type: "boolean",
218
+ describe: "By default, strings from imported dependencies are also included. Specify --exclude-deps to only include strings from projects you explicitly specify.",
219
+ default: false,
211
220
  })
212
221
  .option("output", {
213
222
  alias: "o",
@@ -188,6 +188,10 @@
188
188
  "hash"
189
189
  ],
190
190
  "type": "string"
191
+ },
192
+ "tagPrefix": {
193
+ "description": "For localization, rich text with embedded tags are exported as\n\"Hello <0>there</0>, I am <1>here</1>\". Some frameworks, like\nreact-intl, doesn't work with numbers as tag names, so you can\nspecify a prefix. For example, a tagPrefix of \"n\" turns the above\ninto \"Hello <n0>there</n0>, I am <n1>here</n1>\".",
194
+ "type": "string"
191
195
  }
192
196
  },
193
197
  "required": [
@@ -254,6 +254,14 @@ export interface I18NConfig {
254
254
  * or by a hash of its content
255
255
  */
256
256
  keyScheme: "content" | "hash";
257
+ /**
258
+ * For localization, rich text with embedded tags are exported as
259
+ * "Hello <0>there</0>, I am <1>here</1>". Some frameworks, like
260
+ * react-intl, doesn't work with numbers as tag names, so you can
261
+ * specify a prefix. For example, a tagPrefix of "n" turns the above
262
+ * into "Hello <n0>there</n0>, I am <n1>here</n1>".
263
+ */
264
+ tagPrefix?: string;
257
265
  }
258
266
  export interface PlasmicLock {
259
267
  projects: ProjectLock[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plasmicapp/cli",
3
- "version": "0.1.291",
3
+ "version": "0.1.293",
4
4
  "description": "plasmic cli for syncing local code with Plasmic designs",
5
5
  "engines": {
6
6
  "node": ">=12"
@@ -20,7 +20,6 @@
20
20
  },
21
21
  "devDependencies": {
22
22
  "@babel/preset-typescript": "^7.12.1",
23
- "@plasmicapp/react-web": "0.2.224",
24
23
  "@types/cli-progress": "^3.11.0",
25
24
  "@types/findup-sync": "^2.0.2",
26
25
  "@types/glob": "^7.1.3",
@@ -81,5 +80,5 @@
81
80
  "wrap-ansi": "^7.0.0",
82
81
  "yargs": "^15.4.1"
83
82
  },
84
- "gitHead": "596857aecc29c48046f82c0de3e913063322e8ec"
83
+ "gitHead": "44f8c8ab413dee1f09112df30df9bdf323ac5214"
85
84
  }
@@ -17,7 +17,9 @@ export interface LocalizationStringsArgs extends CommonArgs {
17
17
  format: "po" | "json" | "lingui";
18
18
  output: string;
19
19
  forceOverwrite: boolean;
20
- keyScheme: "content" | "hash" | undefined;
20
+ keyScheme: "content" | "hash" | "path" | undefined;
21
+ tagPrefix: string | undefined;
22
+ excludeDeps: boolean | undefined;
21
23
  }
22
24
 
23
25
  export async function localizationStrings(
@@ -47,6 +49,7 @@ export async function localizationStrings(
47
49
  : "data.json"
48
50
  : opts.output;
49
51
  let keyScheme = opts.keyScheme;
52
+ let tagPrefix = opts.tagPrefix;
50
53
  const projectTokensFromConfig: ProjectIdAndToken[] = [];
51
54
  const auth = await getCurrentAuth(opts.auth);
52
55
  const maybeConfigFile =
@@ -59,6 +62,9 @@ export async function localizationStrings(
59
62
  if (!keyScheme) {
60
63
  keyScheme = context.config.i18n?.keyScheme;
61
64
  }
65
+ if (!tagPrefix) {
66
+ tagPrefix = context.config.i18n?.tagPrefix;
67
+ }
62
68
  }
63
69
 
64
70
  const projectIdsAndTokens = [
@@ -83,7 +89,9 @@ export async function localizationStrings(
83
89
  opts.projects,
84
90
  opts.format,
85
91
  keyScheme ?? "content",
86
- projectIdsAndTokens
92
+ tagPrefix,
93
+ projectIdsAndTokens,
94
+ opts.excludeDeps
87
95
  );
88
96
  if (existsBuffered(output)) {
89
97
  const overwrite = await confirmWithUser(
package/src/api.ts CHANGED
@@ -302,15 +302,23 @@ export class PlasmicApi {
302
302
  async genLocalizationStrings(
303
303
  projects: readonly string[],
304
304
  format: "po" | "json" | "lingui",
305
- keyScheme: "content" | "hash",
306
- projectIdsAndTokens: ProjectIdAndToken[]
305
+ keyScheme: "content" | "hash" | "path",
306
+ tagPrefix: string | undefined,
307
+ projectIdsAndTokens: ProjectIdAndToken[],
308
+ excludeDeps: boolean | undefined
307
309
  ) {
310
+ const params = new URLSearchParams(
311
+ [
312
+ ["format", format],
313
+ ["keyScheme", keyScheme],
314
+ ["preview", "true"],
315
+ ...projects.map((p) => ["projectId", p]),
316
+ tagPrefix ? ["tagPrefix", tagPrefix] : undefined,
317
+ excludeDeps ? ["excludeDeps", "true"] : undefined,
318
+ ].filter((x): x is [string, string] => !!x)
319
+ );
308
320
  const result = await this.get(
309
- `${
310
- this.codegenHost
311
- }/api/v1/localization/gen-texts?format=${format}&keyScheme=${keyScheme}&preview=true&${projects
312
- .map((p) => `projectId=${p}`)
313
- .join("&")}`,
321
+ `${this.codegenHost}/api/v1/localization/gen-texts?${params.toString()}`,
314
322
  undefined,
315
323
  {
316
324
  "x-plasmic-api-project-tokens": projectIdsAndTokens
package/src/index.ts CHANGED
@@ -254,9 +254,20 @@ yargs
254
254
  })
255
255
  .option("key-scheme", {
256
256
  describe:
257
- "What value to use as message keys; either the message content itself, or a hash of it. Defaults to whatever is specified in plasmic.json, or `content`",
257
+ "What value to use as message keys; `content` uses the message content itself, `hash` uses a hash of the content, and `path` uses a a hierarchical string containing the project id, component name, element name, and related variants, and does not encode the text content in the key. Defaults to whatever is specified in plasmic.json, or `content`",
258
258
  type: "string",
259
- choices: ["content", "hash"],
259
+ choices: ["content", "hash", "path"],
260
+ })
261
+ .option("tag-prefix", {
262
+ describe:
263
+ "By default, rich text with markup tags look like '<0>hello</0>'. If your localization framework requires num-numeric tags, then specify a prefix; for example a prefix of 'n' turns it into '<n0>hello</n0>'.",
264
+ type: "string",
265
+ })
266
+ .option("exclude-deps", {
267
+ type: "boolean",
268
+ describe:
269
+ "By default, strings from imported dependencies are also included. Specify --exclude-deps to only include strings from projects you explicitly specify.",
270
+ default: false,
260
271
  })
261
272
  .option("output", {
262
273
  alias: "o",
@@ -355,6 +355,14 @@ export interface I18NConfig {
355
355
  * or by a hash of its content
356
356
  */
357
357
  keyScheme: "content" | "hash";
358
+ /**
359
+ * For localization, rich text with embedded tags are exported as
360
+ * "Hello <0>there</0>, I am <1>here</1>". Some frameworks, like
361
+ * react-intl, doesn't work with numbers as tag names, so you can
362
+ * specify a prefix. For example, a tagPrefix of "n" turns the above
363
+ * into "Hello <n0>there</n0>, I am <n1>here</n1>".
364
+ */
365
+ tagPrefix?: string;
358
366
  }
359
367
 
360
368
  export interface PlasmicLock {