1
0
mirror of https://github.com/twbs/bootstrap.git synced 2025-08-28 15:50:01 +02:00

Docs: unminify package example HTML files (#41637)

This commit is contained in:
Julien Déramond
2025-08-05 20:55:52 +02:00
committed by GitHub
parent b850fcbe49
commit 1eccc810f0
3 changed files with 26 additions and 9 deletions

View File

@@ -11,6 +11,7 @@ import fs from 'node:fs/promises'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
import sh from 'shelljs'
import { format } from 'prettier'
const __dirname = path.dirname(fileURLToPath(import.meta.url))
@@ -83,7 +84,9 @@ for (const file of staticJsFiles) {
sh.rm(`${distFolder}/index.html`)
// get all examples' HTML files
for (const file of sh.find(`${distFolder}/**/*.html`)) {
const htmlFiles = sh.find(`${distFolder}/**/*.html`)
const formatPromises = htmlFiles.map(async file => {
const fileContents = sh.cat(file)
.toString()
.replace(new RegExp(`"/docs/${versionShort}/`, 'g'), '"../')
@@ -91,8 +94,24 @@ for (const file of sh.find(`${distFolder}/**/*.html`)) {
.replace(/(<link href="\.\.\/[^"]*"[^>]*) integrity="[^"]*"/g, '$1')
.replace(/<link[^>]*href="\.\.\/assets\/img\/favicons\/[^"]*"[^>]*>/g, '')
.replace(/(<script src="\.\.\/[^"]*"[^>]*) integrity="[^"]*"/g, '$1')
new sh.ShellString(fileContents).to(file)
}
let formattedHTML
try {
formattedHTML = await format(fileContents, {
parser: 'html',
filepath: file
})
} catch (error) {
console.error(`\nError formatting ${file}:`)
console.error(`Message: ${error.message}`)
console.error('\nSkipping formatting for this file...\n')
formattedHTML = fileContents
}
new sh.ShellString(formattedHTML).to(file)
})
await Promise.all(formatPromises)
// create the zip file
sh.exec(`zip -qr9 "${distFolder}.zip" "${distFolder}"`)