@docusaurus/plugin-content-docs 0.0.0-5047 → 0.0.0-5050

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.js CHANGED
@@ -41,12 +41,7 @@ async function cliDocsVersionCommand(version, { id: pluginId, path: docsPath, si
41
41
  logger_1.default.info `${pluginIdLogPrefix}: Invalid version name provided. Try something like: 1.0.0`;
42
42
  throw err;
43
43
  }
44
- // Load existing versions.
45
- let versions = [];
46
- const versionsJSONFile = (0, files_1.getVersionsFilePath)(siteDir, pluginId);
47
- if (await fs_extra_1.default.pathExists(versionsJSONFile)) {
48
- versions = await fs_extra_1.default.readJSON(versionsJSONFile);
49
- }
44
+ const versions = (await (0, files_1.readVersionsFile)(siteDir, pluginId)) ?? [];
50
45
  // Check if version already exists.
51
46
  if (versions.includes(version)) {
52
47
  throw new Error(`${pluginIdLogPrefix}: this version already exists! Use a version tag that does not already exist.`);
@@ -92,7 +87,7 @@ async function cliDocsVersionCommand(version, { id: pluginId, path: docsPath, si
92
87
  });
93
88
  // Update versions.json file.
94
89
  versions.unshift(version);
95
- await fs_extra_1.default.outputFile(versionsJSONFile, `${JSON.stringify(versions, null, 2)}\n`);
90
+ await fs_extra_1.default.outputFile((0, files_1.getVersionsFilePath)(siteDir, pluginId), `${JSON.stringify(versions, null, 2)}\n`);
96
91
  logger_1.default.success `name=${pluginIdLogPrefix}: version name=${version} created!`;
97
92
  }
98
93
  exports.cliDocsVersionCommand = cliDocsVersionCommand;
@@ -5,4 +5,7 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  import type { Sidebars, SidebarProcessorParams, ProcessedSidebars } from './types';
8
+ export declare type SidebarPostProcessorParams = SidebarProcessorParams & {
9
+ draftIds: Set<string>;
10
+ };
8
11
  export declare function postProcessSidebars(sidebars: ProcessedSidebars, params: SidebarProcessorParams): Sidebars;
@@ -18,6 +18,13 @@ export declare function getDocsDirPathLocalized({ siteDir, locale, pluginId, ver
18
18
  }): string;
19
19
  /** `community` => `[siteDir]/community_versions.json` */
20
20
  export declare function getVersionsFilePath(siteDir: string, pluginId: string): string;
21
+ /**
22
+ * Reads the plugin's respective `versions.json` file, and returns its content.
23
+ *
24
+ * @throws Throws if validation fails, i.e. `versions.json` doesn't contain an
25
+ * array of valid version names.
26
+ */
27
+ export declare function readVersionsFile(siteDir: string, pluginId: string): Promise<string[] | null>;
21
28
  /**
22
29
  * Reads the `versions.json` file, and returns an ordered list of version names.
23
30
  *
@@ -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.getVersionMetadataPaths = exports.readVersionNames = exports.getVersionsFilePath = exports.getDocsDirPathLocalized = exports.getVersionSidebarsPath = exports.getVersionDocsDirPath = void 0;
9
+ exports.getVersionMetadataPaths = exports.readVersionNames = exports.readVersionsFile = exports.getVersionsFilePath = exports.getDocsDirPathLocalized = exports.getVersionSidebarsPath = exports.getVersionDocsDirPath = 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"));
@@ -63,6 +63,7 @@ async function readVersionsFile(siteDir, pluginId) {
63
63
  }
64
64
  return null;
65
65
  }
66
+ exports.readVersionsFile = readVersionsFile;
66
67
  /**
67
68
  * Reads the `versions.json` file, and returns an ordered list of version names.
68
69
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docusaurus/plugin-content-docs",
3
- "version": "0.0.0-5047",
3
+ "version": "0.0.0-5050",
4
4
  "description": "Docs plugin for Docusaurus.",
5
5
  "main": "lib/index.js",
6
6
  "sideEffects": false,
@@ -25,11 +25,11 @@
25
25
  },
26
26
  "license": "MIT",
27
27
  "dependencies": {
28
- "@docusaurus/core": "0.0.0-5047",
29
- "@docusaurus/logger": "0.0.0-5047",
30
- "@docusaurus/mdx-loader": "0.0.0-5047",
31
- "@docusaurus/utils": "0.0.0-5047",
32
- "@docusaurus/utils-validation": "0.0.0-5047",
28
+ "@docusaurus/core": "0.0.0-5050",
29
+ "@docusaurus/logger": "0.0.0-5050",
30
+ "@docusaurus/mdx-loader": "0.0.0-5050",
31
+ "@docusaurus/utils": "0.0.0-5050",
32
+ "@docusaurus/utils-validation": "0.0.0-5050",
33
33
  "combine-promises": "^1.1.0",
34
34
  "fs-extra": "^10.1.0",
35
35
  "import-fresh": "^3.3.0",
@@ -41,8 +41,8 @@
41
41
  "webpack": "^5.72.1"
42
42
  },
43
43
  "devDependencies": {
44
- "@docusaurus/module-type-aliases": "0.0.0-5047",
45
- "@docusaurus/types": "0.0.0-5047",
44
+ "@docusaurus/module-type-aliases": "0.0.0-5050",
45
+ "@docusaurus/types": "0.0.0-5050",
46
46
  "@types/js-yaml": "^4.0.5",
47
47
  "@types/picomatch": "^2.3.0",
48
48
  "commander": "^5.1.0",
@@ -58,5 +58,5 @@
58
58
  "engines": {
59
59
  "node": ">=14"
60
60
  },
61
- "gitHead": "67ac297469d98ac3eb8482d8636aee4648586f33"
61
+ "gitHead": "1e14a127a30082891b24582362a69bca2f8d4b0d"
62
62
  }
package/src/cli.ts CHANGED
@@ -14,6 +14,7 @@ import {
14
14
  getVersionDocsDirPath,
15
15
  getVersionSidebarsPath,
16
16
  getDocsDirPathLocalized,
17
+ readVersionsFile,
17
18
  } from './versions/files';
18
19
  import {validateVersionName} from './versions/validation';
19
20
  import {loadSidebarsFileUnsafe} from './sidebars';
@@ -69,12 +70,7 @@ export async function cliDocsVersionCommand(
69
70
  throw err;
70
71
  }
71
72
 
72
- // Load existing versions.
73
- let versions: string[] = [];
74
- const versionsJSONFile = getVersionsFilePath(siteDir, pluginId);
75
- if (await fs.pathExists(versionsJSONFile)) {
76
- versions = await fs.readJSON(versionsJSONFile);
77
- }
73
+ const versions = (await readVersionsFile(siteDir, pluginId)) ?? [];
78
74
 
79
75
  // Check if version already exists.
80
76
  if (versions.includes(version)) {
@@ -137,7 +133,7 @@ export async function cliDocsVersionCommand(
137
133
  // Update versions.json file.
138
134
  versions.unshift(version);
139
135
  await fs.outputFile(
140
- versionsJSONFile,
136
+ getVersionsFilePath(siteDir, pluginId),
141
137
  `${JSON.stringify(versions, null, 2)}\n`,
142
138
  );
143
139
 
@@ -17,7 +17,7 @@ declare module '@docusaurus/plugin-content-docs' {
17
17
  Tag,
18
18
  } from '@docusaurus/utils';
19
19
  import type {Plugin, LoadContext} from '@docusaurus/types';
20
- import type {Required} from 'utility-types';
20
+ import type {Overwrite, Required} from 'utility-types';
21
21
 
22
22
  export type Assets = {
23
23
  image?: string;
@@ -206,7 +206,22 @@ declare module '@docusaurus/plugin-content-docs' {
206
206
  */
207
207
  tagsBasePath: string;
208
208
  };
209
- export type Options = Partial<PluginOptions>;
209
+ export type Options = Partial<
210
+ Overwrite<
211
+ PluginOptions,
212
+ {
213
+ /**
214
+ * Custom parsing logic to extract number prefixes from file names. Use
215
+ * `false` to disable this behavior and leave the docs untouched, and
216
+ * `true` to use the default parser.
217
+ *
218
+ * @param filename One segment of the path, without any slashes.
219
+ * @see https://docusaurus.io/docs/sidebar#using-number-prefixes
220
+ */
221
+ numberPrefixParser: PluginOptions['numberPrefixParser'] | boolean;
222
+ }
223
+ >
224
+ >;
210
225
  export type SidebarsConfig = import('./sidebars/types').SidebarsConfig;
211
226
 
212
227
  export type VersionMetadata = ContentPaths & {
@@ -18,7 +18,7 @@ import type {
18
18
  SidebarItemCategoryLink,
19
19
  } from './types';
20
20
 
21
- type SidebarPostProcessorParams = SidebarProcessorParams & {
21
+ export type SidebarPostProcessorParams = SidebarProcessorParams & {
22
22
  draftIds: Set<string>;
23
23
  };
24
24
 
@@ -89,7 +89,7 @@ export function getVersionsFilePath(siteDir: string, pluginId: string): string {
89
89
  * @throws Throws if validation fails, i.e. `versions.json` doesn't contain an
90
90
  * array of valid version names.
91
91
  */
92
- async function readVersionsFile(
92
+ export async function readVersionsFile(
93
93
  siteDir: string,
94
94
  pluginId: string,
95
95
  ): Promise<string[] | null> {