2020-04-29 20:21:53 +02:00
|
|
|
#!/usr/bin/env node
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* Script to create the built examples zip archive;
|
|
|
|
* requires the `zip` command to be present!
|
2021-01-07 11:19:16 +01:00
|
|
|
* Copyright 2020-2021 The Bootstrap Authors
|
2020-06-17 07:32:42 +02:00
|
|
|
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
|
2020-04-29 20:21:53 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
'use strict'
|
|
|
|
|
|
|
|
const path = require('path')
|
|
|
|
const sh = require('shelljs')
|
|
|
|
|
2021-01-10 07:19:00 +01:00
|
|
|
const pkg = require('../package.json')
|
2020-04-29 20:21:53 +02:00
|
|
|
|
2021-01-10 07:19:00 +01:00
|
|
|
const versionShort = pkg.config.version_short
|
|
|
|
const folderName = `bootstrap-${pkg.version}-examples`
|
2020-04-29 20:21:53 +02:00
|
|
|
|
|
|
|
sh.config.fatal = true
|
|
|
|
|
|
|
|
if (!sh.test('-d', '_gh_pages')) {
|
2020-05-11 17:01:18 +02:00
|
|
|
throw new Error('The "_gh_pages" folder does not exist, did you forget building the docs?')
|
2020-04-29 20:21:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// switch to the root dir
|
|
|
|
sh.cd(path.join(__dirname, '..'))
|
|
|
|
|
|
|
|
// remove any previously created folder with the same name
|
|
|
|
sh.rm('-rf', folderName)
|
2020-05-11 17:01:18 +02:00
|
|
|
// create any folders so that `cp` works
|
2020-04-29 20:21:53 +02:00
|
|
|
sh.mkdir('-p', folderName)
|
2020-05-11 17:01:18 +02:00
|
|
|
sh.mkdir('-p', `${folderName}/assets/brand/`)
|
|
|
|
|
|
|
|
sh.cp('-Rf', `_gh_pages/docs/${versionShort}/examples/*`, folderName)
|
|
|
|
sh.cp('-Rf', `_gh_pages/docs/${versionShort}/dist/`, `${folderName}/assets/`)
|
|
|
|
// also copy the two brand images we use in the examples
|
|
|
|
sh.cp('-f', [
|
|
|
|
`_gh_pages/docs/${versionShort}/assets/brand/bootstrap-outline.svg`,
|
|
|
|
`_gh_pages/docs/${versionShort}/assets/brand/bootstrap-solid.svg`
|
|
|
|
], `${folderName}/assets/brand/`)
|
2020-04-29 20:21:53 +02:00
|
|
|
sh.rm(`${folderName}/index.html`)
|
|
|
|
|
2020-05-11 17:01:18 +02:00
|
|
|
// get all examples' HTML files
|
2020-06-12 20:50:30 +02:00
|
|
|
sh.find(`${folderName}/**/*.html`).forEach(file => {
|
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)
|
2020-04-29 20:21:53 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
// create the zip file
|
|
|
|
sh.exec(`zip -r9 "${folderName}.zip" "${folderName}"`, {
|
|
|
|
fatal: true
|
|
|
|
})
|
|
|
|
|
|
|
|
// remove the folder we created
|
|
|
|
sh.rm('-rf', folderName)
|