@@ -4,17 +4,7 @@ import { JSDOM } from 'jsdom';
4
4
import { Marked } from 'marked' ;
5
5
import { gfmHeadingId , getHeadingList } from 'marked-gfm-heading-id' ;
6
6
import markedAlert from 'marked-alert' ;
7
-
8
- const DOCS_DIR = 'docs/web/' ;
9
- const BLOG_DIR = 'docs/web/blog/' ;
10
- const RESULT_DIR = 'website/dist/' ;
11
- const TEMPLATES_DIR = 'website/templates/' ;
12
- const SRC_DIR = 'website/src/' ;
13
- const VERSIONS_FILE = 'website/config/versions.json' ;
14
- const TEMPLATE_PATH = `${ TEMPLATES_DIR } index.html` ;
15
- const BUNDLES_PATH = './bundles' ;
16
- const BUNDLE_NAME = 'core-js-bundle.js' ;
17
- const BUNDLE_NAME_ESMODULES = 'core-js-bundle-esmodules.js' ;
7
+ import config from './config/config.mjs' ;
18
8
19
9
const args = process . argv ;
20
10
const lastArg = args . at ( - 1 ) ;
@@ -25,7 +15,7 @@ const BASE = BRANCH ? `/branches/${ BRANCH }/` : '/';
25
15
async function getDefaultVersion ( ) {
26
16
if ( BRANCH ) return BRANCH ;
27
17
28
- const versions = await readJSON ( VERSIONS_FILE ) ;
18
+ const versions = await readJSON ( config . versionsFile ) ;
29
19
return versions . find ( v => v . default ) ?. label ;
30
20
}
31
21
@@ -75,7 +65,7 @@ async function getDocsMenuItems(version) {
75
65
if ( docsMenuItems [ version ] ) return docsMenuItems [ version ] ;
76
66
77
67
echo ( chalk . green ( `Getting menu items from file for version: ${ version } ` ) ) ;
78
- const jsonPath = BRANCH ? `${ DOCS_DIR } docs/menu.json` : `${ DOCS_DIR } ${ version } /docs/menu.json` ;
68
+ const jsonPath = BRANCH ? `${ config . docsDir } docs/menu.json` : `${ config . docsDir } ${ version } /docs/menu.json` ;
79
69
const exists = await isExists ( jsonPath ) ;
80
70
if ( ! exists ) {
81
71
echo ( chalk . yellow ( `Menu JSON file not found: ${ jsonPath } ` ) ) ;
@@ -104,10 +94,9 @@ async function buildDocsMenuForVersion(version) {
104
94
async function buildVersionsMenuList ( versions , currentVersion , section ) {
105
95
let versionsMenuHtml = '<div class="dropdown-block">' ;
106
96
for ( const v of versions ) {
107
- const activityClass = v . label === currentVersion ? ' class="active"' : '' ;
108
97
const defaultBadge = v . default ? ' (default)' : '' ;
109
98
const versionPath = v . default ? '' : `${ v . label } /` ;
110
- versionsMenuHtml += `<a href="./${ versionPath } ${ section } /" ${ activityClass } >${ v . label } ${ defaultBadge } </a>` ;
99
+ versionsMenuHtml += `<a href="./${ versionPath } ${ section } " >${ v . label } ${ defaultBadge } </a>` ;
111
100
}
112
101
versionsMenuHtml += '</div>' ;
113
102
@@ -187,7 +176,7 @@ let blogMenuCache = '';
187
176
async function buildBlogMenu ( ) {
188
177
if ( blogMenuCache !== '' ) return blogMenuCache ;
189
178
190
- const mdFiles = await getAllMdFiles ( BLOG_DIR ) ;
179
+ const mdFiles = await getAllMdFiles ( config . blogDir ) ;
191
180
mdFiles . reverse ( ) ;
192
181
let index = '---\ndisableContentMenu: true\n---\n# Blog\n\n' ;
193
182
let menu = '<ul>' ;
@@ -205,14 +194,14 @@ async function buildBlogMenu() {
205
194
206
195
const match = mdPath . match ( / (?< date > \d { 4 } - \d { 2 } - \d { 2 } ) - / ) ;
207
196
const date = match && match . groups ? match . groups . date : null ;
208
- const htmlFileName = mdPath . replace ( BLOG_DIR , '' ) . replace ( / \. m d $ / i, '' ) ;
197
+ const htmlFileName = mdPath . replace ( config . blogDir , '' ) . replace ( / \. m d $ / i, '' ) ;
209
198
menu += `<li><a href="./blog/${ htmlFileName } ">${ date } : ${ firstH1 . text } </a></li>` ;
210
199
index += `## [${ firstH1 . text } ](./blog/${
211
200
htmlFileName } )\n\n*${ date } *\n\n${ fileMetadata . preview ?? '' } \n\n`;
212
201
}
213
202
menu += '</ul>' ;
214
203
blogMenuCache = menu ;
215
- const blogIndexPath = path . join ( BLOG_DIR , 'index.md' ) ;
204
+ const blogIndexPath = path . join ( config . blogDir , 'index.md' ) ;
216
205
await fs . writeFile ( blogIndexPath , index , 'utf8' ) ;
217
206
echo ( chalk . green ( `File created: ${ blogIndexPath } ` ) ) ;
218
207
@@ -228,7 +217,7 @@ async function getVersionTags() {
228
217
async function getVersionFromMdFile ( mdPath ) {
229
218
const match = mdPath . match ( / \/ w e b \/ (?< version > [ ^ / ] + ) \/ d o c s \/ / ) ;
230
219
if ( match && match . groups && match . groups . version ) {
231
- return match . groups . version
220
+ return match . groups . version ;
232
221
}
233
222
return DEFAULT_VERSION ;
234
223
}
@@ -245,23 +234,23 @@ async function buildPlaygrounds(template, versions) {
245
234
}
246
235
247
236
async function buildPlayground ( template , version , versions ) {
248
- const bundleScript = `<script nomodule src="${ BUNDLES_PATH } /${ version . label } /${ BUNDLE_NAME } "></script>` ;
249
- const bundleESModulesScript = `<script type="module" src="${ BUNDLES_PATH } /${ version . label } /${ BUNDLE_NAME_ESMODULES } "></script>` ;
250
- const playgroundContent = await readFile ( `${ SRC_DIR } playground.html` ) ;
251
- const versionsMenu = await buildVersionsMenu ( versions , version , 'playground' ) ;
237
+ const bundleScript = `<script nomodule src="${ config . bundlesPath } /${ version . label } /${ config . bundleName } "></script>` ;
238
+ const bundleESModulesScript = `<script type="module" src="${ config . bundlesPath } /${ version . label } /${ config . bundleNameESModules } "></script>` ;
239
+ const playgroundContent = await readFile ( `${ config . srcDir } playground.html` ) ;
240
+ const versionsMenu = await buildVersionsMenu ( versions , version . label , 'playground' ) ;
252
241
let playground = template . replace ( '{content}' , playgroundContent ) ;
253
242
playground = playground . replace ( '{base}' , BASE ) ;
254
243
playground = playground . replace ( '{title}' , 'Playground - ' ) ;
255
244
playground = playground . replace ( '{base}' , BASE ) ;
256
245
playground = playground . replace ( '{core-js-bundle}' , bundleScript ) ;
257
246
playground = playground . replace ( '{core-js-bundle-esmodules}' , bundleESModulesScript ) ;
258
247
const playgroundWithVersion = playground . replace ( '{versions-menu}' , versionsMenu ) ;
259
- const playgroundFilePath = path . join ( RESULT_DIR , version . label , 'playground.html' ) ;
248
+ const playgroundFilePath = path . join ( config . resultDir , version . label , 'playground.html' ) ;
260
249
261
250
if ( version . default ) {
262
- const defaultVersionsMenu = await buildVersionsMenu ( versions , version , 'playground' ) ;
251
+ const defaultVersionsMenu = await buildVersionsMenu ( versions , version . label , 'playground' ) ;
263
252
const defaultVersionPlayground = playground . replace ( '{versions-menu}' , defaultVersionsMenu ) ;
264
- const defaultPlaygroundPath = path . join ( RESULT_DIR , 'playground.html' ) ;
253
+ const defaultPlaygroundPath = path . join ( config . resultDir , 'playground.html' ) ;
265
254
await fs . writeFile ( defaultPlaygroundPath , defaultVersionPlayground , 'utf8' ) ;
266
255
echo ( chalk . green ( `File created: ${ defaultPlaygroundPath } ` ) ) ;
267
256
} else {
@@ -274,17 +263,17 @@ async function buildPlayground(template, version, versions) {
274
263
async function createDocsIndexes ( versions ) {
275
264
if ( BRANCH ) {
276
265
const menuItems = await getDocsMenuItems ( BRANCH ) ;
277
- const firstDocPath = path . join ( RESULT_DIR , `${ menuItems [ 0 ] . url } .html` . replace ( '{docs-version}/' , '' ) ) ;
278
- const indexFilePath = path . join ( RESULT_DIR , 'docs/' , 'index.html' ) ;
266
+ const firstDocPath = path . join ( config . resultDir , `${ menuItems [ 0 ] . url } .html` . replace ( '{docs-version}/' , '' ) ) ;
267
+ const indexFilePath = path . join ( config . resultDir , 'docs/' , 'index.html' ) ;
279
268
await fs . copy ( firstDocPath , indexFilePath ) ;
280
269
echo ( chalk . green ( `File created: ${ indexFilePath } ` ) ) ;
281
270
return ;
282
271
}
283
272
284
273
for ( const version of versions ) {
285
274
const menuItems = await getDocsMenuItems ( version . label ) ;
286
- const firstDocPath = path . join ( RESULT_DIR , `${ menuItems [ 0 ] . url } .html` . replace ( '{docs-version}' , version . label ) ) ;
287
- const indexFilePath = path . join ( RESULT_DIR , `${ version . label } /docs/` , 'index.html' ) ;
275
+ const firstDocPath = path . join ( config . resultDir , `${ menuItems [ 0 ] . url } .html` . replace ( '{docs-version}' , version . label ) ) ;
276
+ const indexFilePath = path . join ( config . resultDir , `${ version . label } /docs/` , 'index.html' ) ;
288
277
await fs . copy ( firstDocPath , indexFilePath ) ;
289
278
echo ( chalk . green ( `File created: ${ indexFilePath } ` ) ) ;
290
279
}
@@ -306,7 +295,7 @@ async function getVersions() {
306
295
default : true ,
307
296
} ] ;
308
297
}
309
- const versions = await readJSON ( VERSIONS_FILE ) ;
298
+ const versions = await readJSON ( config . versionsFile ) ;
310
299
echo ( chalk . green ( 'Got versions from file' ) ) ;
311
300
312
301
return versions ;
@@ -324,13 +313,13 @@ let isDocs = false;
324
313
let isChangelog ;
325
314
326
315
async function build ( ) {
327
- const template = await readFile ( TEMPLATE_PATH ) ;
316
+ const template = await readFile ( config . templatePath ) ;
328
317
await buildBlogMenu ( ) ;
329
- const mdFiles = await getAllMdFiles ( DOCS_DIR ) ;
318
+ const mdFiles = await getAllMdFiles ( config . docsDir ) ;
330
319
const versions = await getVersions ( ) ;
331
320
const defaultVersion = BRANCH || DEFAULT_VERSION ;
332
- const bundleScript = `<script nomodule src="${ BUNDLES_PATH } /${ defaultVersion } /${ BUNDLE_NAME } "></script>` ;
333
- const bundleESModulesScript = `<script type="module" src="${ BUNDLES_PATH } /${ defaultVersion } /${ BUNDLE_NAME_ESMODULES } "></script>` ;
321
+ const bundleScript = `<script nomodule src="${ config . bundlesPath } /${ defaultVersion } /${ config . bundleName } "></script>` ;
322
+ const bundleESModulesScript = `<script type="module" src="${ config . bundlesPath } /${ defaultVersion } /${ config . bundleNameESModules } "></script>` ;
334
323
335
324
let currentVersion = '' ;
336
325
let versionsMenu = '' ;
@@ -347,11 +336,11 @@ async function build() {
347
336
if ( currentVersion !== versionFromMdFile ) {
348
337
currentVersion = versionFromMdFile ;
349
338
docsMenu = await buildDocsMenuForVersion ( currentVersion ) ;
350
- versionsMenu = await buildVersionsMenu ( versions , currentVersion , 'docs' ) ;
339
+ versionsMenu = await buildVersionsMenu ( versions , currentVersion , 'docs/ ' ) ;
351
340
}
352
341
353
- htmlFileName = mdPath . replace ( DOCS_DIR , '' ) . replace ( / \. m d $ / i, '.html' ) ;
354
- const htmlFilePath = path . join ( RESULT_DIR , htmlFileName ) ;
342
+ htmlFileName = mdPath . replace ( config . docsDir , '' ) . replace ( / \. m d $ / i, '.html' ) ;
343
+ const htmlFilePath = path . join ( config . resultDir , htmlFileName ) ;
355
344
const htmlContent = isDocs || isBlog || isChangelog ? markedWithContents . parse ( content ) : marked . parse ( content ) ;
356
345
357
346
let resultHtml = template . replace ( '{content}' , htmlContent . replaceAll ( '$' , '$' ) ) ;
0 commit comments