2020-04-29 14:03:26 -04:00
|
|
|
#!/usr/bin/env node
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* Script to create the built examples zip archive;
|
|
|
|
* requires the `zip` command to be present!
|
2022-01-03 08:03:42 -05:00
|
|
|
* Copyright 2020-2022 The Bootstrap Authors
|
2020-06-16 14:41:47 -04:00
|
|
|
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
|
2020-04-29 14:03:26 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
'use strict'
|
|
|
|
|
|
|
|
const path = require('path')
|
|
|
|
const sh = require('shelljs')
|
|
|
|
|
2021-01-10 01:03:49 -05:00
|
|
|
const pkg = require('../package.json')
|
2020-04-29 14:03:26 -04:00
|
|
|
|
2021-01-10 01:03:49 -05:00
|
|
|
const versionShort = pkg.config.version_short
|
2021-01-13 12:21:31 -05:00
|
|
|
const distFolder = `bootstrap-${pkg.version}-examples`
|
2021-03-02 10:05:26 -05:00
|
|
|
const rootDocsDir = '_site'
|
2021-01-13 12:21:31 -05:00
|
|
|
const docsDir = `${rootDocsDir}/docs/${versionShort}/`
|
|
|
|
|
|
|
|
// these are the files we need in the examples
|
|
|
|
const cssFiles = [
|
|
|
|
'bootstrap.min.css',
|
|
|
|
'bootstrap.min.css.map',
|
|
|
|
'bootstrap.rtl.min.css',
|
|
|
|
'bootstrap.rtl.min.css.map'
|
|
|
|
]
|
|
|
|
const jsFiles = [
|
|
|
|
'bootstrap.bundle.min.js',
|
|
|
|
'bootstrap.bundle.min.js.map'
|
|
|
|
]
|
|
|
|
const imgFiles = [
|
|
|
|
'bootstrap-logo.svg',
|
|
|
|
'bootstrap-logo-white.svg'
|
|
|
|
]
|
2020-04-29 14:03:26 -04:00
|
|
|
|
|
|
|
sh.config.fatal = true
|
|
|
|
|
2021-01-13 12:21:31 -05:00
|
|
|
if (!sh.test('-d', rootDocsDir)) {
|
|
|
|
throw new Error(`The "${rootDocsDir}" folder does not exist, did you forget building the docs?`)
|
2020-04-29 14:03:26 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// switch to the root dir
|
|
|
|
sh.cd(path.join(__dirname, '..'))
|
|
|
|
|
2021-01-14 06:28:39 -05:00
|
|
|
// remove any previously created folder/zip with the same name
|
|
|
|
sh.rm('-rf', [distFolder, `${distFolder}.zip`])
|
2021-01-13 12:21:31 -05:00
|
|
|
|
2020-05-11 11:01:18 -04:00
|
|
|
// create any folders so that `cp` works
|
2021-01-13 12:21:31 -05:00
|
|
|
sh.mkdir('-p', [
|
|
|
|
distFolder,
|
|
|
|
`${distFolder}/assets/brand/`,
|
|
|
|
`${distFolder}/assets/dist/css/`,
|
|
|
|
`${distFolder}/assets/dist/js/`
|
|
|
|
])
|
|
|
|
|
|
|
|
sh.cp('-Rf', `${docsDir}/examples/*`, distFolder)
|
|
|
|
|
2021-07-30 02:28:51 -04:00
|
|
|
for (const file of cssFiles) {
|
2021-01-13 12:21:31 -05:00
|
|
|
sh.cp('-f', `${docsDir}/dist/css/${file}`, `${distFolder}/assets/dist/css/`)
|
2021-07-30 02:28:51 -04:00
|
|
|
}
|
2021-01-13 12:21:31 -05:00
|
|
|
|
2021-07-30 02:28:51 -04:00
|
|
|
for (const file of jsFiles) {
|
2021-01-13 12:21:31 -05:00
|
|
|
sh.cp('-f', `${docsDir}/dist/js/${file}`, `${distFolder}/assets/dist/js/`)
|
2021-07-30 02:28:51 -04:00
|
|
|
}
|
2021-01-13 12:21:31 -05:00
|
|
|
|
2021-07-30 02:28:51 -04:00
|
|
|
for (const file of imgFiles) {
|
2021-01-13 12:21:31 -05:00
|
|
|
sh.cp('-f', `${docsDir}/assets/brand/${file}`, `${distFolder}/assets/brand/`)
|
2021-07-30 02:28:51 -04:00
|
|
|
}
|
2021-01-13 12:21:31 -05:00
|
|
|
|
|
|
|
sh.rm(`${distFolder}/index.html`)
|
2020-04-29 14:03:26 -04:00
|
|
|
|
2020-05-11 11:01:18 -04:00
|
|
|
// get all examples' HTML files
|
2021-07-30 02:28:51 -04:00
|
|
|
for (const file of sh.find(`${distFolder}/**/*.html`)) {
|
2020-05-11 11:01:18 -04:00
|
|
|
const fileContents = sh.cat(file)
|
|
|
|
.toString()
|
|
|
|
.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)
|
2021-07-30 02:28:51 -04:00
|
|
|
}
|
2020-04-29 14:03:26 -04:00
|
|
|
|
|
|
|
// create the zip file
|
2021-01-13 12:21:31 -05:00
|
|
|
sh.exec(`zip -r9 "${distFolder}.zip" "${distFolder}"`)
|
2020-04-29 14:03:26 -04:00
|
|
|
|
|
|
|
// remove the folder we created
|
2021-01-13 12:21:31 -05:00
|
|
|
sh.rm('-rf', distFolder)
|