mirror of
https://github.com/twbs/bootstrap.git
synced 2025-01-30 22:52:24 +01:00
Improve zip-examples.js by only including the assets we need
This commit is contained in:
parent
05a108b3d5
commit
5a17956e5e
@ -15,34 +15,62 @@ const sh = require('shelljs')
|
|||||||
const pkg = require('../package.json')
|
const pkg = require('../package.json')
|
||||||
|
|
||||||
const versionShort = pkg.config.version_short
|
const versionShort = pkg.config.version_short
|
||||||
const folderName = `bootstrap-${pkg.version}-examples`
|
const distFolder = `bootstrap-${pkg.version}-examples`
|
||||||
|
const rootDocsDir = '_gh_pages'
|
||||||
|
const docsDir = `${rootDocsDir}/docs/${versionShort}/`
|
||||||
|
|
||||||
|
// these are the files we need in the examples
|
||||||
|
const cssFiles = [
|
||||||
|
'bootstrap.min.css',
|
||||||
|
'bootstrap.min.css.map'
|
||||||
|
]
|
||||||
|
const jsFiles = [
|
||||||
|
'bootstrap.bundle.min.js',
|
||||||
|
'bootstrap.bundle.min.js.map'
|
||||||
|
]
|
||||||
|
const imgFiles = [
|
||||||
|
'bootstrap-outline.svg',
|
||||||
|
'bootstrap-solid.svg'
|
||||||
|
]
|
||||||
|
|
||||||
sh.config.fatal = true
|
sh.config.fatal = true
|
||||||
|
|
||||||
if (!sh.test('-d', '_gh_pages')) {
|
if (!sh.test('-d', rootDocsDir)) {
|
||||||
throw new Error('The "_gh_pages" folder does not exist, did you forget building the docs?')
|
throw new Error(`The "${rootDocsDir}" folder does not exist, did you forget building the docs?`)
|
||||||
}
|
}
|
||||||
|
|
||||||
// switch to the root dir
|
// switch to the root dir
|
||||||
sh.cd(path.join(__dirname, '..'))
|
sh.cd(path.join(__dirname, '..'))
|
||||||
|
|
||||||
// remove any previously created folder with the same name
|
// remove any previously created folder/zip with the same name
|
||||||
sh.rm('-rf', folderName)
|
sh.rm('-rf', [distFolder, `${distFolder}.zip`])
|
||||||
// create any folders so that `cp` works
|
|
||||||
sh.mkdir('-p', folderName)
|
|
||||||
sh.mkdir('-p', `${folderName}/assets/brand/`)
|
|
||||||
|
|
||||||
sh.cp('-Rf', `_gh_pages/docs/${versionShort}/examples/*`, folderName)
|
// create any folders so that `cp` works
|
||||||
sh.cp('-Rf', `_gh_pages/docs/${versionShort}/dist/`, `${folderName}/assets/`)
|
sh.mkdir('-p', [
|
||||||
// also copy the two brand images we use in the examples
|
distFolder,
|
||||||
sh.cp('-f', [
|
`${distFolder}/assets/brand/`,
|
||||||
`_gh_pages/docs/${versionShort}/assets/brand/bootstrap-outline.svg`,
|
`${distFolder}/assets/dist/css/`,
|
||||||
`_gh_pages/docs/${versionShort}/assets/brand/bootstrap-solid.svg`
|
`${distFolder}/assets/dist/js/`
|
||||||
], `${folderName}/assets/brand/`)
|
])
|
||||||
sh.rm(`${folderName}/index.html`)
|
|
||||||
|
sh.cp('-Rf', `${docsDir}/examples/*`, distFolder)
|
||||||
|
|
||||||
|
cssFiles.forEach(file => {
|
||||||
|
sh.cp('-f', `${docsDir}/dist/css/${file}`, `${distFolder}/assets/dist/css/`)
|
||||||
|
})
|
||||||
|
|
||||||
|
jsFiles.forEach(file => {
|
||||||
|
sh.cp('-f', `${docsDir}/dist/js/${file}`, `${distFolder}/assets/dist/js/`)
|
||||||
|
})
|
||||||
|
|
||||||
|
imgFiles.forEach(file => {
|
||||||
|
sh.cp('-f', `${docsDir}/assets/brand/${file}`, `${distFolder}/assets/brand/`)
|
||||||
|
})
|
||||||
|
|
||||||
|
sh.rm(`${distFolder}/index.html`)
|
||||||
|
|
||||||
// get all examples' HTML files
|
// get all examples' HTML files
|
||||||
sh.find(`${folderName}/**/*.html`).forEach(file => {
|
sh.find(`${distFolder}/**/*.html`).forEach(file => {
|
||||||
const fileContents = sh.cat(file)
|
const fileContents = sh.cat(file)
|
||||||
.toString()
|
.toString()
|
||||||
.replace(new RegExp(`"/docs/${versionShort}/`, 'g'), '"../')
|
.replace(new RegExp(`"/docs/${versionShort}/`, 'g'), '"../')
|
||||||
@ -54,9 +82,7 @@ sh.find(`${folderName}/**/*.html`).forEach(file => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
// create the zip file
|
// create the zip file
|
||||||
sh.exec(`zip -r9 "${folderName}.zip" "${folderName}"`, {
|
sh.exec(`zip -r9 "${distFolder}.zip" "${distFolder}"`)
|
||||||
fatal: true
|
|
||||||
})
|
|
||||||
|
|
||||||
// remove the folder we created
|
// remove the folder we created
|
||||||
sh.rm('-rf', folderName)
|
sh.rm('-rf', distFolder)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user