@diplodoc/cli 4.1.0 → 4.2.1
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/build/app.client.css +2678 -41
- package/build/app.client.js +1 -1
- package/build/index.js +376 -267
- package/build/index.js.map +3 -3
- package/build/linter.js +54 -46
- package/build/linter.js.map +2 -2
- package/package.json +12 -11
- package/src/cmd/build/index.ts +29 -15
- package/src/cmd/publish/index.ts +2 -7
- package/src/cmd/publish/upload.ts +24 -18
- package/src/cmd/translate/index.ts +55 -41
- package/src/cmd/xliff/compose.ts +17 -8
- package/src/cmd/xliff/extract.ts +20 -11
- package/src/cmd/xliff/index.ts +4 -1
- package/src/constants.ts +4 -4
- package/src/index.ts +3 -3
- package/src/models.ts +13 -8
- package/src/resolvers/lintPage.ts +2 -8
- package/src/resolvers/md2html.ts +26 -18
- package/src/resolvers/md2md.ts +15 -15
- package/src/services/authors.ts +4 -2
- package/src/services/contributors.ts +26 -12
- package/src/services/includers/batteries/common.ts +14 -2
- package/src/services/includers/batteries/generic.ts +29 -11
- package/src/services/includers/batteries/sourcedocs.ts +4 -1
- package/src/services/includers/batteries/unarchive.ts +11 -7
- package/src/services/includers/index.ts +7 -5
- package/src/services/leading.ts +23 -26
- package/src/services/metadata.ts +37 -12
- package/src/services/plugins.ts +2 -2
- package/src/services/preset.ts +2 -2
- package/src/services/tocs.ts +31 -26
- package/src/services/utils.ts +13 -3
- package/src/steps/processAssets.ts +2 -8
- package/src/steps/processExcludedFiles.ts +12 -21
- package/src/steps/processLinter.ts +11 -10
- package/src/steps/processLogs.ts +1 -6
- package/src/steps/processMapFile.ts +8 -11
- package/src/steps/processPages.ts +102 -72
- package/src/steps/processServiceFiles.ts +4 -2
- package/src/steps/publishFilesToS3.ts +17 -13
- package/src/utils/file.ts +5 -1
- package/src/utils/glob.ts +1 -3
- package/src/utils/markup.ts +30 -15
- package/src/utils/singlePage.ts +11 -10
- package/src/utils/toc.ts +21 -8
- package/src/utils/worker.ts +1 -1
- package/src/validator.ts +25 -17
- package/src/vcs-connector/client/github.ts +17 -9
- package/src/vcs-connector/connector-validator.ts +12 -6
- package/src/vcs-connector/github.ts +38 -11
- package/src/vcs-connector/index.ts +2 -2
- package/src/workers/linter/index.ts +1 -5
- package/CHANGELOG.md +0 -793
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"author": "Yandex Data UI Team <data-ui@yandex-team.ru>",
|
|
4
4
|
"description": "Make documentation using yfm-docs in Markdown and HTML formats",
|
|
5
5
|
"license": "MIT",
|
|
6
|
-
"version": "4.1
|
|
6
|
+
"version": "4.2.1",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
9
9
|
"url": "git@github.com:diplodoc-platform/cli.git"
|
|
@@ -21,20 +21,21 @@
|
|
|
21
21
|
"start": "node build/index.js",
|
|
22
22
|
"lint": "eslint \"src/**/*.{js,jsx,ts,tsx}\"",
|
|
23
23
|
"lint:fix": "npm run lint -- --fix",
|
|
24
|
-
"prepublishOnly": "npm run lint && npm run build"
|
|
24
|
+
"prepublishOnly": "npm run lint && npm run build",
|
|
25
|
+
"git:head": "git checkout master && git pull"
|
|
25
26
|
},
|
|
26
27
|
"engines": {
|
|
27
|
-
"node": "
|
|
28
|
+
"node": "18.*",
|
|
29
|
+
"npm:": "9.*"
|
|
28
30
|
},
|
|
29
31
|
"dependencies": {
|
|
30
32
|
"@apidevtools/swagger-parser": "^10.1.0",
|
|
31
33
|
"@aws-sdk/client-s3": "^3.369.0",
|
|
32
|
-
"@diplodoc/client": "^
|
|
33
|
-
"@diplodoc/markdown-translation": "^1.0.0-beta.
|
|
34
|
+
"@diplodoc/client": "^1.0.2",
|
|
35
|
+
"@diplodoc/markdown-translation": "^1.0.0-beta.4",
|
|
34
36
|
"@diplodoc/mermaid-extension": "^1.1.1",
|
|
35
37
|
"@diplodoc/openapi-extension": "^1.3.3",
|
|
36
38
|
"@diplodoc/transform": "^4.0.0",
|
|
37
|
-
"@doc-tools/yfm2xliff": "0.0.5",
|
|
38
39
|
"@octokit/core": "4.2.4",
|
|
39
40
|
"@types/glob": "^8.0.0",
|
|
40
41
|
"@types/json-stringify-safe": "^5.0.0",
|
|
@@ -65,6 +66,9 @@
|
|
|
65
66
|
"yargs": "17.7.2"
|
|
66
67
|
},
|
|
67
68
|
"devDependencies": {
|
|
69
|
+
"@diplodoc/eslint-config": "^1.0.14",
|
|
70
|
+
"@diplodoc/prettier-config": "^1.0.0",
|
|
71
|
+
"@diplodoc/tsconfig": "^1.0.2",
|
|
68
72
|
"@types/async": "^3.2.15",
|
|
69
73
|
"@types/chalk": "2.2.0",
|
|
70
74
|
"@types/html-escaper": "^3.0.0",
|
|
@@ -75,15 +79,12 @@
|
|
|
75
79
|
"@types/shelljs": "0.8.12",
|
|
76
80
|
"@types/tar-stream": "^2.2.2",
|
|
77
81
|
"@types/yargs": "17.0.24",
|
|
78
|
-
"@typescript-eslint/eslint-plugin": "2.34.0",
|
|
79
|
-
"@typescript-eslint/parser": "2.34.0",
|
|
80
|
-
"babel-eslint": "10.1.0",
|
|
81
82
|
"esbuild": "^0.17.17",
|
|
82
|
-
"eslint": "
|
|
83
|
-
"eslint-plugin-security": "1.7.1",
|
|
83
|
+
"eslint": "^8.0.0",
|
|
84
84
|
"husky": "8.0.3",
|
|
85
85
|
"lint-staged": "13.2.2",
|
|
86
86
|
"lodash": "4.17.21",
|
|
87
|
+
"prettier": "^3.0.3",
|
|
87
88
|
"ts-jest": "29.1.0",
|
|
88
89
|
"ts-node": "^10.9.1",
|
|
89
90
|
"typescript": "4.9.5"
|
package/src/cmd/build/index.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {Arguments, Argv} from 'yargs';
|
|
2
2
|
import {
|
|
3
|
-
BUNDLE_FOLDER,
|
|
3
|
+
BUNDLE_FOLDER,
|
|
4
|
+
LINT_CONFIG_FILENAME,
|
|
4
5
|
REDIRECTS_FILENAME,
|
|
5
6
|
Stage,
|
|
6
7
|
TMP_INPUT_FOLDER,
|
|
@@ -15,7 +16,8 @@ import {
|
|
|
15
16
|
initLinterWorkers,
|
|
16
17
|
processAssets,
|
|
17
18
|
processExcludedFiles,
|
|
18
|
-
processLinter,
|
|
19
|
+
processLinter,
|
|
20
|
+
processLogs,
|
|
19
21
|
processPages,
|
|
20
22
|
processServiceFiles,
|
|
21
23
|
} from '../../steps';
|
|
@@ -166,7 +168,10 @@ function builder<T>(argv: Argv<T>) {
|
|
|
166
168
|
})
|
|
167
169
|
.check(argvValidator)
|
|
168
170
|
.example('yfm -i ./input -o ./output', '')
|
|
169
|
-
.demandOption(
|
|
171
|
+
.demandOption(
|
|
172
|
+
['input', 'output'],
|
|
173
|
+
'Please provide input and output arguments to work with this tool',
|
|
174
|
+
);
|
|
170
175
|
}
|
|
171
176
|
|
|
172
177
|
async function handler(args: Arguments<any>) {
|
|
@@ -235,8 +240,12 @@ async function handler(args: Arguments<any>) {
|
|
|
235
240
|
const resourcePaths: string[] = [];
|
|
236
241
|
|
|
237
242
|
// collect paths of all resources
|
|
238
|
-
Object.keys(resources).forEach(
|
|
239
|
-
|
|
243
|
+
Object.keys(resources).forEach(
|
|
244
|
+
(type) =>
|
|
245
|
+
resources[type as keyof Resources]?.forEach((path: string) =>
|
|
246
|
+
resourcePaths.push(path),
|
|
247
|
+
),
|
|
248
|
+
);
|
|
240
249
|
|
|
241
250
|
//copy resources
|
|
242
251
|
copyFiles(args.input, tmpOutputFolder, resourcePaths);
|
|
@@ -247,7 +256,11 @@ async function handler(args: Arguments<any>) {
|
|
|
247
256
|
}
|
|
248
257
|
|
|
249
258
|
// Copy all generated files to user' output folder
|
|
250
|
-
shell.cp(
|
|
259
|
+
shell.cp(
|
|
260
|
+
'-r',
|
|
261
|
+
[join(tmpOutputFolder, '*'), join(tmpOutputFolder, '.*')],
|
|
262
|
+
userOutputFolder,
|
|
263
|
+
);
|
|
251
264
|
|
|
252
265
|
if (publish) {
|
|
253
266
|
const DEFAULT_PREFIX = process.env.YFM_STORAGE_PREFIX ?? '';
|
|
@@ -292,13 +305,14 @@ function preparingTemporaryFolders(userOutputFolder: string) {
|
|
|
292
305
|
shell.mkdir(args.input, args.output);
|
|
293
306
|
shell.chmod('-R', 'u+w', args.input);
|
|
294
307
|
|
|
295
|
-
copyFiles(
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
308
|
+
copyFiles(
|
|
309
|
+
args.rootInput,
|
|
310
|
+
args.input,
|
|
311
|
+
glob.sync('**', {
|
|
312
|
+
cwd: args.rootInput,
|
|
313
|
+
nodir: true,
|
|
314
|
+
follow: true,
|
|
315
|
+
ignore: ['node_modules/**', '*/node_modules/**'],
|
|
316
|
+
}),
|
|
317
|
+
);
|
|
304
318
|
}
|
package/src/cmd/publish/index.ts
CHANGED
|
@@ -2,7 +2,7 @@ import {join} from 'path';
|
|
|
2
2
|
import {ArgvService} from '../../services';
|
|
3
3
|
import {logger} from '../../utils';
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import {Arguments, Argv} from 'yargs';
|
|
6
6
|
|
|
7
7
|
import {upload} from './upload';
|
|
8
8
|
|
|
@@ -73,12 +73,7 @@ async function handler(args: Arguments<any>) {
|
|
|
73
73
|
...args,
|
|
74
74
|
});
|
|
75
75
|
|
|
76
|
-
const {
|
|
77
|
-
input,
|
|
78
|
-
endpoint,
|
|
79
|
-
bucket,
|
|
80
|
-
prefix,
|
|
81
|
-
} = ArgvService.getConfig();
|
|
76
|
+
const {input, endpoint, bucket, prefix} = ArgvService.getConfig();
|
|
82
77
|
|
|
83
78
|
logger.info('', `Upload artifacts from ${input} to ${join(endpoint, bucket, prefix)}`);
|
|
84
79
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {createReadStream} from 'fs';
|
|
2
2
|
import walkSync from 'walk-sync';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import {join, resolve} from 'path';
|
|
4
|
+
import {PutObjectCommand, S3Client} from '@aws-sdk/client-s3';
|
|
5
5
|
import mime from 'mime-types';
|
|
6
6
|
|
|
7
7
|
import {convertBackSlashToSlash, logger} from '../../utils';
|
|
@@ -42,20 +42,26 @@ export async function upload(props: UploadProps): Promise<void> {
|
|
|
42
42
|
ignore,
|
|
43
43
|
});
|
|
44
44
|
|
|
45
|
-
await mapLimit(
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
45
|
+
await mapLimit(
|
|
46
|
+
filesToPublish,
|
|
47
|
+
100,
|
|
48
|
+
asyncify(async (pathToFile: string) => {
|
|
49
|
+
const mimeType = mime.lookup(pathToFile);
|
|
50
|
+
|
|
51
|
+
logger.upload(pathToFile);
|
|
52
|
+
|
|
53
|
+
try {
|
|
54
|
+
await s3Client.send(
|
|
55
|
+
new PutObjectCommand({
|
|
56
|
+
ContentType: mimeType ? mimeType : undefined,
|
|
57
|
+
Bucket: bucket,
|
|
58
|
+
Key: convertBackSlashToSlash(join(prefix, pathToFile)),
|
|
59
|
+
Body: createReadStream(resolve(input, pathToFile)),
|
|
60
|
+
}),
|
|
61
|
+
);
|
|
62
|
+
} catch (error) {
|
|
63
|
+
logger.error(pathToFile, error.message);
|
|
64
|
+
}
|
|
65
|
+
}),
|
|
66
|
+
);
|
|
61
67
|
}
|
|
@@ -1,39 +1,26 @@
|
|
|
1
|
-
import {
|
|
2
|
-
eachLimit,
|
|
3
|
-
retry,
|
|
4
|
-
asyncify,
|
|
5
|
-
} from 'async';
|
|
1
|
+
import {asyncify, eachLimit, retry} from 'async';
|
|
6
2
|
|
|
7
|
-
import {dirname,
|
|
8
|
-
import {readFile, writeFile
|
|
3
|
+
import {dirname, join, resolve} from 'path';
|
|
4
|
+
import {mkdir, readFile, writeFile} from 'fs/promises';
|
|
9
5
|
import {XMLParser} from 'fast-xml-parser';
|
|
10
6
|
|
|
11
7
|
import {Session} from '@yandex-cloud/nodejs-sdk/dist/session';
|
|
12
8
|
import {TranslationServiceClient} from '@yandex-cloud/nodejs-sdk/dist/generated/yandex/cloud/service_clients';
|
|
13
9
|
import {
|
|
14
|
-
TranslateRequest,
|
|
15
10
|
TranslateRequest_Format as Format,
|
|
11
|
+
TranslateRequest,
|
|
16
12
|
} from '@yandex-cloud/nodejs-sdk/dist/generated/yandex/cloud/ai/translate/v2/translation_service';
|
|
17
13
|
|
|
18
|
-
|
|
14
|
+
import markdownTranslation from '@diplodoc/markdown-translation';
|
|
19
15
|
|
|
20
16
|
import {ArgvService} from '../../services';
|
|
21
17
|
import {getYandexOAuthToken} from '../../packages/credentials';
|
|
22
18
|
import {glob, logger} from '../../utils';
|
|
23
19
|
|
|
24
|
-
import {
|
|
20
|
+
import {Arguments, Argv} from 'yargs';
|
|
25
21
|
|
|
26
22
|
import {YandexCloudTranslateGlossaryPair} from '../../models';
|
|
27
23
|
|
|
28
|
-
const composer = async (xliff: string, skeleton: string): Promise<string> => new Promise((res, rej) =>
|
|
29
|
-
yfm2xliff.compose(xliff, skeleton, (err: Error, composed: string) => {
|
|
30
|
-
if (err) {
|
|
31
|
-
rej(err);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
return res(composed);
|
|
35
|
-
}));
|
|
36
|
-
|
|
37
24
|
const command = 'translate';
|
|
38
25
|
|
|
39
26
|
const description = 'translate documentation with Yandex.Cloud Translator API';
|
|
@@ -64,7 +51,8 @@ function builder<T>(argv: Argv<T>) {
|
|
|
64
51
|
})
|
|
65
52
|
.demandOption(
|
|
66
53
|
['source-language', 'target-language'],
|
|
67
|
-
'command requires to specify source and target languages'
|
|
54
|
+
'command requires to specify source and target languages',
|
|
55
|
+
);
|
|
68
56
|
}
|
|
69
57
|
|
|
70
58
|
class TranslatorError extends Error {
|
|
@@ -83,7 +71,8 @@ async function handler(args: Arguments<any>) {
|
|
|
83
71
|
...args,
|
|
84
72
|
});
|
|
85
73
|
|
|
86
|
-
const {
|
|
74
|
+
const {
|
|
75
|
+
input,
|
|
87
76
|
output,
|
|
88
77
|
yandexCloudTranslateFolderId,
|
|
89
78
|
yandexCloudTranslateGlossaryPairs,
|
|
@@ -91,12 +80,17 @@ async function handler(args: Arguments<any>) {
|
|
|
91
80
|
tl: targetLanguage,
|
|
92
81
|
} = args;
|
|
93
82
|
|
|
94
|
-
logger.info(
|
|
83
|
+
logger.info(
|
|
84
|
+
input,
|
|
85
|
+
`translating documentation from ${sourceLanguage} to ${targetLanguage} language`,
|
|
86
|
+
);
|
|
95
87
|
|
|
96
88
|
try {
|
|
97
89
|
let found = [];
|
|
98
90
|
|
|
99
|
-
({
|
|
91
|
+
({
|
|
92
|
+
state: {found},
|
|
93
|
+
} = await glob(join(input, MD_GLOB), {
|
|
100
94
|
nosort: true,
|
|
101
95
|
}));
|
|
102
96
|
|
|
@@ -125,7 +119,10 @@ async function handler(args: Arguments<any>) {
|
|
|
125
119
|
}
|
|
126
120
|
}
|
|
127
121
|
|
|
128
|
-
logger.info(
|
|
122
|
+
logger.info(
|
|
123
|
+
output,
|
|
124
|
+
`translated documentation from ${sourceLanguage} to ${targetLanguage} language`,
|
|
125
|
+
);
|
|
129
126
|
}
|
|
130
127
|
|
|
131
128
|
export type TranslatorParams = {
|
|
@@ -158,16 +155,21 @@ function translator(params: TranslatorParams) {
|
|
|
158
155
|
|
|
159
156
|
const md = await readFile(resolve(mdPath), {encoding: 'utf-8'});
|
|
160
157
|
|
|
161
|
-
const
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
158
|
+
const {xlf, skeleton} = markdownTranslation.extract({
|
|
159
|
+
source: {
|
|
160
|
+
language: sourceLanguage,
|
|
161
|
+
locale: sourceLanguage.toUpperCase(),
|
|
162
|
+
},
|
|
163
|
+
target: {
|
|
164
|
+
language: targetLanguage,
|
|
165
|
+
locale: targetLanguage.toUpperCase(),
|
|
166
|
+
},
|
|
167
|
+
markdown: md,
|
|
168
|
+
markdownPath: mdPath,
|
|
169
|
+
skeletonPath: '',
|
|
168
170
|
});
|
|
169
171
|
|
|
170
|
-
const texts = parseSourcesFromXLIFF(
|
|
172
|
+
const texts = parseSourcesFromXLIFF(xlf);
|
|
171
173
|
|
|
172
174
|
const machineTranslateParams = TranslateRequest.fromPartial({
|
|
173
175
|
texts,
|
|
@@ -182,14 +184,23 @@ function translator(params: TranslatorParams) {
|
|
|
182
184
|
format: Format.PLAIN_TEXT,
|
|
183
185
|
});
|
|
184
186
|
|
|
185
|
-
const translations = await retry(
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
187
|
+
const translations = await retry(
|
|
188
|
+
{
|
|
189
|
+
times: RETRY_LIMIT,
|
|
190
|
+
interval: (count: number) => {
|
|
191
|
+
// eslint-disable-next-line no-bitwise
|
|
192
|
+
return (1 << count) * 1000;
|
|
193
|
+
},
|
|
194
|
+
},
|
|
195
|
+
asyncify(
|
|
196
|
+
async () =>
|
|
197
|
+
await client
|
|
198
|
+
.translate(machineTranslateParams)
|
|
199
|
+
.then((results: {translations: {text: string}[]}) =>
|
|
200
|
+
results.translations.map(({text}: {text: string}) => text),
|
|
201
|
+
),
|
|
202
|
+
),
|
|
203
|
+
);
|
|
193
204
|
|
|
194
205
|
const createXLIFFDocumentParams = {
|
|
195
206
|
sourceLanguage: sourceLanguage + '-' + MTRANS_LOCALE,
|
|
@@ -200,7 +211,10 @@ function translator(params: TranslatorParams) {
|
|
|
200
211
|
|
|
201
212
|
const translatedXLIFF = createXLIFFDocument(createXLIFFDocumentParams);
|
|
202
213
|
|
|
203
|
-
const composed = await
|
|
214
|
+
const composed = await markdownTranslation.compose({
|
|
215
|
+
xlf: translatedXLIFF,
|
|
216
|
+
skeleton,
|
|
217
|
+
});
|
|
204
218
|
|
|
205
219
|
const outputPath = mdPath.replace(input, output);
|
|
206
220
|
|
package/src/cmd/xliff/compose.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
const {
|
|
2
|
-
|
|
1
|
+
const {
|
|
2
|
+
promises: {readFile, writeFile, mkdir},
|
|
3
|
+
} = require('fs');
|
|
4
|
+
import {dirname, extname, join} from 'path';
|
|
3
5
|
|
|
4
6
|
import markdownTranslation, {ComposeParameters} from '@diplodoc/markdown-translation';
|
|
5
7
|
import {Arguments, Argv} from 'yargs';
|
|
@@ -28,7 +30,8 @@ class ComposeError extends Error {
|
|
|
28
30
|
}
|
|
29
31
|
}
|
|
30
32
|
|
|
31
|
-
const USAGE =
|
|
33
|
+
const USAGE =
|
|
34
|
+
'yfm xliff compose \
|
|
32
35
|
--input <folder-with-xliff-and-skeleton> \
|
|
33
36
|
--ouput <folder-to-store-translated-markdown>';
|
|
34
37
|
|
|
@@ -38,11 +41,13 @@ function builder<T>(argv: Argv<T>) {
|
|
|
38
41
|
alias: 'i',
|
|
39
42
|
describe: 'input folder with xliff and skeleton files',
|
|
40
43
|
type: 'string',
|
|
41
|
-
})
|
|
44
|
+
})
|
|
45
|
+
.option('output', {
|
|
42
46
|
alias: 'o',
|
|
43
47
|
describe: 'output folder where translated markdown will be stored',
|
|
44
48
|
type: 'string',
|
|
45
|
-
})
|
|
49
|
+
})
|
|
50
|
+
.demandOption(['input', 'output'], USAGE);
|
|
46
51
|
}
|
|
47
52
|
|
|
48
53
|
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
|
|
@@ -58,18 +63,22 @@ async function handler(args: Arguments<any>) {
|
|
|
58
63
|
let xliffPaths: string[] = [];
|
|
59
64
|
|
|
60
65
|
try {
|
|
61
|
-
({
|
|
66
|
+
({
|
|
67
|
+
state: {found: skeletonPaths, cache},
|
|
68
|
+
} = await glob(join(input, SKL_MD_GLOB), {
|
|
62
69
|
nosort: false,
|
|
63
70
|
cache,
|
|
64
71
|
}));
|
|
65
72
|
|
|
66
|
-
({
|
|
73
|
+
({
|
|
74
|
+
state: {found: xliffPaths, cache},
|
|
75
|
+
} = await glob(join(input, XLF_GLOB), {
|
|
67
76
|
nosort: false,
|
|
68
77
|
cache,
|
|
69
78
|
}));
|
|
70
79
|
|
|
71
80
|
if (xliffPaths.length !== skeletonPaths.length) {
|
|
72
|
-
throw new ComposeError(
|
|
81
|
+
throw new ComposeError("number of xliff and skeleton files does'not match", input);
|
|
73
82
|
}
|
|
74
83
|
} catch (err) {
|
|
75
84
|
if (err instanceof Error || err instanceof ComposeError) {
|
package/src/cmd/xliff/extract.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
const {
|
|
2
|
-
|
|
1
|
+
const {
|
|
2
|
+
promises: {readFile, writeFile, mkdir},
|
|
3
|
+
} = require('fs');
|
|
4
|
+
import {dirname, extname, join} from 'path';
|
|
3
5
|
|
|
4
6
|
import markdownTranslation, {ExtractParameters} from '@diplodoc/markdown-translation';
|
|
5
7
|
import {Arguments, Argv} from 'yargs';
|
|
6
|
-
import {
|
|
8
|
+
import {asyncify, eachLimit} from 'async';
|
|
7
9
|
|
|
8
10
|
import {ArgvService} from '../../services';
|
|
9
11
|
import {glob, logger} from '../../utils';
|
|
@@ -44,19 +46,26 @@ function builder<T>(argv: Argv<T>) {
|
|
|
44
46
|
alias: 'sll',
|
|
45
47
|
describe: 'source language and locale',
|
|
46
48
|
type: 'string',
|
|
47
|
-
})
|
|
49
|
+
})
|
|
50
|
+
.option('target-language-locale', {
|
|
48
51
|
alias: 'tll',
|
|
49
52
|
describe: 'target language and locale',
|
|
50
53
|
type: 'string',
|
|
51
|
-
})
|
|
54
|
+
})
|
|
55
|
+
.option('input', {
|
|
52
56
|
alias: 'i',
|
|
53
57
|
describe: 'input folder with markdown files',
|
|
54
58
|
type: 'string',
|
|
55
|
-
})
|
|
59
|
+
})
|
|
60
|
+
.option('output', {
|
|
56
61
|
alias: 'o',
|
|
57
62
|
describe: 'output folder to store xliff and skeleton files',
|
|
58
63
|
type: 'string',
|
|
59
|
-
})
|
|
64
|
+
})
|
|
65
|
+
.demandOption(
|
|
66
|
+
['source-language-locale', 'target-language-locale', 'input', 'output'],
|
|
67
|
+
USAGE,
|
|
68
|
+
);
|
|
60
69
|
}
|
|
61
70
|
|
|
62
71
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -83,7 +92,9 @@ async function handler(args: Arguments<any>) {
|
|
|
83
92
|
let found: string[] = [];
|
|
84
93
|
|
|
85
94
|
try {
|
|
86
|
-
({
|
|
95
|
+
({
|
|
96
|
+
state: {found, cache},
|
|
97
|
+
} = await glob(join(input, MD_GLOB), {
|
|
87
98
|
nosort: true,
|
|
88
99
|
cache,
|
|
89
100
|
}));
|
|
@@ -134,9 +145,7 @@ function pipeline(params: PipelineParameters) {
|
|
|
134
145
|
const markdown = await reader({path: markdownPath});
|
|
135
146
|
const extension = extname(markdownPath);
|
|
136
147
|
|
|
137
|
-
const outputRelativePath = markdownPath
|
|
138
|
-
.replace(extension, '')
|
|
139
|
-
.slice(input.length);
|
|
148
|
+
const outputRelativePath = markdownPath.replace(extension, '').slice(input.length);
|
|
140
149
|
|
|
141
150
|
const outputPath = join(output, outputRelativePath);
|
|
142
151
|
const xlfPath = outputPath + '.xliff';
|
package/src/cmd/xliff/index.ts
CHANGED
|
@@ -19,7 +19,10 @@ function builder<T>(argv: Argv<T>) {
|
|
|
19
19
|
return argv
|
|
20
20
|
.command(extract)
|
|
21
21
|
.command(compose)
|
|
22
|
-
.demandCommand(
|
|
22
|
+
.demandCommand(
|
|
23
|
+
1,
|
|
24
|
+
`provide one of the folowing ${command} commands: ${extract.command}, ${compose.command}`,
|
|
25
|
+
);
|
|
23
26
|
}
|
|
24
27
|
|
|
25
28
|
export {xliff};
|
package/src/constants.ts
CHANGED
|
@@ -59,7 +59,7 @@ export enum Platforms {
|
|
|
59
59
|
export enum IncludeMode {
|
|
60
60
|
ROOT_MERGE = 'root_merge',
|
|
61
61
|
MERGE = 'merge',
|
|
62
|
-
LINK = 'link'
|
|
62
|
+
LINK = 'link',
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
export enum ResourceType {
|
|
@@ -95,8 +95,8 @@ export const PROCESSING_FINISHED = 'Processing finished:';
|
|
|
95
95
|
export const LINTING_FINISHED = 'Linting finished:';
|
|
96
96
|
export const GETTING_ALL_CONTRIBUTORS = 'Getting all contributors.';
|
|
97
97
|
export const ALL_CONTRIBUTORS_RECEIVED = 'All contributors received.';
|
|
98
|
-
export const getMsgСonfigurationMustBeProvided =
|
|
99
|
-
|
|
98
|
+
export const getMsgСonfigurationMustBeProvided = (repo: string) =>
|
|
99
|
+
`Сonfiguration must be provided for ${repo} like env variables or in .yfm file`;
|
|
100
100
|
|
|
101
101
|
export const FIRST_COMMIT_FROM_ROBOT_IN_GITHUB = '2dce14271359cd20d7e874956d604de087560cf4';
|
|
102
102
|
|
|
@@ -117,6 +117,6 @@ export const REGEXP_INCLUDE_FILE_PATH = /(?<=[(]).+(?=[)])/g;
|
|
|
117
117
|
export const REGEXP_AUTHOR = /(?<=author:\s).+(?=\r?\n)/g;
|
|
118
118
|
|
|
119
119
|
export const MIN_CHUNK_SIZE = Number(process.env.MIN_CHUNK_SIZE) || 1000;
|
|
120
|
-
export const WORKERS_COUNT = Number(process.env.WORKERS_COUNT) ||
|
|
120
|
+
export const WORKERS_COUNT = Number(process.env.WORKERS_COUNT) || os.cpus().length - 1;
|
|
121
121
|
|
|
122
122
|
export const metadataBorder = '---';
|
package/src/index.ts
CHANGED
|
@@ -5,7 +5,7 @@ import 'threads/register';
|
|
|
5
5
|
|
|
6
6
|
import {MAIN_TIMER_ID} from './constants';
|
|
7
7
|
|
|
8
|
-
import {build,
|
|
8
|
+
import {build, publish, translate, xliff} from './cmd';
|
|
9
9
|
|
|
10
10
|
console.time(MAIN_TIMER_ID);
|
|
11
11
|
|
|
@@ -28,7 +28,7 @@ yargs
|
|
|
28
28
|
.option('quiet', {
|
|
29
29
|
alias: 'q',
|
|
30
30
|
default: false,
|
|
31
|
-
describe:
|
|
31
|
+
describe: "Run in quiet mode. Don't write logs to stdout",
|
|
32
32
|
type: 'boolean',
|
|
33
33
|
})
|
|
34
34
|
.group(['config', 'strict', 'quiet', 'help', 'version'], 'Common options:')
|
|
@@ -44,7 +44,7 @@ yargs
|
|
|
44
44
|
|
|
45
45
|
const {warn, error} = log.get();
|
|
46
46
|
|
|
47
|
-
if (strict && warn.length || error.length) {
|
|
47
|
+
if ((strict && warn.length) || error.length) {
|
|
48
48
|
process.exit(1);
|
|
49
49
|
}
|
|
50
50
|
|
package/src/models.ts
CHANGED
|
@@ -2,10 +2,10 @@ import {Logger} from '@diplodoc/transform/lib/log';
|
|
|
2
2
|
import {LintConfig} from '@diplodoc/transform/lib/yfmlint';
|
|
3
3
|
|
|
4
4
|
import {FileContributors, VCSConnector, VCSConnectorConfig} from './vcs-connector/connector-models';
|
|
5
|
-
import {
|
|
5
|
+
import {IncludeMode, Lang, ResourceType, Stage} from './constants';
|
|
6
6
|
import {ChangelogItem} from '@diplodoc/transform/lib/plugins/changelog/types';
|
|
7
7
|
|
|
8
|
-
export type VarsPreset = 'internal'|'external';
|
|
8
|
+
export type VarsPreset = 'internal' | 'external';
|
|
9
9
|
|
|
10
10
|
export type YfmPreset = Record<string, string>;
|
|
11
11
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -13,7 +13,10 @@ export type Metadata = Record<string, any>;
|
|
|
13
13
|
|
|
14
14
|
export type ExternalAuthorByPathFunction = (path: string) => Contributor | null;
|
|
15
15
|
export type ContributorsByPathFunction = (path: string) => Promise<FileContributors>;
|
|
16
|
-
export type NestedContributorsForPathFunction = (
|
|
16
|
+
export type NestedContributorsForPathFunction = (
|
|
17
|
+
path: string,
|
|
18
|
+
nestedContributors: Contributors,
|
|
19
|
+
) => void;
|
|
17
20
|
export type UserByLoginFunction = (login: string) => Promise<Contributor | null>;
|
|
18
21
|
export type CollectionOfPluginsFunction = (output: string, options: PluginOptions) => string;
|
|
19
22
|
|
|
@@ -96,7 +99,7 @@ export type YfmTocIncluder = {
|
|
|
96
99
|
|
|
97
100
|
export const includersNames = ['sourcedocs', 'openapi', 'generic', 'unarchive'] as const;
|
|
98
101
|
|
|
99
|
-
export type YfmTocIncluderName = typeof includersNames[number];
|
|
102
|
+
export type YfmTocIncluderName = (typeof includersNames)[number];
|
|
100
103
|
|
|
101
104
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
102
105
|
export type Includer<FnParams = any> = {
|
|
@@ -104,7 +107,9 @@ export type Includer<FnParams = any> = {
|
|
|
104
107
|
includerFunction: IncluderFunction<FnParams>;
|
|
105
108
|
};
|
|
106
109
|
|
|
107
|
-
export type IncluderFunction<PassedParams> = (
|
|
110
|
+
export type IncluderFunction<PassedParams> = (
|
|
111
|
+
args: IncluderFunctionParams<PassedParams>,
|
|
112
|
+
) => Promise<void>;
|
|
108
113
|
|
|
109
114
|
export type IncluderFunctionParams<PassedParams> = {
|
|
110
115
|
// item that contains include that uses includer
|
|
@@ -148,7 +153,7 @@ export interface LeadingPageLinks extends Filter {
|
|
|
148
153
|
}
|
|
149
154
|
|
|
150
155
|
export interface Filter {
|
|
151
|
-
when?: boolean|string;
|
|
156
|
+
when?: boolean | string;
|
|
152
157
|
[key: string]: unknown;
|
|
153
158
|
}
|
|
154
159
|
|
|
@@ -239,8 +244,8 @@ export type Resources = {
|
|
|
239
244
|
};
|
|
240
245
|
|
|
241
246
|
export type YandexCloudTranslateGlossaryPair = {
|
|
242
|
-
|
|
243
|
-
|
|
247
|
+
sourceText: string;
|
|
248
|
+
translatedText: string;
|
|
244
249
|
};
|
|
245
250
|
|
|
246
251
|
export type CommitInfo = {
|