1
0
mirror of https://github.com/twbs/bootstrap.git synced 2025-08-18 19:31:35 +02:00

Improve build/zip-examples.js (#30759)

* remove favicons meta tags
* copy the two brand images we use in the examples
* opy dist and brand images into an assets folder
This commit is contained in:
XhmikosR
2020-05-11 18:01:18 +03:00
committed by GitHub
parent 94109cabf4
commit bf06347020

View File

@@ -19,7 +19,7 @@ const folderName = `bootstrap-${version}-examples`
sh.config.fatal = true sh.config.fatal = true
if (!sh.test('-d', '_gh_pages')) { if (!sh.test('-d', '_gh_pages')) {
throw new Error('The _gh_pages folder does not exist, did you forget building the docs?') throw new Error('The "_gh_pages" folder does not exist, did you forget building the docs?')
} }
// switch to the root dir // switch to the root dir
@@ -27,21 +27,29 @@ sh.cd(path.join(__dirname, '..'))
// remove any previously created folder with the same name // remove any previously created folder with the same name
sh.rm('-rf', folderName) sh.rm('-rf', folderName)
// create any folders so that `cp` works
sh.mkdir('-p', folderName) sh.mkdir('-p', folderName)
sh.mkdir('-p', `${folderName}/assets/brand/`)
// copy the examples and dist folders; for the examples we use `*` sh.cp('-Rf', `_gh_pages/docs/${versionShort}/examples/*`, folderName)
// so that its content are copied to the root dist dir sh.cp('-Rf', `_gh_pages/docs/${versionShort}/dist/`, `${folderName}/assets/`)
sh.cp('-Rf', [ // also copy the two brand images we use in the examples
`_gh_pages/docs/${versionShort}/examples/*`, sh.cp('-f', [
`_gh_pages/docs/${versionShort}/dist/` `_gh_pages/docs/${versionShort}/assets/brand/bootstrap-outline.svg`,
], folderName) `_gh_pages/docs/${versionShort}/assets/brand/bootstrap-solid.svg`
], `${folderName}/assets/brand/`)
sh.rm(`${folderName}/index.html`) sh.rm(`${folderName}/index.html`)
// sed-fu // get all examples' HTML files
sh.find(`${folderName}/**/*.html`).forEach(file => { sh.find(`${folderName}/**/*.html`).forEach(file => {
sh.sed('-i', new RegExp(`"/docs/${versionShort}/`, 'g'), '"../', file) const fileContents = sh.cat(file)
sh.sed('-i', /(<link href="\.\.\/.*) integrity=".*>/g, '$1>', file) .toString()
sh.sed('-i', /(<script src="\.\.\/.*) integrity=".*>/g, '$1></script>', file) .replace(new RegExp(`"/docs/${versionShort}/`, 'g'), '"../')
.replace(/"..\/dist\//g, '"../assets/dist/')
.replace(/(<link href="\.\.\/.*) integrity=".*>/g, '$1>')
.replace(/(<script src="\.\.\/.*) integrity=".*>/g, '$1></script>')
.replace(/( +)<!-- favicons(.|\n)+<style>/i, ' <style>')
new sh.ShellString(fileContents).to(file)
}) })
// create the zip file // create the zip file