lingo.dev 0.75.0 → 0.76.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 +80 -71
- package/build/cli.cjs.map +1 -1
- package/build/cli.mjs +40 -31
- package/build/cli.mjs.map +1 -1
- package/package.json +3 -3
package/build/cli.mjs
CHANGED
|
@@ -303,24 +303,30 @@ function findLocaleFilesWithExtension(ext) {
|
|
|
303
303
|
const files = glob.sync(`**/*${ext}`, {
|
|
304
304
|
ignore: ["node_modules/**", "package*.json", "i18n.json", "lingo.json"]
|
|
305
305
|
});
|
|
306
|
-
const localeFilePattern = new RegExp(
|
|
307
|
-
const localeDirectoryPattern = new RegExp(
|
|
306
|
+
const localeFilePattern = new RegExp(`/([a-z]{2}(-[A-Z]{2})?)${ext}$`);
|
|
307
|
+
const localeDirectoryPattern = new RegExp(`/([a-z]{2}(-[A-Z]{2})?)/[^/]+${ext}$`);
|
|
308
308
|
const potentialLocaleFiles = files.filter(
|
|
309
309
|
(file) => localeFilePattern.test(file) || localeDirectoryPattern.test(file)
|
|
310
310
|
);
|
|
311
|
-
const
|
|
312
|
-
const
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
const
|
|
316
|
-
return { file,
|
|
317
|
-
}).
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
311
|
+
const potantialLocaleFilesAndPatterns = potentialLocaleFiles.map((file) => {
|
|
312
|
+
const matchPotentialLocales = Array.from(
|
|
313
|
+
file.matchAll(new RegExp(`/([a-z]{2}(-[A-Z]{2})?|[^/]+)(?=/|${ext})`, "g"))
|
|
314
|
+
);
|
|
315
|
+
const potantialLocales = matchPotentialLocales.map((match) => match[1]);
|
|
316
|
+
return { file, potantialLocales };
|
|
317
|
+
}).map(({ file, potantialLocales }) => {
|
|
318
|
+
for (const locale of potantialLocales) {
|
|
319
|
+
try {
|
|
320
|
+
resolveLocaleCode(locale);
|
|
321
|
+
return { locale, file };
|
|
322
|
+
} catch (e) {
|
|
323
|
+
}
|
|
322
324
|
}
|
|
323
|
-
return
|
|
325
|
+
return { file, locale: null };
|
|
326
|
+
}).filter(({ locale }) => locale !== null);
|
|
327
|
+
const localeFilesAndPatterns = potantialLocaleFilesAndPatterns.map(({ file, locale }) => {
|
|
328
|
+
const pattern = file.replaceAll(new RegExp(`/${locale}${ext}`, "g"), `/[locale]${ext}`).replaceAll(new RegExp(`/${locale}/`, "g"), `/[locale]/`).replaceAll(new RegExp(`/${locale}/`, "g"), `/[locale]/`);
|
|
329
|
+
return { pattern, file };
|
|
324
330
|
});
|
|
325
331
|
const grouppedFilesAndPatterns = _2.groupBy(localeFilesAndPatterns, "pattern");
|
|
326
332
|
const patterns = Object.keys(grouppedFilesAndPatterns);
|
|
@@ -519,6 +525,8 @@ var init_default = new InteractiveCommand().command("init").description("Initial
|
|
|
519
525
|
});
|
|
520
526
|
} else {
|
|
521
527
|
spinner.succeed("No existing locale files found.");
|
|
528
|
+
}
|
|
529
|
+
if (selectedPatterns.length === 0) {
|
|
522
530
|
const useDefault = await confirm({
|
|
523
531
|
message: `Use (and create) default path ${patterns.join(", ")}?`
|
|
524
532
|
});
|
|
@@ -689,24 +697,25 @@ function expandPlaceholderedGlob(_pathPattern, sourceLocale) {
|
|
|
689
697
|
docUrl: "invalidPathPattern"
|
|
690
698
|
});
|
|
691
699
|
}
|
|
692
|
-
if (pathPattern.split("[locale]").length > 2) {
|
|
693
|
-
throw new CLIError({
|
|
694
|
-
message: `Invalid path pattern: ${pathPattern}. Path pattern must contain at most one "[locale]" placeholder.`,
|
|
695
|
-
docUrl: "invalidPathPattern"
|
|
696
|
-
});
|
|
697
|
-
}
|
|
698
700
|
const pathPatternChunks = pathPattern.split(path7.sep);
|
|
699
|
-
const
|
|
700
|
-
|
|
701
|
-
|
|
701
|
+
const localeSegmentIndexes = pathPatternChunks.reduce((indexes, segment, index) => {
|
|
702
|
+
if (segment.includes("[locale]")) {
|
|
703
|
+
indexes.push(index);
|
|
704
|
+
}
|
|
705
|
+
return indexes;
|
|
706
|
+
}, []);
|
|
707
|
+
const sourcePathPattern = pathPattern.replaceAll(/\[locale\]/g, sourceLocale);
|
|
702
708
|
const sourcePaths = glob2.sync(sourcePathPattern, { follow: true, withFileTypes: true }).filter((file) => file.isFile() || file.isSymbolicLink()).map((file) => file.fullpath()).map((fullpath) => path7.relative(process.cwd(), fullpath));
|
|
703
709
|
const placeholderedPaths = sourcePaths.map((sourcePath) => {
|
|
704
710
|
const sourcePathChunks = sourcePath.split(path7.sep);
|
|
705
|
-
|
|
706
|
-
const
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
711
|
+
localeSegmentIndexes.forEach((localeSegmentIndex) => {
|
|
712
|
+
const localePlaceholderIndex = pathPatternChunks[localeSegmentIndex]?.indexOf("[locale]") ?? -1;
|
|
713
|
+
if (localeSegmentIndex >= 0 && localePlaceholderIndex >= 0) {
|
|
714
|
+
const placeholderedPathChunk = sourcePathChunks[localeSegmentIndex];
|
|
715
|
+
const placeholderedSegment = placeholderedPathChunk.substring(0, localePlaceholderIndex) + "[locale]" + placeholderedPathChunk.substring(localePlaceholderIndex + sourceLocale.length);
|
|
716
|
+
sourcePathChunks[localeSegmentIndex] = placeholderedSegment;
|
|
717
|
+
}
|
|
718
|
+
});
|
|
710
719
|
const placeholderedPath = sourcePathChunks.join(path7.sep);
|
|
711
720
|
return placeholderedPath;
|
|
712
721
|
});
|
|
@@ -982,7 +991,7 @@ function createTextFileLoader(pathPattern) {
|
|
|
982
991
|
return trimmedResult;
|
|
983
992
|
},
|
|
984
993
|
async push(locale, data, _21, originalLocale) {
|
|
985
|
-
const draftPath = pathPattern.
|
|
994
|
+
const draftPath = pathPattern.replaceAll("[locale]", locale);
|
|
986
995
|
const finalPath = path8.resolve(draftPath);
|
|
987
996
|
const dirPath = path8.dirname(finalPath);
|
|
988
997
|
await fs6.mkdir(dirPath, { recursive: true });
|
|
@@ -997,7 +1006,7 @@ function createTextFileLoader(pathPattern) {
|
|
|
997
1006
|
});
|
|
998
1007
|
}
|
|
999
1008
|
async function readFileForLocale(pathPattern, locale) {
|
|
1000
|
-
const draftPath = pathPattern.
|
|
1009
|
+
const draftPath = pathPattern.replaceAll("[locale]", locale);
|
|
1001
1010
|
const finalPath = path8.resolve(draftPath);
|
|
1002
1011
|
const exists = await fs6.access(finalPath).then(() => true).catch(() => false);
|
|
1003
1012
|
if (!exists) {
|
|
@@ -3511,7 +3520,7 @@ function displaySummary(results) {
|
|
|
3511
3520
|
// package.json
|
|
3512
3521
|
var package_default = {
|
|
3513
3522
|
name: "lingo.dev",
|
|
3514
|
-
version: "0.
|
|
3523
|
+
version: "0.76.0",
|
|
3515
3524
|
description: "Lingo.dev CLI",
|
|
3516
3525
|
private: false,
|
|
3517
3526
|
publishConfig: {
|