Skip to content

Commit 6d6eded

Browse files
authored
feat(cli): add i18n command --file option (#602)
Further filter files targeted by buckets defined in config.
1 parent 92c52d2 commit 6d6eded

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

.changeset/dull-kiwis-teach.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"lingo.dev": patch
3+
---
4+
5+
add i18n command --file option

packages/cli/src/cli/cmd/i18n.ts

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,18 @@ export default new Command()
2424
.helpOption("-h, --help", "Show help")
2525
.option("--locale <locale>", "Locale to process", (val: string, prev: string[]) => (prev ? [...prev, val] : [val]))
2626
.option("--bucket <bucket>", "Bucket to process", (val: string, prev: string[]) => (prev ? [...prev, val] : [val]))
27-
.option("--key <key>", "Key to process. Process only a specific translation key, useful for debugging or updating a single entry")
28-
.option("--frozen", `Run in read-only mode - fails if any translations need updating, useful for CI/CD pipelines to detect missing translations`)
27+
.option(
28+
"--key <key>",
29+
"Key to process. Process only a specific translation key, useful for debugging or updating a single entry",
30+
)
31+
.option(
32+
"--file [files...]",
33+
"File to process. Process only a specific path, may contain asterisk * to match multiple files. Useful if you have a lot of files and want to focus on a specific one. Specify more files separated by commas or spaces.",
34+
)
35+
.option(
36+
"--frozen",
37+
`Run in read-only mode - fails if any translations need updating, useful for CI/CD pipelines to detect missing translations`,
38+
)
2939
.option("--force", "Ignore lockfile and process all keys, useful for full re-translation")
3040
.option("--verbose", "Show detailed output including intermediate processing data and API communication details")
3141
.option("--interactive", "Enable interactive mode for reviewing and editing translations before they are applied")
@@ -70,6 +80,29 @@ export default new Command()
7080
}
7181
ora.succeed("Buckets retrieved");
7282

83+
if (flags.file?.length) {
84+
buckets = buckets
85+
.map((bucket: any) => {
86+
const config = bucket.config.filter((config: any) =>
87+
flags.file!.find((file) => config.pathPattern?.match(file)),
88+
);
89+
return { ...bucket, config };
90+
})
91+
.filter((bucket: any) => bucket.config.length > 0);
92+
if (buckets.length === 0) {
93+
ora.fail("No buckets found. All buckets were filtered out by --file option.");
94+
process.exit(1);
95+
} else {
96+
ora.info(`\x1b[36mProcessing only filtered buckets:\x1b[0m`);
97+
buckets.map((bucket: any) => {
98+
ora.info(` ${bucket.type}:`);
99+
bucket.config.forEach((config: any) => {
100+
ora.info(` - ${config.pathPattern}`);
101+
});
102+
});
103+
}
104+
}
105+
73106
const targetLocales = flags.locale?.length ? flags.locale : i18nConfig!.locale.targets;
74107
const lockfileHelper = createLockfileHelper();
75108

@@ -451,6 +484,7 @@ function parseFlags(options: any) {
451484
verbose: Z.boolean().optional(),
452485
strict: Z.boolean().optional(),
453486
key: Z.string().optional(),
487+
file: Z.array(Z.string()).optional(),
454488
interactive: Z.boolean().default(false),
455489
debug: Z.boolean().default(false),
456490
}).parse(options);

0 commit comments

Comments
 (0)