lingo.dev 0.77.4 → 0.77.5

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.cjs CHANGED
@@ -332,10 +332,11 @@ function findLocaleFilesWithExtension(ext) {
332
332
  });
333
333
  const grouppedFilesAndPatterns = _lodash2.default.groupBy(localeFilesAndPatterns, "pattern");
334
334
  const patterns = Object.keys(grouppedFilesAndPatterns);
335
+ const defaultPatterns = [`i18n/[locale]${ext}`];
335
336
  if (patterns.length > 0) {
336
- return { found: true, patterns };
337
+ return { patterns, defaultPatterns };
337
338
  }
338
- return { found: false, patterns: [`i18n/[locale]${ext}`] };
339
+ return { patterns: [], defaultPatterns };
339
340
  }
340
341
  function findLocaleFilesForFilename(fileName) {
341
342
  const pattern = fileName;
@@ -348,10 +349,11 @@ function findLocaleFilesForFilename(fileName) {
348
349
  }));
349
350
  const grouppedFilesAndPatterns = _lodash2.default.groupBy(localeFilesAndPatterns, "pattern");
350
351
  const patterns = Object.keys(grouppedFilesAndPatterns);
352
+ const defaultPatterns = [fileName];
351
353
  if (patterns.length > 0) {
352
- return { found: true, patterns };
354
+ return { patterns, defaultPatterns };
353
355
  }
354
- return { found: false, patterns: [fileName] };
356
+ return { patterns: [], defaultPatterns };
355
357
  }
356
358
 
357
359
  // src/cli/utils/ensure-patterns.ts
@@ -473,10 +475,136 @@ function findCurrentProjectRoot() {
473
475
  return null;
474
476
  }
475
477
 
478
+ // src/cli/utils/init-ci-cd.ts
479
+
480
+
481
+
482
+ var platforms = ["github", "bitbucket", "gitlab"];
483
+ async function initCICD(spinner) {
484
+ const initializers = getPlatformInitializers(spinner);
485
+ const init = await _prompts.confirm.call(void 0, {
486
+ message: "Would you like to use Lingo.dev in your CI/CD?"
487
+ });
488
+ if (!init) {
489
+ spinner.warn("CI/CD not initialized. To set it up later, see docs: https://docs.lingo.dev/ci-action/overview");
490
+ return;
491
+ }
492
+ const selectedPlatforms = await _prompts.checkbox.call(void 0, {
493
+ message: "Please select CI/CD platform(s) you want to use:",
494
+ choices: platforms.map((platform) => ({
495
+ name: initializers[platform].name,
496
+ value: platform,
497
+ checked: initializers[platform].isEnabled()
498
+ }))
499
+ });
500
+ for (const platform of selectedPlatforms) {
501
+ await initializers[platform].init();
502
+ }
503
+ }
504
+ function getPlatformInitializers(spinner) {
505
+ return {
506
+ github: makeGithubInitializer(spinner),
507
+ bitbucket: makeBitbucketInitializer(spinner),
508
+ gitlab: makeGitlabInitializer(spinner)
509
+ };
510
+ }
511
+ function makePlatformInitializer(config, spinner) {
512
+ return {
513
+ name: config.name,
514
+ isEnabled: () => {
515
+ const filePath = _path2.default.join(process.cwd(), config.checkPath);
516
+ return _fs2.default.existsSync(filePath);
517
+ },
518
+ init: async () => {
519
+ const filePath = _path2.default.join(process.cwd(), config.ciConfigPath);
520
+ const dirPath = _path2.default.dirname(filePath);
521
+ if (!_fs2.default.existsSync(dirPath)) {
522
+ _fs2.default.mkdirSync(dirPath, { recursive: true });
523
+ }
524
+ let canWrite = true;
525
+ if (_fs2.default.existsSync(filePath)) {
526
+ canWrite = await _prompts.confirm.call(void 0, {
527
+ message: `File ${filePath} already exists. Do you want to overwrite it?`,
528
+ default: false
529
+ });
530
+ }
531
+ if (canWrite) {
532
+ _fs2.default.writeFileSync(filePath, config.ciConfigContent);
533
+ spinner.succeed(`CI/CD initialized for ${config.name}`);
534
+ } else {
535
+ spinner.warn(`CI/CD not initialized for ${config.name}`);
536
+ }
537
+ }
538
+ };
539
+ }
540
+ function makeGithubInitializer(spinner) {
541
+ return makePlatformInitializer(
542
+ {
543
+ name: "GitHub Action",
544
+ checkPath: ".github",
545
+ ciConfigPath: ".github/workflows/i18n.yml",
546
+ ciConfigContent: `name: Lingo.dev i18n
547
+
548
+ on:
549
+ push:
550
+ branches:
551
+ - main
552
+
553
+ permissions:
554
+ contents: write
555
+ pull-requests: write
556
+
557
+ jobs:
558
+ i18n:
559
+ name: Run i18n
560
+ runs-on: ubuntu-latest
561
+ steps:
562
+ - uses: actions/checkout@v4
563
+ - uses: lingodotdev/lingo.dev@main
564
+ with:
565
+ api-key: \${{ secrets.LINGODOTDEV_API_KEY }}
566
+ `
567
+ },
568
+ spinner
569
+ );
570
+ }
571
+ function makeBitbucketInitializer(spinner) {
572
+ return makePlatformInitializer(
573
+ {
574
+ name: "Bitbucket Pipeline",
575
+ checkPath: "bitbucket-pipelines.yml",
576
+ ciConfigPath: "bitbucket-pipelines.yml",
577
+ ciConfigContent: `pipelines:
578
+ branches:
579
+ main:
580
+ - step:
581
+ name: Run i18n
582
+ script:
583
+ - pipe: lingodotdev/lingo.dev:main`
584
+ },
585
+ spinner
586
+ );
587
+ }
588
+ function makeGitlabInitializer(spinner) {
589
+ return makePlatformInitializer(
590
+ {
591
+ name: "Gitlab CI",
592
+ checkPath: ".gitlab-ci.yml",
593
+ ciConfigPath: ".gitlab-ci.yml",
594
+ ciConfigContent: `lingodotdev:
595
+ image: lingodotdev/ci-action:latest
596
+ script:
597
+ - echo "Done"
598
+ `
599
+ },
600
+ spinner
601
+ );
602
+ }
603
+
476
604
  // src/cli/cmd/init.ts
477
- var openUrl = (path12) => {
605
+ var openUrl = (path13) => {
478
606
  const settings = getSettings(void 0);
479
- _child_process.spawn.call(void 0, "open", [`${settings.auth.webUrl}${path12}`]);
607
+ _child_process.spawn.call(void 0, "open", [`${settings.auth.webUrl}${path13}`]);
480
608
  };
481
609
  var throwHelpError = (option, value) => {
482
610
  if (value === "help") {
@@ -553,8 +681,8 @@ var init_default = new (0, _interactivecommander.InteractiveCommand)().command("
553
681
  };
554
682
  } else {
555
683
  let selectedPatterns = [];
556
- const { found, patterns } = findLocaleFiles(options.bucket);
557
- if (found) {
684
+ const { patterns, defaultPatterns } = findLocaleFiles(options.bucket);
685
+ if (patterns.length > 0) {
558
686
  spinner.succeed("Found existing locale files:");
559
687
  selectedPatterns = await _prompts.checkbox.call(void 0, {
560
688
  message: "Select the paths to use",
@@ -567,11 +695,11 @@ var init_default = new (0, _interactivecommander.InteractiveCommand)().command("
567
695
  }
568
696
  if (selectedPatterns.length === 0) {
569
697
  const useDefault = await _prompts.confirm.call(void 0, {
570
- message: `Use (and create) default path ${patterns.join(", ")}?`
698
+ message: `Use (and create) default path ${defaultPatterns.join(", ")}?`
571
699
  });
572
- ensurePatterns(patterns, options.source);
573
700
  if (useDefault) {
574
- selectedPatterns = patterns;
701
+ ensurePatterns(defaultPatterns, options.source);
702
+ selectedPatterns = defaultPatterns;
575
703
  }
576
704
  }
577
705
  if (selectedPatterns.length === 0) {
@@ -589,6 +717,7 @@ var init_default = new (0, _interactivecommander.InteractiveCommand)().command("
589
717
  await saveConfig(newConfig);
590
718
  spinner.succeed("Lingo.dev project initialized");
591
719
  if (isInteractive) {
720
+ await initCICD(spinner);
592
721
  const openDocs = await _prompts.confirm.call(void 0, { message: "Would you like to see our docs?" });
593
722
  if (openDocs) {
594
723
  openUrl("/go/docs");
@@ -803,8 +932,8 @@ var files_default = new (0, _interactivecommander.Command)().command("files").de
803
932
  } else if (type.target) {
804
933
  result.push(...targetPaths);
805
934
  }
806
- result.forEach((path12) => {
807
- console.log(path12);
935
+ result.forEach((path13) => {
936
+ console.log(path13);
808
937
  });
809
938
  }
810
939
  }
@@ -1344,9 +1473,9 @@ function createHtmlLoader() {
1344
1473
  const bDepth = b.split("/").length;
1345
1474
  return aDepth - bDepth;
1346
1475
  });
1347
- paths.forEach((path12) => {
1348
- const value = data[path12];
1349
- const [nodePath, attribute] = path12.split("#");
1476
+ paths.forEach((path13) => {
1477
+ const value = data[path13];
1478
+ const [nodePath, attribute] = path13.split("#");
1350
1479
  const [rootTag, ...indices] = nodePath.split("/");
1351
1480
  let parent = rootTag === "head" ? document.head : document.body;
1352
1481
  let current = parent;
@@ -2353,18 +2482,18 @@ function createRawDatoValue(parsedDatoValue, originalRawDatoValue, isClean = fal
2353
2482
  }
2354
2483
  function serializeStructuredText(rawStructuredText) {
2355
2484
  return serializeStructuredTextNode(rawStructuredText);
2356
- function serializeStructuredTextNode(node, path12 = [], acc = {}) {
2485
+ function serializeStructuredTextNode(node, path13 = [], acc = {}) {
2357
2486
  if ("document" in node) {
2358
- return serializeStructuredTextNode(node.document, [...path12, "document"], acc);
2487
+ return serializeStructuredTextNode(node.document, [...path13, "document"], acc);
2359
2488
  }
2360
2489
  if (!_lodash2.default.isNil(node.value)) {
2361
- acc[[...path12, "value"].join(".")] = node.value;
2490
+ acc[[...path13, "value"].join(".")] = node.value;
2362
2491
  } else if (_lodash2.default.get(node, "type") === "block") {
2363
- acc[[...path12, "item"].join(".")] = serializeBlock(node.item);
2492
+ acc[[...path13, "item"].join(".")] = serializeBlock(node.item);
2364
2493
  }
2365
2494
  if (node.children) {
2366
2495
  for (let i = 0; i < node.children.length; i++) {
2367
- serializeStructuredTextNode(node.children[i], [...path12, i.toString()], acc);
2496
+ serializeStructuredTextNode(node.children[i], [...path13, i.toString()], acc);
2368
2497
  }
2369
2498
  }
2370
2499
  return acc;
@@ -2423,8 +2552,8 @@ function deserializeBlockList(parsedBlockList, originalRawBlockList, isClean = f
2423
2552
  }
2424
2553
  function deserializeStructuredText(parsedStructuredText, originalRawStructuredText) {
2425
2554
  const result = _lodash2.default.cloneDeep(originalRawStructuredText);
2426
- for (const [path12, value] of _lodash2.default.entries(parsedStructuredText)) {
2427
- const realPath = _lodash2.default.chain(path12.split(".")).flatMap((s) => !_lodash2.default.isNaN(_lodash2.default.toNumber(s)) ? ["children", s] : s).value();
2555
+ for (const [path13, value] of _lodash2.default.entries(parsedStructuredText)) {
2556
+ const realPath = _lodash2.default.chain(path13.split(".")).flatMap((s) => !_lodash2.default.isNaN(_lodash2.default.toNumber(s)) ? ["children", s] : s).value();
2428
2557
  const deserializedValue = createRawDatoValue(value, _lodash2.default.get(originalRawStructuredText, realPath), true);
2429
2558
  _lodash2.default.set(result, realPath, deserializedValue);
2430
2559
  }
@@ -3623,7 +3752,7 @@ var mcp_default = new (0, _interactivecommander.Command)().command("mcp").descri
3623
3752
  // package.json
3624
3753
  var package_default = {
3625
3754
  name: "lingo.dev",
3626
- version: "0.77.4",
3755
+ version: "0.77.5",
3627
3756
  description: "Lingo.dev CLI",
3628
3757
  private: false,
3629
3758
  publishConfig: {