@diplodoc/cli 4.15.0 → 4.16.0
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/index.js +233 -218
- package/build/index.js.map +3 -3
- package/package.json +4 -4
- package/src/cmd/translate/compose.ts +1 -9
- package/src/cmd/translate/extract.ts +7 -10
- package/src/cmd/translate/handler.ts +5 -1
- package/src/cmd/translate/utils/fs.ts +46 -9
- package/src/cmd/translate/utils/index.ts +1 -5
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.
|
|
6
|
+
"version": "4.16.0",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
9
9
|
"url": "git@github.com:diplodoc-platform/cli.git"
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"@diplodoc/client": "^2.1.1",
|
|
34
|
-
"@diplodoc/translation": "^1.0
|
|
34
|
+
"@diplodoc/translation": "^1.1.0",
|
|
35
35
|
"katex": "^0.16.9",
|
|
36
36
|
"shelljs": "0.8.5",
|
|
37
37
|
"threads": "1.7.0",
|
|
@@ -62,13 +62,13 @@
|
|
|
62
62
|
"ajv": "^8.11.0",
|
|
63
63
|
"async": "^3.2.4",
|
|
64
64
|
"axios": "^1.6.7",
|
|
65
|
-
"chalk": "4.1.2",
|
|
65
|
+
"chalk": "^4.1.2",
|
|
66
66
|
"esbuild": "^0.20.0",
|
|
67
67
|
"glob": "^8.0.3",
|
|
68
68
|
"html-escaper": "^3.0.3",
|
|
69
69
|
"husky": "8.0.3",
|
|
70
70
|
"js-yaml": "4.1.0",
|
|
71
|
-
"lint-staged": "
|
|
71
|
+
"lint-staged": "^12.5.0",
|
|
72
72
|
"lodash": "4.17.21",
|
|
73
73
|
"mime-types": "2.1.35",
|
|
74
74
|
"minimatch": "^9.0.3",
|
|
@@ -100,15 +100,7 @@ function pipeline(input: string, output: string, {useSource}: ComposeOptions) {
|
|
|
100
100
|
loadFile<string>(join(input, file.xliff)),
|
|
101
101
|
]);
|
|
102
102
|
|
|
103
|
-
|
|
104
|
-
if (['.yaml', '.json'].includes(file.ext)) {
|
|
105
|
-
schemas = resolveSchemas(file.path);
|
|
106
|
-
|
|
107
|
-
if (!schemas) {
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
103
|
+
const schemas = await resolveSchemas(file.path);
|
|
112
104
|
const result = _compose(skeleton, xliff, {useSource, schemas});
|
|
113
105
|
const filePath = join(output, file.path);
|
|
114
106
|
|
|
@@ -121,24 +121,21 @@ function pipeline(params: PipelineParameters) {
|
|
|
121
121
|
const xliffPath = join(outputRoot, outputPath + '.xliff');
|
|
122
122
|
const skeletonPath = join(outputRoot, outputPath + '.skl');
|
|
123
123
|
|
|
124
|
-
|
|
125
|
-
if (['.yaml', '.json'].includes(ext)) {
|
|
126
|
-
schemas = resolveSchemas(path);
|
|
127
|
-
|
|
128
|
-
if (!schemas) {
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
|
|
124
|
+
const schemas = await resolveSchemas(path);
|
|
133
125
|
const content = await loadFile(inputPath);
|
|
134
126
|
|
|
135
127
|
await mkdir(dirname(xliffPath), {recursive: true});
|
|
136
128
|
|
|
137
|
-
const {xliff, skeleton} = _extract(content, {
|
|
129
|
+
const {xliff, skeleton, units} = _extract(content, {
|
|
138
130
|
source,
|
|
139
131
|
target,
|
|
132
|
+
schemas,
|
|
140
133
|
});
|
|
141
134
|
|
|
135
|
+
if (!units.length) {
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
|
|
142
139
|
await Promise.all([dumpFile(skeletonPath, skeleton), dumpFile(xliffPath, xliff)]);
|
|
143
140
|
};
|
|
144
141
|
}
|
|
@@ -22,6 +22,7 @@ import {
|
|
|
22
22
|
extract,
|
|
23
23
|
loadFile,
|
|
24
24
|
normalizeParams,
|
|
25
|
+
resolveSchemas,
|
|
25
26
|
} from './utils';
|
|
26
27
|
|
|
27
28
|
const REQUESTS_LIMIT = 20;
|
|
@@ -262,7 +263,9 @@ function translator(params: TranslatorParams, split: Split) {
|
|
|
262
263
|
return;
|
|
263
264
|
}
|
|
264
265
|
|
|
266
|
+
const schemas = await resolveSchemas(path);
|
|
265
267
|
const {units, skeleton} = extract(content, {
|
|
268
|
+
compact: true,
|
|
266
269
|
source: {
|
|
267
270
|
language: sourceLanguage,
|
|
268
271
|
locale: 'RU',
|
|
@@ -271,6 +274,7 @@ function translator(params: TranslatorParams, split: Split) {
|
|
|
271
274
|
language: targetLanguage,
|
|
272
275
|
locale: 'US',
|
|
273
276
|
},
|
|
277
|
+
schemas,
|
|
274
278
|
});
|
|
275
279
|
|
|
276
280
|
if (!units.length) {
|
|
@@ -279,7 +283,7 @@ function translator(params: TranslatorParams, split: Split) {
|
|
|
279
283
|
}
|
|
280
284
|
|
|
281
285
|
const parts = await split(path, units);
|
|
282
|
-
const composed = compose(skeleton, parts, {useSource: true});
|
|
286
|
+
const composed = compose(skeleton, parts, {useSource: true, schemas});
|
|
283
287
|
|
|
284
288
|
await dumpFile(outputPath, composed);
|
|
285
289
|
};
|
|
@@ -1,17 +1,30 @@
|
|
|
1
1
|
import {JSONValue, resolveRefs} from '@diplodoc/translation';
|
|
2
|
-
import {extname} from 'path';
|
|
3
2
|
import {dump, load} from 'js-yaml';
|
|
4
3
|
import {readFile, writeFile} from 'fs/promises';
|
|
5
4
|
|
|
5
|
+
function last<T>(array: T[]): T | undefined {
|
|
6
|
+
return array[array.length - 1];
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function ext(path: string) {
|
|
10
|
+
const parts = path.split('.');
|
|
11
|
+
|
|
12
|
+
if (last(parts) === 'skl') {
|
|
13
|
+
parts.pop();
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return last(parts);
|
|
17
|
+
}
|
|
18
|
+
|
|
6
19
|
function parseFile(text: string, path: string): JSONValue | string {
|
|
7
20
|
if (typeof text !== 'string') {
|
|
8
21
|
return text;
|
|
9
22
|
}
|
|
10
23
|
|
|
11
|
-
switch (
|
|
12
|
-
case '
|
|
24
|
+
switch (ext(path)) {
|
|
25
|
+
case 'yaml':
|
|
13
26
|
return load(text) as object;
|
|
14
|
-
case '
|
|
27
|
+
case 'json':
|
|
15
28
|
return JSON.parse(text);
|
|
16
29
|
default:
|
|
17
30
|
return text;
|
|
@@ -23,22 +36,22 @@ function stringifyFile(content: JSONValue | string, path: string): string {
|
|
|
23
36
|
return content;
|
|
24
37
|
}
|
|
25
38
|
|
|
26
|
-
switch (
|
|
27
|
-
case '
|
|
39
|
+
switch (ext(path)) {
|
|
40
|
+
case 'yaml':
|
|
28
41
|
return dump(content);
|
|
29
|
-
case '
|
|
42
|
+
case 'json':
|
|
30
43
|
return JSON.stringify(content);
|
|
31
44
|
default:
|
|
32
45
|
return content as unknown as string;
|
|
33
46
|
}
|
|
34
47
|
}
|
|
35
48
|
|
|
36
|
-
export async function loadFile<T = string | JSONValue>(path: string): Promise<T> {
|
|
49
|
+
export async function loadFile<T = string | JSONValue>(path: string, resolve = true): Promise<T> {
|
|
37
50
|
const text = await readFile(path, 'utf8');
|
|
38
51
|
|
|
39
52
|
let content = parseFile(text, path);
|
|
40
53
|
|
|
41
|
-
if (content && typeof content === 'object') {
|
|
54
|
+
if (content && typeof content === 'object' && resolve) {
|
|
42
55
|
content = await resolveRefs(content, path, parseFile);
|
|
43
56
|
}
|
|
44
57
|
|
|
@@ -50,3 +63,27 @@ export async function dumpFile(path: string, content: string | JSONValue) {
|
|
|
50
63
|
|
|
51
64
|
await writeFile(path, text, 'utf8');
|
|
52
65
|
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Takes toc schema if file matched as toc.
|
|
69
|
+
* Takes leading schema if file matched as leading page.
|
|
70
|
+
* Takes presets schema if file matched as presets.
|
|
71
|
+
* Any way translation inner logic will search `$schema` attribute with high priority.
|
|
72
|
+
* If `$schema` attribute not found anc precise schema not resolved,
|
|
73
|
+
* we think that current yaml is a part of complex toc.yaml
|
|
74
|
+
*/
|
|
75
|
+
export async function resolveSchemas(path: string) {
|
|
76
|
+
if (path.endsWith('toc.yaml')) {
|
|
77
|
+
return [await loadFile('schemas/toc-schema.yaml', false)];
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (path.endsWith('index.yaml')) {
|
|
81
|
+
return [await loadFile('schemas/leading-schema.yaml', false)];
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (path.endsWith('presets.yaml')) {
|
|
85
|
+
return [await loadFile('schemas/presets-schema.yaml', false)];
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return [await loadFile('schemas/toc-schema.yaml', false)];
|
|
89
|
+
}
|
|
@@ -3,7 +3,7 @@ import {basename, dirname, extname, resolve} from 'path';
|
|
|
3
3
|
import {readFileSync} from 'node:fs';
|
|
4
4
|
import glob from 'glob';
|
|
5
5
|
|
|
6
|
-
export {dumpFile, loadFile} from './fs';
|
|
6
|
+
export {dumpFile, loadFile, resolveSchemas} from './fs';
|
|
7
7
|
export {extract, compose} from './translate';
|
|
8
8
|
export {TranslateError, LimitExceed, RequestError, AuthError} from './errors';
|
|
9
9
|
|
|
@@ -138,10 +138,6 @@ function normalizeInput(params: TranslateArgs, language: string, exts: string[])
|
|
|
138
138
|
return {input, files};
|
|
139
139
|
}
|
|
140
140
|
|
|
141
|
-
export function resolveSchemas(_path: string) {
|
|
142
|
-
return null;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
141
|
export class Defer<T = string> {
|
|
146
142
|
resolve!: (text: T) => void;
|
|
147
143
|
|