Skip to content

Commit 2d30c7e

Browse files
committed
Improve zip-examples.js
Only include the needed dist files
1 parent cefdcf6 commit 2d30c7e

File tree

1 file changed

+48
-18
lines changed

1 file changed

+48
-18
lines changed

build/zip-examples.js

Lines changed: 48 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,34 +14,64 @@ const sh = require('shelljs')
1414

1515
const { version, version_short: versionShort } = require('../package.json')
1616

17-
const folderName = `bootstrap-${version}-examples`
17+
const distFolder = `bootstrap-${version}-examples`
18+
const rootDocsDir = '_gh_pages'
19+
const docsDir = `${rootDocsDir}/docs/${versionShort}/`
20+
21+
// these are the files we need in the examples
22+
const cssFiles = [
23+
'bootstrap.min.css',
24+
'bootstrap.min.css.map',
25+
'bootstrap.rtl.min.css',
26+
'bootstrap.rtl.min.css.map'
27+
]
28+
const jsFiles = [
29+
'bootstrap.bundle.min.js',
30+
'bootstrap.bundle.min.js.map'
31+
]
32+
const imgFiles = [
33+
'bootstrap-logo.svg',
34+
'bootstrap-logo-white.svg'
35+
]
1836

1937
sh.config.fatal = true
2038

21-
if (!sh.test('-d', '_gh_pages')) {
22-
throw new Error('The "_gh_pages" folder does not exist, did you forget building the docs?')
39+
if (!sh.test('-d', rootDocsDir)) {
40+
throw new Error(`The "${rootDocsDir}" folder does not exist, did you forget building the docs?`)
2341
}
2442

2543
// switch to the root dir
2644
sh.cd(path.join(__dirname, '..'))
2745

2846
// remove any previously created folder with the same name
29-
sh.rm('-rf', folderName)
47+
sh.rm('-rf', distFolder)
48+
3049
// create any folders so that `cp` works
31-
sh.mkdir('-p', folderName)
32-
sh.mkdir('-p', `${folderName}/assets/brand/`)
33-
34-
sh.cp('-Rf', `_gh_pages/docs/${versionShort}/examples/*`, folderName)
35-
sh.cp('-Rf', `_gh_pages/docs/${versionShort}/dist/`, `${folderName}/assets/`)
36-
// also copy the two brand images we use in the examples
37-
sh.cp('-f', [
38-
`_gh_pages/docs/${versionShort}/assets/brand/bootstrap-logo.svg`,
39-
`_gh_pages/docs/${versionShort}/assets/brand/bootstrap-logo-white.svg`
40-
], `${folderName}/assets/brand/`)
41-
sh.rm(`${folderName}/index.html`)
50+
sh.mkdir('-p', [
51+
distFolder,
52+
`${distFolder}/assets/brand/`,
53+
`${distFolder}/assets/dist/css/`,
54+
`${distFolder}/assets/dist/js/`
55+
])
56+
57+
sh.cp('-Rf', `${docsDir}/examples/*`, distFolder)
58+
59+
cssFiles.forEach(file => {
60+
sh.cp('-f', `${docsDir}/dist/css/${file}`, `${distFolder}/assets/dist/css/`)
61+
})
62+
63+
jsFiles.forEach(file => {
64+
sh.cp('-f', `${docsDir}/dist/js/${file}`, `${distFolder}/assets/dist/js/`)
65+
})
66+
67+
imgFiles.forEach(file => {
68+
sh.cp('-f', `${docsDir}/assets/brand/${file}`, `${distFolder}/assets/brand/`)
69+
})
70+
71+
sh.rm(`${distFolder}/index.html`)
4272

4373
// get all examples' HTML files
44-
sh.find(`${folderName}/**/*.html`).forEach(file => {
74+
sh.find(`${distFolder}/**/*.html`).forEach(file => {
4575
const fileContents = sh.cat(file)
4676
.toString()
4777
.replace(new RegExp(`"/docs/${versionShort}/`, 'g'), '"../')
@@ -53,7 +83,7 @@ sh.find(`${folderName}/**/*.html`).forEach(file => {
5383
})
5484

5585
// create the zip file
56-
sh.exec(`zip -r9 "${folderName}.zip" "${folderName}"`, { fatal: true })
86+
sh.exec(`zip -r9 "${distFolder}.zip" "${distFolder}"`)
5787

5888
// remove the folder we created
59-
sh.rm('-rf', folderName)
89+
sh.rm('-rf', distFolder)

0 commit comments

Comments
 (0)