@@ -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 } ` ) ) ;
@@ -187,7 +177,7 @@ let blogMenuCache = '';
187
177
async function buildBlogMenu ( ) {
188
178
if ( blogMenuCache !== '' ) return blogMenuCache ;
189
179
190
- const mdFiles = await getAllMdFiles ( BLOG_DIR ) ;
180
+ const mdFiles = await getAllMdFiles ( config . blogDir ) ;
191
181
mdFiles . reverse ( ) ;
192
182
let index = '---\ndisableContentMenu: true\n---\n# Blog\n\n' ;
193
183
let menu = '<ul>' ;
@@ -205,14 +195,14 @@ async function buildBlogMenu() {
205
195
206
196
const match = mdPath . match ( / (?< date > \d { 4 } - \d { 2 } - \d { 2 } ) - / ) ;
207
197
const date = match && match . groups ? match . groups . date : null ;
208
- const htmlFileName = mdPath . replace ( BLOG_DIR , '' ) . replace ( / \. m d $ / i, '' ) ;
198
+ const htmlFileName = mdPath . replace ( config . blogDir , '' ) . replace ( / \. m d $ / i, '' ) ;
209
199
menu += `<li><a href="./blog/${ htmlFileName } ">${ date } : ${ firstH1 . text } </a></li>` ;
210
200
index += `## [${ firstH1 . text } ](./blog/${
211
201
htmlFileName } )\n\n*${ date } *\n\n${ fileMetadata . preview ?? '' } \n\n`;
212
202
}
213
203
menu += '</ul>' ;
214
204
blogMenuCache = menu ;
215
- const blogIndexPath = path . join ( BLOG_DIR , 'index.md' ) ;
205
+ const blogIndexPath = path . join ( config . blogDir , 'index.md' ) ;
216
206
await fs . writeFile ( blogIndexPath , index , 'utf8' ) ;
217
207
echo ( chalk . green ( `File created: ${ blogIndexPath } ` ) ) ;
218
208
@@ -228,7 +218,7 @@ async function getVersionTags() {
228
218
async function getVersionFromMdFile ( mdPath ) {
229
219
const match = mdPath . match ( / \/ w e b \/ (?< version > [ ^ / ] + ) \/ d o c s \/ / ) ;
230
220
if ( match && match . groups && match . groups . version ) {
231
- return match . groups . version
221
+ return match . groups . version ;
232
222
}
233
223
return DEFAULT_VERSION ;
234
224
}
@@ -245,9 +235,9 @@ async function buildPlaygrounds(template, versions) {
245
235
}
246
236
247
237
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` ) ;
238
+ const bundleScript = `<script nomodule src="${ config . bundlesPath } /${ version . label } /${ config . bundleName } "></script>` ;
239
+ const bundleESModulesScript = `<script type="module" src="${ config . bundlesPath } /${ version . label } /${ config . bundleNameESModules } "></script>` ;
240
+ const playgroundContent = await readFile ( `${ config . srcDir } playground.html` ) ;
251
241
const versionsMenu = await buildVersionsMenu ( versions , version , 'playground' ) ;
252
242
let playground = template . replace ( '{content}' , playgroundContent ) ;
253
243
playground = playground . replace ( '{base}' , BASE ) ;
@@ -256,12 +246,12 @@ async function buildPlayground(template, version, versions) {
256
246
playground = playground . replace ( '{core-js-bundle}' , bundleScript ) ;
257
247
playground = playground . replace ( '{core-js-bundle-esmodules}' , bundleESModulesScript ) ;
258
248
const playgroundWithVersion = playground . replace ( '{versions-menu}' , versionsMenu ) ;
259
- const playgroundFilePath = path . join ( RESULT_DIR , version . label , 'playground.html' ) ;
249
+ const playgroundFilePath = path . join ( config . resultDir , version . label , 'playground.html' ) ;
260
250
261
251
if ( version . default ) {
262
252
const defaultVersionsMenu = await buildVersionsMenu ( versions , version , 'playground' ) ;
263
253
const defaultVersionPlayground = playground . replace ( '{versions-menu}' , defaultVersionsMenu ) ;
264
- const defaultPlaygroundPath = path . join ( RESULT_DIR , 'playground.html' ) ;
254
+ const defaultPlaygroundPath = path . join ( config . resultDir , 'playground.html' ) ;
265
255
await fs . writeFile ( defaultPlaygroundPath , defaultVersionPlayground , 'utf8' ) ;
266
256
echo ( chalk . green ( `File created: ${ defaultPlaygroundPath } ` ) ) ;
267
257
} else {
@@ -274,17 +264,17 @@ async function buildPlayground(template, version, versions) {
274
264
async function createDocsIndexes ( versions ) {
275
265
if ( BRANCH ) {
276
266
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' ) ;
267
+ const firstDocPath = path . join ( config . resultDir , `${ menuItems [ 0 ] . url } .html` . replace ( '{docs-version}/' , '' ) ) ;
268
+ const indexFilePath = path . join ( config . resultDir , 'docs/' , 'index.html' ) ;
279
269
await fs . copy ( firstDocPath , indexFilePath ) ;
280
270
echo ( chalk . green ( `File created: ${ indexFilePath } ` ) ) ;
281
271
return ;
282
272
}
283
273
284
274
for ( const version of versions ) {
285
275
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' ) ;
276
+ const firstDocPath = path . join ( config . resultDir , `${ menuItems [ 0 ] . url } .html` . replace ( '{docs-version}' , version . label ) ) ;
277
+ const indexFilePath = path . join ( config . resultDir , `${ version . label } /docs/` , 'index.html' ) ;
288
278
await fs . copy ( firstDocPath , indexFilePath ) ;
289
279
echo ( chalk . green ( `File created: ${ indexFilePath } ` ) ) ;
290
280
}
@@ -306,7 +296,7 @@ async function getVersions() {
306
296
default : true ,
307
297
} ] ;
308
298
}
309
- const versions = await readJSON ( VERSIONS_FILE ) ;
299
+ const versions = await readJSON ( config . versionsFile ) ;
310
300
echo ( chalk . green ( 'Got versions from file' ) ) ;
311
301
312
302
return versions ;
@@ -324,13 +314,13 @@ let isDocs = false;
324
314
let isChangelog ;
325
315
326
316
async function build ( ) {
327
- const template = await readFile ( TEMPLATE_PATH ) ;
317
+ const template = await readFile ( config . templatePath ) ;
328
318
await buildBlogMenu ( ) ;
329
- const mdFiles = await getAllMdFiles ( DOCS_DIR ) ;
319
+ const mdFiles = await getAllMdFiles ( config . docsDir ) ;
330
320
const versions = await getVersions ( ) ;
331
321
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>` ;
322
+ const bundleScript = `<script nomodule src="${ config . bundlesPath } /${ defaultVersion } /${ config . bundleName } "></script>` ;
323
+ const bundleESModulesScript = `<script type="module" src="${ config . bundlesPath } /${ defaultVersion } /${ config . bundleNameESModules } "></script>` ;
334
324
335
325
let currentVersion = '' ;
336
326
let versionsMenu = '' ;
@@ -350,8 +340,8 @@ async function build() {
350
340
versionsMenu = await buildVersionsMenu ( versions , currentVersion , 'docs' ) ;
351
341
}
352
342
353
- htmlFileName = mdPath . replace ( DOCS_DIR , '' ) . replace ( / \. m d $ / i, '.html' ) ;
354
- const htmlFilePath = path . join ( RESULT_DIR , htmlFileName ) ;
343
+ htmlFileName = mdPath . replace ( config . docsDir , '' ) . replace ( / \. m d $ / i, '.html' ) ;
344
+ const htmlFilePath = path . join ( config . resultDir , htmlFileName ) ;
355
345
const htmlContent = isDocs || isBlog || isChangelog ? markedWithContents . parse ( content ) : marked . parse ( content ) ;
356
346
357
347
let resultHtml = template . replace ( '{content}' , htmlContent . replaceAll ( '$' , '$' ) ) ;
0 commit comments