@docusaurus/plugin-content-docs 0.0.0-4838 → 0.0.0-4841
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/lib/cli.d.ts +3 -2
- package/lib/cli.js +34 -12
- package/lib/index.js +2 -7
- package/lib/versions.d.ts +6 -0
- package/lib/versions.js +2 -1
- package/package.json +9 -9
- package/src/cli.ts +51 -21
- package/src/index.ts +2 -7
- package/src/versions.ts +2 -2
package/lib/cli.d.ts
CHANGED
|
@@ -4,5 +4,6 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
import type {
|
|
8
|
-
|
|
7
|
+
import type { PluginOptions } from '@docusaurus/plugin-content-docs';
|
|
8
|
+
import type { LoadContext } from '@docusaurus/types';
|
|
9
|
+
export declare function cliDocsVersionCommand(version: string | null | undefined, { id: pluginId, path: docsPath, sidebarPath }: PluginOptions, { siteDir, i18n }: LoadContext): Promise<void>;
|
package/lib/cli.js
CHANGED
|
@@ -12,6 +12,7 @@ const versions_1 = require("./versions");
|
|
|
12
12
|
const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
|
|
13
13
|
const path_1 = tslib_1.__importDefault(require("path"));
|
|
14
14
|
const sidebars_1 = require("./sidebars");
|
|
15
|
+
const constants_1 = require("./constants");
|
|
15
16
|
const utils_1 = require("@docusaurus/utils");
|
|
16
17
|
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
17
18
|
async function createVersionedSidebarFile({ siteDir, pluginId, sidebarPath, version, }) {
|
|
@@ -30,7 +31,7 @@ async function createVersionedSidebarFile({ siteDir, pluginId, sidebarPath, vers
|
|
|
30
31
|
}
|
|
31
32
|
}
|
|
32
33
|
// Tests depend on non-default export for mocking.
|
|
33
|
-
async function cliDocsVersionCommand(version,
|
|
34
|
+
async function cliDocsVersionCommand(version, { id: pluginId, path: docsPath, sidebarPath }, { siteDir, i18n }) {
|
|
34
35
|
// It wouldn't be very user-friendly to show a [default] log prefix,
|
|
35
36
|
// so we use [docs] instead of [default]
|
|
36
37
|
const pluginIdLogPrefix = pluginId === utils_1.DEFAULT_PLUGIN_ID ? '[docs]' : `[${pluginId}]`;
|
|
@@ -62,18 +63,39 @@ async function cliDocsVersionCommand(version, siteDir, pluginId, options) {
|
|
|
62
63
|
if (versions.includes(version)) {
|
|
63
64
|
throw new Error(`${pluginIdLogPrefix}: this version already exists! Use a version tag that does not already exist.`);
|
|
64
65
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
const docsDir = path_1.default.resolve(siteDir, docsPath);
|
|
68
|
-
if ((await fs_extra_1.default.pathExists(docsDir)) &&
|
|
69
|
-
(await fs_extra_1.default.readdir(docsDir)).length > 0) {
|
|
70
|
-
const versionedDir = (0, versions_1.getVersionedDocsDirPath)(siteDir, pluginId);
|
|
71
|
-
const newVersionDir = path_1.default.join(versionedDir, `version-${version}`);
|
|
72
|
-
await fs_extra_1.default.copy(docsDir, newVersionDir);
|
|
73
|
-
}
|
|
74
|
-
else {
|
|
75
|
-
throw new Error(`${pluginIdLogPrefix}: no docs found in ${docsDir}.`);
|
|
66
|
+
if (i18n.locales.length > 1) {
|
|
67
|
+
logger_1.default.info `Versioned docs will be created for the following locales: name=${i18n.locales}`;
|
|
76
68
|
}
|
|
69
|
+
await Promise.all(i18n.locales.map(async (locale) => {
|
|
70
|
+
// Copy docs files.
|
|
71
|
+
const docsDir = locale === i18n.defaultLocale
|
|
72
|
+
? path_1.default.resolve(siteDir, docsPath)
|
|
73
|
+
: (0, versions_1.getDocsDirPathLocalized)({
|
|
74
|
+
siteDir,
|
|
75
|
+
locale,
|
|
76
|
+
pluginId,
|
|
77
|
+
versionName: constants_1.CURRENT_VERSION_NAME,
|
|
78
|
+
});
|
|
79
|
+
if (!(await fs_extra_1.default.pathExists(docsDir)) ||
|
|
80
|
+
(await fs_extra_1.default.readdir(docsDir)).length === 0) {
|
|
81
|
+
if (locale === i18n.defaultLocale) {
|
|
82
|
+
throw new Error(logger_1.default.interpolate `${pluginIdLogPrefix}: no docs found in path=${docsDir}.`);
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
logger_1.default.warn `${pluginIdLogPrefix}: no docs found in path=${docsDir}. Skipping.`;
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
const newVersionDir = locale === i18n.defaultLocale
|
|
90
|
+
? path_1.default.join((0, versions_1.getVersionedDocsDirPath)(siteDir, pluginId), `version-${version}`)
|
|
91
|
+
: (0, versions_1.getDocsDirPathLocalized)({
|
|
92
|
+
siteDir,
|
|
93
|
+
locale,
|
|
94
|
+
pluginId,
|
|
95
|
+
versionName: version,
|
|
96
|
+
});
|
|
97
|
+
await fs_extra_1.default.copy(docsDir, newVersionDir);
|
|
98
|
+
}));
|
|
77
99
|
await createVersionedSidebarFile({
|
|
78
100
|
siteDir,
|
|
79
101
|
pluginId,
|
package/lib/index.js
CHANGED
|
@@ -27,7 +27,7 @@ const categoryGeneratedIndex_1 = require("./categoryGeneratedIndex");
|
|
|
27
27
|
async function pluginContentDocs(context, options) {
|
|
28
28
|
const { siteDir, generatedFilesDir, baseUrl, siteConfig } = context;
|
|
29
29
|
const versionsMetadata = await (0, versions_1.readVersionsMetadata)({ context, options });
|
|
30
|
-
const pluginId = options.id
|
|
30
|
+
const pluginId = options.id;
|
|
31
31
|
const pluginDataDirRoot = path_1.default.join(generatedFilesDir, 'docusaurus-plugin-content-docs');
|
|
32
32
|
const dataDir = path_1.default.join(pluginDataDirRoot, pluginId);
|
|
33
33
|
const aliasedSource = (source) => `~docs/${(0, utils_1.posixPath)(path_1.default.relative(pluginDataDirRoot, source))}`;
|
|
@@ -48,12 +48,7 @@ async function pluginContentDocs(context, options) {
|
|
|
48
48
|
.arguments('<version>')
|
|
49
49
|
.description(commandDescription)
|
|
50
50
|
.action((version) => {
|
|
51
|
-
(0, cli_1.cliDocsVersionCommand)(version,
|
|
52
|
-
path: options.path,
|
|
53
|
-
sidebarPath: options.sidebarPath,
|
|
54
|
-
sidebarCollapsed: options.sidebarCollapsed,
|
|
55
|
-
sidebarCollapsible: options.sidebarCollapsible,
|
|
56
|
-
});
|
|
51
|
+
(0, cli_1.cliDocsVersionCommand)(version, options, context);
|
|
57
52
|
});
|
|
58
53
|
},
|
|
59
54
|
getTranslationFiles({ content }) {
|
package/lib/versions.d.ts
CHANGED
|
@@ -11,6 +11,12 @@ export declare function getVersionedSidebarsDirPath(siteDir: string, pluginId: s
|
|
|
11
11
|
export declare function getVersionsFilePath(siteDir: string, pluginId: string): string;
|
|
12
12
|
export declare function readVersionsFile(siteDir: string, pluginId: string): Promise<string[] | null>;
|
|
13
13
|
export declare function readVersionNames(siteDir: string, options: Pick<PluginOptions, 'id' | 'disableVersioning' | 'includeCurrentVersion'>): Promise<string[]>;
|
|
14
|
+
export declare function getDocsDirPathLocalized({ siteDir, locale, pluginId, versionName, }: {
|
|
15
|
+
siteDir: string;
|
|
16
|
+
locale: string;
|
|
17
|
+
pluginId: string;
|
|
18
|
+
versionName: string;
|
|
19
|
+
}): string;
|
|
14
20
|
export declare function getDefaultVersionBanner({ versionName, versionNames, lastVersionName, }: {
|
|
15
21
|
versionName: string;
|
|
16
22
|
versionNames: string[];
|
package/lib/versions.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.readVersionsMetadata = exports.filterVersions = exports.getVersionBadge = exports.getVersionBanner = exports.getDefaultVersionBanner = exports.readVersionNames = exports.readVersionsFile = exports.getVersionsFilePath = exports.getVersionedSidebarsDirPath = exports.getVersionedDocsDirPath = void 0;
|
|
9
|
+
exports.readVersionsMetadata = exports.filterVersions = exports.getVersionBadge = exports.getVersionBanner = exports.getDefaultVersionBanner = exports.getDocsDirPathLocalized = exports.readVersionNames = exports.readVersionsFile = exports.getVersionsFilePath = exports.getVersionedSidebarsDirPath = exports.getVersionedDocsDirPath = void 0;
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
11
|
const path_1 = tslib_1.__importDefault(require("path"));
|
|
12
12
|
const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
|
|
@@ -89,6 +89,7 @@ function getDocsDirPathLocalized({ siteDir, locale, pluginId, versionName, }) {
|
|
|
89
89
|
],
|
|
90
90
|
});
|
|
91
91
|
}
|
|
92
|
+
exports.getDocsDirPathLocalized = getDocsDirPathLocalized;
|
|
92
93
|
function getVersionMetadataPaths({ versionName, context, options, }) {
|
|
93
94
|
const isCurrentVersion = versionName === constants_1.CURRENT_VERSION_NAME;
|
|
94
95
|
const contentPathLocalized = getDocsDirPathLocalized({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docusaurus/plugin-content-docs",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-4841",
|
|
4
4
|
"description": "Docs plugin for Docusaurus.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"exports": {
|
|
@@ -23,11 +23,11 @@
|
|
|
23
23
|
},
|
|
24
24
|
"license": "MIT",
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@docusaurus/core": "0.0.0-
|
|
27
|
-
"@docusaurus/logger": "0.0.0-
|
|
28
|
-
"@docusaurus/mdx-loader": "0.0.0-
|
|
29
|
-
"@docusaurus/utils": "0.0.0-
|
|
30
|
-
"@docusaurus/utils-validation": "0.0.0-
|
|
26
|
+
"@docusaurus/core": "0.0.0-4841",
|
|
27
|
+
"@docusaurus/logger": "0.0.0-4841",
|
|
28
|
+
"@docusaurus/mdx-loader": "0.0.0-4841",
|
|
29
|
+
"@docusaurus/utils": "0.0.0-4841",
|
|
30
|
+
"@docusaurus/utils-validation": "0.0.0-4841",
|
|
31
31
|
"combine-promises": "^1.1.0",
|
|
32
32
|
"fs-extra": "^10.0.1",
|
|
33
33
|
"import-fresh": "^3.3.0",
|
|
@@ -39,8 +39,8 @@
|
|
|
39
39
|
"webpack": "^5.70.1"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@docusaurus/module-type-aliases": "0.0.0-
|
|
43
|
-
"@docusaurus/types": "0.0.0-
|
|
42
|
+
"@docusaurus/module-type-aliases": "0.0.0-4841",
|
|
43
|
+
"@docusaurus/types": "0.0.0-4841",
|
|
44
44
|
"@types/js-yaml": "^4.0.5",
|
|
45
45
|
"@types/picomatch": "^2.3.0",
|
|
46
46
|
"commander": "^5.1.0",
|
|
@@ -56,5 +56,5 @@
|
|
|
56
56
|
"engines": {
|
|
57
57
|
"node": ">=14"
|
|
58
58
|
},
|
|
59
|
-
"gitHead": "
|
|
59
|
+
"gitHead": "d8b0b5fbaeeb5c2f8c380816f817bd2c7b88ff85"
|
|
60
60
|
}
|
package/src/cli.ts
CHANGED
|
@@ -9,16 +9,16 @@ import {
|
|
|
9
9
|
getVersionsFilePath,
|
|
10
10
|
getVersionedDocsDirPath,
|
|
11
11
|
getVersionedSidebarsDirPath,
|
|
12
|
+
getDocsDirPathLocalized,
|
|
12
13
|
} from './versions';
|
|
13
14
|
import fs from 'fs-extra';
|
|
14
15
|
import path from 'path';
|
|
15
|
-
import type {
|
|
16
|
-
PathOptions,
|
|
17
|
-
SidebarOptions,
|
|
18
|
-
} from '@docusaurus/plugin-content-docs';
|
|
16
|
+
import type {PluginOptions} from '@docusaurus/plugin-content-docs';
|
|
19
17
|
import {loadSidebarsFileUnsafe, resolveSidebarPathOption} from './sidebars';
|
|
18
|
+
import {CURRENT_VERSION_NAME} from './constants';
|
|
20
19
|
import {DEFAULT_PLUGIN_ID} from '@docusaurus/utils';
|
|
21
20
|
import logger from '@docusaurus/logger';
|
|
21
|
+
import type {LoadContext} from '@docusaurus/types';
|
|
22
22
|
|
|
23
23
|
async function createVersionedSidebarFile({
|
|
24
24
|
siteDir,
|
|
@@ -58,9 +58,8 @@ async function createVersionedSidebarFile({
|
|
|
58
58
|
// Tests depend on non-default export for mocking.
|
|
59
59
|
export async function cliDocsVersionCommand(
|
|
60
60
|
version: string | null | undefined,
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
options: PathOptions & SidebarOptions,
|
|
61
|
+
{id: pluginId, path: docsPath, sidebarPath}: PluginOptions,
|
|
62
|
+
{siteDir, i18n}: LoadContext,
|
|
64
63
|
): Promise<void> {
|
|
65
64
|
// It wouldn't be very user-friendly to show a [default] log prefix,
|
|
66
65
|
// so we use [docs] instead of [default]
|
|
@@ -114,22 +113,53 @@ export async function cliDocsVersionCommand(
|
|
|
114
113
|
);
|
|
115
114
|
}
|
|
116
115
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
// Copy docs files.
|
|
120
|
-
const docsDir = path.resolve(siteDir, docsPath);
|
|
121
|
-
|
|
122
|
-
if (
|
|
123
|
-
(await fs.pathExists(docsDir)) &&
|
|
124
|
-
(await fs.readdir(docsDir)).length > 0
|
|
125
|
-
) {
|
|
126
|
-
const versionedDir = getVersionedDocsDirPath(siteDir, pluginId);
|
|
127
|
-
const newVersionDir = path.join(versionedDir, `version-${version}`);
|
|
128
|
-
await fs.copy(docsDir, newVersionDir);
|
|
129
|
-
} else {
|
|
130
|
-
throw new Error(`${pluginIdLogPrefix}: no docs found in ${docsDir}.`);
|
|
116
|
+
if (i18n.locales.length > 1) {
|
|
117
|
+
logger.info`Versioned docs will be created for the following locales: name=${i18n.locales}`;
|
|
131
118
|
}
|
|
132
119
|
|
|
120
|
+
await Promise.all(
|
|
121
|
+
i18n.locales.map(async (locale) => {
|
|
122
|
+
// Copy docs files.
|
|
123
|
+
const docsDir =
|
|
124
|
+
locale === i18n.defaultLocale
|
|
125
|
+
? path.resolve(siteDir, docsPath)
|
|
126
|
+
: getDocsDirPathLocalized({
|
|
127
|
+
siteDir,
|
|
128
|
+
locale,
|
|
129
|
+
pluginId,
|
|
130
|
+
versionName: CURRENT_VERSION_NAME,
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
if (
|
|
134
|
+
!(await fs.pathExists(docsDir)) ||
|
|
135
|
+
(await fs.readdir(docsDir)).length === 0
|
|
136
|
+
) {
|
|
137
|
+
if (locale === i18n.defaultLocale) {
|
|
138
|
+
throw new Error(
|
|
139
|
+
logger.interpolate`${pluginIdLogPrefix}: no docs found in path=${docsDir}.`,
|
|
140
|
+
);
|
|
141
|
+
} else {
|
|
142
|
+
logger.warn`${pluginIdLogPrefix}: no docs found in path=${docsDir}. Skipping.`;
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
const newVersionDir =
|
|
148
|
+
locale === i18n.defaultLocale
|
|
149
|
+
? path.join(
|
|
150
|
+
getVersionedDocsDirPath(siteDir, pluginId),
|
|
151
|
+
`version-${version}`,
|
|
152
|
+
)
|
|
153
|
+
: getDocsDirPathLocalized({
|
|
154
|
+
siteDir,
|
|
155
|
+
locale,
|
|
156
|
+
pluginId,
|
|
157
|
+
versionName: version,
|
|
158
|
+
});
|
|
159
|
+
await fs.copy(docsDir, newVersionDir);
|
|
160
|
+
}),
|
|
161
|
+
);
|
|
162
|
+
|
|
133
163
|
await createVersionedSidebarFile({
|
|
134
164
|
siteDir,
|
|
135
165
|
pluginId,
|
package/src/index.ts
CHANGED
|
@@ -67,7 +67,7 @@ export default async function pluginContentDocs(
|
|
|
67
67
|
|
|
68
68
|
const versionsMetadata = await readVersionsMetadata({context, options});
|
|
69
69
|
|
|
70
|
-
const pluginId = options.id
|
|
70
|
+
const pluginId = options.id;
|
|
71
71
|
|
|
72
72
|
const pluginDataDirRoot = path.join(
|
|
73
73
|
generatedFilesDir,
|
|
@@ -97,12 +97,7 @@ export default async function pluginContentDocs(
|
|
|
97
97
|
.arguments('<version>')
|
|
98
98
|
.description(commandDescription)
|
|
99
99
|
.action((version) => {
|
|
100
|
-
cliDocsVersionCommand(version,
|
|
101
|
-
path: options.path,
|
|
102
|
-
sidebarPath: options.sidebarPath,
|
|
103
|
-
sidebarCollapsed: options.sidebarCollapsed,
|
|
104
|
-
sidebarCollapsible: options.sidebarCollapsible,
|
|
105
|
-
});
|
|
100
|
+
cliDocsVersionCommand(version, options, context);
|
|
106
101
|
});
|
|
107
102
|
},
|
|
108
103
|
|
package/src/versions.ts
CHANGED
|
@@ -133,7 +133,7 @@ export async function readVersionNames(
|
|
|
133
133
|
return versions;
|
|
134
134
|
}
|
|
135
135
|
|
|
136
|
-
function getDocsDirPathLocalized({
|
|
136
|
+
export function getDocsDirPathLocalized({
|
|
137
137
|
siteDir,
|
|
138
138
|
locale,
|
|
139
139
|
pluginId,
|
|
@@ -143,7 +143,7 @@ function getDocsDirPathLocalized({
|
|
|
143
143
|
locale: string;
|
|
144
144
|
pluginId: string;
|
|
145
145
|
versionName: string;
|
|
146
|
-
}) {
|
|
146
|
+
}): string {
|
|
147
147
|
return getPluginI18nPath({
|
|
148
148
|
siteDir,
|
|
149
149
|
locale,
|