@diplodoc/cli 4.0.0 → 4.2.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/app.client.css +2678 -41
- package/build/app.client.js +1 -1
- package/build/index.js +418 -309
- package/build/index.js.map +3 -3
- package/build/linter.js +89 -81
- 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 +1 -6
- package/src/cmd/publish/upload.ts +22 -16
- package/src/cmd/translate/index.ts +51 -37
- package/src/cmd/xliff/compose.ts +16 -7
- package/src/cmd/xliff/extract.ts +18 -9
- package/src/cmd/xliff/index.ts +4 -1
- package/src/constants.ts +24 -24
- package/src/index.ts +3 -3
- package/src/models.ts +15 -10
- package/src/resolvers/lintPage.ts +3 -9
- package/src/resolvers/md2html.ts +27 -19
- package/src/resolvers/md2md.ts +16 -16
- 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 +27 -9
- package/src/services/includers/batteries/sourcedocs.ts +4 -1
- package/src/services/includers/batteries/unarchive.ts +8 -4
- package/src/services/includers/index.ts +6 -4
- package/src/services/leading.ts +24 -27
- package/src/services/metadata.ts +35 -10
- package/src/services/plugins.ts +1 -1
- package/src/services/preset.ts +2 -2
- package/src/services/tocs.ts +28 -23
- package/src/services/utils.ts +15 -5
- package/src/steps/processAssets.ts +2 -8
- package/src/steps/processExcludedFiles.ts +11 -20
- package/src/steps/processLinter.ts +9 -8
- package/src/steps/processLogs.ts +2 -7
- package/src/steps/processMapFile.ts +8 -11
- package/src/steps/processPages.ts +97 -67
- package/src/steps/processServiceFiles.ts +4 -2
- package/src/steps/publishFilesToS3.ts +16 -12
- package/src/utils/file.ts +5 -1
- package/src/utils/glob.ts +1 -3
- package/src/utils/logger.ts +1 -1
- package/src/utils/markup.ts +28 -13
- package/src/utils/singlePage.ts +11 -10
- package/src/utils/toc.ts +20 -7
- package/src/utils/worker.ts +1 -1
- package/src/validator.ts +25 -17
- package/src/vcs-connector/client/github.ts +16 -8
- package/src/vcs-connector/connector-validator.ts +13 -7
- package/src/vcs-connector/github.ts +38 -11
- package/src/vcs-connector/index.ts +1 -1
- package/src/workers/linter/index.ts +2 -6
- package/CHANGELOG.md +0 -785
- package/build/lib.js +0 -3374
- package/build/lib.js.map +0 -7
package/src/services/tocs.ts
CHANGED
|
@@ -3,8 +3,8 @@ import {copyFileSync, readFileSync, writeFileSync, existsSync} from 'fs';
|
|
|
3
3
|
import {load, dump} from 'js-yaml';
|
|
4
4
|
import shell from 'shelljs';
|
|
5
5
|
import walkSync from 'walk-sync';
|
|
6
|
-
import liquid from '@
|
|
7
|
-
import log from '@
|
|
6
|
+
import liquid from '@diplodoc/transform/lib/liquid';
|
|
7
|
+
import log from '@diplodoc/transform/lib/log';
|
|
8
8
|
import {bold} from 'chalk';
|
|
9
9
|
|
|
10
10
|
import {ArgvService, PresetService} from './index';
|
|
@@ -49,11 +49,9 @@ async function add(path: string) {
|
|
|
49
49
|
};
|
|
50
50
|
|
|
51
51
|
if (parsedToc.title) {
|
|
52
|
-
parsedToc.title = firstFilterTextItems(
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
{resolveConditions: true},
|
|
56
|
-
);
|
|
52
|
+
parsedToc.title = firstFilterTextItems(parsedToc.title, combinedVars, {
|
|
53
|
+
resolveConditions: true,
|
|
54
|
+
});
|
|
57
55
|
}
|
|
58
56
|
|
|
59
57
|
if (typeof parsedToc.title === 'string') {
|
|
@@ -92,10 +90,7 @@ async function processTocItems(
|
|
|
92
90
|
sourcesDir: string,
|
|
93
91
|
vars: Record<string, string>,
|
|
94
92
|
) {
|
|
95
|
-
const {
|
|
96
|
-
resolveConditions,
|
|
97
|
-
removeHiddenTocItems,
|
|
98
|
-
} = ArgvService.getConfig();
|
|
93
|
+
const {resolveConditions, removeHiddenTocItems} = ArgvService.getConfig();
|
|
99
94
|
|
|
100
95
|
let preparedItems = items;
|
|
101
96
|
|
|
@@ -115,7 +110,7 @@ async function processTocItems(
|
|
|
115
110
|
return _replaceIncludes(path, preparedItems, tocDir, sourcesDir, vars);
|
|
116
111
|
}
|
|
117
112
|
|
|
118
|
-
function getForPath(path: string): YfmToc|undefined {
|
|
113
|
+
function getForPath(path: string): YfmToc | undefined {
|
|
119
114
|
return storage.get(path);
|
|
120
115
|
}
|
|
121
116
|
|
|
@@ -131,11 +126,11 @@ function prepareNavigationPaths(parsedToc: YfmToc, dirPath: string) {
|
|
|
131
126
|
function processItems(items: YfmToc[], pathToDir: string) {
|
|
132
127
|
items.forEach((item) => {
|
|
133
128
|
if (!parsedToc.singlePage && item.items) {
|
|
134
|
-
const preparedSubItems = item.items.map((
|
|
129
|
+
const preparedSubItems = item.items.map((yfmToc: YfmToc, index: number) => {
|
|
135
130
|
// Generate personal id for each navigation item
|
|
136
131
|
yfmToc.id = `${yfmToc.name}-${index}-${Math.random()}`;
|
|
137
132
|
return yfmToc;
|
|
138
|
-
})
|
|
133
|
+
});
|
|
139
134
|
processItems(preparedSubItems, pathToDir);
|
|
140
135
|
}
|
|
141
136
|
|
|
@@ -308,9 +303,10 @@ async function _replaceIncludes(
|
|
|
308
303
|
|
|
309
304
|
if (item.include) {
|
|
310
305
|
const {mode = IncludeMode.ROOT_MERGE} = item.include;
|
|
311
|
-
const includeTocPath =
|
|
312
|
-
|
|
313
|
-
|
|
306
|
+
const includeTocPath =
|
|
307
|
+
mode === IncludeMode.ROOT_MERGE
|
|
308
|
+
? resolve(sourcesDir, item.include.path)
|
|
309
|
+
: resolve(tocDir, item.include.path);
|
|
314
310
|
const includeTocDir = dirname(includeTocPath);
|
|
315
311
|
|
|
316
312
|
try {
|
|
@@ -332,11 +328,21 @@ async function _replaceIncludes(
|
|
|
332
328
|
|
|
333
329
|
/* Resolve nested toc inclusions */
|
|
334
330
|
const baseTocDir = mode === IncludeMode.LINK ? includeTocDir : tocDir;
|
|
335
|
-
includedTocItems = await processTocItems(
|
|
331
|
+
includedTocItems = await processTocItems(
|
|
332
|
+
path,
|
|
333
|
+
includedTocItems,
|
|
334
|
+
baseTocDir,
|
|
335
|
+
sourcesDir,
|
|
336
|
+
vars,
|
|
337
|
+
);
|
|
336
338
|
|
|
337
339
|
/* Make hrefs relative to the main toc */
|
|
338
340
|
if (mode === IncludeMode.LINK) {
|
|
339
|
-
includedTocItems = _replaceIncludesHrefs(
|
|
341
|
+
includedTocItems = _replaceIncludesHrefs(
|
|
342
|
+
includedTocItems,
|
|
343
|
+
includeTocDir,
|
|
344
|
+
tocDir,
|
|
345
|
+
);
|
|
340
346
|
}
|
|
341
347
|
|
|
342
348
|
if (item.name) {
|
|
@@ -345,9 +351,9 @@ async function _replaceIncludes(
|
|
|
345
351
|
includedInlineItems = includedTocItems;
|
|
346
352
|
}
|
|
347
353
|
} catch (err) {
|
|
348
|
-
const message = (
|
|
349
|
-
|
|
350
|
-
)
|
|
354
|
+
const message = `Error while including toc: ${bold(includeTocPath)} to ${bold(
|
|
355
|
+
join(tocDir, 'toc.yaml'),
|
|
356
|
+
)}`;
|
|
351
357
|
|
|
352
358
|
log.error(message);
|
|
353
359
|
|
|
@@ -375,7 +381,6 @@ function getTocDir(pagePath: string): string {
|
|
|
375
381
|
const tocDir = dirname(pagePath);
|
|
376
382
|
const tocPath = resolve(tocDir, 'toc.yaml');
|
|
377
383
|
|
|
378
|
-
|
|
379
384
|
if (!tocDir.includes(inputFolderPath)) {
|
|
380
385
|
throw new Error('Error while finding toc dir');
|
|
381
386
|
}
|
package/src/services/utils.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import evalExp from '@
|
|
1
|
+
import evalExp from '@diplodoc/transform/lib/liquid/evaluation';
|
|
2
2
|
import {Filter, TextItems} from '../models';
|
|
3
|
-
import liquid from '@
|
|
3
|
+
import liquid from '@diplodoc/transform/lib/liquid';
|
|
4
4
|
import {ArgvService} from './index';
|
|
5
5
|
|
|
6
6
|
export interface FilterFilesOptions {
|
|
@@ -93,14 +93,20 @@ export function firstFilterTextItems(
|
|
|
93
93
|
return filteredItems[0] || '';
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
-
function shouldProcessItem<T extends Filter>(
|
|
96
|
+
function shouldProcessItem<T extends Filter>(
|
|
97
|
+
item: T,
|
|
98
|
+
vars: Record<string, string>,
|
|
99
|
+
options?: FilterFilesOptions,
|
|
100
|
+
) {
|
|
97
101
|
const {resolveConditions, removeHiddenTocItems} = options || {};
|
|
98
102
|
let useItem = true;
|
|
99
103
|
|
|
100
104
|
if (resolveConditions) {
|
|
101
105
|
const {when} = item;
|
|
102
106
|
useItem =
|
|
103
|
-
when === true ||
|
|
107
|
+
when === true ||
|
|
108
|
+
when === undefined ||
|
|
109
|
+
(typeof when === 'string' && evalExp(when, vars));
|
|
104
110
|
|
|
105
111
|
delete item.when;
|
|
106
112
|
}
|
|
@@ -114,7 +120,11 @@ function shouldProcessItem<T extends Filter>(item: T, vars: Record<string, strin
|
|
|
114
120
|
return useItem;
|
|
115
121
|
}
|
|
116
122
|
|
|
117
|
-
export function liquidFields(
|
|
123
|
+
export function liquidFields(
|
|
124
|
+
fields: undefined | string | string[],
|
|
125
|
+
vars: Record<string, unknown>,
|
|
126
|
+
path: string,
|
|
127
|
+
) {
|
|
118
128
|
if (typeof fields === 'string') {
|
|
119
129
|
return liquidField(fields, vars, path);
|
|
120
130
|
}
|
|
@@ -11,18 +11,12 @@ import {copyFiles} from '../utils';
|
|
|
11
11
|
* @return {void}
|
|
12
12
|
*/
|
|
13
13
|
export function processAssets(outputBundlePath: string) {
|
|
14
|
-
const {
|
|
15
|
-
input: inputFolderPath,
|
|
16
|
-
output: outputFolderPath,
|
|
17
|
-
} = ArgvService.getConfig();
|
|
14
|
+
const {input: inputFolderPath, output: outputFolderPath} = ArgvService.getConfig();
|
|
18
15
|
|
|
19
16
|
const assetFilePath: string[] = walkSync(inputFolderPath, {
|
|
20
17
|
directories: false,
|
|
21
18
|
includeBasePath: false,
|
|
22
|
-
ignore: [
|
|
23
|
-
'**/*.yaml',
|
|
24
|
-
'**/*.md',
|
|
25
|
-
],
|
|
19
|
+
ignore: ['**/*.yaml', '**/*.md'],
|
|
26
20
|
});
|
|
27
21
|
|
|
28
22
|
copyFiles(inputFolderPath, outputFolderPath, assetFilePath);
|
|
@@ -10,38 +10,29 @@ import {convertBackSlashToSlash} from '../utils';
|
|
|
10
10
|
* @return {void}
|
|
11
11
|
*/
|
|
12
12
|
export function processExcludedFiles() {
|
|
13
|
-
const {
|
|
14
|
-
input: inputFolderPath,
|
|
15
|
-
output: outputFolderPath,
|
|
16
|
-
ignore,
|
|
17
|
-
} = ArgvService.getConfig();
|
|
13
|
+
const {input: inputFolderPath, output: outputFolderPath, ignore} = ArgvService.getConfig();
|
|
18
14
|
|
|
19
15
|
const allContentFiles: string[] = walkSync(inputFolderPath, {
|
|
20
16
|
directories: false,
|
|
21
17
|
includeBasePath: true,
|
|
22
|
-
globs: [
|
|
23
|
-
'**/*.md',
|
|
24
|
-
'**/index.yaml',
|
|
25
|
-
...ignore,
|
|
26
|
-
],
|
|
18
|
+
globs: ['**/*.md', '**/index.yaml', ...ignore],
|
|
27
19
|
// Ignores service directories like "_includes", "_templates" and etc.
|
|
28
20
|
ignore: ['**/_*/**/*'],
|
|
29
21
|
});
|
|
30
|
-
const navigationPaths = TocService.getNavigationPaths()
|
|
31
|
-
|
|
22
|
+
const navigationPaths = TocService.getNavigationPaths().map((filePath) =>
|
|
23
|
+
convertBackSlashToSlash(resolve(inputFolderPath, filePath)),
|
|
24
|
+
);
|
|
32
25
|
const tocSpecifiedFiles = new Set(navigationPaths);
|
|
33
|
-
const excludedFiles = allContentFiles
|
|
34
|
-
.filter((filePath) => !tocSpecifiedFiles.has(filePath));
|
|
26
|
+
const excludedFiles = allContentFiles.filter((filePath) => !tocSpecifiedFiles.has(filePath));
|
|
35
27
|
|
|
36
28
|
shell.rm('-f', excludedFiles);
|
|
37
29
|
|
|
38
|
-
const includedTocPaths = TocService.getIncludedTocPaths()
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
const destTocPath = resolve(outputFolderPath, relativeTocPath);
|
|
30
|
+
const includedTocPaths = TocService.getIncludedTocPaths().map((filePath) => {
|
|
31
|
+
const relativeTocPath = relative(inputFolderPath, filePath);
|
|
32
|
+
const destTocPath = resolve(outputFolderPath, relativeTocPath);
|
|
42
33
|
|
|
43
|
-
|
|
44
|
-
|
|
34
|
+
return convertBackSlashToSlash(destTocPath);
|
|
35
|
+
});
|
|
45
36
|
|
|
46
37
|
shell.rm('-rf', includedTocPaths);
|
|
47
38
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import log from '@
|
|
1
|
+
import log from '@diplodoc/transform/lib/log';
|
|
2
2
|
import {spawn, Worker, Thread} from 'threads';
|
|
3
3
|
import {extname} from 'path';
|
|
4
4
|
|
|
@@ -10,7 +10,7 @@ import {lintPage} from '../resolvers';
|
|
|
10
10
|
import {splitOnChunks} from '../utils/worker';
|
|
11
11
|
|
|
12
12
|
let processLinterWorkers: (ProcessLinterWorker & Thread)[];
|
|
13
|
-
let navigationPathsChunks:
|
|
13
|
+
let navigationPathsChunks: string[][];
|
|
14
14
|
|
|
15
15
|
export async function processLinter(): Promise<void> {
|
|
16
16
|
const argvConfig = ArgvService.getConfig();
|
|
@@ -70,15 +70,16 @@ export async function initLinterWorkers() {
|
|
|
70
70
|
return;
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
-
navigationPathsChunks = splitOnChunks(navigationPaths, chunkSize)
|
|
74
|
-
.filter((arr) => arr.length);
|
|
73
|
+
navigationPathsChunks = splitOnChunks(navigationPaths, chunkSize).filter((arr) => arr.length);
|
|
75
74
|
|
|
76
75
|
const workersCount = navigationPathsChunks.length;
|
|
77
76
|
|
|
78
|
-
processLinterWorkers = await Promise.all(
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
77
|
+
processLinterWorkers = await Promise.all(
|
|
78
|
+
new Array(workersCount).fill(null).map(() => {
|
|
79
|
+
// TODO: get linter path from env
|
|
80
|
+
return spawn<ProcessLinterWorker>(new Worker('./linter'), {timeout: 60000});
|
|
81
|
+
}),
|
|
82
|
+
);
|
|
82
83
|
}
|
|
83
84
|
|
|
84
85
|
function getChunkSize(arr: string[]) {
|
package/src/steps/processLogs.ts
CHANGED
|
@@ -1,15 +1,10 @@
|
|
|
1
|
-
import log from '@
|
|
1
|
+
import log from '@diplodoc/transform/lib/log';
|
|
2
2
|
import _uniq from 'lodash/uniq';
|
|
3
3
|
|
|
4
4
|
export function processLogs(inputFolder: string) {
|
|
5
5
|
const replacementRegExp = new RegExp(inputFolder, 'ig');
|
|
6
6
|
const {info, warn, error} = log.get();
|
|
7
|
-
const outputLogs = _uniq([
|
|
8
|
-
'', ...info,
|
|
9
|
-
'', ...warn,
|
|
10
|
-
'', ...error,
|
|
11
|
-
'',
|
|
12
|
-
]);
|
|
7
|
+
const outputLogs = _uniq(['', ...info, '', ...warn, '', ...error, '']);
|
|
13
8
|
|
|
14
9
|
for (const outputLog of outputLogs) {
|
|
15
10
|
const preparedLog = outputLog.replace(replacementRegExp, '');
|
|
@@ -13,20 +13,17 @@ type TocItem = {
|
|
|
13
13
|
type TocItems = TocItem[];
|
|
14
14
|
|
|
15
15
|
export function prepareMapFile(): void {
|
|
16
|
-
const {
|
|
17
|
-
output: outputFolderPath,
|
|
18
|
-
} = ArgvService.getConfig();
|
|
16
|
+
const {output: outputFolderPath} = ArgvService.getConfig();
|
|
19
17
|
|
|
20
|
-
const navigationPathsWithoutExtensions =
|
|
21
|
-
|
|
22
|
-
let preparedPath = convertBackSlashToSlash(path.replace(extname(path), ''));
|
|
18
|
+
const navigationPathsWithoutExtensions = TocService.getNavigationPaths().map((path) => {
|
|
19
|
+
let preparedPath = convertBackSlashToSlash(path.replace(extname(path), ''));
|
|
23
20
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
21
|
+
if (preparedPath.endsWith('/index')) {
|
|
22
|
+
preparedPath = preparedPath.substring(0, preparedPath.length - 5);
|
|
23
|
+
}
|
|
27
24
|
|
|
28
|
-
|
|
29
|
-
|
|
25
|
+
return preparedPath;
|
|
26
|
+
});
|
|
30
27
|
const navigationPaths = {files: [...new Set(navigationPathsWithoutExtensions)]};
|
|
31
28
|
const filesMapBuffer = Buffer.from(JSON.stringify(navigationPaths, null, '\t'), 'utf8');
|
|
32
29
|
const mapFile = join(outputFolderPath, 'files.json');
|
|
@@ -6,11 +6,16 @@ import {bold} from 'chalk';
|
|
|
6
6
|
import {dump, load} from 'js-yaml';
|
|
7
7
|
import {mapLimit, asyncify} from 'async';
|
|
8
8
|
|
|
9
|
-
import log from '@
|
|
9
|
+
import log from '@diplodoc/transform/lib/log';
|
|
10
10
|
|
|
11
11
|
import {ArgvService, LeadingService, TocService, PluginService} from '../services';
|
|
12
12
|
import {resolveMd2HTML, resolveMd2Md} from '../resolvers';
|
|
13
|
-
import {
|
|
13
|
+
import {
|
|
14
|
+
generateStaticMarkup,
|
|
15
|
+
joinSinglePageResults,
|
|
16
|
+
logger,
|
|
17
|
+
transformTocForSinglePage,
|
|
18
|
+
} from '../utils';
|
|
14
19
|
import {
|
|
15
20
|
MetaDataOptions,
|
|
16
21
|
SinglePageResult,
|
|
@@ -21,11 +26,7 @@ import {
|
|
|
21
26
|
} from '../models';
|
|
22
27
|
import {VCSConnector} from '../vcs-connector/connector-models';
|
|
23
28
|
import {getVCSConnector} from '../vcs-connector';
|
|
24
|
-
import {
|
|
25
|
-
SINGLE_PAGE_FILENAME,
|
|
26
|
-
SINGLE_PAGE_DATA_FILENAME,
|
|
27
|
-
Lang, ResourceType,
|
|
28
|
-
} from '../constants';
|
|
29
|
+
import {SINGLE_PAGE_FILENAME, SINGLE_PAGE_DATA_FILENAME, Lang, ResourceType} from '../constants';
|
|
29
30
|
|
|
30
31
|
const singlePageResults: Record<string, SinglePageResult[]> = {};
|
|
31
32
|
const singlePagePaths: Record<string, Set<string>> = {};
|
|
@@ -47,15 +48,34 @@ export async function processPages(outputBundlePath: string): Promise<void> {
|
|
|
47
48
|
const navigationPaths = TocService.getNavigationPaths();
|
|
48
49
|
const concurrency = 500;
|
|
49
50
|
|
|
50
|
-
await mapLimit(
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
51
|
+
await mapLimit(
|
|
52
|
+
navigationPaths,
|
|
53
|
+
concurrency,
|
|
54
|
+
asyncify(async (pathToFile: string) => {
|
|
55
|
+
const pathData = getPathData(
|
|
56
|
+
pathToFile,
|
|
57
|
+
inputFolderPath,
|
|
58
|
+
outputFolderPath,
|
|
59
|
+
outputFormat,
|
|
60
|
+
outputBundlePath,
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
logger.proc(pathToFile);
|
|
64
|
+
|
|
65
|
+
const metaDataOptions = getMetaDataOptions(
|
|
66
|
+
pathData,
|
|
67
|
+
inputFolderPath.length,
|
|
68
|
+
vcsConnector,
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
await preparingPagesByOutputFormat(
|
|
72
|
+
pathData,
|
|
73
|
+
metaDataOptions,
|
|
74
|
+
resolveConditions,
|
|
75
|
+
singlePage,
|
|
76
|
+
);
|
|
77
|
+
}),
|
|
78
|
+
);
|
|
59
79
|
|
|
60
80
|
if (singlePage) {
|
|
61
81
|
await saveSinglePages(outputBundlePath);
|
|
@@ -106,44 +126,50 @@ async function saveSinglePages(outputBundlePath: string) {
|
|
|
106
126
|
} = ArgvService.getConfig();
|
|
107
127
|
|
|
108
128
|
try {
|
|
109
|
-
await Promise.all(
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
129
|
+
await Promise.all(
|
|
130
|
+
Object.keys(singlePageResults).map(async (tocDir) => {
|
|
131
|
+
if (!singlePageResults[tocDir].length) {
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
113
134
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
135
|
+
const singlePageBody = joinSinglePageResults(
|
|
136
|
+
singlePageResults[tocDir],
|
|
137
|
+
inputFolderPath,
|
|
138
|
+
tocDir,
|
|
139
|
+
);
|
|
140
|
+
const tocPath = join(relative(inputFolderPath, tocDir), 'toc.yaml');
|
|
141
|
+
const toc: YfmToc | null = TocService.getForPath(tocPath) || null;
|
|
142
|
+
const preparedToc = transformTocForSinglePage(toc, {
|
|
143
|
+
root: inputFolderPath,
|
|
144
|
+
currentPath: join(tocDir, SINGLE_PAGE_FILENAME),
|
|
145
|
+
}) as YfmToc;
|
|
146
|
+
|
|
147
|
+
const pageData = {
|
|
148
|
+
data: {
|
|
149
|
+
leading: false as const,
|
|
150
|
+
html: singlePageBody,
|
|
151
|
+
headings: [],
|
|
152
|
+
meta: resources || {},
|
|
153
|
+
toc: preparedToc,
|
|
154
|
+
},
|
|
155
|
+
router: {
|
|
156
|
+
pathname: SINGLE_PAGE_FILENAME,
|
|
157
|
+
},
|
|
158
|
+
lang: lang || Lang.RU,
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
const outputTocDir = resolve(outputFolderPath, relative(inputFolderPath, tocDir));
|
|
162
|
+
const relativeOutputBundlePath = relative(outputTocDir, outputBundlePath);
|
|
163
|
+
|
|
164
|
+
// Save the full single page for viewing locally
|
|
165
|
+
const singlePageFn = join(tocDir, SINGLE_PAGE_FILENAME);
|
|
166
|
+
const singlePageDataFn = join(tocDir, SINGLE_PAGE_DATA_FILENAME);
|
|
167
|
+
const singlePageContent = generateStaticMarkup(pageData, relativeOutputBundlePath);
|
|
168
|
+
|
|
169
|
+
writeFileSync(singlePageFn, singlePageContent);
|
|
170
|
+
writeFileSync(singlePageDataFn, JSON.stringify(pageData));
|
|
171
|
+
}),
|
|
172
|
+
);
|
|
147
173
|
} catch (error) {
|
|
148
174
|
console.log(error);
|
|
149
175
|
}
|
|
@@ -172,7 +198,10 @@ function savePageResultForSinglePage(pageProps: DocInnerProps, pathData: PathDat
|
|
|
172
198
|
});
|
|
173
199
|
}
|
|
174
200
|
|
|
175
|
-
function getMetaDataOptions(
|
|
201
|
+
function getMetaDataOptions(
|
|
202
|
+
pathData: PathData,
|
|
203
|
+
inputFolderPathLength: number,
|
|
204
|
+
vcsConnector?: VCSConnector,
|
|
176
205
|
): MetaDataOptions {
|
|
177
206
|
const {contributors, addSystemMeta, resources, allowCustomResources} = ArgvService.getConfig();
|
|
178
207
|
|
|
@@ -187,7 +216,6 @@ function getMetaDataOptions(pathData: PathData, inputFolderPathLength: number, v
|
|
|
187
216
|
addSystemMeta,
|
|
188
217
|
};
|
|
189
218
|
|
|
190
|
-
|
|
191
219
|
if (allowCustomResources && resources) {
|
|
192
220
|
const allowedResources = Object.entries(resources).reduce((acc: Resources, [key, val]) => {
|
|
193
221
|
if (Object.keys(ResourceType).includes(key)) {
|
|
@@ -199,7 +227,6 @@ function getMetaDataOptions(pathData: PathData, inputFolderPathLength: number, v
|
|
|
199
227
|
metaDataOptions.resources = allowedResources;
|
|
200
228
|
}
|
|
201
229
|
|
|
202
|
-
|
|
203
230
|
return metaDataOptions;
|
|
204
231
|
}
|
|
205
232
|
|
|
@@ -234,8 +261,10 @@ async function preparingPagesByOutputFormat(
|
|
|
234
261
|
return;
|
|
235
262
|
}
|
|
236
263
|
|
|
237
|
-
if (
|
|
238
|
-
outputFormat === '
|
|
264
|
+
if (
|
|
265
|
+
(outputFormat === 'md' && isYamlFileExtension) ||
|
|
266
|
+
(outputFormat === 'html' && !isYamlFileExtension && fileExtension !== '.md')
|
|
267
|
+
) {
|
|
239
268
|
copyFileWithoutChanges(resolvedPathToFile, outputDir, filename);
|
|
240
269
|
return;
|
|
241
270
|
}
|
|
@@ -275,7 +304,11 @@ function processingYamlFile(path: PathData, metaDataOptions: MetaDataOptions) {
|
|
|
275
304
|
writeFileSync(resolve(outputFolderPath, pathToFile), dump(parsedContent));
|
|
276
305
|
}
|
|
277
306
|
|
|
278
|
-
function copyFileWithoutChanges(
|
|
307
|
+
function copyFileWithoutChanges(
|
|
308
|
+
resolvedPathToFile: string,
|
|
309
|
+
outputDir: string,
|
|
310
|
+
filename: string,
|
|
311
|
+
): void {
|
|
279
312
|
const from = resolvedPathToFile;
|
|
280
313
|
const to = resolve(outputDir, filename);
|
|
281
314
|
|
|
@@ -292,14 +325,11 @@ async function processingFileToMd(path: PathData, metaDataOptions: MetaDataOptio
|
|
|
292
325
|
});
|
|
293
326
|
}
|
|
294
327
|
|
|
295
|
-
async function processingFileToHtml(
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
outputPath,
|
|
301
|
-
pathToFile,
|
|
302
|
-
} = path;
|
|
328
|
+
async function processingFileToHtml(
|
|
329
|
+
path: PathData,
|
|
330
|
+
metaDataOptions: MetaDataOptions,
|
|
331
|
+
): Promise<DocInnerProps> {
|
|
332
|
+
const {outputBundlePath, filename, fileExtension, outputPath, pathToFile} = path;
|
|
303
333
|
|
|
304
334
|
return resolveMd2HTML({
|
|
305
335
|
inputPath: pathToFile,
|
|
@@ -2,7 +2,7 @@ import {dirname, resolve} from 'path';
|
|
|
2
2
|
import walkSync from 'walk-sync';
|
|
3
3
|
import {readFileSync, writeFileSync} from 'fs';
|
|
4
4
|
import {load, dump} from 'js-yaml';
|
|
5
|
-
import log from '@
|
|
5
|
+
import log from '@diplodoc/transform/lib/log';
|
|
6
6
|
|
|
7
7
|
import {ArgvService, PresetService, TocService} from '../services';
|
|
8
8
|
import {logger} from '../utils';
|
|
@@ -79,7 +79,9 @@ function saveFilteredPresets(path: string, parsedPreset: DocPreset): void {
|
|
|
79
79
|
writeFileSync(outputPath, outputPreset);
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
-
async function preparingTocFiles(
|
|
82
|
+
async function preparingTocFiles(
|
|
83
|
+
getFilePathsByGlobals: GetFilePathsByGlobalsFunction,
|
|
84
|
+
): Promise<void> {
|
|
83
85
|
try {
|
|
84
86
|
const tocFilePaths = getFilePathsByGlobals(['**/toc.yaml']);
|
|
85
87
|
|
|
@@ -21,7 +21,9 @@ export async function publishFilesToS3(): Promise<void> {
|
|
|
21
21
|
} = ArgvService.getConfig();
|
|
22
22
|
|
|
23
23
|
const s3Client = new S3({
|
|
24
|
-
endpoint,
|
|
24
|
+
endpoint,
|
|
25
|
+
accessKeyId,
|
|
26
|
+
secretAccessKey,
|
|
25
27
|
});
|
|
26
28
|
|
|
27
29
|
const filesToPublish: string[] = walkSync(resolve(outputFolderPath), {
|
|
@@ -30,18 +32,20 @@ export async function publishFilesToS3(): Promise<void> {
|
|
|
30
32
|
ignore,
|
|
31
33
|
});
|
|
32
34
|
|
|
33
|
-
await Promise.all(
|
|
34
|
-
|
|
35
|
+
await Promise.all(
|
|
36
|
+
filesToPublish.map(async (pathToFile) => {
|
|
37
|
+
const mimeType = mime.lookup(pathToFile);
|
|
35
38
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
39
|
+
const params: S3.Types.PutObjectRequest = {
|
|
40
|
+
ContentType: mimeType ? mimeType : undefined,
|
|
41
|
+
Bucket: bucket,
|
|
42
|
+
Key: convertBackSlashToSlash(join(prefix, pathToFile)),
|
|
43
|
+
Body: readFileSync(resolve(outputFolderPath, pathToFile)),
|
|
44
|
+
};
|
|
42
45
|
|
|
43
|
-
|
|
46
|
+
logger.upload(pathToFile);
|
|
44
47
|
|
|
45
|
-
|
|
46
|
-
|
|
48
|
+
return s3Client.upload(params).promise();
|
|
49
|
+
}),
|
|
50
|
+
);
|
|
47
51
|
}
|
package/src/utils/file.ts
CHANGED
|
@@ -3,7 +3,11 @@ import shell from 'shelljs';
|
|
|
3
3
|
import {copyFileSync} from 'fs';
|
|
4
4
|
import {logger} from './logger';
|
|
5
5
|
|
|
6
|
-
export function copyFiles(
|
|
6
|
+
export function copyFiles(
|
|
7
|
+
inputFolderPath: string,
|
|
8
|
+
outputFolderPath: string,
|
|
9
|
+
files: string[],
|
|
10
|
+
): void {
|
|
7
11
|
for (const pathToAsset of files) {
|
|
8
12
|
const outputDir: string = resolve(outputFolderPath, dirname(pathToAsset));
|
|
9
13
|
const from = resolve(inputFolderPath, pathToAsset);
|
package/src/utils/glob.ts
CHANGED
|
@@ -4,9 +4,7 @@ export type Glob = {state: IGlob};
|
|
|
4
4
|
|
|
5
5
|
const glob = async (pattern: string, options: IOptions): Promise<Glob> =>
|
|
6
6
|
new Promise((res, rej) => {
|
|
7
|
-
const state: IGlob = libglob(pattern, options, (err) =>
|
|
8
|
-
err ? rej(err) : res({state}),
|
|
9
|
-
);
|
|
7
|
+
const state: IGlob = libglob(pattern, options, (err) => (err ? rej(err) : res({state})));
|
|
10
8
|
});
|
|
11
9
|
|
|
12
10
|
export {glob};
|
package/src/utils/logger.ts
CHANGED