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