@diplodoc/cli 4.7.0 → 4.8.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/assets/app.css +4 -0
- package/assets/app.js +2 -0
- package/assets/react.js +3 -0
- package/{build/app.client.css → assets/vendor.css} +857 -19
- package/assets/vendor.js +3 -0
- package/build/index.js +203 -230
- package/build/index.js.map +4 -4
- package/build/linter.js +79 -111
- package/build/linter.js.map +4 -4
- package/package.json +8 -23
- package/src/cmd/publish/index.ts +16 -4
- package/src/constants.ts +4 -6
- package/src/resolvers/md2html.ts +4 -0
- package/src/steps/processAssets.ts +3 -5
- package/src/utils/markup.ts +18 -7
- package/src/utils/path.ts +0 -8
- package/src/utils/singlePage.ts +10 -5
- package/build/app.client.js +0 -3
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.8.0",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
9
9
|
"url": "git@github.com:diplodoc-platform/cli.git"
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
"main": "build/index.js",
|
|
15
15
|
"files": [
|
|
16
16
|
"build",
|
|
17
|
+
"assets",
|
|
17
18
|
"src"
|
|
18
19
|
],
|
|
19
20
|
"scripts": {
|
|
@@ -21,20 +22,21 @@
|
|
|
21
22
|
"start": "node build/index.js",
|
|
22
23
|
"lint": "eslint \"src/**/*.{js,jsx,ts,tsx}\"",
|
|
23
24
|
"lint:fix": "npm run lint -- --fix",
|
|
25
|
+
"typecheck": "tsc --noEmit",
|
|
24
26
|
"prepublishOnly": "npm run lint && npm run build",
|
|
25
27
|
"git:head": "git checkout master && git pull"
|
|
26
28
|
},
|
|
27
29
|
"engines": {
|
|
28
|
-
"node": ">=18.*"
|
|
29
|
-
"npm:": ">=9.*"
|
|
30
|
+
"node": ">=18.*"
|
|
30
31
|
},
|
|
31
32
|
"dependencies": {
|
|
32
33
|
"@aws-sdk/client-s3": "^3.369.0",
|
|
33
|
-
"@diplodoc/client": "^
|
|
34
|
+
"@diplodoc/client": "^2.0.0",
|
|
35
|
+
"@diplodoc/latex-extension": "^1.0.2",
|
|
34
36
|
"@diplodoc/markdown-translation": "^1.0.4",
|
|
35
37
|
"@diplodoc/mermaid-extension": "^1.2.1",
|
|
36
38
|
"@diplodoc/openapi-extension": "^1.4.10",
|
|
37
|
-
"@diplodoc/transform": "^4.
|
|
39
|
+
"@diplodoc/transform": "^4.8.1",
|
|
38
40
|
"@octokit/core": "4.2.4",
|
|
39
41
|
"@yandex-cloud/nodejs-sdk": "^2.2.2",
|
|
40
42
|
"ajv": "^8.11.0",
|
|
@@ -92,20 +94,6 @@
|
|
|
92
94
|
"git add"
|
|
93
95
|
]
|
|
94
96
|
},
|
|
95
|
-
"pkg": {
|
|
96
|
-
"scripts": [
|
|
97
|
-
"build/index.js",
|
|
98
|
-
"build/linter.js",
|
|
99
|
-
"build/plugins/*.js",
|
|
100
|
-
"build/lint-rules/*.js",
|
|
101
|
-
"build/default-lint-config.js",
|
|
102
|
-
"build/head-content.js"
|
|
103
|
-
],
|
|
104
|
-
"assets": [
|
|
105
|
-
"build/app.client.js",
|
|
106
|
-
"build/app.client.css"
|
|
107
|
-
]
|
|
108
|
-
},
|
|
109
97
|
"keywords": [
|
|
110
98
|
"markdown",
|
|
111
99
|
"yandex",
|
|
@@ -115,8 +103,5 @@
|
|
|
115
103
|
"tool",
|
|
116
104
|
"tools",
|
|
117
105
|
"generator"
|
|
118
|
-
]
|
|
119
|
-
"overrides": {
|
|
120
|
-
"markdown-it": "^13.0.2"
|
|
121
|
-
}
|
|
106
|
+
]
|
|
122
107
|
}
|
package/src/cmd/publish/index.ts
CHANGED
|
@@ -67,19 +67,31 @@ function builder<T>(argv: Argv<T>) {
|
|
|
67
67
|
});
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
+
type Args = {
|
|
71
|
+
input: string;
|
|
72
|
+
endpoint: string;
|
|
73
|
+
region: string;
|
|
74
|
+
bucket: string;
|
|
75
|
+
prefix: string;
|
|
76
|
+
ignore: string[];
|
|
77
|
+
accessKeyId: string;
|
|
78
|
+
secretAccessKey: string;
|
|
79
|
+
};
|
|
80
|
+
|
|
70
81
|
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
|
|
71
|
-
async function handler(args: Arguments<
|
|
82
|
+
async function handler(args: Arguments<Args>) {
|
|
72
83
|
ArgvService.init({
|
|
73
84
|
...args,
|
|
74
85
|
});
|
|
75
86
|
|
|
76
|
-
const
|
|
87
|
+
const config = ArgvService.getConfig() as unknown as Args;
|
|
88
|
+
const {input, endpoint, bucket, prefix} = config;
|
|
77
89
|
|
|
78
90
|
logger.info('', `Upload artifacts from ${input} to ${join(endpoint, bucket, prefix)}`);
|
|
79
91
|
|
|
80
92
|
try {
|
|
81
|
-
await upload(
|
|
82
|
-
} catch (error) {
|
|
93
|
+
await upload(config);
|
|
94
|
+
} catch (error: any) {
|
|
83
95
|
logger.error('', error.message);
|
|
84
96
|
}
|
|
85
97
|
}
|
package/src/constants.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {resolve} from 'path';
|
|
2
2
|
const os = require('os');
|
|
3
3
|
const notes = require('@diplodoc/transform/lib/plugins/notes');
|
|
4
4
|
const anchors = require('@diplodoc/transform/lib/plugins/anchors');
|
|
@@ -19,16 +19,15 @@ const term = require('@diplodoc/transform/lib/plugins/term');
|
|
|
19
19
|
const blockAnchor = require('@diplodoc/transform/lib/plugins/block-anchor');
|
|
20
20
|
const changelog = require('@diplodoc/transform/lib/plugins/changelog');
|
|
21
21
|
const mermaid = require('@diplodoc/mermaid-extension');
|
|
22
|
+
const latex = require('@diplodoc/latex-extension');
|
|
22
23
|
const openapi = require('@diplodoc/openapi-extension');
|
|
23
24
|
|
|
24
25
|
includes.collect = require('@diplodoc/transform/lib/plugins/includes/collect');
|
|
25
26
|
images.collect = require('@diplodoc/transform/lib/plugins/images/collect');
|
|
26
27
|
changelog.collect = require('@diplodoc/transform/lib/plugins/changelog/collect');
|
|
27
28
|
|
|
28
|
-
export const
|
|
29
|
+
export const ASSETS_FOLDER = resolve(__dirname, '../assets');
|
|
29
30
|
export const BUNDLE_FOLDER = '_bundle';
|
|
30
|
-
export const BUNDLE_JS_FILENAME = 'app.client.js';
|
|
31
|
-
export const BUNDLE_CSS_FILENAME = 'app.client.css';
|
|
32
31
|
export const TMP_INPUT_FOLDER = '.tmp_input';
|
|
33
32
|
export const TMP_OUTPUT_FOLDER = '.tmp_output';
|
|
34
33
|
export const MAIN_TIMER_ID = 'Build time';
|
|
@@ -68,8 +67,6 @@ export enum ResourceType {
|
|
|
68
67
|
script = 'script',
|
|
69
68
|
}
|
|
70
69
|
|
|
71
|
-
export const BUILD_FOLDER_PATH = dirname(require.resolve('@diplodoc/client'));
|
|
72
|
-
|
|
73
70
|
export const YFM_PLUGINS = [
|
|
74
71
|
meta,
|
|
75
72
|
deflist,
|
|
@@ -89,6 +86,7 @@ export const YFM_PLUGINS = [
|
|
|
89
86
|
term,
|
|
90
87
|
openapi.transform(),
|
|
91
88
|
mermaid.transform(),
|
|
89
|
+
latex.transform(),
|
|
92
90
|
changelog,
|
|
93
91
|
blockAnchor,
|
|
94
92
|
];
|
package/src/resolvers/md2html.ts
CHANGED
|
@@ -50,6 +50,10 @@ export async function resolveMd2HTML(options: ResolverOptions): Promise<ResolveM
|
|
|
50
50
|
const transformFn: Function = FileTransformer[fileExtension];
|
|
51
51
|
const {result} = transformFn(content, {path: inputPath});
|
|
52
52
|
|
|
53
|
+
if (result.html) {
|
|
54
|
+
result.html = result.html.replace(/\n+/gm, '');
|
|
55
|
+
}
|
|
56
|
+
|
|
53
57
|
const updatedMetadata =
|
|
54
58
|
metadata && metadata.isContributorsEnabled
|
|
55
59
|
? await getUpdatedMetadata(metadata, content, result?.meta)
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import walkSync from 'walk-sync';
|
|
2
2
|
import shell from 'shelljs';
|
|
3
3
|
|
|
4
|
-
import client from '../../scripts/client';
|
|
5
4
|
import {ArgvService} from '../services';
|
|
6
5
|
import {copyFiles} from '../utils';
|
|
7
6
|
|
|
7
|
+
import {ASSETS_FOLDER} from '../constants';
|
|
8
|
+
|
|
8
9
|
/**
|
|
9
10
|
* Processes assets files (everything except .yaml and .md files)
|
|
10
11
|
* @param {string} outputBundlePath
|
|
@@ -23,8 +24,5 @@ export function processAssets(outputBundlePath: string) {
|
|
|
23
24
|
|
|
24
25
|
/* Copy js bundle to user' output folder */
|
|
25
26
|
shell.mkdir('-p', outputBundlePath);
|
|
26
|
-
|
|
27
|
-
for (const path of Object.values(client.dst)) {
|
|
28
|
-
shell.cp(path, outputBundlePath);
|
|
29
|
-
}
|
|
27
|
+
shell.cp(ASSETS_FOLDER + '/*', outputBundlePath);
|
|
30
28
|
}
|
package/src/utils/markup.ts
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
|
+
import {join} from 'path';
|
|
1
2
|
import {platform} from 'process';
|
|
2
3
|
|
|
3
4
|
import {CUSTOM_STYLE, Platforms, ResourceType} from '../constants';
|
|
4
5
|
import {Resources, SinglePageResult} from '../models';
|
|
5
6
|
import {ArgvService, PluginService} from '../services';
|
|
6
7
|
import {preprocessPageHtmlForSinglePage} from './singlePage';
|
|
7
|
-
|
|
8
|
-
import
|
|
8
|
+
|
|
9
|
+
import {DocInnerProps, DocPageData, render} from '@diplodoc/client/ssr';
|
|
10
|
+
import manifest from '@diplodoc/client/manifest';
|
|
11
|
+
|
|
12
|
+
const dst = (bundlePath: string) => (target: string) => join(bundlePath, target);
|
|
9
13
|
|
|
10
14
|
export interface TitleMeta {
|
|
11
15
|
title?: string;
|
|
@@ -44,7 +48,10 @@ export function generateStaticMarkup(
|
|
|
44
48
|
height: 100vh;
|
|
45
49
|
}
|
|
46
50
|
</style>
|
|
47
|
-
|
|
51
|
+
${manifest.css
|
|
52
|
+
.map(dst(pathToBundle))
|
|
53
|
+
.map((src: string) => `<link type="text/css" rel="stylesheet" href="${src}" />`)
|
|
54
|
+
.join('\n')}
|
|
48
55
|
${PluginService.getHeadContent()}
|
|
49
56
|
${resources}
|
|
50
57
|
</head>
|
|
@@ -54,9 +61,13 @@ export function generateStaticMarkup(
|
|
|
54
61
|
window.STATIC_CONTENT = ${staticContent}
|
|
55
62
|
window.__DATA__ = ${JSON.stringify(props)};
|
|
56
63
|
</script>
|
|
57
|
-
|
|
58
|
-
pathToBundle
|
|
59
|
-
|
|
64
|
+
${manifest.js
|
|
65
|
+
.map(dst(pathToBundle))
|
|
66
|
+
.map(
|
|
67
|
+
(src: string) =>
|
|
68
|
+
`<script type="application/javascript" src="${src}"></script>`,
|
|
69
|
+
)
|
|
70
|
+
.join('\n')}
|
|
60
71
|
</body>
|
|
61
72
|
</html>
|
|
62
73
|
`;
|
|
@@ -126,7 +137,7 @@ export function joinSinglePageResults(
|
|
|
126
137
|
root: string,
|
|
127
138
|
tocDir: string,
|
|
128
139
|
): string {
|
|
129
|
-
const delimeter =
|
|
140
|
+
const delimeter = `<hr class="yfm-page__delimeter">`;
|
|
130
141
|
return singlePageResults
|
|
131
142
|
.filter(({content}) => content)
|
|
132
143
|
.map(({content, path, title}) =>
|
package/src/utils/path.ts
CHANGED
|
@@ -14,11 +14,3 @@ export function convertBackSlashToSlash(path: string): string {
|
|
|
14
14
|
|
|
15
15
|
return path;
|
|
16
16
|
}
|
|
17
|
-
|
|
18
|
-
export function convertSlashToWindowsBackSlashes(path: string): string {
|
|
19
|
-
if (process.platform === Platforms.WINDOWS) {
|
|
20
|
-
return path.replace(/\//g, '\\\\');
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
return path;
|
|
24
|
-
}
|
package/src/utils/singlePage.ts
CHANGED
|
@@ -3,7 +3,7 @@ import {parse} from 'node-html-parser';
|
|
|
3
3
|
import {relative, resolve, sep} from 'path';
|
|
4
4
|
import {resolveRelativePath} from '@diplodoc/transform/lib/utilsFS';
|
|
5
5
|
import url from 'url';
|
|
6
|
-
import
|
|
6
|
+
import escape from 'lodash/escapeRegExp';
|
|
7
7
|
|
|
8
8
|
import {isExternalHref} from './url';
|
|
9
9
|
|
|
@@ -22,6 +22,11 @@ interface PreprocessSinglePageOptions {
|
|
|
22
22
|
|
|
23
23
|
const HEADERS_SELECTOR = 'h1, h2, h3, h4, h5, h6';
|
|
24
24
|
|
|
25
|
+
function toUrl(path: string) {
|
|
26
|
+
// replace windows backslashes
|
|
27
|
+
return path.replace(new RegExp(escape(sep), 'g'), '/');
|
|
28
|
+
}
|
|
29
|
+
|
|
25
30
|
function getNewNode(options: ModifyNode): HTMLElement | null {
|
|
26
31
|
const {rawTagName, innerHTML, attrEntries} = options;
|
|
27
32
|
|
|
@@ -92,7 +97,7 @@ export function replaceLinks(rootEl: HTMLElement, options: PreprocessSinglePageO
|
|
|
92
97
|
}
|
|
93
98
|
}
|
|
94
99
|
|
|
95
|
-
node.setAttribute('href', preparedHref);
|
|
100
|
+
node.setAttribute('href', toUrl(preparedHref));
|
|
96
101
|
});
|
|
97
102
|
}
|
|
98
103
|
|
|
@@ -110,7 +115,7 @@ export function replaceImages(rootEl: HTMLElement, options: PreprocessSinglePage
|
|
|
110
115
|
const linkFullPath = resolveRelativePath(resolvedPath, href);
|
|
111
116
|
const preparedHref = relative(tocDir, linkFullPath);
|
|
112
117
|
|
|
113
|
-
node.setAttribute('src', preparedHref);
|
|
118
|
+
node.setAttribute('src', toUrl(preparedHref));
|
|
114
119
|
});
|
|
115
120
|
}
|
|
116
121
|
|
|
@@ -129,7 +134,7 @@ function prepareAnchorAttrs(node: HTMLElement, pageId: string) {
|
|
|
129
134
|
for (const [name, value] of Object.entries(node.attributes)) {
|
|
130
135
|
const preparedValue = prepareAnchorAttr(name, value, pageId);
|
|
131
136
|
|
|
132
|
-
node.setAttribute(name, preparedValue);
|
|
137
|
+
node.setAttribute(name, toUrl(preparedValue));
|
|
133
138
|
}
|
|
134
139
|
}
|
|
135
140
|
|
|
@@ -197,7 +202,7 @@ export function getSinglePageAnchorId(args: {
|
|
|
197
202
|
resultAnchor = resultAnchor
|
|
198
203
|
.replace(root, '')
|
|
199
204
|
.replace(/\.(md|ya?ml|html)$/i, '')
|
|
200
|
-
.replace(new RegExp(
|
|
205
|
+
.replace(new RegExp(escape(sep), 'gi'), '_');
|
|
201
206
|
|
|
202
207
|
if (hash) {
|
|
203
208
|
resultAnchor = resultAnchor + '_' + hash.slice(1);
|