@fluid-app/fluid-cli-localization 0.1.300 → 0.1.302

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.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../src/countries/commands.ts","../src/translations/commands.ts","../src/index.ts"],"mappings":";;;;iBAiMgB,yBAAA,CACd,MAAA,EAAQ,OAAA,EACR,GAAA,EAAK,cAAA;;;iBCnGS,4BAAA,CACd,MAAA,EAAQ,OAAA,EACR,GAAA,EAAK,cAAA;;;;AD+FP;;;;;cElLM,MAAA,EAAQ,WAAA"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/countries/commands.ts","../src/translations/commands.ts","../src/index.ts"],"mappings":";;;;iBAiMgB,yBAAA,CACd,MAAA,EAAQ,OAAA,EACR,GAAA,EAAK,cAAA;;;iBC/FS,4BAAA,CACd,MAAA,EAAQ,OAAA,EACR,GAAA,EAAK,cAAA;;;;AD2FP;;;;;cElLM,MAAA,EAAQ,WAAA"}
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { NAV_HELP, assertInteractive, createDomainCommand, terminalPrompter } from "@fluid-app/fluid-cli";
1
+ import { NAV_HELP, assertInteractive, createDomainCommand, declareInputs, exitOnInputsError, terminalPrompter } from "@fluid-app/fluid-cli";
2
2
  import prompts from "prompts";
3
3
  import { readFileSync } from "node:fs";
4
4
  //#region src/shared/errors.ts
@@ -252,11 +252,12 @@ function parseValue(raw) {
252
252
  * Read `--file`: a JSON object of field (or key) to string. Long or HTML
253
253
  * values are easier to pass this way than on the command line.
254
254
  */
255
- function readValuesFile(path) {
255
+ function readValuesFile(path, read = (p) => readFileSync(p, "utf8")) {
256
256
  let parsed;
257
257
  try {
258
- parsed = JSON.parse(readFileSync(path, "utf8"));
258
+ parsed = JSON.parse(read(path));
259
259
  } catch (error) {
260
+ exitOnInputsError(error);
260
261
  throw new LocalizationError(`Couldn't read ${path} as JSON: ${error instanceof Error ? error.message : String(error)}`);
261
262
  }
262
263
  if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) throw new LocalizationError(`${path} must hold a JSON object of field to text.`);
@@ -269,9 +270,9 @@ function readValuesFile(path) {
269
270
  return out;
270
271
  }
271
272
  /** `--set` and `--file` together, `--set` winning on a clash. */
272
- function collectValues(sets, file) {
273
+ function collectValues(sets, file, read) {
273
274
  return {
274
- ...file ? readValuesFile(file) : {},
275
+ ...file ? readValuesFile(file, read) : {},
275
276
  ...parseTextAssignments(sets)
276
277
  };
277
278
  }
@@ -4347,10 +4348,10 @@ function registerTranslationsCommands(parent, ctx) {
4347
4348
  });
4348
4349
  }
4349
4350
  }));
4350
- parent.command("set <type> [id]").description("Save a translation: --set field=value for a row, menu item, agreement or label; --set key.path=value for theme strings, or for theme-sections with the template id (changes live content)").option("--lang <iso>", "The language to write, e.g. fr").option("--set <field=value>", "A translated field or theme key (repeatable)", collect, []).option("--file <path>", "A JSON object of field (or theme key) to text, for long or HTML values").option("--theme <id>", "theme and theme-sections: a theme other than the active one").option("--yes", "Confirm without a prompt", false).action((typeName, id, opts) => run(async () => {
4351
+ declareInputs(parent.command("set <type> [id]").description("Save a translation: --set field=value for a row, menu item, agreement or label; --set key.path=value for theme strings, or for theme-sections with the template id (changes live content)").option("--lang <iso>", "The language to write, e.g. fr").option("--set <field=value>", "A translated field or theme key (repeatable)", collect, []).option("--file <path>", "A JSON object of field (or theme key) to text, for long or HTML values").option("--theme <id>", "theme and theme-sections: a theme other than the active one").option("--yes", "Confirm without a prompt", false).action((typeName, id, opts) => run(async () => {
4351
4352
  const api = await client(ctx);
4352
4353
  const type = resourceType(typeName);
4353
- const values = collectValues(opts.set, opts.file);
4354
+ const values = collectValues(opts.set, opts.file, (path) => ctx.inputs.readFile(path, "utf8"));
4354
4355
  const language = await requireActiveLanguage(api, requireLang(opts.lang));
4355
4356
  if (type.kind === "storefront") {
4356
4357
  const rid = rowId(id, type.type);
@@ -4434,7 +4435,10 @@ function registerTranslationsCommands(parent, ctx) {
4434
4435
  keys: Object.keys(values)
4435
4436
  });
4436
4437
  }
4437
- }));
4438
+ })), (opts) => opts["file"] ? [{
4439
+ kind: "file",
4440
+ path: String(opts["file"])
4441
+ }] : []);
4438
4442
  parent.command("auto <iso>").description("Machine-translate what's missing with Fluid AI and print it; --write saves it (changes live content)").option("--type <type>", `Limit to a type: ${TYPE_NAMES.join(", ")} (repeatable)`, collect, []).option("--limit <n>", "Most items to translate per type in this run", "25").option("--write", "Save the translations; without it nothing is written", false).option("--published-only", "Skip drafts, scheduled, and archived rows", false).option("--from <iso>", "The theme's source locale file; storefront rows and menus translate from the store's default language", "en").option("--theme <id>", "Translate this theme's strings instead of the active theme's").option("--model <provider/name>", "A translation model other than Fluid's default").option("--skip <type:id>", "Leave out one item, e.g. products:42, menu-items:12/340, or theme:cart.title (repeatable)", collect, []).option("--store-language <iso>", "The store's default language, used only when it can't be read from the storefront rows").option("--yes", "Confirm --write without a prompt", false).action((iso, opts) => run(async () => {
4439
4443
  const api = await client(ctx);
4440
4444
  const limit = positiveInt(opts.limit, "--limit");