lingo.dev 0.77.3 → 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 +202 -68
- package/build/cli.cjs.map +1 -1
- package/build/cli.mjs +211 -77
- package/build/cli.mjs.map +1 -1
- package/package.json +1 -1
package/build/cli.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/cli/index.ts
|
|
2
2
|
var _dotenv = require('dotenv'); var _dotenv2 = _interopRequireDefault(_dotenv);
|
|
3
3
|
var _interactivecommander = require('interactive-commander');
|
|
4
4
|
var _figlet = require('figlet'); var _figlet2 = _interopRequireDefault(_figlet);
|
|
@@ -272,7 +272,7 @@ var _prompts = require('@inquirer/prompts');
|
|
|
272
272
|
|
|
273
273
|
// src/cli/utils/find-locale-paths.ts
|
|
274
274
|
|
|
275
|
-
var _glob = require('glob');
|
|
275
|
+
var _glob = require('glob');
|
|
276
276
|
|
|
277
277
|
|
|
278
278
|
function findLocaleFiles(bucket) {
|
|
@@ -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 {
|
|
337
|
+
return { patterns, defaultPatterns };
|
|
337
338
|
}
|
|
338
|
-
return {
|
|
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 {
|
|
354
|
+
return { patterns, defaultPatterns };
|
|
353
355
|
}
|
|
354
|
-
return {
|
|
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 = (
|
|
605
|
+
var openUrl = (path13) => {
|
|
478
606
|
const settings = getSettings(void 0);
|
|
479
|
-
_child_process.spawn.call(void 0, "open", [`${settings.auth.webUrl}${
|
|
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 {
|
|
557
|
-
if (
|
|
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 ${
|
|
698
|
+
message: `Use (and create) default path ${defaultPatterns.join(", ")}?`
|
|
571
699
|
});
|
|
572
|
-
ensurePatterns(patterns, options.source);
|
|
573
700
|
if (useDefault) {
|
|
574
|
-
|
|
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");
|
|
@@ -745,14 +874,19 @@ function expandPlaceholderedGlob(_pathPattern, sourceLocale) {
|
|
|
745
874
|
return indexes;
|
|
746
875
|
}, []);
|
|
747
876
|
const sourcePathPattern = pathPattern.replaceAll(/\[locale\]/g, sourceLocale);
|
|
748
|
-
const sourcePaths =
|
|
877
|
+
const sourcePaths = _glob.glob.sync(sourcePathPattern, { follow: true, withFileTypes: true }).filter((file) => file.isFile() || file.isSymbolicLink()).map((file) => file.fullpath()).map((fullpath) => _path2.default.relative(process.cwd(), fullpath));
|
|
749
878
|
const placeholderedPaths = sourcePaths.map((sourcePath) => {
|
|
750
879
|
const sourcePathChunks = sourcePath.split(_path2.default.sep);
|
|
751
880
|
localeSegmentIndexes.forEach((localeSegmentIndex) => {
|
|
752
|
-
const
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
881
|
+
const pathPatternChunk = pathPatternChunks[localeSegmentIndex];
|
|
882
|
+
const sourcePathChunk = sourcePathChunks[localeSegmentIndex];
|
|
883
|
+
const regexp = new RegExp(
|
|
884
|
+
"(" + pathPatternChunk.replaceAll(".", "\\.").replaceAll("*", ".*").replace("[locale]", `)${sourceLocale}(`) + ")"
|
|
885
|
+
);
|
|
886
|
+
const match = sourcePathChunk.match(regexp);
|
|
887
|
+
if (match) {
|
|
888
|
+
const [, prefix, suffix] = match;
|
|
889
|
+
const placeholderedSegment = prefix + "[locale]" + suffix;
|
|
756
890
|
sourcePathChunks[localeSegmentIndex] = placeholderedSegment;
|
|
757
891
|
}
|
|
758
892
|
});
|
|
@@ -798,8 +932,8 @@ var files_default = new (0, _interactivecommander.Command)().command("files").de
|
|
|
798
932
|
} else if (type.target) {
|
|
799
933
|
result.push(...targetPaths);
|
|
800
934
|
}
|
|
801
|
-
result.forEach((
|
|
802
|
-
console.log(
|
|
935
|
+
result.forEach((path13) => {
|
|
936
|
+
console.log(path13);
|
|
803
937
|
});
|
|
804
938
|
}
|
|
805
939
|
}
|
|
@@ -831,12 +965,12 @@ function composeLoaders(...loaders) {
|
|
|
831
965
|
return {
|
|
832
966
|
init: async () => {
|
|
833
967
|
for (const loader of loaders) {
|
|
834
|
-
await _optionalChain([loader, 'access',
|
|
968
|
+
await _optionalChain([loader, 'access', _35 => _35.init, 'optionalCall', _36 => _36()]);
|
|
835
969
|
}
|
|
836
970
|
},
|
|
837
971
|
setDefaultLocale(locale) {
|
|
838
972
|
for (const loader of loaders) {
|
|
839
|
-
_optionalChain([loader, 'access',
|
|
973
|
+
_optionalChain([loader, 'access', _37 => _37.setDefaultLocale, 'optionalCall', _38 => _38(locale)]);
|
|
840
974
|
}
|
|
841
975
|
return this;
|
|
842
976
|
},
|
|
@@ -867,7 +1001,7 @@ function createLoader(lDefinition) {
|
|
|
867
1001
|
if (state.initCtx) {
|
|
868
1002
|
return state.initCtx;
|
|
869
1003
|
}
|
|
870
|
-
state.initCtx = await _optionalChain([lDefinition, 'access',
|
|
1004
|
+
state.initCtx = await _optionalChain([lDefinition, 'access', _39 => _39.init, 'optionalCall', _40 => _40()]);
|
|
871
1005
|
return state.initCtx;
|
|
872
1006
|
},
|
|
873
1007
|
setDefaultLocale(locale) {
|
|
@@ -956,7 +1090,7 @@ function createNormalizeLoader() {
|
|
|
956
1090
|
return normalized;
|
|
957
1091
|
},
|
|
958
1092
|
push: async (locale, data, originalInput) => {
|
|
959
|
-
const keysMap = _nullishCoalesce(_optionalChain([originalInput, 'optionalAccess',
|
|
1093
|
+
const keysMap = _nullishCoalesce(_optionalChain([originalInput, 'optionalAccess', _41 => _41.keysMap]), () => ( {}));
|
|
960
1094
|
const input2 = mapDenormalizedKeys(data, keysMap);
|
|
961
1095
|
const denormalized = _flat.unflatten.call(void 0, input2, {
|
|
962
1096
|
delimiter: "/",
|
|
@@ -1059,8 +1193,8 @@ async function getTrailingNewLine(pathPattern, locale, originalLocale) {
|
|
|
1059
1193
|
if (!templateData) {
|
|
1060
1194
|
templateData = await readFileForLocale(pathPattern, originalLocale);
|
|
1061
1195
|
}
|
|
1062
|
-
if (_optionalChain([templateData, 'optionalAccess',
|
|
1063
|
-
const ending = _optionalChain([templateData, 'optionalAccess',
|
|
1196
|
+
if (_optionalChain([templateData, 'optionalAccess', _42 => _42.match, 'call', _43 => _43(/[\r\n]$/)])) {
|
|
1197
|
+
const ending = _optionalChain([templateData, 'optionalAccess', _44 => _44.includes, 'call', _45 => _45("\r\n")]) ? "\r\n" : _optionalChain([templateData, 'optionalAccess', _46 => _46.includes, 'call', _47 => _47("\r")]) ? "\r" : "\n";
|
|
1064
1198
|
return ending;
|
|
1065
1199
|
}
|
|
1066
1200
|
return "";
|
|
@@ -1287,7 +1421,7 @@ function createHtmlLoader() {
|
|
|
1287
1421
|
break;
|
|
1288
1422
|
}
|
|
1289
1423
|
const siblings = Array.from(parent.childNodes).filter(
|
|
1290
|
-
(n) => n.nodeType === 1 || n.nodeType === 3 && _optionalChain([n, 'access',
|
|
1424
|
+
(n) => n.nodeType === 1 || n.nodeType === 3 && _optionalChain([n, 'access', _48 => _48.textContent, 'optionalAccess', _49 => _49.trim, 'call', _50 => _50()])
|
|
1291
1425
|
);
|
|
1292
1426
|
const index = siblings.indexOf(current);
|
|
1293
1427
|
if (index !== -1) {
|
|
@@ -1322,11 +1456,11 @@ function createHtmlLoader() {
|
|
|
1322
1456
|
result[getPath(element, attr)] = value;
|
|
1323
1457
|
}
|
|
1324
1458
|
});
|
|
1325
|
-
Array.from(element.childNodes).filter((n) => n.nodeType === 1 || n.nodeType === 3 && _optionalChain([n, 'access',
|
|
1459
|
+
Array.from(element.childNodes).filter((n) => n.nodeType === 1 || n.nodeType === 3 && _optionalChain([n, 'access', _51 => _51.textContent, 'optionalAccess', _52 => _52.trim, 'call', _53 => _53()])).forEach(processNode);
|
|
1326
1460
|
}
|
|
1327
1461
|
};
|
|
1328
|
-
Array.from(document.head.childNodes).filter((n) => n.nodeType === 1 || n.nodeType === 3 && _optionalChain([n, 'access',
|
|
1329
|
-
Array.from(document.body.childNodes).filter((n) => n.nodeType === 1 || n.nodeType === 3 && _optionalChain([n, 'access',
|
|
1462
|
+
Array.from(document.head.childNodes).filter((n) => n.nodeType === 1 || n.nodeType === 3 && _optionalChain([n, 'access', _54 => _54.textContent, 'optionalAccess', _55 => _55.trim, 'call', _56 => _56()])).forEach(processNode);
|
|
1463
|
+
Array.from(document.body.childNodes).filter((n) => n.nodeType === 1 || n.nodeType === 3 && _optionalChain([n, 'access', _57 => _57.textContent, 'optionalAccess', _58 => _58.trim, 'call', _59 => _59()])).forEach(processNode);
|
|
1330
1464
|
return result;
|
|
1331
1465
|
},
|
|
1332
1466
|
async push(locale, data, originalInput) {
|
|
@@ -1339,16 +1473,16 @@ function createHtmlLoader() {
|
|
|
1339
1473
|
const bDepth = b.split("/").length;
|
|
1340
1474
|
return aDepth - bDepth;
|
|
1341
1475
|
});
|
|
1342
|
-
paths.forEach((
|
|
1343
|
-
const value = data[
|
|
1344
|
-
const [nodePath, attribute] =
|
|
1476
|
+
paths.forEach((path13) => {
|
|
1477
|
+
const value = data[path13];
|
|
1478
|
+
const [nodePath, attribute] = path13.split("#");
|
|
1345
1479
|
const [rootTag, ...indices] = nodePath.split("/");
|
|
1346
1480
|
let parent = rootTag === "head" ? document.head : document.body;
|
|
1347
1481
|
let current = parent;
|
|
1348
1482
|
for (let i = 0; i < indices.length; i++) {
|
|
1349
1483
|
const index = parseInt(indices[i]);
|
|
1350
1484
|
const siblings = Array.from(parent.childNodes).filter(
|
|
1351
|
-
(n) => n.nodeType === 1 || n.nodeType === 3 && _optionalChain([n, 'access',
|
|
1485
|
+
(n) => n.nodeType === 1 || n.nodeType === 3 && _optionalChain([n, 'access', _60 => _60.textContent, 'optionalAccess', _61 => _61.trim, 'call', _62 => _62()])
|
|
1352
1486
|
);
|
|
1353
1487
|
if (index >= siblings.length) {
|
|
1354
1488
|
if (i === indices.length - 1) {
|
|
@@ -1455,7 +1589,7 @@ function isSkippableLine(line) {
|
|
|
1455
1589
|
function parsePropertyLine(line) {
|
|
1456
1590
|
const [key, ...valueParts] = line.split("=");
|
|
1457
1591
|
return {
|
|
1458
|
-
key: _optionalChain([key, 'optionalAccess',
|
|
1592
|
+
key: _optionalChain([key, 'optionalAccess', _63 => _63.trim, 'call', _64 => _64()]) || "",
|
|
1459
1593
|
value: valueParts.join("=").trim()
|
|
1460
1594
|
};
|
|
1461
1595
|
}
|
|
@@ -1537,7 +1671,7 @@ function createXcodeXcstringsLoader() {
|
|
|
1537
1671
|
const resultData = {};
|
|
1538
1672
|
for (const [translationKey, _translationEntity] of Object.entries(input2.strings)) {
|
|
1539
1673
|
const rootTranslationEntity = _translationEntity;
|
|
1540
|
-
const langTranslationEntity = _optionalChain([rootTranslationEntity, 'optionalAccess',
|
|
1674
|
+
const langTranslationEntity = _optionalChain([rootTranslationEntity, 'optionalAccess', _65 => _65.localizations, 'optionalAccess', _66 => _66[locale]]);
|
|
1541
1675
|
if (langTranslationEntity) {
|
|
1542
1676
|
if ("stringUnit" in langTranslationEntity) {
|
|
1543
1677
|
resultData[translationKey] = langTranslationEntity.stringUnit.value;
|
|
@@ -1546,7 +1680,7 @@ function createXcodeXcstringsLoader() {
|
|
|
1546
1680
|
resultData[translationKey] = {};
|
|
1547
1681
|
const pluralForms = langTranslationEntity.variations.plural;
|
|
1548
1682
|
for (const form in pluralForms) {
|
|
1549
|
-
if (_optionalChain([pluralForms, 'access',
|
|
1683
|
+
if (_optionalChain([pluralForms, 'access', _67 => _67[form], 'optionalAccess', _68 => _68.stringUnit, 'optionalAccess', _69 => _69.value])) {
|
|
1550
1684
|
resultData[translationKey][form] = pluralForms[form].stringUnit.value;
|
|
1551
1685
|
}
|
|
1552
1686
|
}
|
|
@@ -1696,7 +1830,7 @@ function createPoDataLoader(params) {
|
|
|
1696
1830
|
Object.entries(entries).forEach(([msgid, entry]) => {
|
|
1697
1831
|
if (msgid && entry.msgid) {
|
|
1698
1832
|
const context = entry.msgctxt || "";
|
|
1699
|
-
const fullEntry = _optionalChain([parsedPo, 'access',
|
|
1833
|
+
const fullEntry = _optionalChain([parsedPo, 'access', _70 => _70.translations, 'access', _71 => _71[context], 'optionalAccess', _72 => _72[msgid]]);
|
|
1700
1834
|
if (fullEntry) {
|
|
1701
1835
|
result[msgid] = fullEntry;
|
|
1702
1836
|
}
|
|
@@ -1706,7 +1840,7 @@ function createPoDataLoader(params) {
|
|
|
1706
1840
|
return result;
|
|
1707
1841
|
},
|
|
1708
1842
|
async push(locale, data, originalInput) {
|
|
1709
|
-
const sections = _optionalChain([originalInput, 'optionalAccess',
|
|
1843
|
+
const sections = _optionalChain([originalInput, 'optionalAccess', _73 => _73.split, 'call', _74 => _74("\n\n"), 'access', _75 => _75.filter, 'call', _76 => _76(Boolean)]) || [];
|
|
1710
1844
|
const result = sections.map((section) => {
|
|
1711
1845
|
const sectionPo = _gettextparser2.default.po.parse(section);
|
|
1712
1846
|
const contextKey = _lodash2.default.keys(sectionPo.translations)[0];
|
|
@@ -1748,7 +1882,7 @@ function createPoContentLoader() {
|
|
|
1748
1882
|
entry.msgid,
|
|
1749
1883
|
{
|
|
1750
1884
|
...entry,
|
|
1751
|
-
msgstr: [_optionalChain([data, 'access',
|
|
1885
|
+
msgstr: [_optionalChain([data, 'access', _77 => _77[entry.msgid], 'optionalAccess', _78 => _78.singular]), _optionalChain([data, 'access', _79 => _79[entry.msgid], 'optionalAccess', _80 => _80.plural]) || null].filter(Boolean)
|
|
1752
1886
|
}
|
|
1753
1887
|
]).fromPairs().value();
|
|
1754
1888
|
return result;
|
|
@@ -1994,7 +2128,7 @@ function createDatoClient(params) {
|
|
|
1994
2128
|
only_valid: "true",
|
|
1995
2129
|
ids: !records.length ? void 0 : records.join(",")
|
|
1996
2130
|
}
|
|
1997
|
-
}).catch((error) => Promise.reject(_optionalChain([error, 'optionalAccess',
|
|
2131
|
+
}).catch((error) => Promise.reject(_optionalChain([error, 'optionalAccess', _81 => _81.response, 'optionalAccess', _82 => _82.body, 'optionalAccess', _83 => _83.data, 'optionalAccess', _84 => _84[0]]) || error));
|
|
1998
2132
|
},
|
|
1999
2133
|
findRecordsForModel: async (modelId, records) => {
|
|
2000
2134
|
try {
|
|
@@ -2004,9 +2138,9 @@ function createDatoClient(params) {
|
|
|
2004
2138
|
filter: {
|
|
2005
2139
|
type: modelId,
|
|
2006
2140
|
only_valid: "true",
|
|
2007
|
-
ids: !_optionalChain([records, 'optionalAccess',
|
|
2141
|
+
ids: !_optionalChain([records, 'optionalAccess', _85 => _85.length]) ? void 0 : records.join(",")
|
|
2008
2142
|
}
|
|
2009
|
-
}).catch((error) => Promise.reject(_optionalChain([error, 'optionalAccess',
|
|
2143
|
+
}).catch((error) => Promise.reject(_optionalChain([error, 'optionalAccess', _86 => _86.response, 'optionalAccess', _87 => _87.body, 'optionalAccess', _88 => _88.data, 'optionalAccess', _89 => _89[0]]) || error));
|
|
2010
2144
|
return result;
|
|
2011
2145
|
} catch (_error) {
|
|
2012
2146
|
throw new Error(
|
|
@@ -2020,9 +2154,9 @@ function createDatoClient(params) {
|
|
|
2020
2154
|
},
|
|
2021
2155
|
updateRecord: async (id, payload) => {
|
|
2022
2156
|
try {
|
|
2023
|
-
await dato.items.update(id, payload).catch((error) => Promise.reject(_optionalChain([error, 'optionalAccess',
|
|
2157
|
+
await dato.items.update(id, payload).catch((error) => Promise.reject(_optionalChain([error, 'optionalAccess', _90 => _90.response, 'optionalAccess', _91 => _91.body, 'optionalAccess', _92 => _92.data, 'optionalAccess', _93 => _93[0]]) || error));
|
|
2024
2158
|
} catch (_error) {
|
|
2025
|
-
if (_optionalChain([_error, 'optionalAccess',
|
|
2159
|
+
if (_optionalChain([_error, 'optionalAccess', _94 => _94.attributes, 'optionalAccess', _95 => _95.details, 'optionalAccess', _96 => _96.message])) {
|
|
2026
2160
|
throw new Error(
|
|
2027
2161
|
[
|
|
2028
2162
|
`${_error.attributes.details.message}`,
|
|
@@ -2043,9 +2177,9 @@ function createDatoClient(params) {
|
|
|
2043
2177
|
},
|
|
2044
2178
|
enableFieldLocalization: async (args) => {
|
|
2045
2179
|
try {
|
|
2046
|
-
await dato.fields.update(`${args.modelId}::${args.fieldId}`, { localized: true }).catch((error) => Promise.reject(_optionalChain([error, 'optionalAccess',
|
|
2180
|
+
await dato.fields.update(`${args.modelId}::${args.fieldId}`, { localized: true }).catch((error) => Promise.reject(_optionalChain([error, 'optionalAccess', _97 => _97.response, 'optionalAccess', _98 => _98.body, 'optionalAccess', _99 => _99.data, 'optionalAccess', _100 => _100[0]]) || error));
|
|
2047
2181
|
} catch (_error) {
|
|
2048
|
-
if (_optionalChain([_error, 'optionalAccess',
|
|
2182
|
+
if (_optionalChain([_error, 'optionalAccess', _101 => _101.attributes, 'optionalAccess', _102 => _102.code]) === "NOT_FOUND") {
|
|
2049
2183
|
throw new Error(
|
|
2050
2184
|
[
|
|
2051
2185
|
`Field "${args.fieldId}" not found in model "${args.modelId}".`,
|
|
@@ -2053,7 +2187,7 @@ function createDatoClient(params) {
|
|
|
2053
2187
|
].join("\n\n")
|
|
2054
2188
|
);
|
|
2055
2189
|
}
|
|
2056
|
-
if (_optionalChain([_error, 'optionalAccess',
|
|
2190
|
+
if (_optionalChain([_error, 'optionalAccess', _103 => _103.attributes, 'optionalAccess', _104 => _104.details, 'optionalAccess', _105 => _105.message])) {
|
|
2057
2191
|
throw new Error(
|
|
2058
2192
|
[`${_error.attributes.details.message}`, `Error: ${JSON.stringify(_error, null, 2)}`].join("\n\n")
|
|
2059
2193
|
);
|
|
@@ -2119,7 +2253,7 @@ function createDatoApiLoader(config, onConfigUpdate) {
|
|
|
2119
2253
|
}
|
|
2120
2254
|
}
|
|
2121
2255
|
const records = await dato.findRecordsForModel(modelId);
|
|
2122
|
-
const recordChoices = createRecordChoices(records, _optionalChain([config, 'access',
|
|
2256
|
+
const recordChoices = createRecordChoices(records, _optionalChain([config, 'access', _106 => _106.models, 'access', _107 => _107[modelId], 'optionalAccess', _108 => _108.records]) || [], project);
|
|
2123
2257
|
const selectedRecords = await promptRecordSelection(modelName, recordChoices);
|
|
2124
2258
|
result.models[modelId].records = records.filter((record) => selectedRecords.includes(record.id));
|
|
2125
2259
|
updatedConfig.models[modelId].records = selectedRecords;
|
|
@@ -2131,14 +2265,14 @@ function createDatoApiLoader(config, onConfigUpdate) {
|
|
|
2131
2265
|
},
|
|
2132
2266
|
async pull(locale, input2, initCtx) {
|
|
2133
2267
|
const result = {};
|
|
2134
|
-
for (const modelId of _lodash2.default.keys(_optionalChain([initCtx, 'optionalAccess',
|
|
2135
|
-
let records = _optionalChain([initCtx, 'optionalAccess',
|
|
2268
|
+
for (const modelId of _lodash2.default.keys(_optionalChain([initCtx, 'optionalAccess', _109 => _109.models]) || {})) {
|
|
2269
|
+
let records = _optionalChain([initCtx, 'optionalAccess', _110 => _110.models, 'access', _111 => _111[modelId], 'access', _112 => _112.records]) || [];
|
|
2136
2270
|
const recordIds = records.map((record) => record.id);
|
|
2137
2271
|
records = await dato.findRecords(recordIds);
|
|
2138
2272
|
console.log(`Fetched ${records.length} records for model ${modelId}`);
|
|
2139
2273
|
if (records.length > 0) {
|
|
2140
2274
|
result[modelId] = {
|
|
2141
|
-
fields: _optionalChain([initCtx, 'optionalAccess',
|
|
2275
|
+
fields: _optionalChain([initCtx, 'optionalAccess', _113 => _113.models, 'optionalAccess', _114 => _114[modelId], 'optionalAccess', _115 => _115.fields]) || [],
|
|
2142
2276
|
records
|
|
2143
2277
|
};
|
|
2144
2278
|
}
|
|
@@ -2197,7 +2331,7 @@ function createRecordChoices(records, selectedIds = [], project) {
|
|
|
2197
2331
|
return records.map((record) => ({
|
|
2198
2332
|
name: `${record.id} - https://${project.internal_domain}/editor/item_types/${record.item_type.id}/items/${record.id}`,
|
|
2199
2333
|
value: record.id,
|
|
2200
|
-
checked: _optionalChain([selectedIds, 'optionalAccess',
|
|
2334
|
+
checked: _optionalChain([selectedIds, 'optionalAccess', _116 => _116.includes, 'call', _117 => _117(record.id)])
|
|
2201
2335
|
}));
|
|
2202
2336
|
}
|
|
2203
2337
|
async function promptRecordSelection(modelName, choices) {
|
|
@@ -2348,18 +2482,18 @@ function createRawDatoValue(parsedDatoValue, originalRawDatoValue, isClean = fal
|
|
|
2348
2482
|
}
|
|
2349
2483
|
function serializeStructuredText(rawStructuredText) {
|
|
2350
2484
|
return serializeStructuredTextNode(rawStructuredText);
|
|
2351
|
-
function serializeStructuredTextNode(node,
|
|
2485
|
+
function serializeStructuredTextNode(node, path13 = [], acc = {}) {
|
|
2352
2486
|
if ("document" in node) {
|
|
2353
|
-
return serializeStructuredTextNode(node.document, [...
|
|
2487
|
+
return serializeStructuredTextNode(node.document, [...path13, "document"], acc);
|
|
2354
2488
|
}
|
|
2355
2489
|
if (!_lodash2.default.isNil(node.value)) {
|
|
2356
|
-
acc[[...
|
|
2490
|
+
acc[[...path13, "value"].join(".")] = node.value;
|
|
2357
2491
|
} else if (_lodash2.default.get(node, "type") === "block") {
|
|
2358
|
-
acc[[...
|
|
2492
|
+
acc[[...path13, "item"].join(".")] = serializeBlock(node.item);
|
|
2359
2493
|
}
|
|
2360
2494
|
if (node.children) {
|
|
2361
2495
|
for (let i = 0; i < node.children.length; i++) {
|
|
2362
|
-
serializeStructuredTextNode(node.children[i], [...
|
|
2496
|
+
serializeStructuredTextNode(node.children[i], [...path13, i.toString()], acc);
|
|
2363
2497
|
}
|
|
2364
2498
|
}
|
|
2365
2499
|
return acc;
|
|
@@ -2418,8 +2552,8 @@ function deserializeBlockList(parsedBlockList, originalRawBlockList, isClean = f
|
|
|
2418
2552
|
}
|
|
2419
2553
|
function deserializeStructuredText(parsedStructuredText, originalRawStructuredText) {
|
|
2420
2554
|
const result = _lodash2.default.cloneDeep(originalRawStructuredText);
|
|
2421
|
-
for (const [
|
|
2422
|
-
const realPath = _lodash2.default.chain(
|
|
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();
|
|
2423
2557
|
const deserializedValue = createRawDatoValue(value, _lodash2.default.get(originalRawStructuredText, realPath), true);
|
|
2424
2558
|
_lodash2.default.set(result, realPath, deserializedValue);
|
|
2425
2559
|
}
|
|
@@ -2464,7 +2598,7 @@ var _nodewebvtt = require('node-webvtt'); var _nodewebvtt2 = _interopRequireDefa
|
|
|
2464
2598
|
function createVttLoader() {
|
|
2465
2599
|
return createLoader({
|
|
2466
2600
|
async pull(locale, input2) {
|
|
2467
|
-
const vtt = _optionalChain([_nodewebvtt2.default, 'access',
|
|
2601
|
+
const vtt = _optionalChain([_nodewebvtt2.default, 'access', _118 => _118.parse, 'call', _119 => _119(input2), 'optionalAccess', _120 => _120.cues]);
|
|
2468
2602
|
if (Object.keys(vtt).length === 0) {
|
|
2469
2603
|
return {};
|
|
2470
2604
|
} else {
|
|
@@ -2516,7 +2650,7 @@ function variableExtractLoader(params) {
|
|
|
2516
2650
|
for (let i = 0; i < matches.length; i++) {
|
|
2517
2651
|
const match = matches[i];
|
|
2518
2652
|
const currentValue = result[key].value;
|
|
2519
|
-
const newValue = _optionalChain([currentValue, 'optionalAccess',
|
|
2653
|
+
const newValue = _optionalChain([currentValue, 'optionalAccess', _121 => _121.replace, 'call', _122 => _122(match, `{variable:${i}}`)]);
|
|
2520
2654
|
result[key].value = newValue;
|
|
2521
2655
|
result[key].variables[i] = match;
|
|
2522
2656
|
}
|
|
@@ -2530,7 +2664,7 @@ function variableExtractLoader(params) {
|
|
|
2530
2664
|
for (let i = 0; i < valueObj.variables.length; i++) {
|
|
2531
2665
|
const variable = valueObj.variables[i];
|
|
2532
2666
|
const currentValue = result[key];
|
|
2533
|
-
const newValue = _optionalChain([currentValue, 'optionalAccess',
|
|
2667
|
+
const newValue = _optionalChain([currentValue, 'optionalAccess', _123 => _123.replace, 'call', _124 => _124(`{variable:${i}}`, variable)]);
|
|
2534
2668
|
result[key] = newValue;
|
|
2535
2669
|
}
|
|
2536
2670
|
}
|
|
@@ -3039,11 +3173,11 @@ var i18n_default = new (0, _interactivecommander.Command)().command("i18n").desc
|
|
|
3039
3173
|
const auth = await validateAuth(settings);
|
|
3040
3174
|
ora.succeed(`Authenticated as ${auth.email}`);
|
|
3041
3175
|
let buckets = getBuckets(i18nConfig);
|
|
3042
|
-
if (_optionalChain([flags, 'access',
|
|
3176
|
+
if (_optionalChain([flags, 'access', _125 => _125.bucket, 'optionalAccess', _126 => _126.length])) {
|
|
3043
3177
|
buckets = buckets.filter((bucket) => flags.bucket.includes(bucket.type));
|
|
3044
3178
|
}
|
|
3045
3179
|
ora.succeed("Buckets retrieved");
|
|
3046
|
-
const targetLocales = _optionalChain([flags, 'access',
|
|
3180
|
+
const targetLocales = _optionalChain([flags, 'access', _127 => _127.locale, 'optionalAccess', _128 => _128.length]) ? flags.locale : i18nConfig.locale.targets;
|
|
3047
3181
|
const lockfileHelper = createLockfileHelper();
|
|
3048
3182
|
ora.start("Ensuring i18n.lock exists...");
|
|
3049
3183
|
if (!lockfileHelper.isLockfileExists()) {
|
|
@@ -3333,12 +3467,12 @@ function validateParams(i18nConfig, flags) {
|
|
|
3333
3467
|
message: "No buckets found in i18n.json. Please add at least one bucket containing i18n content.",
|
|
3334
3468
|
docUrl: "bucketNotFound"
|
|
3335
3469
|
});
|
|
3336
|
-
} else if (_optionalChain([flags, 'access',
|
|
3470
|
+
} else if (_optionalChain([flags, 'access', _129 => _129.locale, 'optionalAccess', _130 => _130.some, 'call', _131 => _131((locale) => !i18nConfig.locale.targets.includes(locale))])) {
|
|
3337
3471
|
throw new CLIError({
|
|
3338
3472
|
message: `One or more specified locales do not exist in i18n.json locale.targets. Please add them to the list and try again.`,
|
|
3339
3473
|
docUrl: "localeTargetNotFound"
|
|
3340
3474
|
});
|
|
3341
|
-
} else if (_optionalChain([flags, 'access',
|
|
3475
|
+
} else if (_optionalChain([flags, 'access', _132 => _132.bucket, 'optionalAccess', _133 => _133.some, 'call', _134 => _134((bucket) => !i18nConfig.buckets[bucket])])) {
|
|
3342
3476
|
throw new CLIError({
|
|
3343
3477
|
message: `One or more specified buckets do not exist in i18n.json. Please add them to the list and try again.`,
|
|
3344
3478
|
docUrl: "bucketNotFound"
|
|
@@ -3618,7 +3752,7 @@ var mcp_default = new (0, _interactivecommander.Command)().command("mcp").descri
|
|
|
3618
3752
|
// package.json
|
|
3619
3753
|
var package_default = {
|
|
3620
3754
|
name: "lingo.dev",
|
|
3621
|
-
version: "0.77.
|
|
3755
|
+
version: "0.77.5",
|
|
3622
3756
|
description: "Lingo.dev CLI",
|
|
3623
3757
|
private: false,
|
|
3624
3758
|
publishConfig: {
|