Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
3y3 committed Mar 29, 2024
1 parent f8bc3ef commit 6c82287
Show file tree
Hide file tree
Showing 22 changed files with 1,289 additions and 295 deletions.
22 changes: 17 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
"async": "^3.2.4",
"axios": "^1.6.7",
"chalk": "^4.1.2",
"commander": "^12.0.0",
"esbuild": "^0.20.0",
"glob": "^8.0.3",
"html-escaper": "^3.0.3",
Expand All @@ -82,6 +83,7 @@
"node-html-parser": "^6.1.5",
"simple-git": "3.22.0",
"slugify": "^1.6.5",
"tapable": "^2.2.1",
"tar-stream": "^3.1.4",
"typescript": "^5.3.3",
"vite-tsconfig-paths": "^4.2.3",
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/build/features/publishing/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const storageSecretKey = option({
});

const storageRegion = option({
flags: '--storage-secret-key <value>',
flags: '--storage-region <value>',
desc: 'Region of S3 storage.',
defaultInfo: 'eu-central-1',
deprecated: 'Use separated publish command instead.',
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export class Build

protected options = [
options.input(),
options.output,
options.output(),
options.outputFormat,
options.varsPreset,
options.vars,
Expand Down
19 changes: 6 additions & 13 deletions src/cmd/translation/__tests__/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,13 @@ export function testConfig<Config = TranslateConfig>(defaultArgs: string) {
};
});

try {
if (result instanceof Error || typeof result === 'string') {
const message = result.message || result;
await expect(async () => runTranslate(defaultArgs + ' ' + args)).rejects.toThrow(message);

Check failure on line 67 in src/cmd/translation/__tests__/index.ts

View workflow job for this annotation

GitHub Actions / Verify Files

Replace `message` with `⏎····················message,⏎················`
} else {
const instance = await runTranslate(defaultArgs + ' ' + args);
expect(instance.provider?.translate).toBeCalledWith(
expect.objectContaining(result),
);
} catch (error: any) {
const message = error.message || error;
if (result instanceof Error) {
expect(message).toEqual(result.message);
} else if (typeof result === 'string') {
expect(message).toEqual(result);
} else {
throw error;
}

expect(instance.provider?.translate).toBeCalledWith(expect.anything(), expect.objectContaining(result));

Check failure on line 71 in src/cmd/translation/__tests__/index.ts

View workflow job for this annotation

GitHub Actions / Verify Files

Replace `expect.anything(),·expect.objectContaining(result)` with `⏎····················expect.anything(),⏎····················expect.objectContaining(result),⏎················`
}
});
}
Expand Down
64 changes: 54 additions & 10 deletions src/cmd/translation/config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {green} from 'chalk';
import {option} from '~/config';
import {cyan, green, underline} from 'chalk';
import {option, toArray} from '~/config';
import {options as globalOptions} from '~/program';
import {withListResolver} from './utils';

export const NAME = 'translate';

Expand All @@ -16,27 +17,70 @@ const provider = option({
desc: 'Configure translation service provider.',
});

const sourceLanguage = option({
flags: '-sl, --source-language <value>',
const source = option({
flags: '-sl, --source <value>',
desc: `
The text language to translate from.
Specified in ISO 639-1 format (for example, ru).
Specified in ISO 639-1 format (for example, ru or ru-RU).
`,
});

const targetLanguage = option({
flags: '-tl, --target-language <value>',
const target = option({
flags: '-tl, --target <value>',
desc: `
The target language to translate the text.
Specified in ISO 639-1 format (for example, en).
Specified in ISO 639-1 format (for example, en or en-US).
`,
parser: toArray,
});

const include = option({
flags: '--include <value>',
desc: `
Relative to input filtering rule for files need to be translated.
Can be direct file path, glob filter, file ${underline('filter list')}.
Usage of include flag will reset default include rules.
If you need to apply also default rules use special ${cyan('--include ...')}
Read more about ${underline('filter list')} format in documentation ${cyan('docs')}.
Example:
{{PROGRAM}} --include some/direct/path.md
{{PROGRAM}} --include subpath/glob/**/*.md
{{PROGRAM}} --include filter.list
{{PROGRAM}} --include filter.list --include ...
`,
parser: withListResolver(toArray),
});

const exclude = option({
flags: '--exclude <value>',
desc: `
Relative to input filtering rule for files need to be translated.
Can be direct file path, glob filter, file ${underline('filter list')}.
Read more about ${underline('filter list')} format in documentation ${cyan('docs')}.
Example:
{{PROGRAM}} --exclude subpath/glob/**/*.md
`,
parser: withListResolver(toArray),
});

const dryRun = option({
flags: '--dry-run',
desc: 'Do not execute target translation provider, but only calculate required quota.',
});

export const options = {
input: globalOptions.input,
output: globalOptions.output,
config: globalOptions.config,
provider,
sourceLanguage,
targetLanguage,
source,
target,
include,
exclude,
dryRun,
};
Empty file added src/cmd/translation/handler.ts
Empty file.
Loading

0 comments on commit 6c82287

Please sign in to comment.