@docusaurus/plugin-content-docs 2.0.0-beta.2 → 2.0.0-beta.20

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.
Files changed (229) hide show
  1. package/lib/categoryGeneratedIndex.d.ts +12 -0
  2. package/lib/categoryGeneratedIndex.js +37 -0
  3. package/lib/cli.d.ts +3 -2
  4. package/lib/cli.js +60 -69
  5. package/lib/client/docsClientUtils.d.ts +9 -28
  6. package/lib/client/docsClientUtils.js +33 -34
  7. package/lib/client/index.d.ts +22 -0
  8. package/lib/client/index.js +72 -0
  9. package/lib/constants.d.ts +4 -0
  10. package/lib/constants.js +4 -1
  11. package/lib/docs.d.ts +32 -3
  12. package/lib/docs.js +164 -63
  13. package/{src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docusaurus.config.js → lib/frontMatter.d.ts} +4 -8
  14. package/lib/{docFrontMatter.js → frontMatter.js} +13 -4
  15. package/lib/globalData.d.ts +3 -3
  16. package/lib/globalData.js +35 -6
  17. package/lib/index.d.ts +3 -3
  18. package/lib/index.js +122 -148
  19. package/lib/lastUpdate.d.ts +4 -6
  20. package/lib/lastUpdate.js +22 -26
  21. package/lib/markdown/index.d.ts +3 -6
  22. package/lib/markdown/index.js +3 -3
  23. package/lib/markdown/linkify.d.ts +1 -1
  24. package/lib/markdown/linkify.js +6 -3
  25. package/lib/numberPrefix.d.ts +1 -1
  26. package/lib/numberPrefix.js +16 -21
  27. package/lib/options.d.ts +3 -5
  28. package/lib/options.js +54 -13
  29. package/lib/props.d.ts +7 -2
  30. package/lib/props.js +69 -13
  31. package/lib/routes.d.ts +29 -0
  32. package/lib/routes.js +96 -0
  33. package/lib/server-export.d.ts +9 -0
  34. package/lib/server-export.js +22 -0
  35. package/lib/{sidebarItemsGenerator.d.ts → sidebars/generator.d.ts} +1 -6
  36. package/lib/sidebars/generator.js +209 -0
  37. package/lib/sidebars/index.d.ts +13 -0
  38. package/lib/sidebars/index.js +92 -0
  39. package/lib/sidebars/normalization.d.ts +13 -0
  40. package/lib/sidebars/normalization.js +55 -0
  41. package/lib/sidebars/postProcessor.d.ts +8 -0
  42. package/lib/sidebars/postProcessor.js +65 -0
  43. package/lib/sidebars/processor.d.ts +10 -0
  44. package/lib/sidebars/processor.js +90 -0
  45. package/lib/sidebars/types.d.ts +178 -0
  46. package/lib/{docFrontMatter.d.ts → sidebars/types.js} +2 -2
  47. package/lib/sidebars/utils.d.ts +54 -0
  48. package/lib/sidebars/utils.js +255 -0
  49. package/lib/sidebars/validation.d.ts +11 -0
  50. package/lib/sidebars/validation.js +138 -0
  51. package/lib/slug.d.ts +5 -4
  52. package/lib/slug.js +28 -18
  53. package/{src/__tests__/__fixtures__/sidebars/sidebars-first-level-not-category.js → lib/tags.d.ts} +3 -14
  54. package/lib/tags.js +21 -0
  55. package/lib/translations.d.ts +3 -3
  56. package/lib/translations.js +84 -94
  57. package/lib/types.d.ts +13 -184
  58. package/lib/versions/files.d.ts +44 -0
  59. package/lib/versions/files.js +142 -0
  60. package/lib/versions/index.d.ts +36 -0
  61. package/lib/versions/index.js +155 -0
  62. package/lib/versions/validation.d.ts +17 -0
  63. package/lib/versions/validation.js +71 -0
  64. package/package.json +32 -27
  65. package/src/categoryGeneratedIndex.ts +60 -0
  66. package/src/cli.ts +84 -109
  67. package/src/client/docsClientUtils.ts +43 -70
  68. package/src/client/index.ts +103 -0
  69. package/src/constants.ts +4 -2
  70. package/{types.d.ts → src/deps.d.ts} +1 -1
  71. package/src/docs.ts +228 -65
  72. package/src/{docFrontMatter.ts → frontMatter.ts} +21 -11
  73. package/src/globalData.ts +57 -7
  74. package/src/index.ts +169 -210
  75. package/src/lastUpdate.ts +26 -37
  76. package/src/markdown/index.ts +10 -16
  77. package/src/markdown/linkify.ts +7 -4
  78. package/src/numberPrefix.ts +19 -26
  79. package/src/options.ts +60 -18
  80. package/src/plugin-content-docs.d.ts +625 -89
  81. package/src/props.ts +102 -20
  82. package/src/routes.ts +159 -0
  83. package/src/server-export.ts +22 -0
  84. package/src/sidebars/README.md +9 -0
  85. package/src/sidebars/generator.ts +292 -0
  86. package/src/sidebars/index.ts +118 -0
  87. package/src/sidebars/normalization.ts +85 -0
  88. package/src/sidebars/postProcessor.ts +89 -0
  89. package/src/sidebars/processor.ts +139 -0
  90. package/src/sidebars/types.ts +275 -0
  91. package/src/sidebars/utils.ts +391 -0
  92. package/src/sidebars/validation.ts +174 -0
  93. package/src/slug.ts +41 -22
  94. package/src/tags.ts +20 -0
  95. package/src/translations.ts +124 -117
  96. package/src/types.ts +18 -247
  97. package/src/versions/files.ts +220 -0
  98. package/src/versions/index.ts +247 -0
  99. package/src/versions/validation.ts +113 -0
  100. package/lib/.tsbuildinfo +0 -1
  101. package/lib/sidebarItemsGenerator.js +0 -211
  102. package/lib/sidebars.d.ts +0 -43
  103. package/lib/sidebars.js +0 -320
  104. package/lib/theme/hooks/useDocs.d.ts +0 -20
  105. package/lib/theme/hooks/useDocs.js +0 -72
  106. package/lib/versions.d.ts +0 -16
  107. package/lib/versions.js +0 -319
  108. package/src/__tests__/__fixtures__/bad-id-site/docs/invalid-id.md +0 -5
  109. package/src/__tests__/__fixtures__/bad-slug-on-doc-home-site/docs/docWithSlug.md +0 -5
  110. package/src/__tests__/__fixtures__/empty-site/docusaurus.config.js +0 -16
  111. package/src/__tests__/__fixtures__/empty-site/sidebars.json +0 -1
  112. package/src/__tests__/__fixtures__/sidebars/sidebars-category-shorthand.js +0 -34
  113. package/src/__tests__/__fixtures__/sidebars/sidebars-category-wrong-items.json +0 -11
  114. package/src/__tests__/__fixtures__/sidebars/sidebars-category-wrong-label.json +0 -11
  115. package/src/__tests__/__fixtures__/sidebars/sidebars-category.js +0 -44
  116. package/src/__tests__/__fixtures__/sidebars/sidebars-collapsed-first-level.json +0 -20
  117. package/src/__tests__/__fixtures__/sidebars/sidebars-collapsed.json +0 -21
  118. package/src/__tests__/__fixtures__/sidebars/sidebars-doc-id-not-string.json +0 -10
  119. package/src/__tests__/__fixtures__/sidebars/sidebars-link-wrong-href.json +0 -11
  120. package/src/__tests__/__fixtures__/sidebars/sidebars-link-wrong-label.json +0 -11
  121. package/src/__tests__/__fixtures__/sidebars/sidebars-link.json +0 -11
  122. package/src/__tests__/__fixtures__/sidebars/sidebars-unknown-type.json +0 -14
  123. package/src/__tests__/__fixtures__/sidebars/sidebars-wrong-field.json +0 -20
  124. package/src/__tests__/__fixtures__/sidebars/sidebars.json +0 -20
  125. package/src/__tests__/__fixtures__/simple-site/docs/foo/bar.md +0 -69
  126. package/src/__tests__/__fixtures__/simple-site/docs/foo/baz.md +0 -70
  127. package/src/__tests__/__fixtures__/simple-site/docs/headingAsTitle.md +0 -1
  128. package/src/__tests__/__fixtures__/simple-site/docs/hello.md +0 -53
  129. package/src/__tests__/__fixtures__/simple-site/docs/ipsum.md +0 -5
  130. package/src/__tests__/__fixtures__/simple-site/docs/lorem.md +0 -6
  131. package/src/__tests__/__fixtures__/simple-site/docs/rootAbsoluteSlug.md +0 -5
  132. package/src/__tests__/__fixtures__/simple-site/docs/rootRelativeSlug.md +0 -5
  133. package/src/__tests__/__fixtures__/simple-site/docs/rootResolvedSlug.md +0 -5
  134. package/src/__tests__/__fixtures__/simple-site/docs/rootTryToEscapeSlug.md +0 -5
  135. package/src/__tests__/__fixtures__/simple-site/docs/slugs/absoluteSlug.md +0 -5
  136. package/src/__tests__/__fixtures__/simple-site/docs/slugs/relativeSlug.md +0 -5
  137. package/src/__tests__/__fixtures__/simple-site/docs/slugs/resolvedSlug.md +0 -5
  138. package/src/__tests__/__fixtures__/simple-site/docs/slugs/tryToEscapeSlug.md +0 -5
  139. package/src/__tests__/__fixtures__/simple-site/docusaurus.config.js +0 -14
  140. package/src/__tests__/__fixtures__/simple-site/sidebars.json +0 -23
  141. package/src/__tests__/__fixtures__/simple-site/wrong-sidebars.json +0 -7
  142. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/0-getting-started.md +0 -3
  143. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/1-installation.md +0 -3
  144. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/3-API/00_api-overview.md +0 -3
  145. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/3-API/01_Core APIs/0 --- Client API.md +0 -1
  146. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/3-API/01_Core APIs/1 --- Server API.md +0 -1
  147. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/3-API/02_Extension APIs/0. Plugin API.md +0 -1
  148. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/3-API/02_Extension APIs/1. Theme API.md +0 -1
  149. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/3-API/02_Extension APIs/_category_.yml +0 -1
  150. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/3-API/03_api-end.md +0 -3
  151. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/3-API/_category_.json +0 -3
  152. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/Guides/0-guide2.5.md +0 -8
  153. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/Guides/02-guide2.md +0 -7
  154. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/Guides/_category_.json +0 -3
  155. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/Guides/a-guide4.md +0 -7
  156. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/Guides/b-guide5.md +0 -7
  157. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/Guides/guide3.md +0 -8
  158. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/docs/Guides/z-guide1.md +0 -8
  159. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/partialAutogeneratedSidebars.js +0 -23
  160. package/src/__tests__/__fixtures__/site-with-autogenerated-sidebar/partialAutogeneratedSidebars2.js +0 -16
  161. package/src/__tests__/__fixtures__/site-with-doc-label/docs/hello-1.md +0 -7
  162. package/src/__tests__/__fixtures__/site-with-doc-label/docs/hello-2.md +0 -8
  163. package/src/__tests__/__fixtures__/site-with-doc-label/docusaurus.config.js +0 -14
  164. package/src/__tests__/__fixtures__/site-with-doc-label/sidebars.json +0 -14
  165. package/src/__tests__/__fixtures__/versioned-site/community/team.md +0 -1
  166. package/src/__tests__/__fixtures__/versioned-site/community_sidebars.json +0 -3
  167. package/src/__tests__/__fixtures__/versioned-site/community_versioned_docs/version-1.0.0/team.md +0 -1
  168. package/src/__tests__/__fixtures__/versioned-site/community_versioned_sidebars/version-1.0.0-sidebars.json +0 -3
  169. package/src/__tests__/__fixtures__/versioned-site/community_versions.json +0 -1
  170. package/src/__tests__/__fixtures__/versioned-site/docs/foo/bar.md +0 -4
  171. package/src/__tests__/__fixtures__/versioned-site/docs/hello.md +0 -1
  172. package/src/__tests__/__fixtures__/versioned-site/docs/slugs/absoluteSlug.md +0 -5
  173. package/src/__tests__/__fixtures__/versioned-site/docs/slugs/relativeSlug.md +0 -5
  174. package/src/__tests__/__fixtures__/versioned-site/docs/slugs/resolvedSlug.md +0 -5
  175. package/src/__tests__/__fixtures__/versioned-site/docs/slugs/tryToEscapeSlug.md +0 -5
  176. package/src/__tests__/__fixtures__/versioned-site/docusaurus.config.js +0 -18
  177. package/src/__tests__/__fixtures__/versioned-site/i18n/en/docusaurus-plugin-content-docs/version-1.0.0/hello.md +0 -1
  178. package/src/__tests__/__fixtures__/versioned-site/i18n/en/docusaurus-plugin-content-docs-community/current/team.md +0 -5
  179. package/src/__tests__/__fixtures__/versioned-site/i18n/fr/docusaurus-plugin-content-docs/version-1.0.0/hello.md +0 -1
  180. package/src/__tests__/__fixtures__/versioned-site/sidebars.json +0 -10
  181. package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-1.0.0/foo/bar.md +0 -4
  182. package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-1.0.0/foo/baz.md +0 -1
  183. package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-1.0.0/hello.md +0 -1
  184. package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-1.0.1/foo/bar.md +0 -1
  185. package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-1.0.1/hello.md +0 -1
  186. package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-withSlugs/rootAbsoluteSlug.md +0 -5
  187. package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-withSlugs/rootRelativeSlug.md +0 -5
  188. package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-withSlugs/rootResolvedSlug.md +0 -5
  189. package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-withSlugs/rootTryToEscapeSlug.md +0 -5
  190. package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-withSlugs/slugs/absoluteSlug.md +0 -5
  191. package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-withSlugs/slugs/relativeSlug.md +0 -5
  192. package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-withSlugs/slugs/resolvedSlug.md +0 -5
  193. package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-withSlugs/slugs/tryToEscapeSlug.md +0 -5
  194. package/src/__tests__/__fixtures__/versioned-site/versioned_sidebars/version-1.0.0-sidebars.json +0 -11
  195. package/src/__tests__/__fixtures__/versioned-site/versioned_sidebars/version-1.0.1-sidebars.json +0 -10
  196. package/src/__tests__/__fixtures__/versioned-site/versioned_sidebars/version-withSlugs-sidebars.json +0 -5
  197. package/src/__tests__/__fixtures__/versioned-site/versions.json +0 -5
  198. package/src/__tests__/__snapshots__/cli.test.ts.snap +0 -90
  199. package/src/__tests__/__snapshots__/index.test.ts.snap +0 -1916
  200. package/src/__tests__/__snapshots__/sidebars.test.ts.snap +0 -218
  201. package/src/__tests__/__snapshots__/translations.test.ts.snap +0 -487
  202. package/src/__tests__/cli.test.ts +0 -333
  203. package/src/__tests__/docFrontMatter.test.ts +0 -244
  204. package/src/__tests__/docs.test.ts +0 -878
  205. package/src/__tests__/index.test.ts +0 -1871
  206. package/src/__tests__/lastUpdate.test.ts +0 -69
  207. package/src/__tests__/numberPrefix.test.ts +0 -199
  208. package/src/__tests__/options.test.ts +0 -231
  209. package/src/__tests__/sidebarItemsGenerator.test.ts +0 -336
  210. package/src/__tests__/sidebars.test.ts +0 -639
  211. package/src/__tests__/slug.test.ts +0 -109
  212. package/src/__tests__/translations.test.ts +0 -159
  213. package/src/__tests__/versions.test.ts +0 -741
  214. package/src/client/__tests__/docsClientUtils.test.ts +0 -371
  215. package/src/markdown/__tests__/__fixtures__/docs/doc-localized.md +0 -1
  216. package/src/markdown/__tests__/__fixtures__/docs/doc1.md +0 -13
  217. package/src/markdown/__tests__/__fixtures__/docs/doc2.md +0 -12
  218. package/src/markdown/__tests__/__fixtures__/docs/doc4.md +0 -19
  219. package/src/markdown/__tests__/__fixtures__/docs/doc5.md +0 -6
  220. package/src/markdown/__tests__/__fixtures__/docs/subdir/doc3.md +0 -3
  221. package/src/markdown/__tests__/__fixtures__/versioned_docs/version-1.0.0/doc2.md +0 -7
  222. package/src/markdown/__tests__/__fixtures__/versioned_docs/version-1.0.0/subdir/doc1.md +0 -3
  223. package/src/markdown/__tests__/__snapshots__/linkify.test.ts.snap +0 -82
  224. package/src/markdown/__tests__/linkify.test.ts +0 -190
  225. package/src/sidebarItemsGenerator.ts +0 -307
  226. package/src/sidebars.ts +0 -522
  227. package/src/theme/hooks/useDocs.ts +0 -99
  228. package/src/versions.ts +0 -572
  229. package/tsconfig.json +0 -9
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ import type { PluginOptions, VersionBanner, VersionMetadata } from '@docusaurus/plugin-content-docs';
8
+ import type { LoadContext } from '@docusaurus/types';
9
+ export declare type VersionContext = {
10
+ /** The version name to get banner of. */
11
+ versionName: string;
12
+ /** All versions, ordered from newest to oldest. */
13
+ versionNames: string[];
14
+ lastVersionName: string;
15
+ context: LoadContext;
16
+ options: PluginOptions;
17
+ };
18
+ /**
19
+ * The default version banner depends on the version's relative position to the
20
+ * latest version. More recent ones are "unreleased", and older ones are
21
+ * "unmaintained".
22
+ */
23
+ export declare function getDefaultVersionBanner({ versionName, versionNames, lastVersionName, }: VersionContext): VersionBanner | null;
24
+ export declare function getVersionBanner(context: VersionContext): VersionMetadata['banner'];
25
+ export declare function getVersionBadge({ versionName, versionNames, options, }: VersionContext): VersionMetadata['badge'];
26
+ /**
27
+ * Filter versions according to provided options (i.e. `onlyIncludeVersions`).
28
+ *
29
+ * Note: we preserve the order in which versions are provided; the order of the
30
+ * `onlyIncludeVersions` array does not matter
31
+ */
32
+ export declare function filterVersions(versionNamesUnfiltered: string[], options: PluginOptions): string[];
33
+ export declare function readVersionsMetadata({ context, options, }: {
34
+ context: LoadContext;
35
+ options: PluginOptions;
36
+ }): Promise<VersionMetadata[]>;
@@ -0,0 +1,155 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) Facebook, Inc. and its affiliates.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.readVersionsMetadata = exports.filterVersions = exports.getVersionBadge = exports.getVersionBanner = exports.getDefaultVersionBanner = void 0;
10
+ const tslib_1 = require("tslib");
11
+ const path_1 = tslib_1.__importDefault(require("path"));
12
+ const constants_1 = require("../constants");
13
+ const utils_1 = require("@docusaurus/utils");
14
+ const validation_1 = require("./validation");
15
+ const files_1 = require("./files");
16
+ function getVersionEditUrls({ contentPath, contentPathLocalized, context, options, }) {
17
+ // If the user is using the functional form of editUrl,
18
+ // she has total freedom and we can't compute a "version edit url"
19
+ if (!options.editUrl || typeof options.editUrl === 'function') {
20
+ return { editUrl: undefined, editUrlLocalized: undefined };
21
+ }
22
+ const editDirPath = options.editCurrentVersion ? options.path : contentPath;
23
+ const editDirPathLocalized = options.editCurrentVersion
24
+ ? (0, files_1.getDocsDirPathLocalized)({
25
+ siteDir: context.siteDir,
26
+ locale: context.i18n.currentLocale,
27
+ versionName: constants_1.CURRENT_VERSION_NAME,
28
+ pluginId: options.id,
29
+ })
30
+ : contentPathLocalized;
31
+ const versionPathSegment = (0, utils_1.posixPath)(path_1.default.relative(context.siteDir, path_1.default.resolve(context.siteDir, editDirPath)));
32
+ const versionPathSegmentLocalized = (0, utils_1.posixPath)(path_1.default.relative(context.siteDir, path_1.default.resolve(context.siteDir, editDirPathLocalized)));
33
+ const editUrl = (0, utils_1.normalizeUrl)([options.editUrl, versionPathSegment]);
34
+ const editUrlLocalized = (0, utils_1.normalizeUrl)([
35
+ options.editUrl,
36
+ versionPathSegmentLocalized,
37
+ ]);
38
+ return { editUrl, editUrlLocalized };
39
+ }
40
+ /**
41
+ * The default version banner depends on the version's relative position to the
42
+ * latest version. More recent ones are "unreleased", and older ones are
43
+ * "unmaintained".
44
+ */
45
+ function getDefaultVersionBanner({ versionName, versionNames, lastVersionName, }) {
46
+ // Current version: good, no banner
47
+ if (versionName === lastVersionName) {
48
+ return null;
49
+ }
50
+ // Upcoming versions: unreleased banner
51
+ if (versionNames.indexOf(versionName) < versionNames.indexOf(lastVersionName)) {
52
+ return 'unreleased';
53
+ }
54
+ // Older versions: display unmaintained banner
55
+ return 'unmaintained';
56
+ }
57
+ exports.getDefaultVersionBanner = getDefaultVersionBanner;
58
+ function getVersionBanner(context) {
59
+ const { versionName, options } = context;
60
+ const versionBannerOption = options.versions[versionName]?.banner;
61
+ if (versionBannerOption) {
62
+ return versionBannerOption === 'none' ? null : versionBannerOption;
63
+ }
64
+ return getDefaultVersionBanner(context);
65
+ }
66
+ exports.getVersionBanner = getVersionBanner;
67
+ function getVersionBadge({ versionName, versionNames, options, }) {
68
+ // If site is not versioned or only one version is included
69
+ // we don't show the version badge by default
70
+ // See https://github.com/facebook/docusaurus/issues/3362
71
+ const defaultVersionBadge = versionNames.length !== 1;
72
+ return options.versions[versionName]?.badge ?? defaultVersionBadge;
73
+ }
74
+ exports.getVersionBadge = getVersionBadge;
75
+ function getVersionClassName({ versionName, options, }) {
76
+ const defaultVersionClassName = `docs-version-${versionName}`;
77
+ return options.versions[versionName]?.className ?? defaultVersionClassName;
78
+ }
79
+ function getVersionLabel({ versionName, options, }) {
80
+ const defaultVersionLabel = versionName === constants_1.CURRENT_VERSION_NAME ? 'Next' : versionName;
81
+ return options.versions[versionName]?.label ?? defaultVersionLabel;
82
+ }
83
+ function getVersionPathPart({ versionName, options, lastVersionName, }) {
84
+ function getDefaultVersionPathPart() {
85
+ if (versionName === lastVersionName) {
86
+ return '';
87
+ }
88
+ return versionName === constants_1.CURRENT_VERSION_NAME ? 'next' : versionName;
89
+ }
90
+ return options.versions[versionName]?.path ?? getDefaultVersionPathPart();
91
+ }
92
+ async function createVersionMetadata(context) {
93
+ const { versionName, lastVersionName, options, context: loadContext } = context;
94
+ const { sidebarFilePath, contentPath, contentPathLocalized } = await (0, files_1.getVersionMetadataPaths)(context);
95
+ const versionPathPart = getVersionPathPart(context);
96
+ const routePath = (0, utils_1.normalizeUrl)([
97
+ loadContext.baseUrl,
98
+ options.routeBasePath,
99
+ versionPathPart,
100
+ ]);
101
+ const versionEditUrls = getVersionEditUrls({
102
+ contentPath,
103
+ contentPathLocalized,
104
+ context: loadContext,
105
+ options,
106
+ });
107
+ return {
108
+ versionName,
109
+ label: getVersionLabel(context),
110
+ banner: getVersionBanner(context),
111
+ badge: getVersionBadge(context),
112
+ className: getVersionClassName(context),
113
+ path: routePath,
114
+ tagsPath: (0, utils_1.normalizeUrl)([routePath, options.tagsBasePath]),
115
+ ...versionEditUrls,
116
+ isLast: versionName === lastVersionName,
117
+ routePriority: versionPathPart === '' ? -1 : undefined,
118
+ sidebarFilePath,
119
+ contentPath,
120
+ contentPathLocalized,
121
+ };
122
+ }
123
+ /**
124
+ * Filter versions according to provided options (i.e. `onlyIncludeVersions`).
125
+ *
126
+ * Note: we preserve the order in which versions are provided; the order of the
127
+ * `onlyIncludeVersions` array does not matter
128
+ */
129
+ function filterVersions(versionNamesUnfiltered, options) {
130
+ if (options.onlyIncludeVersions) {
131
+ return versionNamesUnfiltered.filter((name) => options.onlyIncludeVersions.includes(name));
132
+ }
133
+ return versionNamesUnfiltered;
134
+ }
135
+ exports.filterVersions = filterVersions;
136
+ function getLastVersionName({ versionNames, options, }) {
137
+ return (options.lastVersion ??
138
+ versionNames.find((name) => name !== constants_1.CURRENT_VERSION_NAME) ??
139
+ constants_1.CURRENT_VERSION_NAME);
140
+ }
141
+ async function readVersionsMetadata({ context, options, }) {
142
+ const allVersionNames = await (0, files_1.readVersionNames)(context.siteDir, options);
143
+ (0, validation_1.validateVersionsOptions)(allVersionNames, options);
144
+ const versionNames = filterVersions(allVersionNames, options);
145
+ const lastVersionName = getLastVersionName({ versionNames, options });
146
+ const versionsMetadata = await Promise.all(versionNames.map((versionName) => createVersionMetadata({
147
+ versionName,
148
+ versionNames,
149
+ lastVersionName,
150
+ context,
151
+ options,
152
+ })));
153
+ return versionsMetadata;
154
+ }
155
+ exports.readVersionsMetadata = readVersionsMetadata;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ import type { VersionsOptions } from '@docusaurus/plugin-content-docs';
8
+ export declare function validateVersionName(name: unknown): asserts name is string;
9
+ export declare function validateVersionNames(names: unknown): asserts names is string[];
10
+ /**
11
+ * @throws Throws for one of the following invalid options:
12
+ * - `lastVersion` is non-existent
13
+ * - `versions` includes unknown keys
14
+ * - `onlyIncludeVersions` is empty, contains unknown names, or doesn't include
15
+ * `latestVersion` (if provided)
16
+ */
17
+ export declare function validateVersionsOptions(availableVersionNames: string[], options: VersionsOptions): void;
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) Facebook, Inc. and its affiliates.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.validateVersionsOptions = exports.validateVersionNames = exports.validateVersionName = void 0;
10
+ const tslib_1 = require("tslib");
11
+ const lodash_1 = tslib_1.__importDefault(require("lodash"));
12
+ function validateVersionName(name) {
13
+ if (typeof name !== 'string') {
14
+ throw new Error(`Versions should be strings. Found type "${typeof name}" for version "${name}".`);
15
+ }
16
+ if (!name.trim()) {
17
+ throw new Error(`Invalid version name "${name}": version name must contain at least one non-whitespace character.`);
18
+ }
19
+ const errors = [
20
+ [/[/\\]/, 'should not include slash (/) or backslash (\\)'],
21
+ [/.{33,}/, 'cannot be longer than 32 characters'],
22
+ // eslint-disable-next-line no-control-regex
23
+ [/[<>:"|?*\x00-\x1F]/, 'should be a valid file path'],
24
+ [/^\.\.?$/, 'should not be "." or ".."'],
25
+ ];
26
+ errors.forEach(([pattern, message]) => {
27
+ if (pattern.test(name)) {
28
+ throw new Error(`Invalid version name "${name}": version name ${message}.`);
29
+ }
30
+ });
31
+ }
32
+ exports.validateVersionName = validateVersionName;
33
+ function validateVersionNames(names) {
34
+ if (!Array.isArray(names)) {
35
+ throw new Error(`The versions file should contain an array of version names! Found content: ${JSON.stringify(names)}`);
36
+ }
37
+ names.forEach(validateVersionName);
38
+ }
39
+ exports.validateVersionNames = validateVersionNames;
40
+ /**
41
+ * @throws Throws for one of the following invalid options:
42
+ * - `lastVersion` is non-existent
43
+ * - `versions` includes unknown keys
44
+ * - `onlyIncludeVersions` is empty, contains unknown names, or doesn't include
45
+ * `latestVersion` (if provided)
46
+ */
47
+ function validateVersionsOptions(availableVersionNames, options) {
48
+ const availableVersionNamesMsg = `Available version names are: ${availableVersionNames.join(', ')}`;
49
+ if (options.lastVersion &&
50
+ !availableVersionNames.includes(options.lastVersion)) {
51
+ throw new Error(`Docs option lastVersion: ${options.lastVersion} is invalid. ${availableVersionNamesMsg}`);
52
+ }
53
+ const unknownVersionConfigNames = lodash_1.default.difference(Object.keys(options.versions), availableVersionNames);
54
+ if (unknownVersionConfigNames.length > 0) {
55
+ throw new Error(`Invalid docs option "versions": unknown versions (${unknownVersionConfigNames.join(',')}) found. ${availableVersionNamesMsg}`);
56
+ }
57
+ if (options.onlyIncludeVersions) {
58
+ if (options.onlyIncludeVersions.length === 0) {
59
+ throw new Error(`Invalid docs option "onlyIncludeVersions": an empty array is not allowed, at least one version is needed.`);
60
+ }
61
+ const unknownOnlyIncludeVersionNames = lodash_1.default.difference(options.onlyIncludeVersions, availableVersionNames);
62
+ if (unknownOnlyIncludeVersionNames.length > 0) {
63
+ throw new Error(`Invalid docs option "onlyIncludeVersions": unknown versions (${unknownOnlyIncludeVersionNames.join(',')}) found. ${availableVersionNamesMsg}`);
64
+ }
65
+ if (options.lastVersion &&
66
+ !options.onlyIncludeVersions.includes(options.lastVersion)) {
67
+ throw new Error(`Invalid docs option "lastVersion": if you use both the "onlyIncludeVersions" and "lastVersion" options, then "lastVersion" must be present in the provided "onlyIncludeVersions" array.`);
68
+ }
69
+ }
70
+ }
71
+ exports.validateVersionsOptions = validateVersionsOptions;
package/package.json CHANGED
@@ -1,8 +1,15 @@
1
1
  {
2
2
  "name": "@docusaurus/plugin-content-docs",
3
- "version": "2.0.0-beta.2",
3
+ "version": "2.0.0-beta.20",
4
4
  "description": "Docs plugin for Docusaurus.",
5
5
  "main": "lib/index.js",
6
+ "sideEffects": false,
7
+ "exports": {
8
+ "./src/*": "./src/*",
9
+ "./client": "./lib/client/index.js",
10
+ "./server": "./lib/server-export.js",
11
+ ".": "./lib/index.js"
12
+ },
6
13
  "types": "src/plugin-content-docs.d.ts",
7
14
  "scripts": {
8
15
  "build": "tsc",
@@ -17,41 +24,39 @@
17
24
  "directory": "packages/docusaurus-plugin-content-docs"
18
25
  },
19
26
  "license": "MIT",
20
- "devDependencies": {
21
- "@docusaurus/module-type-aliases": "2.0.0-beta.2",
22
- "@types/js-yaml": "^4.0.0",
23
- "@types/picomatch": "^2.2.1",
24
- "commander": "^5.1.0",
25
- "picomatch": "^2.1.1"
26
- },
27
27
  "dependencies": {
28
- "@docusaurus/core": "2.0.0-beta.2",
29
- "@docusaurus/mdx-loader": "2.0.0-beta.2",
30
- "@docusaurus/types": "2.0.0-beta.2",
31
- "@docusaurus/utils": "2.0.0-beta.2",
32
- "@docusaurus/utils-validation": "2.0.0-beta.2",
33
- "chalk": "^4.1.1",
28
+ "@docusaurus/core": "2.0.0-beta.20",
29
+ "@docusaurus/logger": "2.0.0-beta.20",
30
+ "@docusaurus/mdx-loader": "2.0.0-beta.20",
31
+ "@docusaurus/utils": "2.0.0-beta.20",
32
+ "@docusaurus/utils-validation": "2.0.0-beta.20",
34
33
  "combine-promises": "^1.1.0",
35
- "escape-string-regexp": "^4.0.0",
36
- "execa": "^5.0.0",
37
- "fs-extra": "^10.0.0",
38
- "globby": "^11.0.2",
39
- "import-fresh": "^3.2.2",
40
- "js-yaml": "^4.0.0",
41
- "loader-utils": "^1.2.3",
42
- "lodash": "^4.17.20",
34
+ "fs-extra": "^10.1.0",
35
+ "import-fresh": "^3.3.0",
36
+ "js-yaml": "^4.1.0",
37
+ "lodash": "^4.17.21",
43
38
  "remark-admonitions": "^1.2.1",
44
- "shelljs": "^0.8.4",
45
- "tslib": "^2.2.0",
39
+ "tslib": "^2.4.0",
46
40
  "utility-types": "^3.10.0",
47
- "webpack": "^5.40.0"
41
+ "webpack": "^5.72.0"
42
+ },
43
+ "devDependencies": {
44
+ "@docusaurus/module-type-aliases": "2.0.0-beta.20",
45
+ "@docusaurus/types": "2.0.0-beta.20",
46
+ "@types/js-yaml": "^4.0.5",
47
+ "@types/picomatch": "^2.3.0",
48
+ "commander": "^5.1.0",
49
+ "escape-string-regexp": "^4.0.0",
50
+ "picomatch": "^2.3.1",
51
+ "shelljs": "^0.8.5",
52
+ "utility-types": "^3.10.0"
48
53
  },
49
54
  "peerDependencies": {
50
55
  "react": "^16.8.4 || ^17.0.0",
51
56
  "react-dom": "^16.8.4 || ^17.0.0"
52
57
  },
53
58
  "engines": {
54
- "node": ">=12.13.0"
59
+ "node": ">=14"
55
60
  },
56
- "gitHead": "883f07fddffaf1657407c8e202e370cc436e25f7"
61
+ "gitHead": "ed5cdba401a5948e187e927039b142a0decc702d"
57
62
  }
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ import type {
9
+ CategoryGeneratedIndexMetadata,
10
+ DocMetadataBase,
11
+ } from '@docusaurus/plugin-content-docs';
12
+ import type {SidebarItemCategoryWithGeneratedIndex} from './sidebars/types';
13
+ import {type SidebarsUtils, toNavigationLink} from './sidebars/utils';
14
+ import {createDocsByIdIndex} from './docs';
15
+
16
+ function getCategoryGeneratedIndexMetadata({
17
+ category,
18
+ sidebarsUtils,
19
+ docsById,
20
+ }: {
21
+ category: SidebarItemCategoryWithGeneratedIndex;
22
+ sidebarsUtils: SidebarsUtils;
23
+ docsById: {[docId: string]: DocMetadataBase};
24
+ }): CategoryGeneratedIndexMetadata {
25
+ const {sidebarName, previous, next} =
26
+ sidebarsUtils.getCategoryGeneratedIndexNavigation(category.link.permalink);
27
+ return {
28
+ title: category.link.title ?? category.label,
29
+ description: category.link.description,
30
+ image: category.link.image,
31
+ keywords: category.link.keywords,
32
+ slug: category.link.slug,
33
+ permalink: category.link.permalink,
34
+ sidebar: sidebarName!,
35
+ navigation: {
36
+ previous: toNavigationLink(previous, docsById),
37
+ next: toNavigationLink(next, docsById),
38
+ },
39
+ };
40
+ }
41
+
42
+ export function getCategoryGeneratedIndexMetadataList({
43
+ docs,
44
+ sidebarsUtils,
45
+ }: {
46
+ sidebarsUtils: SidebarsUtils;
47
+ docs: DocMetadataBase[];
48
+ }): CategoryGeneratedIndexMetadata[] {
49
+ const docsById = createDocsByIdIndex(docs);
50
+
51
+ const categoryGeneratedIndexItems =
52
+ sidebarsUtils.getCategoryGeneratedIndexList();
53
+ return categoryGeneratedIndexItems.map((category) =>
54
+ getCategoryGeneratedIndexMetadata({
55
+ category,
56
+ sidebarsUtils,
57
+ docsById,
58
+ }),
59
+ );
60
+ }
package/src/cli.ts CHANGED
@@ -7,20 +7,21 @@
7
7
 
8
8
  import {
9
9
  getVersionsFilePath,
10
- getVersionedDocsDirPath,
11
- getVersionedSidebarsDirPath,
12
- } from './versions';
10
+ getVersionDocsDirPath,
11
+ getVersionSidebarsPath,
12
+ getDocsDirPathLocalized,
13
+ } from './versions/files';
14
+ import {validateVersionName} from './versions/validation';
13
15
  import fs from 'fs-extra';
14
16
  import path from 'path';
15
- import {
16
- PathOptions,
17
- UnprocessedSidebarItem,
18
- UnprocessedSidebars,
19
- } from './types';
20
- import {loadSidebars, resolveSidebarPathOption} from './sidebars';
21
- import {DEFAULT_PLUGIN_ID} from '@docusaurus/core/lib/constants';
22
-
23
- function createVersionedSidebarFile({
17
+ import type {PluginOptions} from '@docusaurus/plugin-content-docs';
18
+ import {loadSidebarsFileUnsafe} from './sidebars';
19
+ import {CURRENT_VERSION_NAME} from './constants';
20
+ import {DEFAULT_PLUGIN_ID} from '@docusaurus/utils';
21
+ import logger from '@docusaurus/logger';
22
+ import type {LoadContext} from '@docusaurus/types';
23
+
24
+ async function createVersionedSidebarFile({
24
25
  siteDir,
25
26
  pluginId,
26
27
  sidebarPath,
@@ -32,106 +33,47 @@ function createVersionedSidebarFile({
32
33
  version: string;
33
34
  }) {
34
35
  // Load current sidebar and create a new versioned sidebars file (if needed).
35
- const loadedSidebars = loadSidebars(sidebarPath);
36
+ // Note: we don't need the sidebars file to be normalized: it's ok to let
37
+ // plugin option changes to impact older, versioned sidebars
38
+ // We don't validate here, assuming the user has already built the version
39
+ const sidebars = await loadSidebarsFileUnsafe(sidebarPath);
36
40
 
37
- // Do not create a useless versioned sidebars file if sidebars file is empty or sidebars are disabled/false)
38
- const shouldCreateVersionedSidebarFile =
39
- Object.keys(loadedSidebars).length > 0;
41
+ // Do not create a useless versioned sidebars file if sidebars file is empty
42
+ // or sidebars are disabled/false)
43
+ const shouldCreateVersionedSidebarFile = Object.keys(sidebars).length > 0;
40
44
 
41
45
  if (shouldCreateVersionedSidebarFile) {
42
- // TODO @slorber: this "version prefix" in versioned sidebars looks like a bad idea to me
43
- // TODO try to get rid of it
44
- // Transform id in original sidebar to versioned id.
45
- const normalizeItem = (
46
- item: UnprocessedSidebarItem,
47
- ): UnprocessedSidebarItem => {
48
- switch (item.type) {
49
- case 'category':
50
- return {...item, items: item.items.map(normalizeItem)};
51
- case 'ref':
52
- case 'doc':
53
- return {
54
- type: item.type,
55
- id: `version-${version}/${item.id}`,
56
- };
57
- default:
58
- return item;
59
- }
60
- };
61
-
62
- const versionedSidebar: UnprocessedSidebars = Object.entries(
63
- loadedSidebars,
64
- ).reduce((acc: UnprocessedSidebars, [sidebarId, sidebarItems]) => {
65
- const newVersionedSidebarId = `version-${version}/${sidebarId}`;
66
- acc[newVersionedSidebarId] = sidebarItems.map(normalizeItem);
67
- return acc;
68
- }, {});
69
-
70
- const versionedSidebarsDir = getVersionedSidebarsDirPath(siteDir, pluginId);
71
- const newSidebarFile = path.join(
72
- versionedSidebarsDir,
73
- `version-${version}-sidebars.json`,
74
- );
75
- fs.ensureDirSync(path.dirname(newSidebarFile));
76
- fs.writeFileSync(
77
- newSidebarFile,
78
- `${JSON.stringify(versionedSidebar, null, 2)}\n`,
46
+ await fs.outputFile(
47
+ getVersionSidebarsPath(siteDir, pluginId, version),
48
+ `${JSON.stringify(sidebars, null, 2)}\n`,
79
49
  'utf8',
80
50
  );
81
51
  }
82
52
  }
83
53
 
84
54
  // Tests depend on non-default export for mocking.
85
- // eslint-disable-next-line import/prefer-default-export
86
- export function cliDocsVersionCommand(
87
- version: string | null | undefined,
88
- siteDir: string,
89
- pluginId: string,
90
- options: PathOptions,
91
- ): void {
55
+ export async function cliDocsVersionCommand(
56
+ version: string,
57
+ {id: pluginId, path: docsPath, sidebarPath}: PluginOptions,
58
+ {siteDir, i18n}: LoadContext,
59
+ ): Promise<void> {
92
60
  // It wouldn't be very user-friendly to show a [default] log prefix,
93
61
  // so we use [docs] instead of [default]
94
62
  const pluginIdLogPrefix =
95
63
  pluginId === DEFAULT_PLUGIN_ID ? '[docs]' : `[${pluginId}]`;
96
64
 
97
- if (!version) {
98
- throw new Error(
99
- `${pluginIdLogPrefix}: no version tag specified! Pass the version you wish to create as an argument, for example: 1.0.0.`,
100
- );
101
- }
102
-
103
- if (version.includes('/') || version.includes('\\')) {
104
- throw new Error(
105
- `${pluginIdLogPrefix}: invalid version tag specified! Do not include slash (/) or backslash (\\). Try something like: 1.0.0.`,
106
- );
107
- }
108
-
109
- if (version.length > 32) {
110
- throw new Error(
111
- `${pluginIdLogPrefix}: invalid version tag specified! Length cannot exceed 32 characters. Try something like: 1.0.0.`,
112
- );
113
- }
114
-
115
- // Since we are going to create `version-${version}` folder, we need to make
116
- // sure it's a valid pathname.
117
- // eslint-disable-next-line no-control-regex
118
- if (/[<>:"|?*\x00-\x1F]/g.test(version)) {
119
- throw new Error(
120
- `${pluginIdLogPrefix}: invalid version tag specified! Please ensure its a valid pathname too. Try something like: 1.0.0.`,
121
- );
122
- }
123
-
124
- if (/^\.\.?$/.test(version)) {
125
- throw new Error(
126
- `${pluginIdLogPrefix}: invalid version tag specified! Do not name your version "." or "..". Try something like: 1.0.0.`,
127
- );
65
+ try {
66
+ validateVersionName(version);
67
+ } catch (e) {
68
+ logger.info`${pluginIdLogPrefix}: Invalid version name provided. Try something like: 1.0.0`;
69
+ throw e;
128
70
  }
129
71
 
130
72
  // Load existing versions.
131
73
  let versions = [];
132
74
  const versionsJSONFile = getVersionsFilePath(siteDir, pluginId);
133
- if (fs.existsSync(versionsJSONFile)) {
134
- versions = JSON.parse(fs.readFileSync(versionsJSONFile, 'utf8'));
75
+ if (await fs.pathExists(versionsJSONFile)) {
76
+ versions = await fs.readJSON(versionsJSONFile);
135
77
  }
136
78
 
137
79
  // Check if version already exists.
@@ -141,30 +83,63 @@ export function cliDocsVersionCommand(
141
83
  );
142
84
  }
143
85
 
144
- const {path: docsPath, sidebarPath} = options;
145
-
146
- // Copy docs files.
147
- const docsDir = path.join(siteDir, docsPath);
148
-
149
- if (fs.existsSync(docsDir) && fs.readdirSync(docsDir).length > 0) {
150
- const versionedDir = getVersionedDocsDirPath(siteDir, pluginId);
151
- const newVersionDir = path.join(versionedDir, `version-${version}`);
152
- fs.copySync(docsDir, newVersionDir);
153
- } else {
154
- throw new Error(`${pluginIdLogPrefix}: there is no docs to version!`);
86
+ if (i18n.locales.length > 1) {
87
+ logger.info`Versioned docs will be created for the following locales: name=${i18n.locales}`;
155
88
  }
156
89
 
157
- createVersionedSidebarFile({
90
+ await Promise.all(
91
+ i18n.locales.map(async (locale) => {
92
+ // Copy docs files.
93
+ const docsDir =
94
+ locale === i18n.defaultLocale
95
+ ? path.resolve(siteDir, docsPath)
96
+ : getDocsDirPathLocalized({
97
+ siteDir,
98
+ locale,
99
+ pluginId,
100
+ versionName: CURRENT_VERSION_NAME,
101
+ });
102
+
103
+ if (
104
+ !(await fs.pathExists(docsDir)) ||
105
+ (await fs.readdir(docsDir)).length === 0
106
+ ) {
107
+ if (locale === i18n.defaultLocale) {
108
+ throw new Error(
109
+ logger.interpolate`${pluginIdLogPrefix}: no docs found in path=${docsDir}.`,
110
+ );
111
+ } else {
112
+ logger.warn`${pluginIdLogPrefix}: no docs found in path=${docsDir}. Skipping.`;
113
+ return;
114
+ }
115
+ }
116
+
117
+ const newVersionDir =
118
+ locale === i18n.defaultLocale
119
+ ? getVersionDocsDirPath(siteDir, pluginId, version)
120
+ : getDocsDirPathLocalized({
121
+ siteDir,
122
+ locale,
123
+ pluginId,
124
+ versionName: version,
125
+ });
126
+ await fs.copy(docsDir, newVersionDir);
127
+ }),
128
+ );
129
+
130
+ await createVersionedSidebarFile({
158
131
  siteDir,
159
132
  pluginId,
160
133
  version,
161
- sidebarPath: resolveSidebarPathOption(siteDir, sidebarPath),
134
+ sidebarPath,
162
135
  });
163
136
 
164
137
  // Update versions.json file.
165
138
  versions.unshift(version);
166
- fs.ensureDirSync(path.dirname(versionsJSONFile));
167
- fs.writeFileSync(versionsJSONFile, `${JSON.stringify(versions, null, 2)}\n`);
139
+ await fs.outputFile(
140
+ versionsJSONFile,
141
+ `${JSON.stringify(versions, null, 2)}\n`,
142
+ );
168
143
 
169
- console.log(`${pluginIdLogPrefix}: version ${version} created!`);
144
+ logger.success`name=${pluginIdLogPrefix}: version name=${version} created!`;
170
145
  }