lingo.dev 0.74.9 → 0.74.10
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 +27 -22
- package/build/cli.cjs.map +1 -1
- package/build/cli.mjs +45 -40
- package/build/cli.mjs.map +1 -1
- package/package.json +2 -2
package/build/cli.mjs
CHANGED
|
@@ -265,12 +265,13 @@ function _getConfigFilePath() {
|
|
|
265
265
|
// src/cli/cmd/init.ts
|
|
266
266
|
import { defaultConfig, resolveLocaleCode, bucketTypes } from "@lingo.dev/_spec";
|
|
267
267
|
import fs3 from "fs";
|
|
268
|
+
import path3 from "path";
|
|
268
269
|
import { spawn } from "child_process";
|
|
269
270
|
import _2 from "lodash";
|
|
270
271
|
import { confirm } from "@inquirer/prompts";
|
|
271
|
-
var openUrl = (
|
|
272
|
+
var openUrl = (path9) => {
|
|
272
273
|
const settings = getSettings(void 0);
|
|
273
|
-
spawn("open", [`${settings.auth.webUrl}${
|
|
274
|
+
spawn("open", [`${settings.auth.webUrl}${path9}`]);
|
|
274
275
|
};
|
|
275
276
|
var throwHelpError = (option, value) => {
|
|
276
277
|
if (value === "help") {
|
|
@@ -311,20 +312,22 @@ var init_default = new InteractiveCommand().command("init").description("Initial
|
|
|
311
312
|
return value;
|
|
312
313
|
}).default("json")
|
|
313
314
|
).addOption(
|
|
314
|
-
new InteractiveOption("-p, --paths
|
|
315
|
+
new InteractiveOption("-p, --paths [path...]", "List of paths for the bucket").argParser((value) => {
|
|
316
|
+
if (!value || value.length === 0) return [];
|
|
315
317
|
const values = value.includes(",") ? value.split(",") : value.split(" ");
|
|
316
|
-
for (const
|
|
318
|
+
for (const p of values) {
|
|
317
319
|
try {
|
|
318
|
-
const
|
|
320
|
+
const dirPath = path3.dirname(p);
|
|
321
|
+
const stats = fs3.statSync(dirPath);
|
|
319
322
|
if (!stats.isDirectory()) {
|
|
320
|
-
throw new Error(`${
|
|
323
|
+
throw new Error(`${dirPath} is not a directory`);
|
|
321
324
|
}
|
|
322
325
|
} catch (err) {
|
|
323
|
-
throw new Error(`Invalid
|
|
326
|
+
throw new Error(`Invalid path: ${p}`);
|
|
324
327
|
}
|
|
325
328
|
}
|
|
326
329
|
return values;
|
|
327
|
-
}).default(
|
|
330
|
+
}).default([])
|
|
328
331
|
).action(async (options) => {
|
|
329
332
|
const settings = getSettings(void 0);
|
|
330
333
|
const spinner = Ora2().start("Initializing Lingo.dev project");
|
|
@@ -337,7 +340,9 @@ var init_default = new InteractiveCommand().command("init").description("Initial
|
|
|
337
340
|
newConfig.locale.source = options.source;
|
|
338
341
|
newConfig.locale.targets = options.targets;
|
|
339
342
|
newConfig.buckets = {
|
|
340
|
-
[options.bucket]:
|
|
343
|
+
[options.bucket]: {
|
|
344
|
+
include: options.paths || []
|
|
345
|
+
}
|
|
341
346
|
};
|
|
342
347
|
await saveConfig(newConfig);
|
|
343
348
|
spinner.succeed("Lingo.dev project initialized");
|
|
@@ -391,7 +396,7 @@ import { Command as Command5 } from "interactive-commander";
|
|
|
391
396
|
import { Command as Command2 } from "interactive-commander";
|
|
392
397
|
import _3 from "lodash";
|
|
393
398
|
import fs4 from "fs";
|
|
394
|
-
import
|
|
399
|
+
import path4 from "path";
|
|
395
400
|
import { defaultConfig as defaultConfig2 } from "@lingo.dev/_spec";
|
|
396
401
|
var config_default = new Command2().command("config").description("Print out the current configuration").helpOption("-h, --help", "Show help").action(async (options) => {
|
|
397
402
|
const fileConfig = loadReplexicaFileConfig();
|
|
@@ -399,7 +404,7 @@ var config_default = new Command2().command("config").description("Print out the
|
|
|
399
404
|
console.log(JSON.stringify(config, null, 2));
|
|
400
405
|
});
|
|
401
406
|
function loadReplexicaFileConfig() {
|
|
402
|
-
const replexicaConfigPath =
|
|
407
|
+
const replexicaConfigPath = path4.resolve(process.cwd(), "i18n.json");
|
|
403
408
|
const fileExists = fs4.existsSync(replexicaConfigPath);
|
|
404
409
|
if (!fileExists) {
|
|
405
410
|
return void 0;
|
|
@@ -441,7 +446,7 @@ import Ora4 from "ora";
|
|
|
441
446
|
|
|
442
447
|
// src/cli/utils/buckets.ts
|
|
443
448
|
import _4 from "lodash";
|
|
444
|
-
import
|
|
449
|
+
import path5 from "path";
|
|
445
450
|
import * as glob from "glob";
|
|
446
451
|
import { resolveOverridenLocale } from "@lingo.dev/_spec";
|
|
447
452
|
function getBuckets(i18nConfig) {
|
|
@@ -476,9 +481,9 @@ function extractPathPatterns(sourceLocale, include, exclude) {
|
|
|
476
481
|
return result;
|
|
477
482
|
}
|
|
478
483
|
function expandPlaceholderedGlob(_pathPattern, sourceLocale) {
|
|
479
|
-
const absolutePathPattern =
|
|
480
|
-
const pathPattern =
|
|
481
|
-
if (
|
|
484
|
+
const absolutePathPattern = path5.resolve(_pathPattern);
|
|
485
|
+
const pathPattern = path5.relative(process.cwd(), absolutePathPattern);
|
|
486
|
+
if (path5.relative(process.cwd(), pathPattern).startsWith("..")) {
|
|
482
487
|
throw new CLIError({
|
|
483
488
|
message: `Invalid path pattern: ${pathPattern}. Path pattern must be within the current working directory.`,
|
|
484
489
|
docUrl: "invalidPathPattern"
|
|
@@ -496,19 +501,19 @@ function expandPlaceholderedGlob(_pathPattern, sourceLocale) {
|
|
|
496
501
|
docUrl: "invalidPathPattern"
|
|
497
502
|
});
|
|
498
503
|
}
|
|
499
|
-
const pathPatternChunks = pathPattern.split(
|
|
504
|
+
const pathPatternChunks = pathPattern.split(path5.sep);
|
|
500
505
|
const localeSegmentIndex = pathPatternChunks.findIndex((segment) => segment.includes("[locale]"));
|
|
501
506
|
const localePlaceholderIndex = pathPatternChunks[localeSegmentIndex]?.indexOf("[locale]") ?? -1;
|
|
502
507
|
const sourcePathPattern = pathPattern.replace(/\[locale\]/g, sourceLocale);
|
|
503
|
-
const sourcePaths = glob.sync(sourcePathPattern, { follow: true, withFileTypes: true }).filter((file) => file.isFile() || file.isSymbolicLink()).map((file) => file.fullpath()).map((fullpath) =>
|
|
508
|
+
const sourcePaths = glob.sync(sourcePathPattern, { follow: true, withFileTypes: true }).filter((file) => file.isFile() || file.isSymbolicLink()).map((file) => file.fullpath()).map((fullpath) => path5.relative(process.cwd(), fullpath));
|
|
504
509
|
const placeholderedPaths = sourcePaths.map((sourcePath) => {
|
|
505
|
-
const sourcePathChunks = sourcePath.split(
|
|
510
|
+
const sourcePathChunks = sourcePath.split(path5.sep);
|
|
506
511
|
if (localeSegmentIndex >= 0 && localePlaceholderIndex >= 0) {
|
|
507
512
|
const placeholderedPathChunk = sourcePathChunks[localeSegmentIndex];
|
|
508
513
|
const placeholderedSegment = placeholderedPathChunk.substring(0, localePlaceholderIndex) + "[locale]" + placeholderedPathChunk.substring(localePlaceholderIndex + sourceLocale.length);
|
|
509
514
|
sourcePathChunks[localeSegmentIndex] = placeholderedSegment;
|
|
510
515
|
}
|
|
511
|
-
const placeholderedPath = sourcePathChunks.join(
|
|
516
|
+
const placeholderedPath = sourcePathChunks.join(path5.sep);
|
|
512
517
|
return placeholderedPath;
|
|
513
518
|
});
|
|
514
519
|
return placeholderedPaths;
|
|
@@ -550,8 +555,8 @@ var files_default = new Command4().command("files").description("Print out the l
|
|
|
550
555
|
} else if (type.target) {
|
|
551
556
|
result.push(...targetPaths);
|
|
552
557
|
}
|
|
553
|
-
result.forEach((
|
|
554
|
-
console.log(
|
|
558
|
+
result.forEach((path9) => {
|
|
559
|
+
console.log(path9);
|
|
555
560
|
});
|
|
556
561
|
}
|
|
557
562
|
}
|
|
@@ -700,7 +705,7 @@ function createFlatLoader() {
|
|
|
700
705
|
|
|
701
706
|
// src/cli/loaders/text-file.ts
|
|
702
707
|
import fs5 from "fs/promises";
|
|
703
|
-
import
|
|
708
|
+
import path6 from "path";
|
|
704
709
|
function createTextFileLoader(pathPattern) {
|
|
705
710
|
return createLoader({
|
|
706
711
|
async pull(locale) {
|
|
@@ -710,8 +715,8 @@ function createTextFileLoader(pathPattern) {
|
|
|
710
715
|
},
|
|
711
716
|
async push(locale, data, _19, originalLocale) {
|
|
712
717
|
const draftPath = pathPattern.replace("[locale]", locale);
|
|
713
|
-
const finalPath =
|
|
714
|
-
const dirPath =
|
|
718
|
+
const finalPath = path6.resolve(draftPath);
|
|
719
|
+
const dirPath = path6.dirname(finalPath);
|
|
715
720
|
await fs5.mkdir(dirPath, { recursive: true });
|
|
716
721
|
const trimmedPayload = data.trim();
|
|
717
722
|
const trailingNewLine = await getTrailingNewLine(pathPattern, locale, originalLocale);
|
|
@@ -725,7 +730,7 @@ function createTextFileLoader(pathPattern) {
|
|
|
725
730
|
}
|
|
726
731
|
async function readFileForLocale(pathPattern, locale) {
|
|
727
732
|
const draftPath = pathPattern.replace("[locale]", locale);
|
|
728
|
-
const finalPath =
|
|
733
|
+
const finalPath = path6.resolve(draftPath);
|
|
729
734
|
const exists = await fs5.access(finalPath).then(() => true).catch(() => false);
|
|
730
735
|
if (!exists) {
|
|
731
736
|
return "";
|
|
@@ -1008,9 +1013,9 @@ function createHtmlLoader() {
|
|
|
1008
1013
|
const bDepth = b.split("/").length;
|
|
1009
1014
|
return aDepth - bDepth;
|
|
1010
1015
|
});
|
|
1011
|
-
paths.forEach((
|
|
1012
|
-
const value = data[
|
|
1013
|
-
const [nodePath, attribute] =
|
|
1016
|
+
paths.forEach((path9) => {
|
|
1017
|
+
const value = data[path9];
|
|
1018
|
+
const [nodePath, attribute] = path9.split("#");
|
|
1014
1019
|
const [rootTag, ...indices] = nodePath.split("/");
|
|
1015
1020
|
let parent = rootTag === "head" ? document.head : document.body;
|
|
1016
1021
|
let current = parent;
|
|
@@ -2014,18 +2019,18 @@ function createRawDatoValue(parsedDatoValue, originalRawDatoValue, isClean = fal
|
|
|
2014
2019
|
}
|
|
2015
2020
|
function serializeStructuredText(rawStructuredText) {
|
|
2016
2021
|
return serializeStructuredTextNode(rawStructuredText);
|
|
2017
|
-
function serializeStructuredTextNode(node,
|
|
2022
|
+
function serializeStructuredTextNode(node, path9 = [], acc = {}) {
|
|
2018
2023
|
if ("document" in node) {
|
|
2019
|
-
return serializeStructuredTextNode(node.document, [...
|
|
2024
|
+
return serializeStructuredTextNode(node.document, [...path9, "document"], acc);
|
|
2020
2025
|
}
|
|
2021
2026
|
if (!_13.isNil(node.value)) {
|
|
2022
|
-
acc[[...
|
|
2027
|
+
acc[[...path9, "value"].join(".")] = node.value;
|
|
2023
2028
|
} else if (_13.get(node, "type") === "block") {
|
|
2024
|
-
acc[[...
|
|
2029
|
+
acc[[...path9, "item"].join(".")] = serializeBlock(node.item);
|
|
2025
2030
|
}
|
|
2026
2031
|
if (node.children) {
|
|
2027
2032
|
for (let i = 0; i < node.children.length; i++) {
|
|
2028
|
-
serializeStructuredTextNode(node.children[i], [...
|
|
2033
|
+
serializeStructuredTextNode(node.children[i], [...path9, i.toString()], acc);
|
|
2029
2034
|
}
|
|
2030
2035
|
}
|
|
2031
2036
|
return acc;
|
|
@@ -2084,8 +2089,8 @@ function deserializeBlockList(parsedBlockList, originalRawBlockList, isClean = f
|
|
|
2084
2089
|
}
|
|
2085
2090
|
function deserializeStructuredText(parsedStructuredText, originalRawStructuredText) {
|
|
2086
2091
|
const result = _13.cloneDeep(originalRawStructuredText);
|
|
2087
|
-
for (const [
|
|
2088
|
-
const realPath = _13.chain(
|
|
2092
|
+
for (const [path9, value] of _13.entries(parsedStructuredText)) {
|
|
2093
|
+
const realPath = _13.chain(path9.split(".")).flatMap((s) => !_13.isNaN(_13.toNumber(s)) ? ["children", s] : s).value();
|
|
2089
2094
|
const deserializedValue = createRawDatoValue(value, _13.get(originalRawStructuredText, realPath), true);
|
|
2090
2095
|
_13.set(result, realPath, deserializedValue);
|
|
2091
2096
|
}
|
|
@@ -2470,7 +2475,7 @@ function createBucketLoader(bucketType, bucketPathPattern) {
|
|
|
2470
2475
|
|
|
2471
2476
|
// src/cli/utils/lockfile.ts
|
|
2472
2477
|
import fs7 from "fs";
|
|
2473
|
-
import
|
|
2478
|
+
import path7 from "path";
|
|
2474
2479
|
import Z3 from "zod";
|
|
2475
2480
|
import YAML3 from "yaml";
|
|
2476
2481
|
import { MD5 } from "object-hash";
|
|
@@ -2519,7 +2524,7 @@ function createLockfileHelper() {
|
|
|
2519
2524
|
fs7.writeFileSync(lockfilePath, content);
|
|
2520
2525
|
}
|
|
2521
2526
|
function _getLockfilePath() {
|
|
2522
|
-
return
|
|
2527
|
+
return path7.join(process.cwd(), "i18n.lock");
|
|
2523
2528
|
}
|
|
2524
2529
|
}
|
|
2525
2530
|
var LockfileSchema = Z3.object({
|
|
@@ -2544,7 +2549,7 @@ import inquirer2 from "inquirer";
|
|
|
2544
2549
|
import externalEditor from "external-editor";
|
|
2545
2550
|
|
|
2546
2551
|
// src/cli/utils/cache.ts
|
|
2547
|
-
import
|
|
2552
|
+
import path8 from "path";
|
|
2548
2553
|
import fs8 from "fs";
|
|
2549
2554
|
var cacheChunk = (targetLocale, sourceChunk, processedChunk) => {
|
|
2550
2555
|
const rows = Object.entries(sourceChunk).map(([key, source]) => ({
|
|
@@ -2594,7 +2599,7 @@ function _appendToCache(rows) {
|
|
|
2594
2599
|
fs8.appendFileSync(cacheFilePath, lines);
|
|
2595
2600
|
}
|
|
2596
2601
|
function _getCacheFilePath() {
|
|
2597
|
-
return
|
|
2602
|
+
return path8.join(process.cwd(), "i18n.cache");
|
|
2598
2603
|
}
|
|
2599
2604
|
function _buildJSONLines(rows) {
|
|
2600
2605
|
return rows.map((row) => JSON.stringify(row)).join("\n") + "\n";
|
|
@@ -3158,7 +3163,7 @@ function displaySummary(results) {
|
|
|
3158
3163
|
// package.json
|
|
3159
3164
|
var package_default = {
|
|
3160
3165
|
name: "lingo.dev",
|
|
3161
|
-
version: "0.74.
|
|
3166
|
+
version: "0.74.10",
|
|
3162
3167
|
description: "Lingo.dev CLI",
|
|
3163
3168
|
private: false,
|
|
3164
3169
|
publishConfig: {
|