Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add more options to tolgeerc and test them #149

Merged
merged 9 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@
"items": {
"type": "string"
}
},
"removeOtherKeys": {
"description": "Remove keys which are not present in the import.",
"type": "boolean"
}
}
},
Expand Down Expand Up @@ -136,6 +140,78 @@
"type": ["string", "null"]
}
}
},
"sync": {
"type": "object",
"properties": {
"backup": {
"description": "Store translation files backup (only translation files, not states, comments, tags, etc.). If something goes wrong, the backup can be used to restore the project to its previous state.",
"type": "string"
},
"continueOnWarning": {
"description": "Continue the sync regardless of whether warnings are detected during string extraction. By default, as warnings may indicate an invalid extraction, the CLI will abort the sync.",
"type": "boolean"
},
"removeUnused": {
"description": "Delete unused keys from the Tolgee project",
"type": "boolean"
}
}
},
"tag": {
"type": "object",
"properties": {
"filterExtracted": {
"description": "Extract keys from code and filter by it.",
"type": "boolean"
},
"filterNotExtracted": {
"description": "Extract keys from code and filter them out.",
"type": "boolean"
},
"filterTag": {
"description": "Filter only keys with tag. Use * as a wildcard.",
"type": "array",
"items": {
"type": "string"
}
},
"filterNoTag": {
"description": "Filter only keys without tag. Use * as a wildcard.",
"type": "array",
"items": {
"type": "string"
}
},
"tag": {
"description": "Add tag to filtered keys.",
"type": "array",
"items": {
"type": "string"
}
},
"tagOther": {
"description": "Tag keys which are not filtered.",
"type": "array",
"items": {
"type": "string"
}
},
"untag": {
"description": "Remove tag from filtered keys. Use * as a wildcard.",
"type": "array",
"items": {
"type": "string"
}
},
"untagOther": {
"description": "Remove tag from keys which are not filtered. Use * as a wildcard.",
"type": "array",
"items": {
"type": "string"
}
}
}
}
},
"$defs": {
Expand Down
2 changes: 1 addition & 1 deletion src/commands/push.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,6 @@ export default (config: Schema) =>
new Option(
'--remove-other-keys',
'Remove keys which are not present in the import.'
).default(false)
).default(config.push?.removeOtherKeys)
)
.action(pushHandler(config));
36 changes: 22 additions & 14 deletions src/commands/sync/sync.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { BaseOptions } from '../../options.js';
import { Command } from 'commander';
import { Command, Option } from 'commander';
import ansi from 'ansi-colors';

import {
Expand All @@ -21,7 +21,7 @@ import {
} from '../../client/TolgeeClient.js';

type Options = BaseOptions & {
backup?: string;
backup?: string | false;
removeUnused?: boolean;
continueOnWarning?: boolean;
yes?: boolean;
Expand Down Expand Up @@ -211,21 +211,29 @@ export default (config: Schema) =>
.description(
'Synchronizes the keys in your code project and in the Tolgee project, by creating missing keys and optionally deleting unused ones. For a dry-run, use `tolgee compare`.'
)
.option(
'-B, --backup <path>',
'Store translation files backup (only translation files, not states, comments, tags, etc.). If something goes wrong, the backup can be used to restore the project to its previous state.'
.addOption(
new Option(
'-B, --backup <path>',
'Store translation files backup (only translation files, not states, comments, tags, etc.). If something goes wrong, the backup can be used to restore the project to its previous state.'
).default(config.sync?.backup ?? false)
)
.option(
'--continue-on-warning',
'Set this flag to continue the sync if warnings are detected during string extraction. By default, as warnings may indicate an invalid extraction, the CLI will abort the sync.'
.addOption(
new Option(
'--continue-on-warning',
'Set this flag to continue the sync if warnings are detected during string extraction. By default, as warnings may indicate an invalid extraction, the CLI will abort the sync.'
).default(config.sync?.continueOnWarning ?? false)
)
.option(
'-Y, --yes',
'Skip prompts and automatically say yes to them. You will not be asked for confirmation before creating/deleting keys.'
.addOption(
new Option(
'-Y, --yes',
'Skip prompts and automatically say yes to them. You will not be asked for confirmation before creating/deleting keys.'
).default(false)
)
.option(
'--remove-unused',
'Also delete unused keys from the Tolgee project.'
.addOption(
new Option(
'--remove-unused',
'Delete unused keys from the Tolgee project.'
).default(config.sync?.removeUnused ?? false)
)
.option(
'--tag-new-keys <tags...>',
Expand Down
21 changes: 14 additions & 7 deletions src/commands/tag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,40 +71,47 @@ export default (config: Schema) =>
new Option(
'--filter-extracted',
'Extract keys from code and filter by it.'
)
).default(config.tag?.filterExtracted)
)
.addOption(
new Option(
'--filter-not-extracted',
'Extract keys from code and filter them out.'
)
).default(config.tag?.filterNotExtracted)
)
.addOption(
new Option(
'--filter-tag <tags...>',
'Filter only keys with tag. Use * as a wildcard.'
)
).default(config.tag?.filterTag)
)
.addOption(
new Option(
'--filter-no-tag <tags...>',
'Filter only keys without tag. Use * as a wildcard.'
).default(config.tag?.filterNoTag)
)
.addOption(
new Option('--tag <tags...>', 'Add tag to filtered keys.').default(
config.tag?.tag
)
)
.addOption(new Option('--tag <tags...>', 'Add tag to filtered keys.'))
.addOption(
new Option('--tag-other <tags...>', 'Tag keys which are not filtered.')
new Option(
'--tag-other <tags...>',
'Tag keys which are not filtered.'
).default(config.tag?.tagOther)
)
.addOption(
new Option(
'--untag <tags...>',
'Remove tag from filtered keys. Use * as a wildcard.'
)
).default(config.tag?.untag)
)
.addOption(
new Option(
'--untag-other <tags...>',
'Remove tag from keys which are not filtered. Use * as a wildcard.'
)
).default(config.tag?.untagOther)
)
.action(tagHandler(config));
52 changes: 52 additions & 0 deletions src/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ export interface Schema {
* Specify tags that will be added to newly created keys.
*/
tagNewKeys?: string[];
/**
* Remove keys which are not present in the import.
*/
removeOtherKeys?: boolean;
};
pull?: {
/**
Expand Down Expand Up @@ -162,6 +166,54 @@ export interface Schema {
*/
delimiter?: string | null;
};
sync?: {
/**
* Store translation files backup (only translation files, not states, comments, tags, etc.). If something goes wrong, the backup can be used to restore the project to its previous state.
*/
backup?: string;
/**
* Continue the sync regardless of whether warnings are detected during string extraction. By default, as warnings may indicate an invalid extraction, the CLI will abort the sync.
*/
continueOnWarning?: boolean;
/**
* Delete unused keys from the Tolgee project
*/
removeUnused?: boolean;
};
tag?: {
/**
* Extract keys from code and filter by it.
*/
filterExtracted?: boolean;
/**
* Extract keys from code and filter them out.
*/
filterNotExtracted?: boolean;
/**
* Filter only keys with tag. Use * as a wildcard.
*/
filterTag?: string[];
/**
* Filter only keys without tag. Use * as a wildcard.
*/
filterNoTag?: string[];
/**
* Add tag to filtered keys.
*/
tag?: string[];
/**
* Tag keys which are not filtered.
*/
tagOther?: string[];
/**
* Remove tag from filtered keys. Use * as a wildcard.
*/
untag?: string[];
/**
* Remove tag from keys which are not filtered. Use * as a wildcard.
*/
untagOther?: string[];
};
}
export interface FileMatch {
path: Path;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "../../../../schema.json",
"$schema": "../../../schema.json",
"pull": {
"delimiter": "."
},
Expand Down
18 changes: 0 additions & 18 deletions test/__fixtures__/nestedKeysProject/tolgee.config.flat.json

This file was deleted.

18 changes: 0 additions & 18 deletions test/__fixtures__/nestedKeysProject/tolgee.config.nested.json

This file was deleted.

4 changes: 0 additions & 4 deletions test/__fixtures__/parserDetection/config.mixed.json

This file was deleted.

5 changes: 0 additions & 5 deletions test/__fixtures__/parserDetection/config.parser.json

This file was deleted.

4 changes: 0 additions & 4 deletions test/__fixtures__/parserDetection/config.react.json

This file was deleted.

4 changes: 0 additions & 4 deletions test/__fixtures__/parserDetection/config.svelte.json

This file was deleted.

4 changes: 0 additions & 4 deletions test/__fixtures__/parserDetection/config.unknown.json

This file was deleted.

4 changes: 0 additions & 4 deletions test/__fixtures__/parserDetection/config.vue.json

This file was deleted.

6 changes: 0 additions & 6 deletions test/__fixtures__/parserOptions/config.react.default.json

This file was deleted.

4 changes: 0 additions & 4 deletions test/__fixtures__/parserOptions/config.react.json

This file was deleted.

5 changes: 0 additions & 5 deletions test/__fixtures__/parserOptions/config.react.noStrict.json

This file was deleted.

6 changes: 0 additions & 6 deletions test/__fixtures__/parserOptions/config.svelte.default.json

This file was deleted.

4 changes: 0 additions & 4 deletions test/__fixtures__/parserOptions/config.svelte.json

This file was deleted.

5 changes: 0 additions & 5 deletions test/__fixtures__/parserOptions/config.svelte.noStrict.json

This file was deleted.

6 changes: 0 additions & 6 deletions test/__fixtures__/parserOptions/config.vue.default.json

This file was deleted.

Loading
Loading