Skip to content

Commit

Permalink
feat: add --tag-new-keys property to sync command (#142)
Browse files Browse the repository at this point in the history
  • Loading branch information
stepan662 authored Jan 6, 2025
1 parent 5d9eee0 commit bef01d2
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/commands/sync/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type Options = BaseOptions & {
removeUnused?: boolean;
continueOnWarning?: boolean;
yes?: boolean;
tagNewKeys?: string[];
};

async function backup(client: TolgeeClient, dest: string) {
Expand Down Expand Up @@ -136,6 +137,7 @@ const syncHandler = (config: Schema) =>
translations: key.defaultValue
? { [baseLanguage.tag]: key.defaultValue }
: {},
tags: opts.tagNewKeys,
}));

const loadable = await loading(
Expand Down Expand Up @@ -225,4 +227,8 @@ export default (config: Schema) =>
'--remove-unused',
'Also delete unused keys from the Tolgee project.'
)
.option(
'--tag-new-keys <tags...>',
'Specify tags that will be added to newly created keys.'
)
.action(syncHandler(config));
44 changes: 44 additions & 0 deletions test/e2e/sync.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,50 @@ describe('Project 2', () => {
});
}, 30e3);

it('tags new keys', async () => {
const out = await run(
[
'sync',
'--yes',
'--api-key',
pak,
'--tag-new-keys',
'new',
'keys',
'-pt',
CODE_PROJECT_2_ADDED,
],
undefined,
20e3
);

expect(out.code).toBe(0);
expect(out.stdout).toContain('+ 2 strings');

const keys = await client.GET('/v2/projects/{projectId}/translations', {
params: {
path: { projectId: client.getProjectId() },
query: {
filterTag: ['new', 'keys'],
},
},
});

expect(keys.data?._embedded?.keys).toHaveLength(2);

const stored = tolgeeDataToDict(keys!.data);
expect(stored).toEqual({
'mouse-name': {
__ns: null,
en: 'Mouse',
},
'mouse-sound': {
__ns: null,
en: 'Squeek',
},
});
}, 30e3);

it('deletes keys that no longer exist', async () => {
const pakWithDelete = await createPak(client, [
...DEFAULT_SCOPES,
Expand Down

0 comments on commit bef01d2

Please sign in to comment.