Skip to content

Commit c06a1f3

Browse files
committed
Backport #30130
Add a script to zip the built examples
1 parent 1b16736 commit c06a1f3

File tree

5 files changed

+65
-1
lines changed

5 files changed

+65
-1
lines changed

_config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ icons: "https://icons.getbootstrap.com"
5151
download:
5252
source: "https://github.com/twbs/bootstrap/archive/v4.4.1.zip"
5353
dist: "https://github.com/twbs/bootstrap/releases/download/v4.4.1/bootstrap-4.4.1-dist.zip"
54+
dist_examples: "https://github.com/twbs/bootstrap/releases/download/v4.4.1/bootstrap-4.4.1-examples.zip"
5455

5556
cdn:
5657
# See https://www.srihash.org for info on how to generate the hashes

build/zip-examples.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/usr/bin/env node
2+
3+
/*!
4+
* Script to create the built examples zip archive;
5+
* requires the `zip` command to be present!
6+
* Copyright 2020 The Bootstrap Authors
7+
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
8+
*/
9+
10+
'use strict'
11+
12+
const path = require('path')
13+
const sh = require('shelljs')
14+
15+
const {
16+
version, version_short: versionShort
17+
} = require('../package.json')
18+
19+
const folderName = `bootstrap-${version}-examples`
20+
21+
sh.config.fatal = true
22+
23+
if (!sh.test('-d', '_gh_pages')) {
24+
throw new Error('The _gh_pages folder does not exist, did you forget building the docs?')
25+
}
26+
27+
// switch to the root dir
28+
sh.cd(path.join(__dirname, '..'))
29+
30+
// remove any previously created folder with the same name
31+
sh.rm('-rf', folderName)
32+
sh.mkdir('-p', folderName)
33+
34+
// copy the examples and dist folders; for the examples we use `*`
35+
// so that its content are copied to the root dist dir
36+
sh.cp('-Rf', [
37+
`_gh_pages/docs/${versionShort}/examples/*`,
38+
`_gh_pages/docs/${versionShort}/dist/`
39+
], folderName)
40+
sh.rm(`${folderName}/index.html`)
41+
42+
// sed-fu
43+
sh.find(`${folderName}/**/*.html`).forEach((file) => {
44+
sh.sed('-i', new RegExp(`"/docs/${versionShort}/`, 'g'), '"../', file)
45+
sh.sed('-i', /(<link href="\.\.\/.*) integrity=".*>/g, '$1>', file)
46+
sh.sed('-i', /(<script src="\.\.\/.*) integrity=".*>/g, '$1></script>', file)
47+
})
48+
49+
// create the zip file
50+
sh.exec(`zip -r9 "${folderName}.zip" "${folderName}"`, {
51+
fatal: true
52+
})
53+
54+
// remove the folder we created
55+
sh.rm('-rf', folderName)

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,11 @@
7373
"docs-serve-only": "npm run docs-serve -- --skip-initial-build --no-watch",
7474
"lockfile-lint": "lockfile-lint --allowed-hosts npm --allowed-schemes https: --empty-hostname false --type npm --path package-lock.json",
7575
"update-deps": "ncu -u -x \"jquery,karma-browserstack-launcher,popper.js,qunit,sinon\" && npm update && bundle update && cross-env-shell echo Manually update \\\"site/docs/$npm_package_version_short/assets/js/vendor/\\\"",
76-
"release": "npm-run-all dist release-sri release-zip docs-production",
76+
"release": "npm-run-all dist release-sri docs-build release-zip*",
7777
"release-sri": "node build/generate-sri.js",
7878
"release-version": "node build/change-version.js",
7979
"release-zip": "cross-env-shell \"shx rm -rf bootstrap-$npm_package_version-dist && shx cp -r dist/ bootstrap-$npm_package_version-dist && zip -r9 bootstrap-$npm_package_version-dist.zip bootstrap-$npm_package_version-dist && shx rm -rf bootstrap-$npm_package_version-dist\"",
80+
"release-zip-examples": "node build/zip-examples.js",
8081
"dist": "npm-run-all --parallel css js",
8182
"test": "npm-run-all lint dist js-test docs-compile docs-lint",
8283
"netlify": "npm-run-all dist release-sri docs-netlify",

site/_layouts/simple.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ <h1 class="bd-title mt-0">{{ page.title | smartify }}</h1>
88
<p class="bd-lead">{{ page.description | smartify }}</p>
99
{%- if page.title == "Examples" -%}
1010
<a href="{{ site.download.source }}" class="btn btn-lg btn-bd-primary" onclick="ga('send', 'event', 'Examples', 'Hero', 'Download');">Download source code</a>
11+
<a href="{{ site.download.dist_examples }}" class="btn btn-lg btn-bd-primary mt-3 mt-sm-0 ml-sm-3 ml-md-5" onclick="ga('send', 'event', 'Examples', 'Hero', 'Download Examples');">Download Examples</a>
1112
{%- endif -%}
1213
</div>
1314
{% include ads.html %}

site/docs/4.4/getting-started/download.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ Should you require [build tools]({{ site.baseurl }}/docs/{{ site.docs_version }}
2828

2929
<a href="{{ site.download.source }}" class="btn btn-bd-primary" onclick="ga('send', 'event', 'Getting started', 'Download', 'Download source');">Download source</a>
3030

31+
## Examples
32+
33+
If you want to download and examine our [examples]({{ site.baseurl }}/docs/{{ site.docs_version }}/examples/), you can grab the already built examples:
34+
35+
<a href="{{ site.download.dist_examples }}" class="btn btn-bd-primary" onclick="ga('send', 'event', 'Getting started', 'Download', 'Download Examples');">Download Examples</a>
36+
3137
## BootstrapCDN
3238

3339
Skip the download with [BootstrapCDN](https://www.bootstrapcdn.com/) to deliver cached version of Bootstrap's compiled CSS and JS to your project.

0 commit comments

Comments
 (0)