1- import { getDefaultVersion } from './scripts/helpers.mjs' ;
1+ import { expandVersionsConfig , getDefaultVersion } from './scripts/helpers.mjs' ;
22import fm from 'front-matter' ;
33import { JSDOM } from 'jsdom' ;
44import { Marked } from 'marked' ;
@@ -20,14 +20,6 @@ let docsMenu = '';
2020let isBlog = false ;
2121let isDocs = false ;
2222
23- async function getDefaultVersionTarget ( versionFile , defaultTarget = null ) {
24- if ( defaultTarget ) return defaultTarget ;
25-
26- const versions = await readJson ( versionFile ) ;
27- const defaultVersion = versions . find ( v => v . default ) ;
28- return defaultVersion ?. branch ?? defaultVersion ?. tag ;
29- }
30-
3123async function getAllMdFiles ( dir ) {
3224 const entries = await readdir ( dir , { withFileTypes : true } ) ;
3325 const files = [ ] ;
@@ -89,12 +81,16 @@ async function buildDocsMenuForVersion(version) {
8981 return menu ;
9082}
9183
84+ function getBundlesPath ( version ) {
85+ return path . join ( config . bundlesPath , version . branch ?? version . tag ) ;
86+ }
87+
9288async function buildVersionsMenuList ( versions , currentVersion , section ) {
9389 let versionsMenuHtml = '<div class="dropdown-block">' ;
9490 for ( const v of versions ) {
9591 const activityClass = v . label === currentVersion && ! v . default ? ' class="active"' : '' ;
9692 const defaultBadge = v . default ? ' (default)' : '' ;
97- const versionPath = v . default ? '' : `${ v . path ?? v . label } /` ;
93+ const versionPath = v . default ? '' : `${ v . path } /` ;
9894 versionsMenuHtml += `<a href="./${ versionPath } ${ section } "${ activityClass } >${ v . label } ${ defaultBadge } </a>` ;
9995 }
10096 versionsMenuHtml += '</div>' ;
@@ -227,9 +223,9 @@ async function buildPlaygrounds(template, versions) {
227223}
228224
229225async function buildPlayground ( template , version , versions ) {
230- const versionPath = version . branch ?? version . tag ;
231- const bundleScript = `<script nomodule src="${ config . bundlesPath } / ${ versionPath } /${ config . bundleName } "></script>` ;
232- const bundleESModulesScript = `<script type="module" src="${ config . bundlesPath } / ${ versionPath } /${ config . bundleNameESModules } "></script>` ;
226+ const bundlesPath = getBundlesPath ( version ) ;
227+ const bundleScript = `<script nomodule src="${ bundlesPath } /${ config . bundleName } "></script>` ;
228+ const bundleESModulesScript = `<script type="module" src="${ bundlesPath } /${ config . bundleNameESModules } "></script>` ;
233229 const babelScript = '<script src="./babel.min.js"></script>' ;
234230 const playgroundContent = await readFileContent ( `${ config . srcDir } playground.html` ) ;
235231 const versionsMenu = await buildVersionsMenu ( versions , version . label , 'playground' ) ;
@@ -240,7 +236,7 @@ async function buildPlayground(template, version, versions) {
240236 playground = playground . replace ( '{core-js-bundle-esmodules}' , bundleESModulesScript ) ;
241237 playground = playground . replace ( '{babel-script}' , babelScript ) ;
242238 const playgroundWithVersion = playground . replace ( '{versions-menu}' , versionsMenu ) ;
243- const playgroundFilePath = path . join ( config . resultDir , versionPath , 'playground.html' ) ;
239+ const playgroundFilePath = path . join ( config . resultDir , version . path , 'playground.html' ) ;
244240
245241 if ( version . default ) {
246242 const defaultVersionsMenu = await buildVersionsMenu ( versions , version . label , 'playground' ) ;
@@ -256,11 +252,11 @@ async function buildPlayground(template, version, versions) {
256252}
257253
258254async function createDocsIndexes ( versions ) {
259- if ( BRANCH ) versions = [ { label : '' } ] ;
255+ if ( BRANCH ) versions = [ { path : '' } ] ;
260256
261257 for ( const version of versions ) {
262- if ( version . default ) continue ;
263- const versionPath = version . path ?? version . label ;
258+ if ( version . default && versions . length > 1 ) continue ;
259+ const versionPath = version . path ;
264260 const menuItems = await getDocsMenuItems ( versionPath ) ;
265261 const firstDocPath = path . join ( config . resultDir ,
266262 `${ menuItems [ 0 ] . url } .html` . replace ( `{docs-version}${ BRANCH ? '/' : '' } ` , versionPath ) ) ;
@@ -273,15 +269,17 @@ async function createDocsIndexes(versions) {
273269async function getVersions ( ) {
274270 if ( BRANCH ) {
275271 return [ {
276- label : BRANCH ,
277- default : true ,
278272 branch : BRANCH ,
273+ default : true ,
274+ label : BRANCH ,
275+ path : BRANCH ,
279276 } ] ;
280277 }
278+
281279 const versions = await readJson ( config . versionsFile ) ;
282280 echo ( chalk . green ( 'Got versions from file' ) ) ;
283281
284- return versions ;
282+ return expandVersionsConfig ( versions ) ;
285283}
286284
287285function getTitle ( content ) {
@@ -294,7 +292,8 @@ async function build() {
294292 await buildBlogMenu ( ) ;
295293 const mdFiles = await getAllMdFiles ( config . docsDir ) ;
296294 const versions = await getVersions ( ) ;
297- const bundlesPath = `${ config . bundlesPath } /${ await getDefaultVersionTarget ( config . versionsFile , BRANCH ) } ` ;
295+ const [ defaultVersion ] = versions ;
296+ const bundlesPath = getBundlesPath ( defaultVersion ) ;
298297 const bundleScript = `<script nomodule src="${ bundlesPath } /${ config . bundleName } "></script>` ;
299298 const bundleESModulesScript = `<script type="module" src="${ bundlesPath } /${ config . bundleNameESModules } "></script>` ;
300299
0 commit comments