@plasmicapp/cli 0.1.293 → 0.1.294

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.
@@ -26,12 +26,36 @@ const user_utils_1 = require("../utils/user-utils");
26
26
  function localizationStrings(opts) {
27
27
  var _a, _b, _c;
28
28
  return __awaiter(this, void 0, void 0, function* () {
29
- if (!opts.projects || opts.projects.length === 0) {
29
+ if (!opts.baseDir) {
30
+ opts.baseDir = process.cwd();
31
+ }
32
+ const maybeConfigFile = opts.config || config_utils_1.findConfigFile(opts.baseDir, { traverseParents: true });
33
+ let projectSpecs = opts.projects;
34
+ let keyScheme = opts.keyScheme;
35
+ let tagPrefix = opts.tagPrefix;
36
+ const projectTokensFromConfig = [];
37
+ if (maybeConfigFile) {
38
+ // if plasmic.json exists, then we can derive some settings from
39
+ // there instead.
40
+ deps_1.logger.info(`Using settings from ${maybeConfigFile}...`);
41
+ const context = yield get_context_1.getContext(opts, { enableSkipAuth: true });
42
+ context.config.projects.forEach((p) => {
43
+ projectTokensFromConfig.push(lodash_1.pick(p, "projectId", "projectApiToken"));
44
+ });
45
+ if (!projectSpecs || projectSpecs.length === 0) {
46
+ projectSpecs = context.config.projects.map((p) => p.projectId + (p.version === "latest" ? "" : `@${p.version}`));
47
+ }
48
+ if (!keyScheme) {
49
+ keyScheme = (_a = context.config.i18n) === null || _a === void 0 ? void 0 : _a.keyScheme;
50
+ }
51
+ if (!tagPrefix) {
52
+ tagPrefix = (_b = context.config.i18n) === null || _b === void 0 ? void 0 : _b.tagPrefix;
53
+ }
54
+ }
55
+ if (!projectSpecs || projectSpecs.length === 0) {
30
56
  throw new lib_1.HandledError(`Missing projects.`);
31
57
  }
32
- if (!opts.baseDir)
33
- opts.baseDir = process.cwd();
34
- const parsedProjectTokens = ((_a = opts.projectTokens) !== null && _a !== void 0 ? _a : []).map((val) => {
58
+ const parsedProjectTokens = ((_c = opts.projectTokens) !== null && _c !== void 0 ? _c : []).map((val) => {
35
59
  const [projectId, projectApiToken] = val.split(":");
36
60
  if (!projectId || !projectApiToken) {
37
61
  throw new Error(`Invalid value passed to '--project-tokens': ${val}\nPlease provide the API tokens with the format PROJECT_ID:PROJECT_API_TOKEN`);
@@ -46,23 +70,7 @@ function localizationStrings(opts) {
46
70
  ? "data.po"
47
71
  : "data.json"
48
72
  : opts.output;
49
- let keyScheme = opts.keyScheme;
50
- let tagPrefix = opts.tagPrefix;
51
- const projectTokensFromConfig = [];
52
73
  const auth = yield auth_utils_1.getCurrentAuth(opts.auth);
53
- const maybeConfigFile = opts.config || config_utils_1.findConfigFile(opts.baseDir, { traverseParents: true });
54
- if (maybeConfigFile) {
55
- const context = yield get_context_1.getContext(opts, { enableSkipAuth: true });
56
- context.config.projects.forEach((p) => {
57
- projectTokensFromConfig.push(lodash_1.pick(p, "projectId", "projectApiToken"));
58
- });
59
- if (!keyScheme) {
60
- keyScheme = (_b = context.config.i18n) === null || _b === void 0 ? void 0 : _b.keyScheme;
61
- }
62
- if (!tagPrefix) {
63
- tagPrefix = (_c = context.config.i18n) === null || _c === void 0 ? void 0 : _c.tagPrefix;
64
- }
65
- }
66
74
  const projectIdsAndTokens = [
67
75
  ...parsedProjectTokens,
68
76
  ...projectTokensFromConfig,
@@ -73,8 +81,8 @@ function localizationStrings(opts) {
73
81
  user: "",
74
82
  token: "",
75
83
  });
76
- deps_1.logger.info(`Generating localization strings for ${chalk_1.default.bold(opts.projects.join(", "))}...`);
77
- const data = yield api.genLocalizationStrings(opts.projects, opts.format, keyScheme !== null && keyScheme !== void 0 ? keyScheme : "content", tagPrefix, projectIdsAndTokens, opts.excludeDeps);
84
+ deps_1.logger.info(`Generating localization strings for ${chalk_1.default.bold(projectSpecs.join(", "))}...`);
85
+ const data = yield api.genLocalizationStrings(projectSpecs, opts.format, keyScheme !== null && keyScheme !== void 0 ? keyScheme : "content", tagPrefix, projectIdsAndTokens, opts.excludeDeps);
78
86
  if (file_utils_1.existsBuffered(output)) {
79
87
  const overwrite = yield user_utils_1.confirmWithUser(`File ${output} already exists. Do you want to overwrite?`, opts.forceOverwrite);
80
88
  if (!overwrite) {
package/dist/index.js CHANGED
@@ -190,7 +190,7 @@ yargs_1.default
190
190
  .command("localization-strings", false, (yargs) => yargs
191
191
  .option("projects", {
192
192
  alias: "p",
193
- describe: "One or more projects to generate localization strings, separated by comma. Version constraints can be specified using @. Example: projectid, projectid@>=version",
193
+ describe: "One or more projects to generate localization strings, separated by comma. Version constraints can be specified using @. Example: projectid, projectid@>=version. If not specified, will be derived from plasmic.json if you are using codegen.",
194
194
  type: "array",
195
195
  })
196
196
  .option("host", {
@@ -182,10 +182,11 @@
182
182
  "I18NConfig": {
183
183
  "properties": {
184
184
  "keyScheme": {
185
- "description": "For localization, whether the extracted strings are keyed by its content\nor by a hash of its content",
185
+ "description": "For localization, whether the extracted strings are keyed by its content,\nor by a hash of its content, or by where the string is found (\"path\")",
186
186
  "enum": [
187
187
  "content",
188
- "hash"
188
+ "hash",
189
+ "path"
189
190
  ],
190
191
  "type": "string"
191
192
  },
@@ -250,10 +250,10 @@ export interface ProjectLock {
250
250
  }
251
251
  export interface I18NConfig {
252
252
  /**
253
- * For localization, whether the extracted strings are keyed by its content
254
- * or by a hash of its content
253
+ * For localization, whether the extracted strings are keyed by its content,
254
+ * or by a hash of its content, or by where the string is found ("path")
255
255
  */
256
- keyScheme: "content" | "hash";
256
+ keyScheme: "content" | "hash" | "path";
257
257
  /**
258
258
  * For localization, rich text with embedded tags are exported as
259
259
  * "Hello <0>there</0>, I am <1>here</1>". Some frameworks, like
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plasmicapp/cli",
3
- "version": "0.1.293",
3
+ "version": "0.1.294",
4
4
  "description": "plasmic cli for syncing local code with Plasmic designs",
5
5
  "engines": {
6
6
  "node": ">=12"
@@ -80,5 +80,5 @@
80
80
  "wrap-ansi": "^7.0.0",
81
81
  "yargs": "^15.4.1"
82
82
  },
83
- "gitHead": "44f8c8ab413dee1f09112df30df9bdf323ac5214"
83
+ "gitHead": "ff42d1b747943bedcc21cb39f8ffb92d38347292"
84
84
  }
@@ -25,10 +25,40 @@ export interface LocalizationStringsArgs extends CommonArgs {
25
25
  export async function localizationStrings(
26
26
  opts: LocalizationStringsArgs
27
27
  ): Promise<void> {
28
- if (!opts.projects || opts.projects.length === 0) {
28
+ if (!opts.baseDir) {
29
+ opts.baseDir = process.cwd();
30
+ }
31
+
32
+ const maybeConfigFile =
33
+ opts.config || findConfigFile(opts.baseDir, { traverseParents: true });
34
+
35
+ let projectSpecs = opts.projects;
36
+ let keyScheme = opts.keyScheme;
37
+ let tagPrefix = opts.tagPrefix;
38
+ const projectTokensFromConfig: ProjectIdAndToken[] = [];
39
+ if (maybeConfigFile) {
40
+ // if plasmic.json exists, then we can derive some settings from
41
+ // there instead.
42
+ logger.info(`Using settings from ${maybeConfigFile}...`);
43
+ const context = await getContext(opts, { enableSkipAuth: true });
44
+ context.config.projects.forEach((p) => {
45
+ projectTokensFromConfig.push(pick(p, "projectId", "projectApiToken"));
46
+ });
47
+ if (!projectSpecs || projectSpecs.length === 0) {
48
+ projectSpecs = context.config.projects.map(
49
+ (p) => p.projectId + (p.version === "latest" ? "" : `@${p.version}`)
50
+ );
51
+ }
52
+ if (!keyScheme) {
53
+ keyScheme = context.config.i18n?.keyScheme;
54
+ }
55
+ if (!tagPrefix) {
56
+ tagPrefix = context.config.i18n?.tagPrefix;
57
+ }
58
+ }
59
+ if (!projectSpecs || projectSpecs.length === 0) {
29
60
  throw new HandledError(`Missing projects.`);
30
61
  }
31
- if (!opts.baseDir) opts.baseDir = process.cwd();
32
62
  const parsedProjectTokens: ProjectIdAndToken[] = (
33
63
  opts.projectTokens ?? []
34
64
  ).map((val) => {
@@ -48,24 +78,7 @@ export async function localizationStrings(
48
78
  ? "data.po"
49
79
  : "data.json"
50
80
  : opts.output;
51
- let keyScheme = opts.keyScheme;
52
- let tagPrefix = opts.tagPrefix;
53
- const projectTokensFromConfig: ProjectIdAndToken[] = [];
54
81
  const auth = await getCurrentAuth(opts.auth);
55
- const maybeConfigFile =
56
- opts.config || findConfigFile(opts.baseDir, { traverseParents: true });
57
- if (maybeConfigFile) {
58
- const context = await getContext(opts, { enableSkipAuth: true });
59
- context.config.projects.forEach((p) => {
60
- projectTokensFromConfig.push(pick(p, "projectId", "projectApiToken"));
61
- });
62
- if (!keyScheme) {
63
- keyScheme = context.config.i18n?.keyScheme;
64
- }
65
- if (!tagPrefix) {
66
- tagPrefix = context.config.i18n?.tagPrefix;
67
- }
68
- }
69
82
 
70
83
  const projectIdsAndTokens = [
71
84
  ...parsedProjectTokens,
@@ -82,11 +95,11 @@ export async function localizationStrings(
82
95
  );
83
96
  logger.info(
84
97
  `Generating localization strings for ${chalk.bold(
85
- opts.projects.join(", ")
98
+ projectSpecs.join(", ")
86
99
  )}...`
87
100
  );
88
101
  const data = await api.genLocalizationStrings(
89
- opts.projects,
102
+ projectSpecs,
90
103
  opts.format,
91
104
  keyScheme ?? "content",
92
105
  tagPrefix,
package/src/index.ts CHANGED
@@ -238,7 +238,7 @@ yargs
238
238
  .option("projects", {
239
239
  alias: "p",
240
240
  describe:
241
- "One or more projects to generate localization strings, separated by comma. Version constraints can be specified using @. Example: projectid, projectid@>=version",
241
+ "One or more projects to generate localization strings, separated by comma. Version constraints can be specified using @. Example: projectid, projectid@>=version. If not specified, will be derived from plasmic.json if you are using codegen.",
242
242
  type: "array",
243
243
  })
244
244
  .option("host", {
@@ -351,10 +351,10 @@ export interface ProjectLock {
351
351
 
352
352
  export interface I18NConfig {
353
353
  /**
354
- * For localization, whether the extracted strings are keyed by its content
355
- * or by a hash of its content
354
+ * For localization, whether the extracted strings are keyed by its content,
355
+ * or by a hash of its content, or by where the string is found ("path")
356
356
  */
357
- keyScheme: "content" | "hash";
357
+ keyScheme: "content" | "hash" | "path";
358
358
  /**
359
359
  * For localization, rich text with embedded tags are exported as
360
360
  * "Hello <0>there</0>, I am <1>here</1>". Some frameworks, like