lingo.dev 0.71.0 → 0.73.0

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.
package/build/cli.mjs CHANGED
@@ -18,7 +18,7 @@ import { InteractiveCommand as InteractiveCommand2 } from "interactive-commander
18
18
  import figlet from "figlet";
19
19
  import { vice } from "gradient-string";
20
20
 
21
- // src/cli/cli/auth.ts
21
+ // src/cli/cmd/auth.ts
22
22
  import { Command } from "interactive-commander";
23
23
  import Ora from "ora";
24
24
  import express from "express";
@@ -174,7 +174,7 @@ function createAuthenticator(params) {
174
174
  };
175
175
  }
176
176
 
177
- // src/cli/cli/auth.ts
177
+ // src/cli/cmd/auth.ts
178
178
  var auth_default = new Command().command("auth").description("Authenticate with Lingo.dev API").helpOption("-h, --help", "Show help").option("--logout", "Delete existing authentication").option("--login", "Authenticate with Lingo.dev API").action(async (options) => {
179
179
  try {
180
180
  let settings = await getSettings(void 0);
@@ -242,7 +242,7 @@ async function waitForApiKey(cb) {
242
242
  });
243
243
  }
244
244
 
245
- // src/cli/cli/init.ts
245
+ // src/cli/cmd/init.ts
246
246
  import { InteractiveCommand, InteractiveOption } from "interactive-commander";
247
247
  import Ora2 from "ora";
248
248
 
@@ -275,7 +275,7 @@ function _getConfigFilePath() {
275
275
  return path2.join(process.cwd(), "i18n.json");
276
276
  }
277
277
 
278
- // src/cli/cli/init.ts
278
+ // src/cli/cmd/init.ts
279
279
  import fs3 from "fs";
280
280
  import { spawn } from "child_process";
281
281
  import _2 from "lodash";
@@ -396,10 +396,10 @@ var init_default = new InteractiveCommand().command("init").description("Initial
396
396
  }
397
397
  });
398
398
 
399
- // src/cli/cli/show/index.ts
399
+ // src/cli/cmd/show/index.ts
400
400
  import { Command as Command5 } from "interactive-commander";
401
401
 
402
- // src/cli/cli/show/config.ts
402
+ // src/cli/cmd/show/config.ts
403
403
  import { Command as Command2 } from "interactive-commander";
404
404
  import _3 from "lodash";
405
405
  import fs4 from "fs";
@@ -420,7 +420,7 @@ function loadReplexicaFileConfig() {
420
420
  return replexicaFileConfig;
421
421
  }
422
422
 
423
- // src/cli/cli/show/locale.ts
423
+ // src/cli/cmd/show/locale.ts
424
424
  import { Command as Command3 } from "interactive-commander";
425
425
  import Ora3 from "ora";
426
426
  var locale_default = new Command3().command("locale").description("Print out the list of locales").helpOption("-h, --help", "Show help").argument("<type>", 'Type of locales to show, either "sources" or "targets"').action(async (type) => {
@@ -445,7 +445,7 @@ var locale_default = new Command3().command("locale").description("Print out the
445
445
  }
446
446
  });
447
447
 
448
- // src/cli/cli/show/files.ts
448
+ // src/cli/cmd/show/files.ts
449
449
  import { Command as Command4 } from "interactive-commander";
450
450
  import Ora4 from "ora";
451
451
 
@@ -529,7 +529,7 @@ function resolveBucketItem(bucketItem) {
529
529
  return bucketItem;
530
530
  }
531
531
 
532
- // src/cli/cli/show/files.ts
532
+ // src/cli/cmd/show/files.ts
533
533
  var files_default = new Command4().command("files").description("Print out the list of files managed by Lingo.dev").option("--source", "Only show source files").option("--target", "Only show target files").helpOption("-h, --help", "Show help").action(async (type) => {
534
534
  const ora = Ora4();
535
535
  try {
@@ -575,10 +575,10 @@ var files_default = new Command4().command("files").description("Print out the l
575
575
  }
576
576
  });
577
577
 
578
- // src/cli/cli/show/index.ts
578
+ // src/cli/cmd/show/index.ts
579
579
  var show_default = new Command5().command("show").description("Prints out the current configuration").helpOption("-h, --help", "Show help").addCommand(config_default).addCommand(locale_default).addCommand(files_default);
580
580
 
581
- // src/cli/cli/i18n.ts
581
+ // src/cli/cmd/i18n.ts
582
582
  import { Command as Command6 } from "interactive-commander";
583
583
  import Z4 from "zod";
584
584
  import _17 from "lodash";
@@ -724,7 +724,7 @@ function createTextFileLoader(pathPattern) {
724
724
  const finalPath = path5.resolve(draftPath);
725
725
  const dirPath = path5.dirname(finalPath);
726
726
  await fs5.mkdir(dirPath, { recursive: true });
727
- const finalPayload = data.trim() + "\n";
727
+ const finalPayload = data.trim();
728
728
  await fs5.writeFile(finalPath, finalPayload, {
729
729
  encoding: "utf-8",
730
730
  flag: "w"
@@ -1271,7 +1271,7 @@ function createPrettierLoader(options) {
1271
1271
  return data;
1272
1272
  }
1273
1273
  const result = prettier.format(data, {
1274
- ...prettierConfig || { printWidth: 2500 },
1274
+ ...prettierConfig || { printWidth: 2500, bracketSameLine: false },
1275
1275
  parser: options.parser,
1276
1276
  // For HTML parser, preserve comments and quotes
1277
1277
  ...options.parser === "html" ? {
@@ -2136,7 +2136,6 @@ function createVttLoader() {
2136
2136
  text
2137
2137
  };
2138
2138
  });
2139
- console.log(payload, output);
2140
2139
  const input = {
2141
2140
  valid: true,
2142
2141
  strict: true,
@@ -2236,6 +2235,100 @@ function createSyncLoader() {
2236
2235
  });
2237
2236
  }
2238
2237
 
2238
+ // src/cli/utils/plutil-formatter.ts
2239
+ function formatPlutilStyle(jsonData, existingJson) {
2240
+ const indent = existingJson ? detectIndentation(existingJson) : " ";
2241
+ function format(data, level = 0) {
2242
+ const currentIndent = indent.repeat(level);
2243
+ const nextIndent = indent.repeat(level + 1);
2244
+ if (typeof data !== "object" || data === null) {
2245
+ return JSON.stringify(data);
2246
+ }
2247
+ if (Array.isArray(data)) {
2248
+ if (data.length === 0) return "[]";
2249
+ const items2 = data.map((item) => `${nextIndent}${format(item, level + 1)}`);
2250
+ return `[
2251
+ ${items2.join(",\n")}
2252
+ ${currentIndent}]`;
2253
+ }
2254
+ const keys = Object.keys(data);
2255
+ if (keys.length === 0) {
2256
+ return `{
2257
+
2258
+ ${currentIndent}}`;
2259
+ }
2260
+ const items = keys.map((key) => {
2261
+ const value = data[key];
2262
+ return `${nextIndent}${JSON.stringify(key)} : ${format(value, level + 1)}`;
2263
+ });
2264
+ return `{
2265
+ ${items.join(",\n")}
2266
+ ${currentIndent}}`;
2267
+ }
2268
+ return format(jsonData);
2269
+ }
2270
+ function detectIndentation(jsonStr) {
2271
+ const match = jsonStr.match(/\n(\s+)/);
2272
+ return match ? match[1] : " ";
2273
+ }
2274
+
2275
+ // src/cli/loaders/plutil-json-loader.ts
2276
+ function createPlutilJsonTextLoader() {
2277
+ return createLoader({
2278
+ async pull(locale, data) {
2279
+ return data;
2280
+ },
2281
+ async push(locale, data, originalInput) {
2282
+ const jsonData = JSON.parse(data);
2283
+ const result = formatPlutilStyle(jsonData, originalInput || "");
2284
+ console.log(result[result.length - 1]);
2285
+ return result;
2286
+ }
2287
+ });
2288
+ }
2289
+
2290
+ // src/cli/loaders/new-line.ts
2291
+ function createNewLineLoader() {
2292
+ return createLoader({
2293
+ async pull(locale, input) {
2294
+ return input;
2295
+ },
2296
+ async push(locale, data, originalInput) {
2297
+ if (!data) return "";
2298
+ const trimmed = data.replace(/[\r\n]+$/, "");
2299
+ if (originalInput?.match(/[\r\n]$/)) {
2300
+ const ending = originalInput?.includes("\r\n") ? "\r\n" : originalInput?.includes("\r") ? "\r" : "\n";
2301
+ return trimmed + ending;
2302
+ }
2303
+ return trimmed;
2304
+ }
2305
+ });
2306
+ }
2307
+
2308
+ // src/cli/loaders/json-sorting.ts
2309
+ function createJsonSortingLoader() {
2310
+ return createLoader({
2311
+ async pull(locale, input) {
2312
+ return input;
2313
+ },
2314
+ async push(locale, data, originalInput) {
2315
+ return sortObjectDeep(data);
2316
+ }
2317
+ });
2318
+ }
2319
+ function sortObjectDeep(obj) {
2320
+ if (Array.isArray(obj)) {
2321
+ return obj.map(sortObjectDeep);
2322
+ }
2323
+ if (obj !== null && typeof obj === "object") {
2324
+ return Object.keys(obj).sort().reduce((result, key) => {
2325
+ result[key] = sortObjectDeep(obj[key]);
2326
+ return result;
2327
+ }, {});
2328
+ }
2329
+ return obj;
2330
+ }
2331
+
2239
2332
  // src/cli/loaders/index.ts
2240
2333
  function createBucketLoader(bucketType, bucketPathPattern) {
2241
2334
  switch (bucketType) {
@@ -2244,6 +2337,7 @@ function createBucketLoader(bucketType, bucketPathPattern) {
2244
2337
  case "android":
2245
2338
  return composeLoaders(
2246
2339
  createTextFileLoader(bucketPathPattern),
2340
+ createNewLineLoader(),
2247
2341
  createAndroidLoader(),
2248
2342
  createFlatLoader(),
2249
2343
  createSyncLoader(),
@@ -2252,6 +2346,7 @@ function createBucketLoader(bucketType, bucketPathPattern) {
2252
2346
  case "csv":
2253
2347
  return composeLoaders(
2254
2348
  createTextFileLoader(bucketPathPattern),
2349
+ createNewLineLoader(),
2255
2350
  createCsvLoader(),
2256
2351
  createFlatLoader(),
2257
2352
  createSyncLoader(),
@@ -2260,6 +2355,7 @@ function createBucketLoader(bucketType, bucketPathPattern) {
2260
2355
  case "html":
2261
2356
  return composeLoaders(
2262
2357
  createTextFileLoader(bucketPathPattern),
2358
+ createNewLineLoader(),
2263
2359
  createPrettierLoader({ parser: "html", alwaysFormat: true }),
2264
2360
  createHtmlLoader(),
2265
2361
  createSyncLoader(),
@@ -2268,6 +2364,7 @@ function createBucketLoader(bucketType, bucketPathPattern) {
2268
2364
  case "json":
2269
2365
  return composeLoaders(
2270
2366
  createTextFileLoader(bucketPathPattern),
2367
+ createNewLineLoader(),
2271
2368
  createPrettierLoader({ parser: "json" }),
2272
2369
  createJsonLoader(),
2273
2370
  createFlatLoader(),
@@ -2277,6 +2374,7 @@ function createBucketLoader(bucketType, bucketPathPattern) {
2277
2374
  case "markdown":
2278
2375
  return composeLoaders(
2279
2376
  createTextFileLoader(bucketPathPattern),
2377
+ createNewLineLoader(),
2280
2378
  createPrettierLoader({ parser: "markdown" }),
2281
2379
  createMarkdownLoader(),
2282
2380
  createSyncLoader(),
@@ -2285,6 +2383,7 @@ function createBucketLoader(bucketType, bucketPathPattern) {
2285
2383
  case "po":
2286
2384
  return composeLoaders(
2287
2385
  createTextFileLoader(bucketPathPattern),
2386
+ createNewLineLoader(),
2288
2387
  createPoLoader(),
2289
2388
  createFlatLoader(),
2290
2389
  createSyncLoader(),
@@ -2294,6 +2393,7 @@ function createBucketLoader(bucketType, bucketPathPattern) {
2294
2393
  case "properties":
2295
2394
  return composeLoaders(
2296
2395
  createTextFileLoader(bucketPathPattern),
2396
+ createNewLineLoader(),
2297
2397
  createPropertiesLoader(),
2298
2398
  createSyncLoader(),
2299
2399
  createUnlocalizableLoader()
@@ -2301,6 +2401,7 @@ function createBucketLoader(bucketType, bucketPathPattern) {
2301
2401
  case "xcode-strings":
2302
2402
  return composeLoaders(
2303
2403
  createTextFileLoader(bucketPathPattern),
2404
+ createNewLineLoader(),
2304
2405
  createXcodeStringsLoader(),
2305
2406
  createSyncLoader(),
2306
2407
  createUnlocalizableLoader()
@@ -2308,6 +2409,7 @@ function createBucketLoader(bucketType, bucketPathPattern) {
2308
2409
  case "xcode-stringsdict":
2309
2410
  return composeLoaders(
2310
2411
  createTextFileLoader(bucketPathPattern),
2412
+ createNewLineLoader(),
2311
2413
  createXcodeStringsdictLoader(),
2312
2414
  createFlatLoader(),
2313
2415
  createSyncLoader(),
@@ -2316,8 +2418,10 @@ function createBucketLoader(bucketType, bucketPathPattern) {
2316
2418
  case "xcode-xcstrings":
2317
2419
  return composeLoaders(
2318
2420
  createTextFileLoader(bucketPathPattern),
2319
- createPrettierLoader({ parser: "json" }),
2421
+ createNewLineLoader(),
2422
+ createPlutilJsonTextLoader(),
2320
2423
  createJsonLoader(),
2424
+ createJsonSortingLoader(),
2321
2425
  createXcodeXcstringsLoader(),
2322
2426
  createFlatLoader(),
2323
2427
  createSyncLoader(),
@@ -2327,6 +2431,7 @@ function createBucketLoader(bucketType, bucketPathPattern) {
2327
2431
  case "yaml":
2328
2432
  return composeLoaders(
2329
2433
  createTextFileLoader(bucketPathPattern),
2434
+ createNewLineLoader(),
2330
2435
  createPrettierLoader({ parser: "yaml" }),
2331
2436
  createYamlLoader(),
2332
2437
  createFlatLoader(),
@@ -2336,6 +2441,7 @@ function createBucketLoader(bucketType, bucketPathPattern) {
2336
2441
  case "yaml-root-key":
2337
2442
  return composeLoaders(
2338
2443
  createTextFileLoader(bucketPathPattern),
2444
+ createNewLineLoader(),
2339
2445
  createPrettierLoader({ parser: "yaml" }),
2340
2446
  createYamlLoader(),
2341
2447
  createRootKeyLoader(true),
@@ -2346,6 +2452,7 @@ function createBucketLoader(bucketType, bucketPathPattern) {
2346
2452
  case "flutter":
2347
2453
  return composeLoaders(
2348
2454
  createTextFileLoader(bucketPathPattern),
2455
+ createNewLineLoader(),
2349
2456
  createPrettierLoader({ parser: "json" }),
2350
2457
  createJsonLoader(),
2351
2458
  createFlutterLoader(),
@@ -2356,6 +2463,7 @@ function createBucketLoader(bucketType, bucketPathPattern) {
2356
2463
  case "xliff":
2357
2464
  return composeLoaders(
2358
2465
  createTextFileLoader(bucketPathPattern),
2466
+ createNewLineLoader(),
2359
2467
  createXliffLoader(),
2360
2468
  createFlatLoader(),
2361
2469
  createSyncLoader(),
@@ -2364,6 +2472,7 @@ function createBucketLoader(bucketType, bucketPathPattern) {
2364
2472
  case "xml":
2365
2473
  return composeLoaders(
2366
2474
  createTextFileLoader(bucketPathPattern),
2475
+ createNewLineLoader(),
2367
2476
  createXmlLoader(),
2368
2477
  createFlatLoader(),
2369
2478
  createSyncLoader(),
@@ -2372,6 +2481,7 @@ function createBucketLoader(bucketType, bucketPathPattern) {
2372
2481
  case "srt":
2373
2482
  return composeLoaders(
2374
2483
  createTextFileLoader(bucketPathPattern),
2484
+ createNewLineLoader(),
2375
2485
  createSrtLoader(),
2376
2486
  createSyncLoader(),
2377
2487
  createUnlocalizableLoader()
@@ -2379,6 +2489,7 @@ function createBucketLoader(bucketType, bucketPathPattern) {
2379
2489
  case "dato":
2380
2490
  return composeLoaders(
2381
2491
  createDatoLoader(bucketPathPattern),
2492
+ createNewLineLoader(),
2382
2493
  createSyncLoader(),
2383
2494
  createFlatLoader(),
2384
2495
  createUnlocalizableLoader()
@@ -2386,6 +2497,7 @@ function createBucketLoader(bucketType, bucketPathPattern) {
2386
2497
  case "vtt":
2387
2498
  return composeLoaders(
2388
2499
  createTextFileLoader(bucketPathPattern),
2500
+ createNewLineLoader(),
2389
2501
  createVttLoader(),
2390
2502
  createSyncLoader(),
2391
2503
  createUnlocalizableLoader()
@@ -2462,7 +2574,7 @@ var LockfileSchema = Z3.object({
2462
2574
  ).default({})
2463
2575
  });
2464
2576
 
2465
- // src/cli/cli/i18n.ts
2577
+ // src/cli/cmd/i18n.ts
2466
2578
  import chalk from "chalk";
2467
2579
  import { createTwoFilesPatch } from "diff";
2468
2580
  import inquirer2 from "inquirer";
@@ -2535,7 +2647,7 @@ function _tryParseJSON(line) {
2535
2647
  }
2536
2648
  }
2537
2649
 
2538
- // src/cli/cli/i18n.ts
2650
+ // src/cli/cmd/i18n.ts
2539
2651
  var i18n_default = new Command6().command("i18n").description("Run Localization engine").helpOption("-h, --help", "Show help").option("--locale <locale>", "Locale to process", (val, prev) => prev ? [...prev, val] : [val]).option("--bucket <bucket>", "Bucket to process", (val, prev) => prev ? [...prev, val] : [val]).option("--key <key>", "Key to process").option("--frozen", `Don't update the translations and fail if an update is needed`).option("--force", "Ignore lockfile and process all keys").option("--verbose", "Show verbose output").option("--interactive", "Interactive mode").option("--api-key <api-key>", "Explicitly set the API key to use").option("--debug", "Debug mode").option("--strict", "Stop on first error").action(async function(options) {
2540
2652
  const ora = Ora5();
2541
2653
  const flags = parseFlags(options);
@@ -2958,7 +3070,7 @@ Editing value for: ${chalk.cyan(key)}`);
2958
3070
  return customData;
2959
3071
  }
2960
3072
 
2961
- // src/cli/cli/lockfile.ts
3073
+ // src/cli/cmd/lockfile.ts
2962
3074
  import { Command as Command7 } from "interactive-commander";
2963
3075
  import Z5 from "zod";
2964
3076
  import Ora6 from "ora";
@@ -2987,7 +3099,7 @@ var flagsSchema = Z5.object({
2987
3099
  force: Z5.boolean().default(false)
2988
3100
  });
2989
3101
 
2990
- // src/cli/cli/cleanup.ts
3102
+ // src/cli/cmd/cleanup.ts
2991
3103
  import { Command as Command8 } from "interactive-commander";
2992
3104
  import _18 from "lodash";
2993
3105
  import Ora7 from "ora";
@@ -3080,7 +3192,7 @@ function displaySummary(results) {
3080
3192
  // package.json
3081
3193
  var package_default = {
3082
3194
  name: "lingo.dev",
3083
- version: "0.71.0",
3195
+ version: "0.73.0",
3084
3196
  description: "Lingo.dev CLI",
3085
3197
  private: false,
3086
3198
  type: "module",