@diplodoc/cli 4.13.4 → 4.13.5
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/assets/vendor.js +1 -1
- package/build/index.js +175 -287
- package/build/index.js.map +4 -4
- package/package.json +3 -3
- package/src/cmd/translate/handler.ts +311 -0
- package/src/cmd/translate/index.ts +14 -320
- package/src/cmd/xliff/compose.ts +71 -177
- package/src/cmd/xliff/extract.ts +97 -168
package/build/index.js
CHANGED
|
@@ -56,7 +56,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
56
56
|
mod
|
|
57
57
|
));
|
|
58
58
|
var __async = (__this, __arguments, generator) => {
|
|
59
|
-
return new Promise((
|
|
59
|
+
return new Promise((resolve19, reject) => {
|
|
60
60
|
var fulfilled = (value) => {
|
|
61
61
|
try {
|
|
62
62
|
step(generator.next(value));
|
|
@@ -71,7 +71,7 @@ var __async = (__this, __arguments, generator) => {
|
|
|
71
71
|
reject(e);
|
|
72
72
|
}
|
|
73
73
|
};
|
|
74
|
-
var step = (x) => x.done ?
|
|
74
|
+
var step = (x) => x.done ? resolve19(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
75
75
|
step((generator = generator.apply(__this, __arguments)).next());
|
|
76
76
|
});
|
|
77
77
|
};
|
|
@@ -1373,33 +1373,33 @@ var UnarchiveIncluderError = class extends Error {
|
|
|
1373
1373
|
};
|
|
1374
1374
|
function pipeline(readPath, writeBasePath) {
|
|
1375
1375
|
return new Promise((res, rej) => {
|
|
1376
|
-
const
|
|
1377
|
-
|
|
1376
|
+
const reader = (0, import_fs2.createReadStream)(readPath);
|
|
1377
|
+
reader.on("error", (err) => {
|
|
1378
1378
|
rej(err);
|
|
1379
1379
|
});
|
|
1380
|
-
const
|
|
1381
|
-
|
|
1380
|
+
const extractor = (0, import_tar_stream.extract)();
|
|
1381
|
+
extractor.on("error", (err) => {
|
|
1382
1382
|
rej(err);
|
|
1383
1383
|
});
|
|
1384
1384
|
(0, import_fs2.mkdirSync)(writeBasePath, { recursive: true });
|
|
1385
|
-
|
|
1385
|
+
extractor.on("entry", (header, stream, next) => {
|
|
1386
1386
|
const { type, name: name4 } = header;
|
|
1387
1387
|
const writePath = (0, import_path12.join)(writeBasePath, name4);
|
|
1388
1388
|
const writeDirPath = type === "directory" ? writePath : (0, import_path12.dirname)(writePath);
|
|
1389
1389
|
(0, import_fs2.mkdirSync)(writeDirPath, { recursive: true });
|
|
1390
1390
|
if (type !== "directory") {
|
|
1391
|
-
const
|
|
1392
|
-
|
|
1391
|
+
const writer = (0, import_fs2.createWriteStream)(writePath, { flags: "w" });
|
|
1392
|
+
writer.on("error", (err) => {
|
|
1393
1393
|
rej(err);
|
|
1394
1394
|
});
|
|
1395
|
-
stream.pipe(
|
|
1395
|
+
stream.pipe(writer);
|
|
1396
1396
|
}
|
|
1397
1397
|
stream.on("end", () => {
|
|
1398
1398
|
next();
|
|
1399
1399
|
});
|
|
1400
1400
|
stream.resume();
|
|
1401
1401
|
});
|
|
1402
|
-
|
|
1402
|
+
reader.pipe(extractor).on("finish", () => {
|
|
1403
1403
|
res();
|
|
1404
1404
|
});
|
|
1405
1405
|
});
|
|
@@ -3641,8 +3641,10 @@ function handler2(args) {
|
|
|
3641
3641
|
}
|
|
3642
3642
|
|
|
3643
3643
|
// src/cmd/xliff/extract.ts
|
|
3644
|
+
var import_assert = require("assert");
|
|
3645
|
+
var import_glob4 = __toESM(require("glob"));
|
|
3644
3646
|
var import_path30 = require("path");
|
|
3645
|
-
var import_markdown_translation =
|
|
3647
|
+
var import_markdown_translation = require("@diplodoc/markdown-translation");
|
|
3646
3648
|
var import_async3 = require("async");
|
|
3647
3649
|
var {
|
|
3648
3650
|
promises: { readFile: readFile3, writeFile: writeFile2, mkdir: mkdir2 }
|
|
@@ -3650,19 +3652,7 @@ var {
|
|
|
3650
3652
|
var command2 = "extract";
|
|
3651
3653
|
var description2 = "extract xliff and skeleton from yfm documentation";
|
|
3652
3654
|
var extract2 = { command: command2, description: description2, handler: handler3, builder: builder3 };
|
|
3653
|
-
var MD_GLOB2 = "**/*.md";
|
|
3654
3655
|
var MAX_CONCURRENCY = 50;
|
|
3655
|
-
var ExtractError = class extends Error {
|
|
3656
|
-
constructor(message, path) {
|
|
3657
|
-
super(message);
|
|
3658
|
-
this.path = path;
|
|
3659
|
-
}
|
|
3660
|
-
};
|
|
3661
|
-
var USAGE = `yfm xliff extract --input <folder-with-markdown> --output <folder-to-store-xlff-and-skeleton> --sll <source-language>-<source-locale> --tll <target-language>-<target-locale>
|
|
3662
|
-
|
|
3663
|
-
where <source/target-language> is the language code, as described in ISO 639-1.
|
|
3664
|
-
|
|
3665
|
-
where <source/target-locale> is the locale code in alpha-2 format, as described in ISO 3166-1`;
|
|
3666
3656
|
function builder3(argv) {
|
|
3667
3657
|
return argv.option("source-language-locale", {
|
|
3668
3658
|
alias: "sll",
|
|
@@ -3680,130 +3670,96 @@ function builder3(argv) {
|
|
|
3680
3670
|
alias: "o",
|
|
3681
3671
|
describe: "output folder to store xliff and skeleton files",
|
|
3682
3672
|
type: "string"
|
|
3683
|
-
}).
|
|
3684
|
-
["source-language-locale", "target-language-locale", "input", "output"],
|
|
3685
|
-
USAGE
|
|
3686
|
-
);
|
|
3673
|
+
}).check(argvValidator);
|
|
3687
3674
|
}
|
|
3688
3675
|
function handler3(args) {
|
|
3689
3676
|
return __async(this, null, function* () {
|
|
3677
|
+
args = Object.assign({}, args.translate || {}, args);
|
|
3678
|
+
delete args.translate;
|
|
3690
3679
|
argv_default.init(__spreadValues({}, args));
|
|
3691
|
-
const {
|
|
3692
|
-
|
|
3693
|
-
|
|
3694
|
-
|
|
3695
|
-
|
|
3696
|
-
|
|
3697
|
-
|
|
3698
|
-
|
|
3699
|
-
|
|
3700
|
-
|
|
3701
|
-
|
|
3702
|
-
|
|
3703
|
-
|
|
3704
|
-
|
|
3705
|
-
|
|
3706
|
-
|
|
3707
|
-
|
|
3708
|
-
|
|
3709
|
-
|
|
3710
|
-
|
|
3711
|
-
|
|
3712
|
-
|
|
3713
|
-
|
|
3714
|
-
|
|
3715
|
-
|
|
3716
|
-
|
|
3717
|
-
const
|
|
3718
|
-
|
|
3719
|
-
|
|
3720
|
-
|
|
3721
|
-
|
|
3722
|
-
}
|
|
3723
|
-
|
|
3724
|
-
const file = err instanceof ExtractError ? err.path : input;
|
|
3725
|
-
logger.error(file, err.message);
|
|
3726
|
-
}
|
|
3680
|
+
const {
|
|
3681
|
+
output,
|
|
3682
|
+
exclude = [],
|
|
3683
|
+
sourceLanguage,
|
|
3684
|
+
sourceLocale,
|
|
3685
|
+
targetLanguage,
|
|
3686
|
+
targetLocale
|
|
3687
|
+
} = argv_default.getConfig();
|
|
3688
|
+
let {
|
|
3689
|
+
input,
|
|
3690
|
+
include = [],
|
|
3691
|
+
sourceLanguageLocale,
|
|
3692
|
+
targetLanguageLocale
|
|
3693
|
+
} = argv_default.getConfig();
|
|
3694
|
+
(0, import_assert.ok)(input);
|
|
3695
|
+
(0, import_assert.ok)(output);
|
|
3696
|
+
(0, import_assert.ok)(
|
|
3697
|
+
sourceLanguageLocale || sourceLanguage && sourceLocale,
|
|
3698
|
+
"Source language and locale should be configured"
|
|
3699
|
+
);
|
|
3700
|
+
(0, import_assert.ok)(
|
|
3701
|
+
targetLanguageLocale || targetLanguage && targetLocale,
|
|
3702
|
+
"Source language and locale should be configured"
|
|
3703
|
+
);
|
|
3704
|
+
sourceLanguageLocale = sourceLanguageLocale || sourceLanguage + "-" + sourceLocale;
|
|
3705
|
+
targetLanguageLocale = targetLanguageLocale || targetLanguage + "-" + targetLocale;
|
|
3706
|
+
const source = parseLanguageLocale(sourceLanguageLocale);
|
|
3707
|
+
const target = parseLanguageLocale(targetLanguageLocale);
|
|
3708
|
+
if (input.endsWith(".md")) {
|
|
3709
|
+
include = [(0, import_path30.basename)(input)];
|
|
3710
|
+
input = (0, import_path30.dirname)(input);
|
|
3711
|
+
} else if (!include.length) {
|
|
3712
|
+
include.push("**/*");
|
|
3727
3713
|
}
|
|
3714
|
+
const files = [].concat(
|
|
3715
|
+
...include.map(
|
|
3716
|
+
(match) => import_glob4.default.sync(match, {
|
|
3717
|
+
cwd: (0, import_path30.join)(input, source.language),
|
|
3718
|
+
ignore: exclude
|
|
3719
|
+
})
|
|
3720
|
+
)
|
|
3721
|
+
);
|
|
3722
|
+
const found = [...new Set(files)];
|
|
3723
|
+
const configuredPipeline = pipeline2({ source, target, input, output });
|
|
3724
|
+
yield (0, import_async3.eachLimit)(found, MAX_CONCURRENCY, (0, import_async3.asyncify)(configuredPipeline));
|
|
3728
3725
|
});
|
|
3729
3726
|
}
|
|
3730
3727
|
function parseLanguageLocale(languageLocale) {
|
|
3731
3728
|
const [language, locale] = languageLocale.split("-");
|
|
3732
|
-
if ((language == null ? void 0 : language.length)
|
|
3733
|
-
|
|
3729
|
+
if (!(language == null ? void 0 : language.length) || !(locale == null ? void 0 : locale.length)) {
|
|
3730
|
+
throw new Error("invalid language-locale string");
|
|
3734
3731
|
}
|
|
3735
|
-
|
|
3732
|
+
return { language, locale };
|
|
3736
3733
|
}
|
|
3737
3734
|
function pipeline2(params) {
|
|
3738
3735
|
const { input, output, source, target } = params;
|
|
3739
|
-
|
|
3740
|
-
|
|
3741
|
-
|
|
3742
|
-
|
|
3743
|
-
|
|
3744
|
-
|
|
3745
|
-
const
|
|
3746
|
-
const
|
|
3747
|
-
|
|
3736
|
+
const inputRoot = (0, import_path30.resolve)(input, source.language);
|
|
3737
|
+
const outputRoot = (0, import_path30.resolve)(output, target.language);
|
|
3738
|
+
return (path) => __async(this, null, function* () {
|
|
3739
|
+
if (!path.endsWith(".md")) {
|
|
3740
|
+
return;
|
|
3741
|
+
}
|
|
3742
|
+
const inputPath = (0, import_path30.join)(inputRoot, path);
|
|
3743
|
+
const xliffPath = (0, import_path30.join)(outputRoot, path + ".xliff");
|
|
3744
|
+
const skeletonPath = (0, import_path30.join)(outputRoot, path + ".skl");
|
|
3745
|
+
const markdown = yield readFile3(inputPath, "utf-8");
|
|
3746
|
+
yield mkdir2((0, import_path30.dirname)(xliffPath), { recursive: true });
|
|
3747
|
+
const { xliff: xliff2, skeleton } = yield (0, import_markdown_translation.extract)({
|
|
3748
|
+
markdownPath: path,
|
|
3748
3749
|
skeletonPath,
|
|
3749
3750
|
markdown,
|
|
3750
3751
|
source,
|
|
3751
3752
|
target
|
|
3752
|
-
};
|
|
3753
|
-
const extracted = yield extractor(extractParameters);
|
|
3754
|
-
const writerParameters = __spreadProps(__spreadValues({}, extracted), {
|
|
3755
|
-
xlfPath,
|
|
3756
|
-
skeletonPath
|
|
3757
3753
|
});
|
|
3758
|
-
yield
|
|
3759
|
-
});
|
|
3760
|
-
}
|
|
3761
|
-
function reader(params) {
|
|
3762
|
-
return __async(this, null, function* () {
|
|
3763
|
-
const { path } = params;
|
|
3764
|
-
let markdown;
|
|
3765
|
-
try {
|
|
3766
|
-
logger.info(path, "reading markdown file");
|
|
3767
|
-
markdown = yield readFile3(path, { encoding: "utf-8" });
|
|
3768
|
-
logger.info(path, "finished reading markdown file");
|
|
3769
|
-
} catch (err) {
|
|
3770
|
-
if (err instanceof Error) {
|
|
3771
|
-
throw new ExtractError(err.message, path);
|
|
3772
|
-
}
|
|
3773
|
-
}
|
|
3774
|
-
return markdown;
|
|
3775
|
-
});
|
|
3776
|
-
}
|
|
3777
|
-
function extractor(params) {
|
|
3778
|
-
return __async(this, null, function* () {
|
|
3779
|
-
let extracted;
|
|
3780
|
-
logger.info(params.markdownPath, "generating skeleton and xliff from markdown");
|
|
3781
|
-
try {
|
|
3782
|
-
extracted = import_markdown_translation.default.extract(params);
|
|
3783
|
-
} catch (err) {
|
|
3784
|
-
if (err instanceof Error) {
|
|
3785
|
-
throw new ExtractError(err.message, params.markdownPath);
|
|
3786
|
-
}
|
|
3787
|
-
}
|
|
3788
|
-
logger.info(params.markdownPath, "finished generating skeleton and xliff from markdown");
|
|
3789
|
-
return extracted;
|
|
3790
|
-
});
|
|
3791
|
-
}
|
|
3792
|
-
function writer(params) {
|
|
3793
|
-
return __async(this, null, function* () {
|
|
3794
|
-
const { xlfPath, skeletonPath, xlf, skeleton } = params;
|
|
3795
|
-
logger.info(params.xlfPath, "writing xliff file");
|
|
3796
|
-
logger.info(params.skeletonPath, "writing skeleton file");
|
|
3797
|
-
yield mkdir2((0, import_path30.dirname)(xlfPath), { recursive: true });
|
|
3798
|
-
yield Promise.all([writeFile2(skeletonPath, skeleton), writeFile2(xlfPath, xlf)]);
|
|
3799
|
-
logger.info(params.xlfPath, "finished writing xliff file");
|
|
3800
|
-
logger.info(params.skeletonPath, "finished writing skeleton file");
|
|
3754
|
+
yield Promise.all([writeFile2(skeletonPath, skeleton), writeFile2(xliffPath, xliff2)]);
|
|
3801
3755
|
});
|
|
3802
3756
|
}
|
|
3803
3757
|
|
|
3804
3758
|
// src/cmd/xliff/compose.ts
|
|
3759
|
+
var import_assert2 = require("assert");
|
|
3760
|
+
var import_glob5 = __toESM(require("glob"));
|
|
3805
3761
|
var import_path31 = require("path");
|
|
3806
|
-
var import_markdown_translation2 =
|
|
3762
|
+
var import_markdown_translation2 = require("@diplodoc/markdown-translation");
|
|
3807
3763
|
var import_async4 = require("async");
|
|
3808
3764
|
var {
|
|
3809
3765
|
promises: { readFile: readFile4, writeFile: writeFile3, mkdir: mkdir3 }
|
|
@@ -3811,16 +3767,7 @@ var {
|
|
|
3811
3767
|
var command3 = "compose";
|
|
3812
3768
|
var description3 = "compose xliff and skeleton into documentation";
|
|
3813
3769
|
var compose = { command: command3, description: description3, handler: handler4, builder: builder4 };
|
|
3814
|
-
var SKL_MD_GLOB = "**/*.skl.md";
|
|
3815
|
-
var XLF_GLOB = "**/*.xliff";
|
|
3816
3770
|
var MAX_CONCURRENCY2 = 50;
|
|
3817
|
-
var ComposeError = class extends Error {
|
|
3818
|
-
constructor(message, path) {
|
|
3819
|
-
super(message);
|
|
3820
|
-
this.path = path;
|
|
3821
|
-
}
|
|
3822
|
-
};
|
|
3823
|
-
var USAGE2 = "yfm xliff compose --input <folder-with-xliff-and-skeleton> --ouput <folder-to-store-translated-markdown>";
|
|
3824
3771
|
function builder4(argv) {
|
|
3825
3772
|
return argv.option("input", {
|
|
3826
3773
|
alias: "i",
|
|
@@ -3830,130 +3777,63 @@ function builder4(argv) {
|
|
|
3830
3777
|
alias: "o",
|
|
3831
3778
|
describe: "output folder where translated markdown will be stored",
|
|
3832
3779
|
type: "string"
|
|
3833
|
-
}).
|
|
3780
|
+
}).option("target-language", {
|
|
3781
|
+
alias: "tl",
|
|
3782
|
+
describe: "target language",
|
|
3783
|
+
type: "string"
|
|
3784
|
+
}).option("use-source", {
|
|
3785
|
+
describe: "for debug",
|
|
3786
|
+
type: "boolean"
|
|
3787
|
+
}).check(argvValidator);
|
|
3834
3788
|
}
|
|
3835
3789
|
function handler4(args) {
|
|
3836
3790
|
return __async(this, null, function* () {
|
|
3791
|
+
args = Object.assign({}, args.translate || {}, args);
|
|
3792
|
+
delete args.translate;
|
|
3837
3793
|
argv_default.init(__spreadValues({}, args));
|
|
3838
|
-
const {
|
|
3839
|
-
|
|
3840
|
-
|
|
3841
|
-
|
|
3842
|
-
|
|
3843
|
-
|
|
3844
|
-
|
|
3845
|
-
|
|
3846
|
-
|
|
3847
|
-
|
|
3848
|
-
|
|
3849
|
-
(
|
|
3850
|
-
|
|
3851
|
-
|
|
3852
|
-
|
|
3853
|
-
|
|
3854
|
-
|
|
3855
|
-
|
|
3856
|
-
|
|
3857
|
-
|
|
3858
|
-
} catch (err) {
|
|
3859
|
-
if (err instanceof Error || err instanceof ComposeError) {
|
|
3860
|
-
const file = err instanceof ComposeError ? err.path : input;
|
|
3861
|
-
logger.error(file, err.message);
|
|
3862
|
-
}
|
|
3863
|
-
}
|
|
3864
|
-
const pipelineParameters = { input, output };
|
|
3794
|
+
const {
|
|
3795
|
+
input,
|
|
3796
|
+
output,
|
|
3797
|
+
exclude = [],
|
|
3798
|
+
targetLanguage,
|
|
3799
|
+
useSource = false
|
|
3800
|
+
} = argv_default.getConfig();
|
|
3801
|
+
(0, import_assert2.ok)(input);
|
|
3802
|
+
(0, import_assert2.ok)(output);
|
|
3803
|
+
(0, import_assert2.ok)(targetLanguage);
|
|
3804
|
+
const skeletons = import_glob5.default.sync("**/*.skl", {
|
|
3805
|
+
cwd: (0, import_path31.join)(input, targetLanguage),
|
|
3806
|
+
ignore: exclude
|
|
3807
|
+
});
|
|
3808
|
+
const xliffs = import_glob5.default.sync("**/*.xliff", {
|
|
3809
|
+
cwd: (0, import_path31.join)(input, targetLanguage),
|
|
3810
|
+
ignore: exclude
|
|
3811
|
+
});
|
|
3812
|
+
(0, import_assert2.ok)(xliffs.length === skeletons.length, "Inconsistent number of xliff and skeleton files.");
|
|
3813
|
+
const pipelineParameters = { input, output, targetLanguage, useSource };
|
|
3865
3814
|
const configuredPipeline = pipeline3(pipelineParameters);
|
|
3866
|
-
|
|
3867
|
-
logger.info(input, "staring translated markdown composition pipeline");
|
|
3868
|
-
yield (0, import_async4.eachLimit)(xliffPaths, MAX_CONCURRENCY2, configuredPipeline);
|
|
3869
|
-
logger.info(input, "finished translated markdown composition pipeline");
|
|
3870
|
-
} catch (err) {
|
|
3871
|
-
if (err instanceof Error || err instanceof ComposeError) {
|
|
3872
|
-
const file = err instanceof ComposeError ? err.path : input;
|
|
3873
|
-
logger.error(file, err.message);
|
|
3874
|
-
}
|
|
3875
|
-
}
|
|
3815
|
+
yield (0, import_async4.eachLimit)(skeletons, MAX_CONCURRENCY2, configuredPipeline);
|
|
3876
3816
|
});
|
|
3877
3817
|
}
|
|
3878
3818
|
function pipeline3(params) {
|
|
3879
|
-
const { input, output } = params;
|
|
3880
|
-
return (
|
|
3881
|
-
const
|
|
3882
|
-
const
|
|
3883
|
-
const
|
|
3884
|
-
|
|
3885
|
-
|
|
3886
|
-
|
|
3819
|
+
const { input, output, targetLanguage, useSource } = params;
|
|
3820
|
+
return (skeletonPath) => __async(this, null, function* () {
|
|
3821
|
+
const fileName = skeletonPath.split(".").slice(0, -1).join(".");
|
|
3822
|
+
const xliffPath = fileName + ".xliff";
|
|
3823
|
+
const [skeleton, xliff2] = yield Promise.all([
|
|
3824
|
+
readFile4((0, import_path31.join)(input, targetLanguage, skeletonPath), "utf-8"),
|
|
3825
|
+
readFile4((0, import_path31.join)(input, targetLanguage, xliffPath), "utf-8")
|
|
3826
|
+
]);
|
|
3827
|
+
const markdown = (0, import_markdown_translation2.compose)({
|
|
3828
|
+
skeleton,
|
|
3829
|
+
xliff: xliff2,
|
|
3887
3830
|
skeletonPath,
|
|
3888
|
-
xliffPath
|
|
3831
|
+
xliffPath,
|
|
3832
|
+
useSource
|
|
3889
3833
|
});
|
|
3890
|
-
const
|
|
3891
|
-
|
|
3892
|
-
|
|
3893
|
-
const writerParameters = {
|
|
3894
|
-
markdown,
|
|
3895
|
-
markdownPath
|
|
3896
|
-
};
|
|
3897
|
-
yield writer2(writerParameters);
|
|
3898
|
-
});
|
|
3899
|
-
}
|
|
3900
|
-
function reader2(params) {
|
|
3901
|
-
return __async(this, null, function* () {
|
|
3902
|
-
const { skeletonPath, xliffPath } = params;
|
|
3903
|
-
let skeleton;
|
|
3904
|
-
let xlf;
|
|
3905
|
-
try {
|
|
3906
|
-
logger.info(skeletonPath, "reading skeleton file");
|
|
3907
|
-
skeleton = yield readFile4(skeletonPath, { encoding: "utf-8" });
|
|
3908
|
-
logger.info(skeletonPath, "finished reading skeleton file");
|
|
3909
|
-
} catch (err) {
|
|
3910
|
-
if (err instanceof Error) {
|
|
3911
|
-
throw new ComposeError(err.message, skeletonPath);
|
|
3912
|
-
}
|
|
3913
|
-
}
|
|
3914
|
-
try {
|
|
3915
|
-
logger.info(xliffPath, "reading xliff file");
|
|
3916
|
-
xlf = yield readFile4(xliffPath, { encoding: "utf-8" });
|
|
3917
|
-
logger.info(xliffPath, "finished reading xliff file");
|
|
3918
|
-
} catch (err) {
|
|
3919
|
-
if (err instanceof Error) {
|
|
3920
|
-
throw new ComposeError(err.message, xliffPath);
|
|
3921
|
-
}
|
|
3922
|
-
}
|
|
3923
|
-
return { skeleton, xlf };
|
|
3924
|
-
});
|
|
3925
|
-
}
|
|
3926
|
-
function composer(params) {
|
|
3927
|
-
return __async(this, null, function* () {
|
|
3928
|
-
const { skeletonPath, xliffPath } = params;
|
|
3929
|
-
let markdown;
|
|
3930
|
-
try {
|
|
3931
|
-
logger.info(skeletonPath, "composing markdown from xliff and skeleton");
|
|
3932
|
-
logger.info(xliffPath, "composing markdown from xliff and skeleton");
|
|
3933
|
-
markdown = import_markdown_translation2.default.compose(params);
|
|
3934
|
-
logger.info(skeletonPath, "finished composing markdown from xliff and skeleton");
|
|
3935
|
-
logger.info(xliffPath, "finished composing markdown from xliff and skeleton");
|
|
3936
|
-
} catch (err) {
|
|
3937
|
-
if (err instanceof Error) {
|
|
3938
|
-
throw new ComposeError(err.message, `${xliffPath} ${skeletonPath}`);
|
|
3939
|
-
}
|
|
3940
|
-
}
|
|
3941
|
-
return { markdown };
|
|
3942
|
-
});
|
|
3943
|
-
}
|
|
3944
|
-
function writer2(params) {
|
|
3945
|
-
return __async(this, null, function* () {
|
|
3946
|
-
const { markdown, markdownPath } = params;
|
|
3947
|
-
try {
|
|
3948
|
-
logger.info(markdownPath, "writing markdown file");
|
|
3949
|
-
yield mkdir3((0, import_path31.dirname)(markdownPath), { recursive: true });
|
|
3950
|
-
yield writeFile3(markdownPath, markdown);
|
|
3951
|
-
logger.info(markdownPath, "finished writing markdown file");
|
|
3952
|
-
} catch (err) {
|
|
3953
|
-
if (err instanceof Error) {
|
|
3954
|
-
throw new ComposeError(err.message, markdownPath);
|
|
3955
|
-
}
|
|
3956
|
-
}
|
|
3834
|
+
const markdownPath = (0, import_path31.join)(output, targetLanguage, fileName);
|
|
3835
|
+
yield mkdir3((0, import_path31.dirname)(markdownPath), { recursive: true });
|
|
3836
|
+
yield writeFile3(markdownPath, markdown);
|
|
3957
3837
|
});
|
|
3958
3838
|
}
|
|
3959
3839
|
|
|
@@ -3974,16 +3854,10 @@ function builder5(argv) {
|
|
|
3974
3854
|
);
|
|
3975
3855
|
}
|
|
3976
3856
|
|
|
3977
|
-
// src/cmd/translate/
|
|
3978
|
-
var
|
|
3979
|
-
var import_assert = require("assert");
|
|
3980
|
-
var import_async5 = require("async");
|
|
3857
|
+
// src/cmd/translate/handler.ts
|
|
3858
|
+
var import_assert3 = require("assert");
|
|
3981
3859
|
var import_path33 = require("path");
|
|
3982
|
-
var
|
|
3983
|
-
var import_session = require("@yandex-cloud/nodejs-sdk/dist/session");
|
|
3984
|
-
var import_service_clients = require("@yandex-cloud/nodejs-sdk/dist/generated/yandex/cloud/service_clients");
|
|
3985
|
-
var import_translation_service = require("@yandex-cloud/nodejs-sdk/dist/generated/yandex/cloud/ai/translate/v2/translation_service");
|
|
3986
|
-
var import_markdown_translation3 = require("@diplodoc/markdown-translation");
|
|
3860
|
+
var import_glob6 = __toESM(require("glob"));
|
|
3987
3861
|
|
|
3988
3862
|
// src/packages/credentials/yandex-oauth.ts
|
|
3989
3863
|
var import_promises3 = require("fs/promises");
|
|
@@ -4016,32 +3890,16 @@ function getYandexOAuthTokenFromHomeDir() {
|
|
|
4016
3890
|
});
|
|
4017
3891
|
}
|
|
4018
3892
|
|
|
4019
|
-
// src/cmd/translate/
|
|
4020
|
-
var
|
|
4021
|
-
var
|
|
4022
|
-
var
|
|
4023
|
-
|
|
4024
|
-
|
|
4025
|
-
|
|
4026
|
-
builder: builder6
|
|
4027
|
-
};
|
|
3893
|
+
// src/cmd/translate/handler.ts
|
|
3894
|
+
var import_async5 = require("async");
|
|
3895
|
+
var import_session = require("@yandex-cloud/nodejs-sdk/dist/session");
|
|
3896
|
+
var import_service_clients = require("@yandex-cloud/nodejs-sdk/dist/generated/yandex/cloud/service_clients");
|
|
3897
|
+
var import_translation_service = require("@yandex-cloud/nodejs-sdk/dist/generated/yandex/cloud/ai/translate/v2/translation_service");
|
|
3898
|
+
var import_promises4 = require("fs/promises");
|
|
3899
|
+
var import_markdown_translation3 = require("@diplodoc/markdown-translation");
|
|
4028
3900
|
var REQUESTS_LIMIT = 20;
|
|
4029
3901
|
var BYTES_LIMIT = 1e4;
|
|
4030
3902
|
var RETRY_LIMIT = 3;
|
|
4031
|
-
function builder6(argv) {
|
|
4032
|
-
return argv.option("folder-id", {
|
|
4033
|
-
describe: "folder id",
|
|
4034
|
-
type: "string"
|
|
4035
|
-
}).option("source-language", {
|
|
4036
|
-
alias: "sl",
|
|
4037
|
-
describe: "source language code",
|
|
4038
|
-
type: "string"
|
|
4039
|
-
}).option("target-language", {
|
|
4040
|
-
alias: "tl",
|
|
4041
|
-
describe: "target language code",
|
|
4042
|
-
type: "string"
|
|
4043
|
-
}).check(argvValidator);
|
|
4044
|
-
}
|
|
4045
3903
|
var TranslatorError = class extends Error {
|
|
4046
3904
|
constructor(message, path) {
|
|
4047
3905
|
super(message);
|
|
@@ -4064,9 +3922,9 @@ function handler5(args) {
|
|
|
4064
3922
|
`translating documentation from ${sourceLanguage} to ${targetLanguage} language`
|
|
4065
3923
|
);
|
|
4066
3924
|
output = output || input;
|
|
4067
|
-
(0,
|
|
4068
|
-
(0,
|
|
4069
|
-
(0,
|
|
3925
|
+
(0, import_assert3.ok)(input, "Required param input is not configured");
|
|
3926
|
+
(0, import_assert3.ok)(sourceLanguage, "Required param sourceLanguage is not configured");
|
|
3927
|
+
(0, import_assert3.ok)(targetLanguage, "Required param targetLanguage is not configured");
|
|
4070
3928
|
try {
|
|
4071
3929
|
if (input.endsWith(".md")) {
|
|
4072
3930
|
include = [(0, import_path33.basename)(input)];
|
|
@@ -4076,7 +3934,7 @@ function handler5(args) {
|
|
|
4076
3934
|
}
|
|
4077
3935
|
const files = [].concat(
|
|
4078
3936
|
...include.map(
|
|
4079
|
-
(match) =>
|
|
3937
|
+
(match) => import_glob6.default.sync(match, {
|
|
4080
3938
|
cwd: (0, import_path33.join)(input, sourceLanguage),
|
|
4081
3939
|
ignore: exclude
|
|
4082
3940
|
})
|
|
@@ -4245,13 +4103,43 @@ function backoff(action) {
|
|
|
4245
4103
|
}
|
|
4246
4104
|
var Defer = class {
|
|
4247
4105
|
constructor() {
|
|
4248
|
-
this.promise = new Promise((
|
|
4249
|
-
this.resolve =
|
|
4106
|
+
this.promise = new Promise((resolve19, reject) => {
|
|
4107
|
+
this.resolve = resolve19;
|
|
4250
4108
|
this.reject = reject;
|
|
4251
4109
|
});
|
|
4252
4110
|
}
|
|
4253
4111
|
};
|
|
4254
4112
|
|
|
4113
|
+
// src/cmd/translate/index.ts
|
|
4114
|
+
var command5 = "translate";
|
|
4115
|
+
var description5 = "translate documentation with Yandex.Cloud Translator API";
|
|
4116
|
+
var translate = {
|
|
4117
|
+
command: command5,
|
|
4118
|
+
description: description5,
|
|
4119
|
+
handler: handler5,
|
|
4120
|
+
builder: builder6
|
|
4121
|
+
};
|
|
4122
|
+
function builder6(argv) {
|
|
4123
|
+
return argv.command(extract2).command(compose).option("folder-id", {
|
|
4124
|
+
describe: "folder id",
|
|
4125
|
+
type: "string"
|
|
4126
|
+
}).option("source-language", {
|
|
4127
|
+
alias: "sl",
|
|
4128
|
+
describe: "source language code",
|
|
4129
|
+
type: "string"
|
|
4130
|
+
}).option("target-language", {
|
|
4131
|
+
alias: "tl",
|
|
4132
|
+
describe: "target language code",
|
|
4133
|
+
type: "string"
|
|
4134
|
+
}).option("include", {
|
|
4135
|
+
describe: "relative to input globs to include in processing",
|
|
4136
|
+
type: "string"
|
|
4137
|
+
}).option("exclude", {
|
|
4138
|
+
describe: "relative to input globs to exclude from processing",
|
|
4139
|
+
type: "string"
|
|
4140
|
+
}).check(argvValidator);
|
|
4141
|
+
}
|
|
4142
|
+
|
|
4255
4143
|
// src/index.ts
|
|
4256
4144
|
console.time(MAIN_TIMER_ID);
|
|
4257
4145
|
import_yargs.default.command(build).command(publish).command(xliff).command(translate).option("config", {
|
|
@@ -4268,7 +4156,7 @@ import_yargs.default.command(build).command(publish).command(xliff).command(tran
|
|
|
4268
4156
|
default: false,
|
|
4269
4157
|
describe: "Run in quiet mode. Don't write logs to stdout",
|
|
4270
4158
|
type: "boolean"
|
|
4271
|
-
}).group(["config", "strict", "quiet", "help", "version"], "Common options:").version(true ? "4.13.
|
|
4159
|
+
}).group(["config", "strict", "quiet", "help", "version"], "Common options:").version(true ? "4.13.5" : "").help().parse((0, import_helpers.hideBin)(process.argv), {}, (err, { strict }, output) => {
|
|
4272
4160
|
console.timeEnd(MAIN_TIMER_ID);
|
|
4273
4161
|
if (err) {
|
|
4274
4162
|
console.error(err);
|