lingo.dev 0.80.1 → 0.82.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.cjs +509 -276
- package/build/cli.cjs.map +1 -1
- package/build/cli.mjs +426 -193
- package/build/cli.mjs.map +1 -1
- package/package.json +3 -3
package/build/cli.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
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
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } 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);
|
|
@@ -14,9 +14,9 @@ var _promises = require('readline/promises'); var _promises2 = _interopRequireDe
|
|
|
14
14
|
|
|
15
15
|
// src/cli/utils/settings.ts
|
|
16
16
|
var _os = require('os'); var _os2 = _interopRequireDefault(_os);
|
|
17
|
-
var _path = require('path'); var
|
|
17
|
+
var _path = require('path'); var path15 = _interopRequireWildcard(_path); var path13 = _interopRequireWildcard(_path); var path14 = _interopRequireWildcard(_path);
|
|
18
18
|
var _zod = require('zod'); var _zod2 = _interopRequireDefault(_zod);
|
|
19
|
-
var _fs = require('fs'); var
|
|
19
|
+
var _fs = require('fs'); var fs11 = _interopRequireWildcard(_fs);
|
|
20
20
|
var _ini = require('ini'); var _ini2 = _interopRequireDefault(_ini);
|
|
21
21
|
function getSettings(explicitApiKey) {
|
|
22
22
|
const env = _loadEnv();
|
|
@@ -26,9 +26,9 @@ function getSettings(explicitApiKey) {
|
|
|
26
26
|
_envVarsInfo();
|
|
27
27
|
return {
|
|
28
28
|
auth: {
|
|
29
|
-
apiKey: explicitApiKey || env.LINGODOTDEV_API_KEY || _optionalChain([systemFile, 'access',
|
|
30
|
-
apiUrl: env.LINGODOTDEV_API_URL || _optionalChain([systemFile, 'access',
|
|
31
|
-
webUrl: env.LINGODOTDEV_WEB_URL || _optionalChain([systemFile, 'access',
|
|
29
|
+
apiKey: explicitApiKey || env.LINGODOTDEV_API_KEY || _optionalChain([systemFile, 'access', _25 => _25.auth, 'optionalAccess', _26 => _26.apiKey]) || defaults.auth.apiKey,
|
|
30
|
+
apiUrl: env.LINGODOTDEV_API_URL || _optionalChain([systemFile, 'access', _27 => _27.auth, 'optionalAccess', _28 => _28.apiUrl]) || defaults.auth.apiUrl,
|
|
31
|
+
webUrl: env.LINGODOTDEV_WEB_URL || _optionalChain([systemFile, 'access', _29 => _29.auth, 'optionalAccess', _30 => _30.webUrl]) || defaults.auth.webUrl
|
|
32
32
|
}
|
|
33
33
|
};
|
|
34
34
|
}
|
|
@@ -60,7 +60,7 @@ function _loadEnv() {
|
|
|
60
60
|
}
|
|
61
61
|
function _loadSystemFile() {
|
|
62
62
|
const settingsFilePath = _getSettingsFilePath();
|
|
63
|
-
const content =
|
|
63
|
+
const content = fs11.default.existsSync(settingsFilePath) ? fs11.default.readFileSync(settingsFilePath, "utf-8") : "";
|
|
64
64
|
const data = _ini2.default.parse(content);
|
|
65
65
|
return _zod2.default.object({
|
|
66
66
|
auth: _zod2.default.object({
|
|
@@ -73,12 +73,12 @@ function _loadSystemFile() {
|
|
|
73
73
|
function _saveSystemFile(settings) {
|
|
74
74
|
const settingsFilePath = _getSettingsFilePath();
|
|
75
75
|
const content = _ini2.default.stringify(settings);
|
|
76
|
-
|
|
76
|
+
fs11.default.writeFileSync(settingsFilePath, content);
|
|
77
77
|
}
|
|
78
78
|
function _getSettingsFilePath() {
|
|
79
79
|
const settingsFile = ".lingodotdevrc";
|
|
80
80
|
const homedir = _os2.default.homedir();
|
|
81
|
-
const settingsFilePath =
|
|
81
|
+
const settingsFilePath = path15.default.join(homedir, settingsFile);
|
|
82
82
|
return settingsFilePath;
|
|
83
83
|
}
|
|
84
84
|
function _legacyEnvVarWarning() {
|
|
@@ -99,7 +99,7 @@ Please use LINGODOTDEV_API_KEY instead.
|
|
|
99
99
|
function _envVarsInfo() {
|
|
100
100
|
const env = _loadEnv();
|
|
101
101
|
const systemFile = _loadSystemFile();
|
|
102
|
-
if (env.LINGODOTDEV_API_KEY && _optionalChain([systemFile, 'access',
|
|
102
|
+
if (env.LINGODOTDEV_API_KEY && _optionalChain([systemFile, 'access', _31 => _31.auth, 'optionalAccess', _32 => _32.apiKey])) {
|
|
103
103
|
console.info(
|
|
104
104
|
"\x1B[36m%s\x1B[0m",
|
|
105
105
|
`\u2139\uFE0F Using LINGODOTDEV_API_KEY env var instead of credentials from login flow (saved in .lingodotdevrc)`
|
|
@@ -154,7 +154,7 @@ function createAuthenticator(params) {
|
|
|
154
154
|
});
|
|
155
155
|
if (res.ok) {
|
|
156
156
|
const payload = await res.json();
|
|
157
|
-
if (!_optionalChain([payload, 'optionalAccess',
|
|
157
|
+
if (!_optionalChain([payload, 'optionalAccess', _33 => _33.email])) {
|
|
158
158
|
return null;
|
|
159
159
|
}
|
|
160
160
|
return {
|
|
@@ -257,11 +257,11 @@ var _lodash = require('lodash'); var _lodash2 = _interopRequireDefault(_lodash);
|
|
|
257
257
|
var __spec = require('@lingo.dev/_spec');
|
|
258
258
|
function getConfig(resave = true) {
|
|
259
259
|
const configFilePath = _getConfigFilePath();
|
|
260
|
-
const configFileExists =
|
|
260
|
+
const configFileExists = fs11.default.existsSync(configFilePath);
|
|
261
261
|
if (!configFileExists) {
|
|
262
262
|
return null;
|
|
263
263
|
}
|
|
264
|
-
const fileContents =
|
|
264
|
+
const fileContents = fs11.default.readFileSync(configFilePath, "utf8");
|
|
265
265
|
const rawConfig = JSON.parse(fileContents);
|
|
266
266
|
const result = __spec.parseI18nConfig.call(void 0, rawConfig);
|
|
267
267
|
const didConfigChange = !_lodash2.default.isEqual(rawConfig, result);
|
|
@@ -273,11 +273,11 @@ function getConfig(resave = true) {
|
|
|
273
273
|
function saveConfig(config) {
|
|
274
274
|
const configFilePath = _getConfigFilePath();
|
|
275
275
|
const serialized = JSON.stringify(config, null, 2);
|
|
276
|
-
|
|
276
|
+
fs11.default.writeFileSync(configFilePath, serialized);
|
|
277
277
|
return config;
|
|
278
278
|
}
|
|
279
279
|
function _getConfigFilePath() {
|
|
280
|
-
return
|
|
280
|
+
return path15.default.join(process.cwd(), "i18n.json");
|
|
281
281
|
}
|
|
282
282
|
|
|
283
283
|
// src/cli/cmd/init.ts
|
|
@@ -362,7 +362,7 @@ function findLocaleFilesForFilename(fileName) {
|
|
|
362
362
|
});
|
|
363
363
|
const localeFilesAndPatterns = localeFiles.map((file) => ({
|
|
364
364
|
file,
|
|
365
|
-
pattern:
|
|
365
|
+
pattern: path15.default.join(path15.default.dirname(file), pattern)
|
|
366
366
|
}));
|
|
367
367
|
const grouppedFilesAndPatterns = _lodash2.default.groupBy(localeFilesAndPatterns, "pattern");
|
|
368
368
|
const patterns = Object.keys(grouppedFilesAndPatterns);
|
|
@@ -382,10 +382,10 @@ function ensurePatterns(patterns, source) {
|
|
|
382
382
|
}
|
|
383
383
|
patterns.forEach((pattern) => {
|
|
384
384
|
const filePath = pattern.replace("[locale]", source);
|
|
385
|
-
if (!
|
|
386
|
-
const defaultContent = getDefaultContent(
|
|
387
|
-
|
|
388
|
-
|
|
385
|
+
if (!fs11.default.existsSync(filePath)) {
|
|
386
|
+
const defaultContent = getDefaultContent(path15.default.extname(filePath), source);
|
|
387
|
+
fs11.default.mkdirSync(path15.default.dirname(filePath), { recursive: true });
|
|
388
|
+
fs11.default.writeFileSync(filePath, defaultContent);
|
|
389
389
|
}
|
|
390
390
|
});
|
|
391
391
|
}
|
|
@@ -464,31 +464,31 @@ function updateGitignore() {
|
|
|
464
464
|
if (!projectRoot) {
|
|
465
465
|
return;
|
|
466
466
|
}
|
|
467
|
-
const gitignorePath =
|
|
468
|
-
if (!
|
|
467
|
+
const gitignorePath = path15.default.join(projectRoot, ".gitignore");
|
|
468
|
+
if (!fs11.default.existsSync(gitignorePath)) {
|
|
469
469
|
return;
|
|
470
470
|
}
|
|
471
|
-
const gitignore =
|
|
471
|
+
const gitignore = fs11.default.readFileSync(gitignorePath, "utf8").split("\n");
|
|
472
472
|
const cacheIsIgnored = gitignore.includes(cacheFile);
|
|
473
473
|
if (!cacheIsIgnored) {
|
|
474
474
|
let content = "";
|
|
475
|
-
content =
|
|
475
|
+
content = fs11.default.readFileSync(gitignorePath, "utf8");
|
|
476
476
|
if (content !== "" && !content.endsWith("\n")) {
|
|
477
477
|
content += "\n";
|
|
478
478
|
}
|
|
479
479
|
content += `${cacheFile}
|
|
480
480
|
`;
|
|
481
|
-
|
|
481
|
+
fs11.default.writeFileSync(gitignorePath, content);
|
|
482
482
|
}
|
|
483
483
|
}
|
|
484
484
|
function findCurrentProjectRoot() {
|
|
485
485
|
let currentDir = process.cwd();
|
|
486
|
-
while (currentDir !==
|
|
487
|
-
const gitDirPath =
|
|
488
|
-
if (
|
|
486
|
+
while (currentDir !== path15.default.parse(currentDir).root) {
|
|
487
|
+
const gitDirPath = path15.default.join(currentDir, ".git");
|
|
488
|
+
if (fs11.default.existsSync(gitDirPath) && fs11.default.lstatSync(gitDirPath).isDirectory()) {
|
|
489
489
|
return currentDir;
|
|
490
490
|
}
|
|
491
|
-
currentDir =
|
|
491
|
+
currentDir = path15.default.dirname(currentDir);
|
|
492
492
|
}
|
|
493
493
|
return null;
|
|
494
494
|
}
|
|
@@ -530,24 +530,24 @@ function makePlatformInitializer(config, spinner) {
|
|
|
530
530
|
return {
|
|
531
531
|
name: config.name,
|
|
532
532
|
isEnabled: () => {
|
|
533
|
-
const filePath =
|
|
534
|
-
return
|
|
533
|
+
const filePath = path15.default.join(process.cwd(), config.checkPath);
|
|
534
|
+
return fs11.default.existsSync(filePath);
|
|
535
535
|
},
|
|
536
536
|
init: async () => {
|
|
537
|
-
const filePath =
|
|
538
|
-
const dirPath =
|
|
539
|
-
if (!
|
|
540
|
-
|
|
537
|
+
const filePath = path15.default.join(process.cwd(), config.ciConfigPath);
|
|
538
|
+
const dirPath = path15.default.dirname(filePath);
|
|
539
|
+
if (!fs11.default.existsSync(dirPath)) {
|
|
540
|
+
fs11.default.mkdirSync(dirPath, { recursive: true });
|
|
541
541
|
}
|
|
542
542
|
let canWrite = true;
|
|
543
|
-
if (
|
|
543
|
+
if (fs11.default.existsSync(filePath)) {
|
|
544
544
|
canWrite = await _prompts.confirm.call(void 0, {
|
|
545
545
|
message: `File ${filePath} already exists. Do you want to overwrite it?`,
|
|
546
546
|
default: false
|
|
547
547
|
});
|
|
548
548
|
}
|
|
549
549
|
if (canWrite) {
|
|
550
|
-
|
|
550
|
+
fs11.default.writeFileSync(filePath, config.ciConfigContent);
|
|
551
551
|
spinner.succeed(`CI/CD initialized for ${config.name}`);
|
|
552
552
|
} else {
|
|
553
553
|
spinner.warn(`CI/CD not initialized for ${config.name}`);
|
|
@@ -621,9 +621,9 @@ function makeGitlabInitializer(spinner) {
|
|
|
621
621
|
|
|
622
622
|
// src/cli/cmd/init.ts
|
|
623
623
|
|
|
624
|
-
var openUrl = (
|
|
624
|
+
var openUrl = (path18) => {
|
|
625
625
|
const settings = getSettings(void 0);
|
|
626
|
-
_open2.default.call(void 0, `${settings.auth.webUrl}${
|
|
626
|
+
_open2.default.call(void 0, `${settings.auth.webUrl}${path18}`, { wait: false });
|
|
627
627
|
};
|
|
628
628
|
var throwHelpError = (option, value) => {
|
|
629
629
|
if (value === "help") {
|
|
@@ -669,8 +669,8 @@ var init_default = new (0, _interactivecommander.InteractiveCommand)().command("
|
|
|
669
669
|
const values = value.includes(",") ? value.split(",") : value.split(" ");
|
|
670
670
|
for (const p of values) {
|
|
671
671
|
try {
|
|
672
|
-
const dirPath =
|
|
673
|
-
const stats =
|
|
672
|
+
const dirPath = path15.default.dirname(p);
|
|
673
|
+
const stats = fs11.default.statSync(dirPath);
|
|
674
674
|
if (!stats.isDirectory()) {
|
|
675
675
|
throw new Error(`${dirPath} is not a directory`);
|
|
676
676
|
}
|
|
@@ -774,7 +774,7 @@ var init_default = new (0, _interactivecommander.InteractiveCommand)().command("
|
|
|
774
774
|
});
|
|
775
775
|
const auth2 = await newAuthenticator.whoami();
|
|
776
776
|
if (auth2) {
|
|
777
|
-
_ora2.default.call(void 0, ).succeed(`Authenticated as ${_optionalChain([auth2, 'optionalAccess',
|
|
777
|
+
_ora2.default.call(void 0, ).succeed(`Authenticated as ${_optionalChain([auth2, 'optionalAccess', _34 => _34.email])}`);
|
|
778
778
|
} else {
|
|
779
779
|
_ora2.default.call(void 0, ).fail("Authentication failed.");
|
|
780
780
|
}
|
|
@@ -806,12 +806,12 @@ var config_default = new (0, _interactivecommander.Command)().command("config").
|
|
|
806
806
|
console.log(JSON.stringify(config, null, 2));
|
|
807
807
|
});
|
|
808
808
|
function loadReplexicaFileConfig() {
|
|
809
|
-
const replexicaConfigPath =
|
|
810
|
-
const fileExists =
|
|
809
|
+
const replexicaConfigPath = path15.default.resolve(process.cwd(), "i18n.json");
|
|
810
|
+
const fileExists = fs11.default.existsSync(replexicaConfigPath);
|
|
811
811
|
if (!fileExists) {
|
|
812
812
|
return void 0;
|
|
813
813
|
}
|
|
814
|
-
const fileContent =
|
|
814
|
+
const fileContent = fs11.default.readFileSync(replexicaConfigPath, "utf-8");
|
|
815
815
|
const replexicaFileConfig = JSON.parse(fileContent);
|
|
816
816
|
return replexicaFileConfig;
|
|
817
817
|
}
|
|
@@ -854,7 +854,7 @@ var locale_default = new (0, _interactivecommander.Command)().command("locale").
|
|
|
854
854
|
function getBuckets(i18nConfig) {
|
|
855
855
|
const result = Object.entries(i18nConfig.buckets).map(([bucketType, bucketEntry]) => {
|
|
856
856
|
const includeItems = bucketEntry.include.map((item) => resolveBucketItem(item));
|
|
857
|
-
const excludeItems = _optionalChain([bucketEntry, 'access',
|
|
857
|
+
const excludeItems = _optionalChain([bucketEntry, 'access', _35 => _35.exclude, 'optionalAccess', _36 => _36.map, 'call', _37 => _37((item) => resolveBucketItem(item))]);
|
|
858
858
|
const config = {
|
|
859
859
|
type: bucketType,
|
|
860
860
|
paths: extractPathPatterns(i18nConfig.locale.source, includeItems, excludeItems)
|
|
@@ -862,6 +862,9 @@ function getBuckets(i18nConfig) {
|
|
|
862
862
|
if (bucketEntry.injectLocale) {
|
|
863
863
|
config.injectLocale = bucketEntry.injectLocale;
|
|
864
864
|
}
|
|
865
|
+
if (bucketEntry.lockedKeys) {
|
|
866
|
+
config.lockedKeys = bucketEntry.lockedKeys;
|
|
867
|
+
}
|
|
865
868
|
return config;
|
|
866
869
|
});
|
|
867
870
|
return result;
|
|
@@ -875,7 +878,7 @@ function extractPathPatterns(sourceLocale, include, exclude) {
|
|
|
875
878
|
})
|
|
876
879
|
)
|
|
877
880
|
);
|
|
878
|
-
const excludedPatterns = _optionalChain([exclude, 'optionalAccess',
|
|
881
|
+
const excludedPatterns = _optionalChain([exclude, 'optionalAccess', _38 => _38.flatMap, 'call', _39 => _39(
|
|
879
882
|
(pattern) => expandPlaceholderedGlob(pattern.path, __spec.resolveOverriddenLocale.call(void 0, sourceLocale, pattern.delimiter)).map(
|
|
880
883
|
(pathPattern) => ({
|
|
881
884
|
pathPattern,
|
|
@@ -887,9 +890,9 @@ function extractPathPatterns(sourceLocale, include, exclude) {
|
|
|
887
890
|
return result;
|
|
888
891
|
}
|
|
889
892
|
function expandPlaceholderedGlob(_pathPattern, sourceLocale) {
|
|
890
|
-
const absolutePathPattern =
|
|
891
|
-
const pathPattern =
|
|
892
|
-
if (
|
|
893
|
+
const absolutePathPattern = path15.default.resolve(_pathPattern);
|
|
894
|
+
const pathPattern = path15.default.relative(process.cwd(), absolutePathPattern);
|
|
895
|
+
if (path15.default.relative(process.cwd(), pathPattern).startsWith("..")) {
|
|
893
896
|
throw new CLIError({
|
|
894
897
|
message: `Invalid path pattern: ${pathPattern}. Path pattern must be within the current working directory.`,
|
|
895
898
|
docUrl: "invalidPathPattern"
|
|
@@ -901,7 +904,7 @@ function expandPlaceholderedGlob(_pathPattern, sourceLocale) {
|
|
|
901
904
|
docUrl: "invalidPathPattern"
|
|
902
905
|
});
|
|
903
906
|
}
|
|
904
|
-
const pathPatternChunks = pathPattern.split(
|
|
907
|
+
const pathPatternChunks = pathPattern.split(path15.default.sep);
|
|
905
908
|
const localeSegmentIndexes = pathPatternChunks.reduce((indexes, segment, index) => {
|
|
906
909
|
if (segment.includes("[locale]")) {
|
|
907
910
|
indexes.push(index);
|
|
@@ -909,9 +912,9 @@ function expandPlaceholderedGlob(_pathPattern, sourceLocale) {
|
|
|
909
912
|
return indexes;
|
|
910
913
|
}, []);
|
|
911
914
|
const sourcePathPattern = pathPattern.replaceAll(/\[locale\]/g, sourceLocale);
|
|
912
|
-
const sourcePaths = _glob.glob.sync(sourcePathPattern, { follow: true, withFileTypes: true }).filter((file) => file.isFile() || file.isSymbolicLink()).map((file) => file.fullpath()).map((fullpath) =>
|
|
915
|
+
const sourcePaths = _glob.glob.sync(sourcePathPattern, { follow: true, withFileTypes: true }).filter((file) => file.isFile() || file.isSymbolicLink()).map((file) => file.fullpath()).map((fullpath) => path15.default.relative(process.cwd(), fullpath));
|
|
913
916
|
const placeholderedPaths = sourcePaths.map((sourcePath) => {
|
|
914
|
-
const sourcePathChunks = sourcePath.split(
|
|
917
|
+
const sourcePathChunks = sourcePath.split(path15.default.sep);
|
|
915
918
|
localeSegmentIndexes.forEach((localeSegmentIndex) => {
|
|
916
919
|
const pathPatternChunk = pathPatternChunks[localeSegmentIndex];
|
|
917
920
|
const sourcePathChunk = sourcePathChunks[localeSegmentIndex];
|
|
@@ -925,7 +928,7 @@ function expandPlaceholderedGlob(_pathPattern, sourceLocale) {
|
|
|
925
928
|
sourcePathChunks[localeSegmentIndex] = placeholderedSegment;
|
|
926
929
|
}
|
|
927
930
|
});
|
|
928
|
-
const placeholderedPath = sourcePathChunks.join(
|
|
931
|
+
const placeholderedPath = sourcePathChunks.join(path15.default.sep);
|
|
929
932
|
return placeholderedPath;
|
|
930
933
|
});
|
|
931
934
|
return placeholderedPaths;
|
|
@@ -967,8 +970,8 @@ var files_default = new (0, _interactivecommander.Command)().command("files").de
|
|
|
967
970
|
} else if (type.target) {
|
|
968
971
|
result.push(...targetPaths);
|
|
969
972
|
}
|
|
970
|
-
result.forEach((
|
|
971
|
-
console.log(
|
|
973
|
+
result.forEach((path18) => {
|
|
974
|
+
console.log(path18);
|
|
972
975
|
});
|
|
973
976
|
}
|
|
974
977
|
}
|
|
@@ -994,17 +997,18 @@ var show_default = new (0, _interactivecommander.Command)().command("show").desc
|
|
|
994
997
|
|
|
995
998
|
|
|
996
999
|
|
|
1000
|
+
|
|
997
1001
|
// src/cli/loaders/_utils.ts
|
|
998
1002
|
function composeLoaders(...loaders) {
|
|
999
1003
|
return {
|
|
1000
1004
|
init: async () => {
|
|
1001
1005
|
for (const loader of loaders) {
|
|
1002
|
-
await _optionalChain([loader, 'access',
|
|
1006
|
+
await _optionalChain([loader, 'access', _40 => _40.init, 'optionalCall', _41 => _41()]);
|
|
1003
1007
|
}
|
|
1004
1008
|
},
|
|
1005
1009
|
setDefaultLocale(locale) {
|
|
1006
1010
|
for (const loader of loaders) {
|
|
1007
|
-
_optionalChain([loader, 'access',
|
|
1011
|
+
_optionalChain([loader, 'access', _42 => _42.setDefaultLocale, 'optionalCall', _43 => _43(locale)]);
|
|
1008
1012
|
}
|
|
1009
1013
|
return this;
|
|
1010
1014
|
},
|
|
@@ -1035,7 +1039,7 @@ function createLoader(lDefinition) {
|
|
|
1035
1039
|
if (state.initCtx) {
|
|
1036
1040
|
return state.initCtx;
|
|
1037
1041
|
}
|
|
1038
|
-
state.initCtx = await _optionalChain([lDefinition, 'access',
|
|
1042
|
+
state.initCtx = await _optionalChain([lDefinition, 'access', _44 => _44.init, 'optionalCall', _45 => _45()]);
|
|
1039
1043
|
return state.initCtx;
|
|
1040
1044
|
},
|
|
1041
1045
|
setDefaultLocale(locale) {
|
|
@@ -1124,7 +1128,7 @@ function createNormalizeLoader() {
|
|
|
1124
1128
|
return normalized;
|
|
1125
1129
|
},
|
|
1126
1130
|
push: async (locale, data, originalInput) => {
|
|
1127
|
-
const keysMap = _nullishCoalesce(_optionalChain([originalInput, 'optionalAccess',
|
|
1131
|
+
const keysMap = _nullishCoalesce(_optionalChain([originalInput, 'optionalAccess', _46 => _46.keysMap]), () => ( {}));
|
|
1128
1132
|
const input2 = mapDenormalizedKeys(data, keysMap);
|
|
1129
1133
|
const denormalized = _flat.unflatten.call(void 0, input2, {
|
|
1130
1134
|
delimiter: "/",
|
|
@@ -1198,10 +1202,10 @@ function createTextFileLoader(pathPattern) {
|
|
|
1198
1202
|
const trimmedResult = result.trim();
|
|
1199
1203
|
return trimmedResult;
|
|
1200
1204
|
},
|
|
1201
|
-
async push(locale, data,
|
|
1205
|
+
async push(locale, data, _24, originalLocale) {
|
|
1202
1206
|
const draftPath = pathPattern.replaceAll("[locale]", locale);
|
|
1203
|
-
const finalPath =
|
|
1204
|
-
const dirPath =
|
|
1207
|
+
const finalPath = path15.default.resolve(draftPath);
|
|
1208
|
+
const dirPath = path15.default.dirname(finalPath);
|
|
1205
1209
|
await _promises4.default.mkdir(dirPath, { recursive: true });
|
|
1206
1210
|
const trimmedPayload = data.trim();
|
|
1207
1211
|
const trailingNewLine = await getTrailingNewLine(pathPattern, locale, originalLocale);
|
|
@@ -1215,7 +1219,7 @@ function createTextFileLoader(pathPattern) {
|
|
|
1215
1219
|
}
|
|
1216
1220
|
async function readFileForLocale(pathPattern, locale) {
|
|
1217
1221
|
const draftPath = pathPattern.replaceAll("[locale]", locale);
|
|
1218
|
-
const finalPath =
|
|
1222
|
+
const finalPath = path15.default.resolve(draftPath);
|
|
1219
1223
|
const exists = await _promises4.default.access(finalPath).then(() => true).catch(() => false);
|
|
1220
1224
|
if (!exists) {
|
|
1221
1225
|
return "";
|
|
@@ -1227,8 +1231,8 @@ async function getTrailingNewLine(pathPattern, locale, originalLocale) {
|
|
|
1227
1231
|
if (!templateData) {
|
|
1228
1232
|
templateData = await readFileForLocale(pathPattern, originalLocale);
|
|
1229
1233
|
}
|
|
1230
|
-
if (_optionalChain([templateData, 'optionalAccess',
|
|
1231
|
-
const ending = _optionalChain([templateData, 'optionalAccess',
|
|
1234
|
+
if (_optionalChain([templateData, 'optionalAccess', _47 => _47.match, 'call', _48 => _48(/[\r\n]$/)])) {
|
|
1235
|
+
const ending = _optionalChain([templateData, 'optionalAccess', _49 => _49.includes, 'call', _50 => _50("\r\n")]) ? "\r\n" : _optionalChain([templateData, 'optionalAccess', _51 => _51.includes, 'call', _52 => _52("\r")]) ? "\r" : "\n";
|
|
1232
1236
|
return ending;
|
|
1233
1237
|
}
|
|
1234
1238
|
return "";
|
|
@@ -1483,7 +1487,7 @@ function createHtmlLoader() {
|
|
|
1483
1487
|
break;
|
|
1484
1488
|
}
|
|
1485
1489
|
const siblings = Array.from(parent.childNodes).filter(
|
|
1486
|
-
(n) => n.nodeType === 1 || n.nodeType === 3 && _optionalChain([n, 'access',
|
|
1490
|
+
(n) => n.nodeType === 1 || n.nodeType === 3 && _optionalChain([n, 'access', _53 => _53.textContent, 'optionalAccess', _54 => _54.trim, 'call', _55 => _55()])
|
|
1487
1491
|
);
|
|
1488
1492
|
const index = siblings.indexOf(current);
|
|
1489
1493
|
if (index !== -1) {
|
|
@@ -1518,11 +1522,11 @@ function createHtmlLoader() {
|
|
|
1518
1522
|
result[getPath(element, attr)] = value;
|
|
1519
1523
|
}
|
|
1520
1524
|
});
|
|
1521
|
-
Array.from(element.childNodes).filter((n) => n.nodeType === 1 || n.nodeType === 3 && _optionalChain([n, 'access',
|
|
1525
|
+
Array.from(element.childNodes).filter((n) => n.nodeType === 1 || n.nodeType === 3 && _optionalChain([n, 'access', _56 => _56.textContent, 'optionalAccess', _57 => _57.trim, 'call', _58 => _58()])).forEach(processNode);
|
|
1522
1526
|
}
|
|
1523
1527
|
};
|
|
1524
|
-
Array.from(document.head.childNodes).filter((n) => n.nodeType === 1 || n.nodeType === 3 && _optionalChain([n, 'access',
|
|
1525
|
-
Array.from(document.body.childNodes).filter((n) => n.nodeType === 1 || n.nodeType === 3 && _optionalChain([n, 'access',
|
|
1528
|
+
Array.from(document.head.childNodes).filter((n) => n.nodeType === 1 || n.nodeType === 3 && _optionalChain([n, 'access', _59 => _59.textContent, 'optionalAccess', _60 => _60.trim, 'call', _61 => _61()])).forEach(processNode);
|
|
1529
|
+
Array.from(document.body.childNodes).filter((n) => n.nodeType === 1 || n.nodeType === 3 && _optionalChain([n, 'access', _62 => _62.textContent, 'optionalAccess', _63 => _63.trim, 'call', _64 => _64()])).forEach(processNode);
|
|
1526
1530
|
return result;
|
|
1527
1531
|
},
|
|
1528
1532
|
async push(locale, data, originalInput) {
|
|
@@ -1535,16 +1539,16 @@ function createHtmlLoader() {
|
|
|
1535
1539
|
const bDepth = b.split("/").length;
|
|
1536
1540
|
return aDepth - bDepth;
|
|
1537
1541
|
});
|
|
1538
|
-
paths.forEach((
|
|
1539
|
-
const value = data[
|
|
1540
|
-
const [nodePath, attribute] =
|
|
1542
|
+
paths.forEach((path18) => {
|
|
1543
|
+
const value = data[path18];
|
|
1544
|
+
const [nodePath, attribute] = path18.split("#");
|
|
1541
1545
|
const [rootTag, ...indices] = nodePath.split("/");
|
|
1542
1546
|
let parent = rootTag === "head" ? document.head : document.body;
|
|
1543
1547
|
let current = parent;
|
|
1544
1548
|
for (let i = 0; i < indices.length; i++) {
|
|
1545
1549
|
const index = parseInt(indices[i]);
|
|
1546
1550
|
const siblings = Array.from(parent.childNodes).filter(
|
|
1547
|
-
(n) => n.nodeType === 1 || n.nodeType === 3 && _optionalChain([n, 'access',
|
|
1551
|
+
(n) => n.nodeType === 1 || n.nodeType === 3 && _optionalChain([n, 'access', _65 => _65.textContent, 'optionalAccess', _66 => _66.trim, 'call', _67 => _67()])
|
|
1548
1552
|
);
|
|
1549
1553
|
if (index >= siblings.length) {
|
|
1550
1554
|
if (i === indices.length - 1) {
|
|
@@ -1595,7 +1599,7 @@ function createMarkdownLoader() {
|
|
|
1595
1599
|
yaml: yamlEngine
|
|
1596
1600
|
}
|
|
1597
1601
|
});
|
|
1598
|
-
const sections = content.split(SECTION_REGEX).map((section) => _nullishCoalesce(_optionalChain([section, 'optionalAccess',
|
|
1602
|
+
const sections = content.split(SECTION_REGEX).map((section) => _nullishCoalesce(_optionalChain([section, 'optionalAccess', _68 => _68.trim, 'call', _69 => _69()]), () => ( ""))).filter(Boolean);
|
|
1599
1603
|
return {
|
|
1600
1604
|
...Object.fromEntries(
|
|
1601
1605
|
sections.map((section, index) => [`${MD_SECTION_PREFIX}${index}`, section]).filter(([, section]) => Boolean(section))
|
|
@@ -1607,7 +1611,7 @@ function createMarkdownLoader() {
|
|
|
1607
1611
|
const frontmatter = Object.fromEntries(
|
|
1608
1612
|
Object.entries(data).filter(([key]) => key.startsWith(FM_ATTR_PREFIX)).map(([key, value]) => [key.replace(FM_ATTR_PREFIX, ""), value])
|
|
1609
1613
|
);
|
|
1610
|
-
let content = Object.entries(data).filter(([key]) => key.startsWith(MD_SECTION_PREFIX)).sort(([a], [b]) => Number(a.split("-").pop()) - Number(b.split("-").pop())).map(([, value]) => _nullishCoalesce(_optionalChain([value, 'optionalAccess',
|
|
1614
|
+
let content = Object.entries(data).filter(([key]) => key.startsWith(MD_SECTION_PREFIX)).sort(([a], [b]) => Number(a.split("-").pop()) - Number(b.split("-").pop())).map(([, value]) => _nullishCoalesce(_optionalChain([value, 'optionalAccess', _70 => _70.trim, 'call', _71 => _71()]), () => ( ""))).filter(Boolean).join("\n\n");
|
|
1611
1615
|
if (Object.keys(frontmatter).length > 0) {
|
|
1612
1616
|
content = `
|
|
1613
1617
|
${content}`;
|
|
@@ -1640,7 +1644,7 @@ function createPropertiesLoader() {
|
|
|
1640
1644
|
return result;
|
|
1641
1645
|
},
|
|
1642
1646
|
async push(locale, payload) {
|
|
1643
|
-
const result = Object.entries(payload).filter(([
|
|
1647
|
+
const result = Object.entries(payload).filter(([_24, value]) => value != null).map(([key, value]) => `${key}=${value}`).join("\n");
|
|
1644
1648
|
return result;
|
|
1645
1649
|
}
|
|
1646
1650
|
});
|
|
@@ -1651,7 +1655,7 @@ function isSkippableLine(line) {
|
|
|
1651
1655
|
function parsePropertyLine(line) {
|
|
1652
1656
|
const [key, ...valueParts] = line.split("=");
|
|
1653
1657
|
return {
|
|
1654
|
-
key: _optionalChain([key, 'optionalAccess',
|
|
1658
|
+
key: _optionalChain([key, 'optionalAccess', _72 => _72.trim, 'call', _73 => _73()]) || "",
|
|
1655
1659
|
value: valueParts.join("=").trim()
|
|
1656
1660
|
};
|
|
1657
1661
|
}
|
|
@@ -1737,7 +1741,7 @@ function createXcodeXcstringsLoader(defaultLocale) {
|
|
|
1737
1741
|
if (rootTranslationEntity.shouldTranslate === false) {
|
|
1738
1742
|
continue;
|
|
1739
1743
|
}
|
|
1740
|
-
const langTranslationEntity = _optionalChain([rootTranslationEntity, 'optionalAccess',
|
|
1744
|
+
const langTranslationEntity = _optionalChain([rootTranslationEntity, 'optionalAccess', _74 => _74.localizations, 'optionalAccess', _75 => _75[locale]]);
|
|
1741
1745
|
if (langTranslationEntity) {
|
|
1742
1746
|
if ("stringUnit" in langTranslationEntity) {
|
|
1743
1747
|
resultData[translationKey] = langTranslationEntity.stringUnit.value;
|
|
@@ -1746,7 +1750,7 @@ function createXcodeXcstringsLoader(defaultLocale) {
|
|
|
1746
1750
|
resultData[translationKey] = {};
|
|
1747
1751
|
const pluralForms = langTranslationEntity.variations.plural;
|
|
1748
1752
|
for (const form in pluralForms) {
|
|
1749
|
-
if (_optionalChain([pluralForms, 'access',
|
|
1753
|
+
if (_optionalChain([pluralForms, 'access', _76 => _76[form], 'optionalAccess', _77 => _77.stringUnit, 'optionalAccess', _78 => _78.value])) {
|
|
1750
1754
|
resultData[translationKey][form] = pluralForms[form].stringUnit.value;
|
|
1751
1755
|
}
|
|
1752
1756
|
}
|
|
@@ -1770,7 +1774,7 @@ function createXcodeXcstringsLoader(defaultLocale) {
|
|
|
1770
1774
|
const hasDoNotTranslateFlag = originalInput && originalInput.strings && originalInput.strings[key] && originalInput.strings[key].shouldTranslate === false;
|
|
1771
1775
|
if (typeof value === "string") {
|
|
1772
1776
|
langDataToMerge.strings[key] = {
|
|
1773
|
-
extractionState: _optionalChain([originalInput, 'optionalAccess',
|
|
1777
|
+
extractionState: _optionalChain([originalInput, 'optionalAccess', _79 => _79.strings, 'optionalAccess', _80 => _80[key], 'optionalAccess', _81 => _81.extractionState]),
|
|
1774
1778
|
localizations: {
|
|
1775
1779
|
[locale]: {
|
|
1776
1780
|
stringUnit: {
|
|
@@ -1824,7 +1828,7 @@ function createPrettierLoader(options) {
|
|
|
1824
1828
|
},
|
|
1825
1829
|
async push(locale, data) {
|
|
1826
1830
|
const draftPath = options.bucketPathPattern.replaceAll("[locale]", locale);
|
|
1827
|
-
const finalPath =
|
|
1831
|
+
const finalPath = path15.default.resolve(draftPath);
|
|
1828
1832
|
const prettierConfig = await loadPrettierConfig(finalPath);
|
|
1829
1833
|
if (!prettierConfig) {
|
|
1830
1834
|
return data;
|
|
@@ -1889,10 +1893,10 @@ function createUnlocalizableLoader(isCacheRestore = false, returnUnlocalizedKeys
|
|
|
1889
1893
|
}
|
|
1890
1894
|
}
|
|
1891
1895
|
return false;
|
|
1892
|
-
}).map(([key,
|
|
1893
|
-
const result = _lodash2.default.omitBy(input2, (
|
|
1896
|
+
}).map(([key, _24]) => key);
|
|
1897
|
+
const result = _lodash2.default.omitBy(input2, (_24, key) => passthroughKeys.includes(key));
|
|
1894
1898
|
if (returnUnlocalizedKeys) {
|
|
1895
|
-
result.unlocalizable = _lodash2.default.omitBy(input2, (
|
|
1899
|
+
result.unlocalizable = _lodash2.default.omitBy(input2, (_24, key) => !passthroughKeys.includes(key));
|
|
1896
1900
|
}
|
|
1897
1901
|
return result;
|
|
1898
1902
|
},
|
|
@@ -1931,7 +1935,7 @@ function createPoDataLoader(params) {
|
|
|
1931
1935
|
Object.entries(entries).forEach(([msgid, entry]) => {
|
|
1932
1936
|
if (msgid && entry.msgid) {
|
|
1933
1937
|
const context = entry.msgctxt || "";
|
|
1934
|
-
const fullEntry = _optionalChain([parsedPo, 'access',
|
|
1938
|
+
const fullEntry = _optionalChain([parsedPo, 'access', _82 => _82.translations, 'access', _83 => _83[context], 'optionalAccess', _84 => _84[msgid]]);
|
|
1935
1939
|
if (fullEntry) {
|
|
1936
1940
|
result[msgid] = fullEntry;
|
|
1937
1941
|
}
|
|
@@ -1941,7 +1945,7 @@ function createPoDataLoader(params) {
|
|
|
1941
1945
|
return result;
|
|
1942
1946
|
},
|
|
1943
1947
|
async push(locale, data, originalInput) {
|
|
1944
|
-
const sections = _optionalChain([originalInput, 'optionalAccess',
|
|
1948
|
+
const sections = _optionalChain([originalInput, 'optionalAccess', _85 => _85.split, 'call', _86 => _86("\n\n"), 'access', _87 => _87.filter, 'call', _88 => _88(Boolean)]) || [];
|
|
1945
1949
|
const result = sections.map((section) => {
|
|
1946
1950
|
const sectionPo = _gettextparser2.default.po.parse(section);
|
|
1947
1951
|
const contextKey = _lodash2.default.keys(sectionPo.translations)[0];
|
|
@@ -1983,7 +1987,7 @@ function createPoContentLoader() {
|
|
|
1983
1987
|
entry.msgid,
|
|
1984
1988
|
{
|
|
1985
1989
|
...entry,
|
|
1986
|
-
msgstr: [_optionalChain([data, 'access',
|
|
1990
|
+
msgstr: [_optionalChain([data, 'access', _89 => _89[entry.msgid], 'optionalAccess', _90 => _90.singular]), _optionalChain([data, 'access', _91 => _91[entry.msgid], 'optionalAccess', _92 => _92.plural]) || null].filter(Boolean)
|
|
1987
1991
|
}
|
|
1988
1992
|
]).fromPairs().value();
|
|
1989
1993
|
return result;
|
|
@@ -2229,7 +2233,7 @@ function createDatoClient(params) {
|
|
|
2229
2233
|
only_valid: "true",
|
|
2230
2234
|
ids: !records.length ? void 0 : records.join(",")
|
|
2231
2235
|
}
|
|
2232
|
-
}).catch((error) => Promise.reject(_optionalChain([error, 'optionalAccess',
|
|
2236
|
+
}).catch((error) => Promise.reject(_optionalChain([error, 'optionalAccess', _93 => _93.response, 'optionalAccess', _94 => _94.body, 'optionalAccess', _95 => _95.data, 'optionalAccess', _96 => _96[0]]) || error));
|
|
2233
2237
|
},
|
|
2234
2238
|
findRecordsForModel: async (modelId, records) => {
|
|
2235
2239
|
try {
|
|
@@ -2239,9 +2243,9 @@ function createDatoClient(params) {
|
|
|
2239
2243
|
filter: {
|
|
2240
2244
|
type: modelId,
|
|
2241
2245
|
only_valid: "true",
|
|
2242
|
-
ids: !_optionalChain([records, 'optionalAccess',
|
|
2246
|
+
ids: !_optionalChain([records, 'optionalAccess', _97 => _97.length]) ? void 0 : records.join(",")
|
|
2243
2247
|
}
|
|
2244
|
-
}).catch((error) => Promise.reject(_optionalChain([error, 'optionalAccess',
|
|
2248
|
+
}).catch((error) => Promise.reject(_optionalChain([error, 'optionalAccess', _98 => _98.response, 'optionalAccess', _99 => _99.body, 'optionalAccess', _100 => _100.data, 'optionalAccess', _101 => _101[0]]) || error));
|
|
2245
2249
|
return result;
|
|
2246
2250
|
} catch (_error) {
|
|
2247
2251
|
throw new Error(
|
|
@@ -2255,9 +2259,9 @@ function createDatoClient(params) {
|
|
|
2255
2259
|
},
|
|
2256
2260
|
updateRecord: async (id, payload) => {
|
|
2257
2261
|
try {
|
|
2258
|
-
await dato.items.update(id, payload).catch((error) => Promise.reject(_optionalChain([error, 'optionalAccess',
|
|
2262
|
+
await dato.items.update(id, payload).catch((error) => Promise.reject(_optionalChain([error, 'optionalAccess', _102 => _102.response, 'optionalAccess', _103 => _103.body, 'optionalAccess', _104 => _104.data, 'optionalAccess', _105 => _105[0]]) || error));
|
|
2259
2263
|
} catch (_error) {
|
|
2260
|
-
if (_optionalChain([_error, 'optionalAccess',
|
|
2264
|
+
if (_optionalChain([_error, 'optionalAccess', _106 => _106.attributes, 'optionalAccess', _107 => _107.details, 'optionalAccess', _108 => _108.message])) {
|
|
2261
2265
|
throw new Error(
|
|
2262
2266
|
[
|
|
2263
2267
|
`${_error.attributes.details.message}`,
|
|
@@ -2278,9 +2282,9 @@ function createDatoClient(params) {
|
|
|
2278
2282
|
},
|
|
2279
2283
|
enableFieldLocalization: async (args) => {
|
|
2280
2284
|
try {
|
|
2281
|
-
await dato.fields.update(`${args.modelId}::${args.fieldId}`, { localized: true }).catch((error) => Promise.reject(_optionalChain([error, 'optionalAccess',
|
|
2285
|
+
await dato.fields.update(`${args.modelId}::${args.fieldId}`, { localized: true }).catch((error) => Promise.reject(_optionalChain([error, 'optionalAccess', _109 => _109.response, 'optionalAccess', _110 => _110.body, 'optionalAccess', _111 => _111.data, 'optionalAccess', _112 => _112[0]]) || error));
|
|
2282
2286
|
} catch (_error) {
|
|
2283
|
-
if (_optionalChain([_error, 'optionalAccess',
|
|
2287
|
+
if (_optionalChain([_error, 'optionalAccess', _113 => _113.attributes, 'optionalAccess', _114 => _114.code]) === "NOT_FOUND") {
|
|
2284
2288
|
throw new Error(
|
|
2285
2289
|
[
|
|
2286
2290
|
`Field "${args.fieldId}" not found in model "${args.modelId}".`,
|
|
@@ -2288,7 +2292,7 @@ function createDatoClient(params) {
|
|
|
2288
2292
|
].join("\n\n")
|
|
2289
2293
|
);
|
|
2290
2294
|
}
|
|
2291
|
-
if (_optionalChain([_error, 'optionalAccess',
|
|
2295
|
+
if (_optionalChain([_error, 'optionalAccess', _115 => _115.attributes, 'optionalAccess', _116 => _116.details, 'optionalAccess', _117 => _117.message])) {
|
|
2292
2296
|
throw new Error(
|
|
2293
2297
|
[`${_error.attributes.details.message}`, `Error: ${JSON.stringify(_error, null, 2)}`].join("\n\n")
|
|
2294
2298
|
);
|
|
@@ -2354,7 +2358,7 @@ function createDatoApiLoader(config, onConfigUpdate) {
|
|
|
2354
2358
|
}
|
|
2355
2359
|
}
|
|
2356
2360
|
const records = await dato.findRecordsForModel(modelId);
|
|
2357
|
-
const recordChoices = createRecordChoices(records, _optionalChain([config, 'access',
|
|
2361
|
+
const recordChoices = createRecordChoices(records, _optionalChain([config, 'access', _118 => _118.models, 'access', _119 => _119[modelId], 'optionalAccess', _120 => _120.records]) || [], project);
|
|
2358
2362
|
const selectedRecords = await promptRecordSelection(modelName, recordChoices);
|
|
2359
2363
|
result.models[modelId].records = records.filter((record) => selectedRecords.includes(record.id));
|
|
2360
2364
|
updatedConfig.models[modelId].records = selectedRecords;
|
|
@@ -2366,14 +2370,14 @@ function createDatoApiLoader(config, onConfigUpdate) {
|
|
|
2366
2370
|
},
|
|
2367
2371
|
async pull(locale, input2, initCtx) {
|
|
2368
2372
|
const result = {};
|
|
2369
|
-
for (const modelId of _lodash2.default.keys(_optionalChain([initCtx, 'optionalAccess',
|
|
2370
|
-
let records = _optionalChain([initCtx, 'optionalAccess',
|
|
2373
|
+
for (const modelId of _lodash2.default.keys(_optionalChain([initCtx, 'optionalAccess', _121 => _121.models]) || {})) {
|
|
2374
|
+
let records = _optionalChain([initCtx, 'optionalAccess', _122 => _122.models, 'access', _123 => _123[modelId], 'access', _124 => _124.records]) || [];
|
|
2371
2375
|
const recordIds = records.map((record) => record.id);
|
|
2372
2376
|
records = await dato.findRecords(recordIds);
|
|
2373
2377
|
console.log(`Fetched ${records.length} records for model ${modelId}`);
|
|
2374
2378
|
if (records.length > 0) {
|
|
2375
2379
|
result[modelId] = {
|
|
2376
|
-
fields: _optionalChain([initCtx, 'optionalAccess',
|
|
2380
|
+
fields: _optionalChain([initCtx, 'optionalAccess', _125 => _125.models, 'optionalAccess', _126 => _126[modelId], 'optionalAccess', _127 => _127.fields]) || [],
|
|
2377
2381
|
records
|
|
2378
2382
|
};
|
|
2379
2383
|
}
|
|
@@ -2432,7 +2436,7 @@ function createRecordChoices(records, selectedIds = [], project) {
|
|
|
2432
2436
|
return records.map((record) => ({
|
|
2433
2437
|
name: `${record.id} - https://${project.internal_domain}/editor/item_types/${record.item_type.id}/items/${record.id}`,
|
|
2434
2438
|
value: record.id,
|
|
2435
|
-
checked: _optionalChain([selectedIds, 'optionalAccess',
|
|
2439
|
+
checked: _optionalChain([selectedIds, 'optionalAccess', _128 => _128.includes, 'call', _129 => _129(record.id)])
|
|
2436
2440
|
}));
|
|
2437
2441
|
}
|
|
2438
2442
|
async function promptRecordSelection(modelName, choices) {
|
|
@@ -2583,18 +2587,18 @@ function createRawDatoValue(parsedDatoValue, originalRawDatoValue, isClean = fal
|
|
|
2583
2587
|
}
|
|
2584
2588
|
function serializeStructuredText(rawStructuredText) {
|
|
2585
2589
|
return serializeStructuredTextNode(rawStructuredText);
|
|
2586
|
-
function serializeStructuredTextNode(node,
|
|
2590
|
+
function serializeStructuredTextNode(node, path18 = [], acc = {}) {
|
|
2587
2591
|
if ("document" in node) {
|
|
2588
|
-
return serializeStructuredTextNode(node.document, [...
|
|
2592
|
+
return serializeStructuredTextNode(node.document, [...path18, "document"], acc);
|
|
2589
2593
|
}
|
|
2590
2594
|
if (!_lodash2.default.isNil(node.value)) {
|
|
2591
|
-
acc[[...
|
|
2595
|
+
acc[[...path18, "value"].join(".")] = node.value;
|
|
2592
2596
|
} else if (_lodash2.default.get(node, "type") === "block") {
|
|
2593
|
-
acc[[...
|
|
2597
|
+
acc[[...path18, "item"].join(".")] = serializeBlock(node.item);
|
|
2594
2598
|
}
|
|
2595
2599
|
if (node.children) {
|
|
2596
2600
|
for (let i = 0; i < node.children.length; i++) {
|
|
2597
|
-
serializeStructuredTextNode(node.children[i], [...
|
|
2601
|
+
serializeStructuredTextNode(node.children[i], [...path18, i.toString()], acc);
|
|
2598
2602
|
}
|
|
2599
2603
|
}
|
|
2600
2604
|
return acc;
|
|
@@ -2653,8 +2657,8 @@ function deserializeBlockList(parsedBlockList, originalRawBlockList, isClean = f
|
|
|
2653
2657
|
}
|
|
2654
2658
|
function deserializeStructuredText(parsedStructuredText, originalRawStructuredText) {
|
|
2655
2659
|
const result = _lodash2.default.cloneDeep(originalRawStructuredText);
|
|
2656
|
-
for (const [
|
|
2657
|
-
const realPath = _lodash2.default.chain(
|
|
2660
|
+
for (const [path18, value] of _lodash2.default.entries(parsedStructuredText)) {
|
|
2661
|
+
const realPath = _lodash2.default.chain(path18.split(".")).flatMap((s) => !_lodash2.default.isNaN(_lodash2.default.toNumber(s)) ? ["children", s] : s).value();
|
|
2658
2662
|
const deserializedValue = createRawDatoValue(value, _lodash2.default.get(originalRawStructuredText, realPath), true);
|
|
2659
2663
|
_lodash2.default.set(result, realPath, deserializedValue);
|
|
2660
2664
|
}
|
|
@@ -2679,12 +2683,12 @@ function _isVideo(rawDatoValue) {
|
|
|
2679
2683
|
// src/cli/loaders/dato/index.ts
|
|
2680
2684
|
function createDatoLoader(configFilePath) {
|
|
2681
2685
|
try {
|
|
2682
|
-
const configContent =
|
|
2686
|
+
const configContent = fs11.default.readFileSync(configFilePath, "utf-8");
|
|
2683
2687
|
const datoConfig = datoConfigSchema.parse(_json52.default.parse(configContent));
|
|
2684
2688
|
return composeLoaders(
|
|
2685
2689
|
createDatoApiLoader(
|
|
2686
2690
|
datoConfig,
|
|
2687
|
-
(updatedConfig) =>
|
|
2691
|
+
(updatedConfig) => fs11.default.writeFileSync(configFilePath, _json52.default.stringify(updatedConfig, null, 2))
|
|
2688
2692
|
),
|
|
2689
2693
|
createDatoFilterLoader(),
|
|
2690
2694
|
createDatoExtractLoader()
|
|
@@ -2699,7 +2703,7 @@ var _nodewebvtt = require('node-webvtt'); var _nodewebvtt2 = _interopRequireDefa
|
|
|
2699
2703
|
function createVttLoader() {
|
|
2700
2704
|
return createLoader({
|
|
2701
2705
|
async pull(locale, input2) {
|
|
2702
|
-
const vtt = _optionalChain([_nodewebvtt2.default, 'access',
|
|
2706
|
+
const vtt = _optionalChain([_nodewebvtt2.default, 'access', _130 => _130.parse, 'call', _131 => _131(input2), 'optionalAccess', _132 => _132.cues]);
|
|
2703
2707
|
if (Object.keys(vtt).length === 0) {
|
|
2704
2708
|
return {};
|
|
2705
2709
|
} else {
|
|
@@ -2752,7 +2756,7 @@ function variableExtractLoader(params) {
|
|
|
2752
2756
|
for (let i = 0; i < matches.length; i++) {
|
|
2753
2757
|
const match = matches[i];
|
|
2754
2758
|
const currentValue = result[key].value;
|
|
2755
|
-
const newValue = _optionalChain([currentValue, 'optionalAccess',
|
|
2759
|
+
const newValue = _optionalChain([currentValue, 'optionalAccess', _133 => _133.replace, 'call', _134 => _134(match, `{variable:${i}}`)]);
|
|
2756
2760
|
result[key].value = newValue;
|
|
2757
2761
|
result[key].variables[i] = match;
|
|
2758
2762
|
}
|
|
@@ -2766,7 +2770,7 @@ function variableExtractLoader(params) {
|
|
|
2766
2770
|
for (let i = 0; i < valueObj.variables.length; i++) {
|
|
2767
2771
|
const variable = valueObj.variables[i];
|
|
2768
2772
|
const currentValue = result[key];
|
|
2769
|
-
const newValue = _optionalChain([currentValue, 'optionalAccess',
|
|
2773
|
+
const newValue = _optionalChain([currentValue, 'optionalAccess', _135 => _135.replace, 'call', _136 => _136(`{variable:${i}}`, variable)]);
|
|
2770
2774
|
result[key] = newValue;
|
|
2771
2775
|
}
|
|
2772
2776
|
}
|
|
@@ -2947,7 +2951,7 @@ function createVueJsonLoader() {
|
|
|
2947
2951
|
return createLoader({
|
|
2948
2952
|
pull: async (locale, input2, ctx) => {
|
|
2949
2953
|
const parsed = parseVueFile(input2);
|
|
2950
|
-
return _nullishCoalesce(_optionalChain([parsed, 'optionalAccess',
|
|
2954
|
+
return _nullishCoalesce(_optionalChain([parsed, 'optionalAccess', _137 => _137.i18n, 'optionalAccess', _138 => _138[locale]]), () => ( {}));
|
|
2951
2955
|
},
|
|
2952
2956
|
push: async (locale, data, originalInput) => {
|
|
2953
2957
|
const parsed = parseVueFile(_nullishCoalesce(originalInput, () => ( "")));
|
|
@@ -3005,8 +3009,24 @@ function createInjectLocaleLoader(injectLocaleKeys) {
|
|
|
3005
3009
|
});
|
|
3006
3010
|
}
|
|
3007
3011
|
|
|
3012
|
+
// src/cli/loaders/locked-keys.ts
|
|
3013
|
+
|
|
3014
|
+
function createLockedKeysLoader(lockedKeys, isCacheRestore = false) {
|
|
3015
|
+
return createLoader({
|
|
3016
|
+
pull: async (locale, data) => _lodash2.default.chain(data).pickBy((value, key) => !lockedKeys.includes(key)).value(),
|
|
3017
|
+
push: async (locale, data, originalInput) => {
|
|
3018
|
+
const lockedSubObject = _lodash2.default.chain(originalInput).pickBy((value, key) => lockedKeys.includes(key)).value();
|
|
3019
|
+
if (isCacheRestore) {
|
|
3020
|
+
return _lodash2.default.merge({}, data, lockedSubObject);
|
|
3021
|
+
} else {
|
|
3022
|
+
return _lodash2.default.merge({}, originalInput, data, lockedSubObject);
|
|
3023
|
+
}
|
|
3024
|
+
}
|
|
3025
|
+
});
|
|
3026
|
+
}
|
|
3027
|
+
|
|
3008
3028
|
// src/cli/loaders/index.ts
|
|
3009
|
-
function createBucketLoader(bucketType, bucketPathPattern, options) {
|
|
3029
|
+
function createBucketLoader(bucketType, bucketPathPattern, options, lockedKeys) {
|
|
3010
3030
|
switch (bucketType) {
|
|
3011
3031
|
default:
|
|
3012
3032
|
throw new Error(`Unsupported bucket type: ${bucketType}`);
|
|
@@ -3041,6 +3061,7 @@ function createBucketLoader(bucketType, bucketPathPattern, options) {
|
|
|
3041
3061
|
createJsonLoader(),
|
|
3042
3062
|
createInjectLocaleLoader(options.injectLocale),
|
|
3043
3063
|
createFlatLoader(),
|
|
3064
|
+
createLockedKeysLoader(lockedKeys || [], options.isCacheRestore),
|
|
3044
3065
|
createSyncLoader(),
|
|
3045
3066
|
createUnlocalizableLoader(options.isCacheRestore, options.returnUnlocalizedKeys)
|
|
3046
3067
|
);
|
|
@@ -3100,6 +3121,7 @@ function createBucketLoader(bucketType, bucketPathPattern, options) {
|
|
|
3100
3121
|
createPrettierLoader({ parser: "yaml", bucketPathPattern }),
|
|
3101
3122
|
createYamlLoader(),
|
|
3102
3123
|
createFlatLoader(),
|
|
3124
|
+
createLockedKeysLoader(lockedKeys || [], options.isCacheRestore),
|
|
3103
3125
|
createSyncLoader(),
|
|
3104
3126
|
createUnlocalizableLoader(options.isCacheRestore, options.returnUnlocalizedKeys)
|
|
3105
3127
|
);
|
|
@@ -3179,75 +3201,6 @@ function createBucketLoader(bucketType, bucketPathPattern, options) {
|
|
|
3179
3201
|
}
|
|
3180
3202
|
}
|
|
3181
3203
|
|
|
3182
|
-
// src/cli/utils/lockfile.ts
|
|
3183
|
-
|
|
3184
|
-
|
|
3185
|
-
|
|
3186
|
-
|
|
3187
|
-
var _objecthash = require('object-hash');
|
|
3188
|
-
|
|
3189
|
-
function createLockfileHelper() {
|
|
3190
|
-
return {
|
|
3191
|
-
isLockfileExists: () => {
|
|
3192
|
-
const lockfilePath = _getLockfilePath();
|
|
3193
|
-
return _fs2.default.existsSync(lockfilePath);
|
|
3194
|
-
},
|
|
3195
|
-
registerSourceData: (pathPattern, sourceData) => {
|
|
3196
|
-
const lockfile = _loadLockfile();
|
|
3197
|
-
const sectionKey = _objecthash.MD5.call(void 0, pathPattern);
|
|
3198
|
-
const sectionChecksums = _lodash2.default.mapValues(sourceData, (value) => _objecthash.MD5.call(void 0, value));
|
|
3199
|
-
lockfile.checksums[sectionKey] = sectionChecksums;
|
|
3200
|
-
_saveLockfile(lockfile);
|
|
3201
|
-
},
|
|
3202
|
-
registerPartialSourceData: (pathPattern, partialSourceData) => {
|
|
3203
|
-
const lockfile = _loadLockfile();
|
|
3204
|
-
const sectionKey = _objecthash.MD5.call(void 0, pathPattern);
|
|
3205
|
-
const sectionChecksums = _lodash2.default.mapValues(partialSourceData, (value) => _objecthash.MD5.call(void 0, value));
|
|
3206
|
-
lockfile.checksums[sectionKey] = _lodash2.default.merge({}, _nullishCoalesce(lockfile.checksums[sectionKey], () => ( {})), sectionChecksums);
|
|
3207
|
-
_saveLockfile(lockfile);
|
|
3208
|
-
},
|
|
3209
|
-
extractUpdatedData: (pathPattern, sourceData) => {
|
|
3210
|
-
const lockfile = _loadLockfile();
|
|
3211
|
-
const sectionKey = _objecthash.MD5.call(void 0, pathPattern);
|
|
3212
|
-
const currentChecksums = _lodash2.default.mapValues(sourceData, (value) => _objecthash.MD5.call(void 0, value));
|
|
3213
|
-
const savedChecksums = lockfile.checksums[sectionKey] || {};
|
|
3214
|
-
const updatedData = _lodash2.default.pickBy(sourceData, (value, key) => savedChecksums[key] !== currentChecksums[key]);
|
|
3215
|
-
return updatedData;
|
|
3216
|
-
}
|
|
3217
|
-
};
|
|
3218
|
-
function _loadLockfile() {
|
|
3219
|
-
const lockfilePath = _getLockfilePath();
|
|
3220
|
-
if (!_fs2.default.existsSync(lockfilePath)) {
|
|
3221
|
-
return LockfileSchema.parse({});
|
|
3222
|
-
}
|
|
3223
|
-
const content = _fs2.default.readFileSync(lockfilePath, "utf-8");
|
|
3224
|
-
const result = LockfileSchema.parse(_yaml2.default.parse(content));
|
|
3225
|
-
return result;
|
|
3226
|
-
}
|
|
3227
|
-
function _saveLockfile(lockfile) {
|
|
3228
|
-
const lockfilePath = _getLockfilePath();
|
|
3229
|
-
const content = _yaml2.default.stringify(lockfile);
|
|
3230
|
-
_fs2.default.writeFileSync(lockfilePath, content);
|
|
3231
|
-
}
|
|
3232
|
-
function _getLockfilePath() {
|
|
3233
|
-
return _path2.default.join(process.cwd(), "i18n.lock");
|
|
3234
|
-
}
|
|
3235
|
-
}
|
|
3236
|
-
var LockfileSchema = _zod2.default.object({
|
|
3237
|
-
version: _zod2.default.literal(1).default(1),
|
|
3238
|
-
checksums: _zod2.default.record(
|
|
3239
|
-
_zod2.default.string(),
|
|
3240
|
-
// localizable files' keys
|
|
3241
|
-
_zod2.default.record(
|
|
3242
|
-
// checksums hashmap
|
|
3243
|
-
_zod2.default.string(),
|
|
3244
|
-
// key
|
|
3245
|
-
_zod2.default.string()
|
|
3246
|
-
// checksum of the key's value in the source locale
|
|
3247
|
-
).default({})
|
|
3248
|
-
).default({})
|
|
3249
|
-
});
|
|
3250
|
-
|
|
3251
3204
|
// src/cli/cmd/i18n.ts
|
|
3252
3205
|
var _chalk = require('chalk'); var _chalk2 = _interopRequireDefault(_chalk);
|
|
3253
3206
|
var _diff = require('diff');
|
|
@@ -3286,26 +3239,26 @@ function getNormalizedCache() {
|
|
|
3286
3239
|
function deleteCache() {
|
|
3287
3240
|
const cacheFilePath = _getCacheFilePath();
|
|
3288
3241
|
try {
|
|
3289
|
-
|
|
3242
|
+
fs11.default.unlinkSync(cacheFilePath);
|
|
3290
3243
|
} catch (e) {
|
|
3291
3244
|
}
|
|
3292
3245
|
}
|
|
3293
3246
|
function _loadCache() {
|
|
3294
3247
|
const cacheFilePath = _getCacheFilePath();
|
|
3295
|
-
if (!
|
|
3248
|
+
if (!fs11.default.existsSync(cacheFilePath)) {
|
|
3296
3249
|
return [];
|
|
3297
3250
|
}
|
|
3298
|
-
const content =
|
|
3251
|
+
const content = fs11.default.readFileSync(cacheFilePath, "utf-8");
|
|
3299
3252
|
const result = _parseJSONLines(content);
|
|
3300
3253
|
return result;
|
|
3301
3254
|
}
|
|
3302
3255
|
function _appendToCache(rows) {
|
|
3303
3256
|
const cacheFilePath = _getCacheFilePath();
|
|
3304
3257
|
const lines = _buildJSONLines(rows);
|
|
3305
|
-
|
|
3258
|
+
fs11.default.appendFileSync(cacheFilePath, lines);
|
|
3306
3259
|
}
|
|
3307
3260
|
function _getCacheFilePath() {
|
|
3308
|
-
return
|
|
3261
|
+
return path15.default.join(process.cwd(), "i18n.cache");
|
|
3309
3262
|
}
|
|
3310
3263
|
function _buildJSONLines(rows) {
|
|
3311
3264
|
return rows.map((row) => JSON.stringify(row)).join("\n") + "\n";
|
|
@@ -3325,6 +3278,9 @@ function _tryParseJSON(line) {
|
|
|
3325
3278
|
var __sdk = require('@lingo.dev/_sdk');
|
|
3326
3279
|
function createLingoLocalizer(params) {
|
|
3327
3280
|
return async (input2, onProgress) => {
|
|
3281
|
+
if (!Object.keys(input2.processableData).length) {
|
|
3282
|
+
return input2.processableData;
|
|
3283
|
+
}
|
|
3328
3284
|
const lingo = new (0, __sdk.LingoDotDevEngine)({
|
|
3329
3285
|
apiKey: params.apiKey,
|
|
3330
3286
|
apiUrl: params.apiUrl
|
|
@@ -3345,10 +3301,13 @@ function createLingoLocalizer(params) {
|
|
|
3345
3301
|
};
|
|
3346
3302
|
}
|
|
3347
3303
|
|
|
3348
|
-
// src/cli/processor/
|
|
3304
|
+
// src/cli/processor/basic.ts
|
|
3349
3305
|
var _ai = require('ai');
|
|
3350
3306
|
function createBasicTranslator(model, systemPrompt) {
|
|
3351
3307
|
return async (input2, onProgress) => {
|
|
3308
|
+
if (!Object.keys(input2.processableData).length) {
|
|
3309
|
+
return input2.processableData;
|
|
3310
|
+
}
|
|
3352
3311
|
if (!process.env.OPENAI_API_KEY) {
|
|
3353
3312
|
throw new Error("OPENAI_API_KEY is not set");
|
|
3354
3313
|
}
|
|
@@ -3393,7 +3352,7 @@ function createBasicTranslator(model, systemPrompt) {
|
|
|
3393
3352
|
]
|
|
3394
3353
|
});
|
|
3395
3354
|
const result = JSON.parse(response.text);
|
|
3396
|
-
return result;
|
|
3355
|
+
return _optionalChain([result, 'optionalAccess', _139 => _139.data]) || {};
|
|
3397
3356
|
};
|
|
3398
3357
|
}
|
|
3399
3358
|
|
|
@@ -3411,7 +3370,7 @@ function createProcessor(provider, params) {
|
|
|
3411
3370
|
}
|
|
3412
3371
|
}
|
|
3413
3372
|
function getPureModelProvider(provider) {
|
|
3414
|
-
switch (_optionalChain([provider, 'optionalAccess',
|
|
3373
|
+
switch (_optionalChain([provider, 'optionalAccess', _140 => _140.id])) {
|
|
3415
3374
|
case "openai":
|
|
3416
3375
|
if (!process.env.OPENAI_API_KEY) {
|
|
3417
3376
|
throw new Error("OPENAI_API_KEY is not set.");
|
|
@@ -3428,7 +3387,7 @@ function getPureModelProvider(provider) {
|
|
|
3428
3387
|
apiKey: process.env.ANTHROPIC_API_KEY
|
|
3429
3388
|
})(provider.model);
|
|
3430
3389
|
default:
|
|
3431
|
-
throw new Error(`Unsupported provider: ${_optionalChain([provider, 'optionalAccess',
|
|
3390
|
+
throw new Error(`Unsupported provider: ${_optionalChain([provider, 'optionalAccess', _141 => _141.id])}`);
|
|
3432
3391
|
}
|
|
3433
3392
|
}
|
|
3434
3393
|
|
|
@@ -3454,20 +3413,141 @@ async function trackEvent(distinctId, event, properties) {
|
|
|
3454
3413
|
if (process.env.DO_NOT_TRACK) {
|
|
3455
3414
|
return;
|
|
3456
3415
|
}
|
|
3457
|
-
|
|
3458
|
-
|
|
3459
|
-
|
|
3460
|
-
|
|
3461
|
-
|
|
3462
|
-
|
|
3463
|
-
|
|
3464
|
-
|
|
3465
|
-
|
|
3466
|
-
|
|
3467
|
-
|
|
3416
|
+
try {
|
|
3417
|
+
const posthog = new (0, _posthognode.PostHog)("phc_eR0iSoQufBxNY36k0f0T15UvHJdTfHlh8rJcxsfhfXk", {
|
|
3418
|
+
host: "https://eu.i.posthog.com",
|
|
3419
|
+
flushAt: 1,
|
|
3420
|
+
flushInterval: 0
|
|
3421
|
+
});
|
|
3422
|
+
await posthog.capture({
|
|
3423
|
+
distinctId,
|
|
3424
|
+
event,
|
|
3425
|
+
properties: {
|
|
3426
|
+
...properties,
|
|
3427
|
+
meta: {
|
|
3428
|
+
version: process.env.npm_package_version,
|
|
3429
|
+
isCi: process.env.CI === "true"
|
|
3430
|
+
}
|
|
3431
|
+
}
|
|
3432
|
+
});
|
|
3433
|
+
await posthog.shutdown();
|
|
3434
|
+
} catch (error) {
|
|
3435
|
+
if (process.env.DEBUG) {
|
|
3436
|
+
console.error(error);
|
|
3437
|
+
}
|
|
3438
|
+
}
|
|
3439
|
+
}
|
|
3440
|
+
|
|
3441
|
+
// src/cli/utils/delta.ts
|
|
3442
|
+
|
|
3443
|
+
|
|
3444
|
+
var _objecthash = require('object-hash');
|
|
3445
|
+
|
|
3446
|
+
// src/cli/utils/fs.ts
|
|
3447
|
+
|
|
3448
|
+
|
|
3449
|
+
function tryReadFile(filePath, defaultValue = null) {
|
|
3450
|
+
try {
|
|
3451
|
+
const content = fs11.readFileSync(filePath, "utf-8");
|
|
3452
|
+
return content;
|
|
3453
|
+
} catch (error) {
|
|
3454
|
+
return defaultValue;
|
|
3455
|
+
}
|
|
3456
|
+
}
|
|
3457
|
+
function writeFile(filePath, content) {
|
|
3458
|
+
const dir = path13.dirname(filePath);
|
|
3459
|
+
if (!fs11.existsSync(dir)) {
|
|
3460
|
+
fs11.mkdirSync(dir, { recursive: true });
|
|
3461
|
+
}
|
|
3462
|
+
fs11.writeFileSync(filePath, content);
|
|
3463
|
+
}
|
|
3464
|
+
function checkIfFileExists(filePath) {
|
|
3465
|
+
return fs11.existsSync(filePath);
|
|
3466
|
+
}
|
|
3467
|
+
|
|
3468
|
+
// src/cli/utils/delta.ts
|
|
3469
|
+
|
|
3470
|
+
|
|
3471
|
+
var LockSchema = _zod2.default.object({
|
|
3472
|
+
version: _zod2.default.literal(1).default(1),
|
|
3473
|
+
checksums: _zod2.default.record(
|
|
3474
|
+
_zod2.default.string(),
|
|
3475
|
+
// localizable files' keys
|
|
3476
|
+
// checksums hashmap
|
|
3477
|
+
_zod2.default.record(
|
|
3478
|
+
// key
|
|
3479
|
+
_zod2.default.string(),
|
|
3480
|
+
// checksum of the key's value in the source locale
|
|
3481
|
+
_zod2.default.string()
|
|
3482
|
+
).default({})
|
|
3483
|
+
).default({})
|
|
3484
|
+
});
|
|
3485
|
+
function createDeltaProcessor(fileKey) {
|
|
3486
|
+
const lockfilePath = path14.join(process.cwd(), "i18n.lock");
|
|
3487
|
+
return {
|
|
3488
|
+
async checkIfLockExists() {
|
|
3489
|
+
return checkIfFileExists(lockfilePath);
|
|
3490
|
+
},
|
|
3491
|
+
async calculateDelta(params) {
|
|
3492
|
+
let added = _lodash2.default.difference(Object.keys(params.sourceData), Object.keys(params.targetData));
|
|
3493
|
+
let removed = _lodash2.default.difference(Object.keys(params.targetData), Object.keys(params.sourceData));
|
|
3494
|
+
const updated = _lodash2.default.filter(Object.keys(params.sourceData), (key) => {
|
|
3495
|
+
return _objecthash.MD5.call(void 0, params.sourceData[key]) !== params.checksums[key] && params.checksums[key];
|
|
3496
|
+
});
|
|
3497
|
+
const renamed = [];
|
|
3498
|
+
for (const addedKey of added) {
|
|
3499
|
+
const addedHash = _objecthash.MD5.call(void 0, params.sourceData[addedKey]);
|
|
3500
|
+
for (const removedKey of removed) {
|
|
3501
|
+
if (params.checksums[removedKey] === addedHash) {
|
|
3502
|
+
renamed.push([removedKey, addedKey]);
|
|
3503
|
+
break;
|
|
3504
|
+
}
|
|
3505
|
+
}
|
|
3506
|
+
}
|
|
3507
|
+
added = added.filter((key) => !renamed.some(([oldKey, newKey]) => newKey === key));
|
|
3508
|
+
removed = removed.filter((key) => !renamed.some(([oldKey, newKey]) => oldKey === key));
|
|
3509
|
+
const hasChanges = [added.length > 0, removed.length > 0, updated.length > 0, renamed.length > 0].some((v) => v);
|
|
3510
|
+
return {
|
|
3511
|
+
added,
|
|
3512
|
+
removed,
|
|
3513
|
+
updated,
|
|
3514
|
+
renamed,
|
|
3515
|
+
hasChanges
|
|
3516
|
+
};
|
|
3517
|
+
},
|
|
3518
|
+
async loadLock() {
|
|
3519
|
+
const lockfileContent = tryReadFile(lockfilePath, null);
|
|
3520
|
+
const lockfileYaml = lockfileContent ? _yaml2.default.parse(lockfileContent) : null;
|
|
3521
|
+
const lockfileData = lockfileYaml ? LockSchema.parse(lockfileYaml) : {
|
|
3522
|
+
version: 1,
|
|
3523
|
+
checksums: {}
|
|
3524
|
+
};
|
|
3525
|
+
return lockfileData;
|
|
3526
|
+
},
|
|
3527
|
+
async saveLock(lockData) {
|
|
3528
|
+
const lockfileYaml = _yaml2.default.stringify(lockData);
|
|
3529
|
+
writeFile(lockfilePath, lockfileYaml);
|
|
3530
|
+
},
|
|
3531
|
+
async loadChecksums() {
|
|
3532
|
+
const id = _objecthash.MD5.call(void 0, fileKey);
|
|
3533
|
+
const lockfileData = await this.loadLock();
|
|
3534
|
+
return lockfileData.checksums[id] || {};
|
|
3535
|
+
},
|
|
3536
|
+
async saveChecksums(checksums) {
|
|
3537
|
+
const id = _objecthash.MD5.call(void 0, fileKey);
|
|
3538
|
+
const lockfileData = await this.loadLock();
|
|
3539
|
+
lockfileData.checksums[id] = checksums;
|
|
3540
|
+
await this.saveLock(lockfileData);
|
|
3541
|
+
},
|
|
3542
|
+
async createChecksums(sourceData) {
|
|
3543
|
+
const checksums = _lodash2.default.mapValues(sourceData, (value) => _objecthash.MD5.call(void 0, value));
|
|
3544
|
+
return checksums;
|
|
3545
|
+
}
|
|
3546
|
+
};
|
|
3468
3547
|
}
|
|
3469
3548
|
|
|
3470
3549
|
// src/cli/cmd/i18n.ts
|
|
3550
|
+
|
|
3471
3551
|
var i18n_default = new (0, _interactivecommander.Command)().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(
|
|
3472
3552
|
"--key <key>",
|
|
3473
3553
|
"Key to process. Process only a specific translation key, useful for debugging or updating a single entry"
|
|
@@ -3509,13 +3589,13 @@ var i18n_default = new (0, _interactivecommander.Command)().command("i18n").desc
|
|
|
3509
3589
|
flags
|
|
3510
3590
|
});
|
|
3511
3591
|
let buckets = getBuckets(i18nConfig);
|
|
3512
|
-
if (_optionalChain([flags, 'access',
|
|
3592
|
+
if (_optionalChain([flags, 'access', _142 => _142.bucket, 'optionalAccess', _143 => _143.length])) {
|
|
3513
3593
|
buckets = buckets.filter((bucket) => flags.bucket.includes(bucket.type));
|
|
3514
3594
|
}
|
|
3515
3595
|
ora.succeed("Buckets retrieved");
|
|
3516
|
-
if (_optionalChain([flags, 'access',
|
|
3596
|
+
if (_optionalChain([flags, 'access', _144 => _144.file, 'optionalAccess', _145 => _145.length])) {
|
|
3517
3597
|
buckets = buckets.map((bucket) => {
|
|
3518
|
-
const paths = bucket.paths.filter((
|
|
3598
|
+
const paths = bucket.paths.filter((path18) => flags.file.find((file) => _optionalChain([path18, 'access', _146 => _146.pathPattern, 'optionalAccess', _147 => _147.match, 'call', _148 => _148(file)])));
|
|
3519
3599
|
return { ...bucket, paths };
|
|
3520
3600
|
}).filter((bucket) => bucket.paths.length > 0);
|
|
3521
3601
|
if (buckets.length === 0) {
|
|
@@ -3525,34 +3605,94 @@ var i18n_default = new (0, _interactivecommander.Command)().command("i18n").desc
|
|
|
3525
3605
|
ora.info(`\x1B[36mProcessing only filtered buckets:\x1B[0m`);
|
|
3526
3606
|
buckets.map((bucket) => {
|
|
3527
3607
|
ora.info(` ${bucket.type}:`);
|
|
3528
|
-
bucket.paths.forEach((
|
|
3529
|
-
ora.info(` - ${
|
|
3608
|
+
bucket.paths.forEach((path18) => {
|
|
3609
|
+
ora.info(` - ${path18.pathPattern}`);
|
|
3530
3610
|
});
|
|
3531
3611
|
});
|
|
3532
3612
|
}
|
|
3533
3613
|
}
|
|
3534
|
-
const targetLocales = _optionalChain([flags, 'access',
|
|
3535
|
-
|
|
3536
|
-
|
|
3537
|
-
|
|
3614
|
+
const targetLocales = _optionalChain([flags, 'access', _149 => _149.locale, 'optionalAccess', _150 => _150.length]) ? flags.locale : i18nConfig.locale.targets;
|
|
3615
|
+
ora.start("Setting up localization cache...");
|
|
3616
|
+
const checkLockfileProcessor = createDeltaProcessor("");
|
|
3617
|
+
const lockfileExists = await checkLockfileProcessor.checkIfLockExists();
|
|
3618
|
+
if (!lockfileExists) {
|
|
3538
3619
|
ora.start("Creating i18n.lock...");
|
|
3539
3620
|
for (const bucket of buckets) {
|
|
3540
3621
|
for (const bucketPath of bucket.paths) {
|
|
3541
3622
|
const sourceLocale = __spec.resolveOverriddenLocale.call(void 0, i18nConfig.locale.source, bucketPath.delimiter);
|
|
3542
|
-
const bucketLoader = createBucketLoader(
|
|
3543
|
-
|
|
3544
|
-
|
|
3545
|
-
|
|
3546
|
-
|
|
3623
|
+
const bucketLoader = createBucketLoader(
|
|
3624
|
+
bucket.type,
|
|
3625
|
+
bucketPath.pathPattern,
|
|
3626
|
+
{
|
|
3627
|
+
isCacheRestore: false,
|
|
3628
|
+
defaultLocale: sourceLocale,
|
|
3629
|
+
injectLocale: bucket.injectLocale
|
|
3630
|
+
},
|
|
3631
|
+
bucket.lockedKeys
|
|
3632
|
+
);
|
|
3547
3633
|
bucketLoader.setDefaultLocale(sourceLocale);
|
|
3548
3634
|
await bucketLoader.init();
|
|
3549
3635
|
const sourceData = await bucketLoader.pull(i18nConfig.locale.source);
|
|
3550
|
-
|
|
3636
|
+
const deltaProcessor = createDeltaProcessor(bucketPath.pathPattern);
|
|
3637
|
+
const checksums = await deltaProcessor.createChecksums(sourceData);
|
|
3638
|
+
await deltaProcessor.saveChecksums(checksums);
|
|
3551
3639
|
}
|
|
3552
3640
|
}
|
|
3553
|
-
ora.succeed("
|
|
3641
|
+
ora.succeed("Localization cache initialized");
|
|
3554
3642
|
} else {
|
|
3555
|
-
ora.succeed("
|
|
3643
|
+
ora.succeed("Localization cache loaded");
|
|
3644
|
+
}
|
|
3645
|
+
for (const bucket of buckets) {
|
|
3646
|
+
if (bucket.type !== "json") {
|
|
3647
|
+
continue;
|
|
3648
|
+
}
|
|
3649
|
+
ora.start("Validating localization state...");
|
|
3650
|
+
for (const bucketPath of bucket.paths) {
|
|
3651
|
+
const sourceLocale = __spec.resolveOverriddenLocale.call(void 0, i18nConfig.locale.source, bucketPath.delimiter);
|
|
3652
|
+
const deltaProcessor = createDeltaProcessor(bucketPath.pathPattern);
|
|
3653
|
+
const sourcePath = path15.join(process.cwd(), bucketPath.pathPattern.replace("[locale]", sourceLocale));
|
|
3654
|
+
const sourceContent = tryReadFile(sourcePath, null);
|
|
3655
|
+
const sourceData = JSON.parse(sourceContent || "{}");
|
|
3656
|
+
const sourceFlattenedData = _flat.flatten.call(void 0, sourceData, {
|
|
3657
|
+
delimiter: "/",
|
|
3658
|
+
transformKey(key) {
|
|
3659
|
+
return encodeURIComponent(key);
|
|
3660
|
+
}
|
|
3661
|
+
});
|
|
3662
|
+
for (const _targetLocale of targetLocales) {
|
|
3663
|
+
const targetLocale = __spec.resolveOverriddenLocale.call(void 0, _targetLocale, bucketPath.delimiter);
|
|
3664
|
+
const targetPath = path15.join(process.cwd(), bucketPath.pathPattern.replace("[locale]", targetLocale));
|
|
3665
|
+
const targetContent = tryReadFile(targetPath, null);
|
|
3666
|
+
const targetData = JSON.parse(targetContent || "{}");
|
|
3667
|
+
const targetFlattenedData = _flat.flatten.call(void 0, targetData, {
|
|
3668
|
+
delimiter: "/",
|
|
3669
|
+
transformKey(key) {
|
|
3670
|
+
return encodeURIComponent(key);
|
|
3671
|
+
}
|
|
3672
|
+
});
|
|
3673
|
+
const checksums = await deltaProcessor.loadChecksums();
|
|
3674
|
+
const delta = await deltaProcessor.calculateDelta({
|
|
3675
|
+
sourceData: sourceFlattenedData,
|
|
3676
|
+
targetData: targetFlattenedData,
|
|
3677
|
+
checksums
|
|
3678
|
+
});
|
|
3679
|
+
if (!delta.hasChanges) {
|
|
3680
|
+
continue;
|
|
3681
|
+
}
|
|
3682
|
+
for (const [oldKey, newKey] of delta.renamed) {
|
|
3683
|
+
targetFlattenedData[newKey] = targetFlattenedData[oldKey];
|
|
3684
|
+
delete targetFlattenedData[oldKey];
|
|
3685
|
+
}
|
|
3686
|
+
const updatedTargetData = _flat.unflatten.call(void 0, targetFlattenedData, {
|
|
3687
|
+
delimiter: "/",
|
|
3688
|
+
transformKey(key) {
|
|
3689
|
+
return decodeURIComponent(key);
|
|
3690
|
+
}
|
|
3691
|
+
});
|
|
3692
|
+
await writeFile(targetPath, JSON.stringify(updatedTargetData, null, 2));
|
|
3693
|
+
}
|
|
3694
|
+
}
|
|
3695
|
+
ora.succeed("Localization state check completed");
|
|
3556
3696
|
}
|
|
3557
3697
|
const cache = getNormalizedCache();
|
|
3558
3698
|
if (cache) {
|
|
@@ -3565,11 +3705,16 @@ var i18n_default = new (0, _interactivecommander.Command)().command("i18n").desc
|
|
|
3565
3705
|
const bucketOra = _ora2.default.call(void 0, { indent: 4 });
|
|
3566
3706
|
bucketOra.info(`Processing path: ${bucketPath.pathPattern}`);
|
|
3567
3707
|
const sourceLocale = __spec.resolveOverriddenLocale.call(void 0, i18nConfig.locale.source, bucketPath.delimiter);
|
|
3568
|
-
const bucketLoader = createBucketLoader(
|
|
3569
|
-
|
|
3570
|
-
|
|
3571
|
-
|
|
3572
|
-
|
|
3708
|
+
const bucketLoader = createBucketLoader(
|
|
3709
|
+
bucket.type,
|
|
3710
|
+
bucketPath.pathPattern,
|
|
3711
|
+
{
|
|
3712
|
+
isCacheRestore: true,
|
|
3713
|
+
defaultLocale: sourceLocale,
|
|
3714
|
+
injectLocale: bucket.injectLocale
|
|
3715
|
+
},
|
|
3716
|
+
bucket.lockedKeys
|
|
3717
|
+
);
|
|
3573
3718
|
bucketLoader.setDefaultLocale(sourceLocale);
|
|
3574
3719
|
await bucketLoader.init();
|
|
3575
3720
|
const sourceData = await bucketLoader.pull(sourceLocale);
|
|
@@ -3584,7 +3729,9 @@ var i18n_default = new (0, _interactivecommander.Command)().command("i18n").desc
|
|
|
3584
3729
|
}
|
|
3585
3730
|
}
|
|
3586
3731
|
await bucketLoader.push(targetLocale, targetData);
|
|
3587
|
-
|
|
3732
|
+
const deltaProcessor = createDeltaProcessor(bucketPath.pathPattern);
|
|
3733
|
+
const checksums = await deltaProcessor.createChecksums(cachedSourceData);
|
|
3734
|
+
await deltaProcessor.saveChecksums(checksums);
|
|
3588
3735
|
bucketOra.succeed(
|
|
3589
3736
|
`[${sourceLocale} -> ${targetLocale}] Recovered ${Object.keys(cachedSourceData).length} entries from cache`
|
|
3590
3737
|
);
|
|
@@ -3604,18 +3751,29 @@ var i18n_default = new (0, _interactivecommander.Command)().command("i18n").desc
|
|
|
3604
3751
|
bucketLoop: for (const bucket of buckets) {
|
|
3605
3752
|
for (const bucketPath of bucket.paths) {
|
|
3606
3753
|
const sourceLocale = __spec.resolveOverriddenLocale.call(void 0, i18nConfig.locale.source, bucketPath.delimiter);
|
|
3607
|
-
const bucketLoader = createBucketLoader(
|
|
3608
|
-
|
|
3609
|
-
|
|
3610
|
-
|
|
3611
|
-
|
|
3612
|
-
|
|
3754
|
+
const bucketLoader = createBucketLoader(
|
|
3755
|
+
bucket.type,
|
|
3756
|
+
bucketPath.pathPattern,
|
|
3757
|
+
{
|
|
3758
|
+
isCacheRestore: false,
|
|
3759
|
+
defaultLocale: sourceLocale,
|
|
3760
|
+
returnUnlocalizedKeys: true,
|
|
3761
|
+
injectLocale: bucket.injectLocale
|
|
3762
|
+
},
|
|
3763
|
+
bucket.lockedKeys
|
|
3764
|
+
);
|
|
3613
3765
|
bucketLoader.setDefaultLocale(sourceLocale);
|
|
3614
3766
|
await bucketLoader.init();
|
|
3615
3767
|
const { unlocalizable: sourceUnlocalizable, ...sourceData } = await bucketLoader.pull(
|
|
3616
3768
|
i18nConfig.locale.source
|
|
3617
3769
|
);
|
|
3618
|
-
const
|
|
3770
|
+
const deltaProcessor = createDeltaProcessor(bucketPath.pathPattern);
|
|
3771
|
+
const sourceChecksums = await deltaProcessor.createChecksums(sourceData);
|
|
3772
|
+
const savedChecksums = await deltaProcessor.loadChecksums();
|
|
3773
|
+
const updatedSourceData = _lodash2.default.pickBy(
|
|
3774
|
+
sourceData,
|
|
3775
|
+
(value, key) => sourceChecksums[key] !== savedChecksums[key]
|
|
3776
|
+
);
|
|
3619
3777
|
if (Object.keys(updatedSourceData).length > 0) {
|
|
3620
3778
|
requiresUpdate = "updated";
|
|
3621
3779
|
break bucketLoop;
|
|
@@ -3662,11 +3820,16 @@ var i18n_default = new (0, _interactivecommander.Command)().command("i18n").desc
|
|
|
3662
3820
|
for (const bucketPath of bucket.paths) {
|
|
3663
3821
|
const bucketOra = _ora2.default.call(void 0, { indent: 2 }).info(`Processing path: ${bucketPath.pathPattern}`);
|
|
3664
3822
|
const sourceLocale = __spec.resolveOverriddenLocale.call(void 0, i18nConfig.locale.source, bucketPath.delimiter);
|
|
3665
|
-
const bucketLoader = createBucketLoader(
|
|
3666
|
-
|
|
3667
|
-
|
|
3668
|
-
|
|
3669
|
-
|
|
3823
|
+
const bucketLoader = createBucketLoader(
|
|
3824
|
+
bucket.type,
|
|
3825
|
+
bucketPath.pathPattern,
|
|
3826
|
+
{
|
|
3827
|
+
isCacheRestore: false,
|
|
3828
|
+
defaultLocale: sourceLocale,
|
|
3829
|
+
injectLocale: bucket.injectLocale
|
|
3830
|
+
},
|
|
3831
|
+
bucket.lockedKeys
|
|
3832
|
+
);
|
|
3670
3833
|
bucketLoader.setDefaultLocale(sourceLocale);
|
|
3671
3834
|
await bucketLoader.init();
|
|
3672
3835
|
let sourceData = await bucketLoader.pull(sourceLocale);
|
|
@@ -3675,15 +3838,17 @@ var i18n_default = new (0, _interactivecommander.Command)().command("i18n").desc
|
|
|
3675
3838
|
try {
|
|
3676
3839
|
bucketOra.start(`[${sourceLocale} -> ${targetLocale}] (0%) Localization in progress...`);
|
|
3677
3840
|
sourceData = await bucketLoader.pull(sourceLocale);
|
|
3678
|
-
const updatedSourceData = flags.force ? sourceData : lockfileHelper.extractUpdatedData(bucketPath.pathPattern, sourceData);
|
|
3679
3841
|
const targetData = await bucketLoader.pull(targetLocale);
|
|
3680
|
-
|
|
3842
|
+
const deltaProcessor2 = createDeltaProcessor(bucketPath.pathPattern);
|
|
3843
|
+
const checksums2 = await deltaProcessor2.loadChecksums();
|
|
3844
|
+
const delta = await deltaProcessor2.calculateDelta({
|
|
3681
3845
|
sourceData,
|
|
3682
|
-
|
|
3683
|
-
|
|
3846
|
+
targetData,
|
|
3847
|
+
checksums: checksums2
|
|
3684
3848
|
});
|
|
3849
|
+
let processableData = _lodash2.default.chain(sourceData).entries().filter(([key, value]) => delta.added.includes(key) || delta.updated.includes(key) || !!flags.force).fromPairs().value();
|
|
3685
3850
|
if (flags.key) {
|
|
3686
|
-
processableData = _lodash2.default.pickBy(processableData, (
|
|
3851
|
+
processableData = _lodash2.default.pickBy(processableData, (_24, key) => key === flags.key);
|
|
3687
3852
|
}
|
|
3688
3853
|
if (flags.verbose) {
|
|
3689
3854
|
bucketOra.info(JSON.stringify(processableData, null, 2));
|
|
@@ -3751,7 +3916,9 @@ var i18n_default = new (0, _interactivecommander.Command)().command("i18n").desc
|
|
|
3751
3916
|
}
|
|
3752
3917
|
}
|
|
3753
3918
|
}
|
|
3754
|
-
|
|
3919
|
+
const deltaProcessor = createDeltaProcessor(bucketPath.pathPattern);
|
|
3920
|
+
const checksums = await deltaProcessor.createChecksums(sourceData);
|
|
3921
|
+
await deltaProcessor.saveChecksums(checksums);
|
|
3755
3922
|
}
|
|
3756
3923
|
} catch (_error) {
|
|
3757
3924
|
const error = new Error(`Failed to process bucket ${bucket.type}: ${_error.message}`);
|
|
@@ -3786,12 +3953,6 @@ var i18n_default = new (0, _interactivecommander.Command)().command("i18n").desc
|
|
|
3786
3953
|
process.exit(1);
|
|
3787
3954
|
}
|
|
3788
3955
|
});
|
|
3789
|
-
function calculateDataDelta(args) {
|
|
3790
|
-
const newKeys = _lodash2.default.difference(Object.keys(args.sourceData), Object.keys(args.targetData));
|
|
3791
|
-
const updatedKeys = Object.keys(args.updatedSourceData);
|
|
3792
|
-
const result = _lodash2.default.chain(args.sourceData).pickBy((value, key) => newKeys.includes(key) || updatedKeys.includes(key)).value();
|
|
3793
|
-
return result;
|
|
3794
|
-
}
|
|
3795
3956
|
function parseFlags(options) {
|
|
3796
3957
|
return _zod2.default.object({
|
|
3797
3958
|
apiKey: _zod2.default.string().optional(),
|
|
@@ -3838,12 +3999,12 @@ function validateParams(i18nConfig, flags) {
|
|
|
3838
3999
|
message: "No buckets found in i18n.json. Please add at least one bucket containing i18n content.",
|
|
3839
4000
|
docUrl: "bucketNotFound"
|
|
3840
4001
|
});
|
|
3841
|
-
} else if (_optionalChain([flags, 'access',
|
|
4002
|
+
} else if (_optionalChain([flags, 'access', _151 => _151.locale, 'optionalAccess', _152 => _152.some, 'call', _153 => _153((locale) => !i18nConfig.locale.targets.includes(locale))])) {
|
|
3842
4003
|
throw new CLIError({
|
|
3843
4004
|
message: `One or more specified locales do not exist in i18n.json locale.targets. Please add them to the list and try again.`,
|
|
3844
4005
|
docUrl: "localeTargetNotFound"
|
|
3845
4006
|
});
|
|
3846
|
-
} else if (_optionalChain([flags, 'access',
|
|
4007
|
+
} else if (_optionalChain([flags, 'access', _154 => _154.bucket, 'optionalAccess', _155 => _155.some, 'call', _156 => _156((bucket) => !i18nConfig.buckets[bucket])])) {
|
|
3847
4008
|
throw new CLIError({
|
|
3848
4009
|
message: `One or more specified buckets do not exist in i18n.json. Please add them to the list and try again.`,
|
|
3849
4010
|
docUrl: "bucketNotFound"
|
|
@@ -3951,6 +4112,77 @@ Editing value for: ${_chalk2.default.cyan(key)}`);
|
|
|
3951
4112
|
|
|
3952
4113
|
|
|
3953
4114
|
|
|
4115
|
+
// src/cli/utils/lockfile.ts
|
|
4116
|
+
|
|
4117
|
+
|
|
4118
|
+
|
|
4119
|
+
|
|
4120
|
+
|
|
4121
|
+
|
|
4122
|
+
function createLockfileHelper() {
|
|
4123
|
+
return {
|
|
4124
|
+
isLockfileExists: () => {
|
|
4125
|
+
const lockfilePath = _getLockfilePath();
|
|
4126
|
+
return fs11.default.existsSync(lockfilePath);
|
|
4127
|
+
},
|
|
4128
|
+
registerSourceData: (pathPattern, sourceData) => {
|
|
4129
|
+
const lockfile = _loadLockfile();
|
|
4130
|
+
const sectionKey = _objecthash.MD5.call(void 0, pathPattern);
|
|
4131
|
+
const sectionChecksums = _lodash2.default.mapValues(sourceData, (value) => _objecthash.MD5.call(void 0, value));
|
|
4132
|
+
lockfile.checksums[sectionKey] = sectionChecksums;
|
|
4133
|
+
_saveLockfile(lockfile);
|
|
4134
|
+
},
|
|
4135
|
+
registerPartialSourceData: (pathPattern, partialSourceData) => {
|
|
4136
|
+
const lockfile = _loadLockfile();
|
|
4137
|
+
const sectionKey = _objecthash.MD5.call(void 0, pathPattern);
|
|
4138
|
+
const sectionChecksums = _lodash2.default.mapValues(partialSourceData, (value) => _objecthash.MD5.call(void 0, value));
|
|
4139
|
+
lockfile.checksums[sectionKey] = _lodash2.default.merge({}, _nullishCoalesce(lockfile.checksums[sectionKey], () => ( {})), sectionChecksums);
|
|
4140
|
+
_saveLockfile(lockfile);
|
|
4141
|
+
},
|
|
4142
|
+
extractUpdatedData: (pathPattern, sourceData) => {
|
|
4143
|
+
const lockfile = _loadLockfile();
|
|
4144
|
+
const sectionKey = _objecthash.MD5.call(void 0, pathPattern);
|
|
4145
|
+
const currentChecksums = _lodash2.default.mapValues(sourceData, (value) => _objecthash.MD5.call(void 0, value));
|
|
4146
|
+
const savedChecksums = lockfile.checksums[sectionKey] || {};
|
|
4147
|
+
const updatedData = _lodash2.default.pickBy(sourceData, (value, key) => savedChecksums[key] !== currentChecksums[key]);
|
|
4148
|
+
return updatedData;
|
|
4149
|
+
}
|
|
4150
|
+
};
|
|
4151
|
+
function _loadLockfile() {
|
|
4152
|
+
const lockfilePath = _getLockfilePath();
|
|
4153
|
+
if (!fs11.default.existsSync(lockfilePath)) {
|
|
4154
|
+
return LockfileSchema.parse({});
|
|
4155
|
+
}
|
|
4156
|
+
const content = fs11.default.readFileSync(lockfilePath, "utf-8");
|
|
4157
|
+
const result = LockfileSchema.parse(_yaml2.default.parse(content));
|
|
4158
|
+
return result;
|
|
4159
|
+
}
|
|
4160
|
+
function _saveLockfile(lockfile) {
|
|
4161
|
+
const lockfilePath = _getLockfilePath();
|
|
4162
|
+
const content = _yaml2.default.stringify(lockfile);
|
|
4163
|
+
fs11.default.writeFileSync(lockfilePath, content);
|
|
4164
|
+
}
|
|
4165
|
+
function _getLockfilePath() {
|
|
4166
|
+
return path15.default.join(process.cwd(), "i18n.lock");
|
|
4167
|
+
}
|
|
4168
|
+
}
|
|
4169
|
+
var LockfileSchema = _zod2.default.object({
|
|
4170
|
+
version: _zod2.default.literal(1).default(1),
|
|
4171
|
+
checksums: _zod2.default.record(
|
|
4172
|
+
_zod2.default.string(),
|
|
4173
|
+
// localizable files' keys
|
|
4174
|
+
_zod2.default.record(
|
|
4175
|
+
// checksums hashmap
|
|
4176
|
+
_zod2.default.string(),
|
|
4177
|
+
// key
|
|
4178
|
+
_zod2.default.string()
|
|
4179
|
+
// checksum of the key's value in the source locale
|
|
4180
|
+
).default({})
|
|
4181
|
+
).default({})
|
|
4182
|
+
});
|
|
4183
|
+
|
|
4184
|
+
// src/cli/cmd/lockfile.ts
|
|
4185
|
+
|
|
3954
4186
|
var lockfile_default = new (0, _interactivecommander.Command)().command("lockfile").description("Create a lockfile if it does not exist").helpOption("-h, --help", "Show help").option("-f, --force", "Force create a lockfile").action(async (options) => {
|
|
3955
4187
|
const flags = flagsSchema.parse(options);
|
|
3956
4188
|
const ora = _ora2.default.call(void 0, );
|
|
@@ -4082,7 +4314,7 @@ var _stdiojs = require('@modelcontextprotocol/sdk/server/stdio.js');
|
|
|
4082
4314
|
var _mcpjs = require('@modelcontextprotocol/sdk/server/mcp.js');
|
|
4083
4315
|
|
|
4084
4316
|
|
|
4085
|
-
var mcp_default = new (0, _interactivecommander.Command)().command("mcp").description("Use Lingo.dev model context provider with your AI agent").helpOption("-h, --help", "Show help").action(async (
|
|
4317
|
+
var mcp_default = new (0, _interactivecommander.Command)().command("mcp").description("Use Lingo.dev model context provider with your AI agent").helpOption("-h, --help", "Show help").action(async (_24, program) => {
|
|
4086
4318
|
const apiKey = program.args[0];
|
|
4087
4319
|
const settings = getSettings(apiKey);
|
|
4088
4320
|
if (!settings.auth.apiKey) {
|
|
@@ -4205,7 +4437,7 @@ var InBranchFlow = class extends IntegrationFlow {
|
|
|
4205
4437
|
_child_process.execSync.call(void 0, `git config --global safe.directory ${process.cwd()}`);
|
|
4206
4438
|
_child_process.execSync.call(void 0, `git config user.name "${gitConfig.userName}"`);
|
|
4207
4439
|
_child_process.execSync.call(void 0, `git config user.email "${gitConfig.userEmail}"`);
|
|
4208
|
-
_optionalChain([this, 'access',
|
|
4440
|
+
_optionalChain([this, 'access', _157 => _157.platformKit, 'optionalAccess', _158 => _158.gitConfig, 'call', _159 => _159()]);
|
|
4209
4441
|
_child_process.execSync.call(void 0, `git fetch origin ${baseBranchName}`, { stdio: "inherit" });
|
|
4210
4442
|
_child_process.execSync.call(void 0, `git checkout ${baseBranchName} --`, { stdio: "inherit" });
|
|
4211
4443
|
if (!processOwnCommits) {
|
|
@@ -4218,7 +4450,7 @@ var InBranchFlow = class extends IntegrationFlow {
|
|
|
4218
4450
|
return false;
|
|
4219
4451
|
}
|
|
4220
4452
|
}
|
|
4221
|
-
const workingDir =
|
|
4453
|
+
const workingDir = path15.default.resolve(process.cwd(), this.platformKit.config.workingDir);
|
|
4222
4454
|
if (workingDir !== process.cwd()) {
|
|
4223
4455
|
this.ora.info(`Changing to working directory: ${this.platformKit.config.workingDir}`);
|
|
4224
4456
|
process.chdir(workingDir);
|
|
@@ -4230,7 +4462,7 @@ var InBranchFlow = class extends IntegrationFlow {
|
|
|
4230
4462
|
// ../../action/src/flows/pull-request.ts
|
|
4231
4463
|
var PullRequestFlow = class extends InBranchFlow {
|
|
4232
4464
|
async preRun() {
|
|
4233
|
-
const canContinue = await _optionalChain([super.preRun.bind(this), 'optionalCall',
|
|
4465
|
+
const canContinue = await _optionalChain([super.preRun.bind(this), 'optionalCall', _160 => _160()]);
|
|
4234
4466
|
if (!canContinue) {
|
|
4235
4467
|
return false;
|
|
4236
4468
|
}
|
|
@@ -4393,9 +4625,15 @@ var _bitbucket = require('bitbucket'); var _bitbucket2 = _interopRequireDefault(
|
|
|
4393
4625
|
|
|
4394
4626
|
// ../../action/src/platforms/_base.ts
|
|
4395
4627
|
|
|
4628
|
+
|
|
4396
4629
|
var defaultMessage = "feat: update translations via @lingodotdev";
|
|
4397
4630
|
var PlatformKit = class {
|
|
4398
|
-
gitConfig() {
|
|
4631
|
+
gitConfig(token, repoUrl) {
|
|
4632
|
+
if (token && repoUrl) {
|
|
4633
|
+
_child_process.execSync.call(void 0, `git remote set-url origin ${repoUrl}`, {
|
|
4634
|
+
stdio: "inherit"
|
|
4635
|
+
});
|
|
4636
|
+
}
|
|
4399
4637
|
}
|
|
4400
4638
|
get config() {
|
|
4401
4639
|
const env = _zod2.default.object({
|
|
@@ -4442,10 +4680,10 @@ var BitbucketPlatformKit = class extends PlatformKit {
|
|
|
4442
4680
|
repo_slug: this.platformConfig.repositoryName,
|
|
4443
4681
|
state: "OPEN"
|
|
4444
4682
|
}).then(({ data: { values } }) => {
|
|
4445
|
-
return _optionalChain([values, 'optionalAccess',
|
|
4446
|
-
({ source, destination }) => _optionalChain([source, 'optionalAccess',
|
|
4683
|
+
return _optionalChain([values, 'optionalAccess', _161 => _161.find, 'call', _162 => _162(
|
|
4684
|
+
({ source, destination }) => _optionalChain([source, 'optionalAccess', _163 => _163.branch, 'optionalAccess', _164 => _164.name]) === branch && _optionalChain([destination, 'optionalAccess', _165 => _165.branch, 'optionalAccess', _166 => _166.name]) === this.platformConfig.baseBranchName
|
|
4447
4685
|
)]);
|
|
4448
|
-
}).then((pr) => _optionalChain([pr, 'optionalAccess',
|
|
4686
|
+
}).then((pr) => _optionalChain([pr, 'optionalAccess', _167 => _167.id]));
|
|
4449
4687
|
}
|
|
4450
4688
|
async closePullRequest({ pullRequestNumber }) {
|
|
4451
4689
|
await this.bb.repositories.declinePullRequest({
|
|
@@ -4509,7 +4747,6 @@ var BitbucketPlatformKit = class extends PlatformKit {
|
|
|
4509
4747
|
// ../../action/src/platforms/github.ts
|
|
4510
4748
|
var _octokit2 = require('octokit');
|
|
4511
4749
|
|
|
4512
|
-
|
|
4513
4750
|
var GitHubPlatformKit = class extends PlatformKit {
|
|
4514
4751
|
|
|
4515
4752
|
get octokit() {
|
|
@@ -4532,7 +4769,7 @@ var GitHubPlatformKit = class extends PlatformKit {
|
|
|
4532
4769
|
repo: this.platformConfig.repositoryName,
|
|
4533
4770
|
base: this.platformConfig.baseBranchName,
|
|
4534
4771
|
state: "open"
|
|
4535
|
-
}).then(({ data }) => data[0]).then((pr) => _optionalChain([pr, 'optionalAccess',
|
|
4772
|
+
}).then(({ data }) => data[0]).then((pr) => _optionalChain([pr, 'optionalAccess', _168 => _168.number]));
|
|
4536
4773
|
}
|
|
4537
4774
|
async closePullRequest({ pullRequestNumber }) {
|
|
4538
4775
|
await this.octokit.rest.pulls.update({
|
|
@@ -4566,9 +4803,7 @@ var GitHubPlatformKit = class extends PlatformKit {
|
|
|
4566
4803
|
if (ghToken && processOwnCommits) {
|
|
4567
4804
|
console.log("Using provided GH_TOKEN. This will trigger your CI/CD pipeline to run again.");
|
|
4568
4805
|
const url = `https://${ghToken}@github.com/${repositoryOwner}/${repositoryName}.git`;
|
|
4569
|
-
|
|
4570
|
-
stdio: "inherit"
|
|
4571
|
-
});
|
|
4806
|
+
super.gitConfig(ghToken, url);
|
|
4572
4807
|
}
|
|
4573
4808
|
}
|
|
4574
4809
|
get platformConfig() {
|
|
@@ -4596,7 +4831,6 @@ var GitHubPlatformKit = class extends PlatformKit {
|
|
|
4596
4831
|
// ../../action/src/platforms/gitlab.ts
|
|
4597
4832
|
var _rest = require('@gitbeaker/rest');
|
|
4598
4833
|
|
|
4599
|
-
|
|
4600
4834
|
var gl = new (0, _rest.Gitlab)({ token: "" });
|
|
4601
4835
|
var GitlabPlatformKit = class extends PlatformKit {
|
|
4602
4836
|
|
|
@@ -4648,7 +4882,7 @@ var GitlabPlatformKit = class extends PlatformKit {
|
|
|
4648
4882
|
sourceBranch: branch,
|
|
4649
4883
|
state: "opened"
|
|
4650
4884
|
});
|
|
4651
|
-
return _optionalChain([mergeRequests, 'access',
|
|
4885
|
+
return _optionalChain([mergeRequests, 'access', _169 => _169[0], 'optionalAccess', _170 => _170.iid]);
|
|
4652
4886
|
}
|
|
4653
4887
|
async closePullRequest({ pullRequestNumber }) {
|
|
4654
4888
|
await this.gitlab.MergeRequests.edit(this.platformConfig.gitlabProjectId, pullRequestNumber, {
|
|
@@ -4671,10 +4905,9 @@ var GitlabPlatformKit = class extends PlatformKit {
|
|
|
4671
4905
|
await this.gitlab.MergeRequestNotes.create(this.platformConfig.gitlabProjectId, pullRequestNumber, body);
|
|
4672
4906
|
}
|
|
4673
4907
|
gitConfig() {
|
|
4674
|
-
const
|
|
4675
|
-
|
|
4676
|
-
|
|
4677
|
-
});
|
|
4908
|
+
const glToken = this.platformConfig.glToken;
|
|
4909
|
+
const url = `https://oauth2:${glToken}@gitlab.com/${this.platformConfig.repositoryOwner}/${this.platformConfig.repositoryName}.git`;
|
|
4910
|
+
super.gitConfig(glToken, url);
|
|
4678
4911
|
}
|
|
4679
4912
|
buildPullRequestUrl(pullRequestNumber) {
|
|
4680
4913
|
return `https://gitlab.com/${this.platformConfig.repositoryOwner}/${this.platformConfig.repositoryName}/-/merge_requests/${pullRequestNumber}`;
|
|
@@ -4702,7 +4935,7 @@ async function main() {
|
|
|
4702
4935
|
const { isPullRequestMode } = platformKit.config;
|
|
4703
4936
|
ora.info(`Pull request mode: ${isPullRequestMode ? "on" : "off"}`);
|
|
4704
4937
|
const flow = isPullRequestMode ? new PullRequestFlow(ora, platformKit) : new InBranchFlow(ora, platformKit);
|
|
4705
|
-
const canRun = await _optionalChain([flow, 'access',
|
|
4938
|
+
const canRun = await _optionalChain([flow, 'access', _171 => _171.preRun, 'optionalCall', _172 => _172()]);
|
|
4706
4939
|
if (canRun === false) {
|
|
4707
4940
|
return;
|
|
4708
4941
|
}
|
|
@@ -4710,7 +4943,7 @@ async function main() {
|
|
|
4710
4943
|
if (!hasChanges) {
|
|
4711
4944
|
return;
|
|
4712
4945
|
}
|
|
4713
|
-
await _optionalChain([flow, 'access',
|
|
4946
|
+
await _optionalChain([flow, 'access', _173 => _173.postRun, 'optionalCall', _174 => _174()]);
|
|
4714
4947
|
}
|
|
4715
4948
|
|
|
4716
4949
|
// src/cli/cmd/ci.ts
|
|
@@ -4732,7 +4965,7 @@ var ci_default = new (0, _interactivecommander.Command)().command("ci").descript
|
|
|
4732
4965
|
}
|
|
4733
4966
|
const env = {
|
|
4734
4967
|
LINGODOTDEV_API_KEY: settings.auth.apiKey,
|
|
4735
|
-
LINGODOTDEV_PULL_REQUEST: _optionalChain([options, 'access',
|
|
4968
|
+
LINGODOTDEV_PULL_REQUEST: _optionalChain([options, 'access', _175 => _175.pullRequest, 'optionalAccess', _176 => _176.toString, 'call', _177 => _177()]) || "false",
|
|
4736
4969
|
...options.commitMessage && { LINGODOTDEV_COMMIT_MESSAGE: options.commitMessage },
|
|
4737
4970
|
...options.pullRequestTitle && { LINGODOTDEV_PULL_REQUEST_TITLE: options.pullRequestTitle },
|
|
4738
4971
|
...options.workingDirectory && { LINGODOTDEV_WORKING_DIRECTORY: options.workingDirectory },
|
|
@@ -4745,7 +4978,7 @@ var ci_default = new (0, _interactivecommander.Command)().command("ci").descript
|
|
|
4745
4978
|
// package.json
|
|
4746
4979
|
var package_default = {
|
|
4747
4980
|
name: "lingo.dev",
|
|
4748
|
-
version: "0.
|
|
4981
|
+
version: "0.82.0",
|
|
4749
4982
|
description: "Lingo.dev CLI",
|
|
4750
4983
|
private: false,
|
|
4751
4984
|
publishConfig: {
|