From df88748eb72f61e61459621f6200d248c05dfe68 Mon Sep 17 00:00:00 2001 From: XhmikosR Date: Wed, 29 Apr 2020 21:03:26 +0300 Subject: [PATCH] Add a script to zip the built examples (#30130) --- build/zip-examples.js | 51 +++++++++++++++++++ config.yml | 1 + package.json | 3 +- .../docs/4.3/getting-started/download.md | 6 +++ site/layouts/_default/single.html | 1 + 5 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 build/zip-examples.js diff --git a/build/zip-examples.js b/build/zip-examples.js new file mode 100644 index 0000000000..0ac64e573c --- /dev/null +++ b/build/zip-examples.js @@ -0,0 +1,51 @@ +#!/usr/bin/env node + +/*! + * Script to create the built examples zip archive; + * requires the `zip` command to be present! + * Copyright 2020 The Bootstrap Authors + * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE) + */ + +'use strict' + +const path = require('path') +const sh = require('shelljs') + +const { version, version_short: versionShort } = require('../package.json') + +const folderName = `bootstrap-${version}-examples` + +sh.config.fatal = true + +if (!sh.test('-d', '_gh_pages')) { + throw new Error('The _gh_pages folder does not exist, did you forget building the docs?') +} + +// switch to the root dir +sh.cd(path.join(__dirname, '..')) + +// remove any previously created folder with the same name +sh.rm('-rf', folderName) +sh.mkdir('-p', folderName) + +// copy the examples and dist folders; for the examples we use `*` +// so that its content are copied to the root dist dir +sh.cp('-Rf', [ + `_gh_pages/docs/${versionShort}/examples/*`, + `_gh_pages/docs/${versionShort}/dist/` +], folderName) +sh.rm(`${folderName}/index.html`) + +// sed-fu +sh.find(`${folderName}/**/*.html`).forEach(file => { + sh.sed('-i', new RegExp(`"/docs/${versionShort}/`, 'g'), '"../', file) + sh.sed('-i', /(/g, '$1>', file) + sh.sed('-i', /(', file) +}) + +// create the zip file +sh.exec(`zip -r9 "${folderName}.zip" "${folderName}"`, { fatal: true }) + +// remove the folder we created +sh.rm('-rf', folderName) diff --git a/config.yml b/config.yml index 6d8d7b9137..5aa137d0bb 100644 --- a/config.yml +++ b/config.yml @@ -64,6 +64,7 @@ params: download: source: "https://github.com/twbs/bootstrap/archive/v4.3.1.zip" dist: "https://github.com/twbs/bootstrap/releases/download/v4.3.1/bootstrap-4.3.1-dist.zip" + dist_examples: "https://github.com/twbs/bootstrap/releases/download/v4.3.1/bootstrap-4.3.1-examples.zip" cdn: # See https://www.srihash.org for info on how to generate the hashes diff --git a/package.json b/package.json index 5492fb03ce..88629fe14f 100644 --- a/package.json +++ b/package.json @@ -56,10 +56,11 @@ "docs-serve-only": "serve _gh_pages --listen 9001", "lockfile-lint": "lockfile-lint --allowed-hosts npm --allowed-schemes https: --empty-hostname false --type npm --path package-lock.json", "update-deps": "ncu -u -x karma-browserstack-launcher,popper.js && npm update && echo Manually update site/assets/js/vendor", - "release": "npm-run-all dist release-sri release-zip docs-build", + "release": "npm-run-all dist release-sri docs-build release-zip*", "release-sri": "node build/generate-sri.js", "release-version": "node build/change-version.js", "release-zip": "cross-env-shell \"rm -rf bootstrap-$npm_package_version-dist && cp -r dist/ bootstrap-$npm_package_version-dist && zip -r9 bootstrap-$npm_package_version-dist.zip bootstrap-$npm_package_version-dist && rm -rf bootstrap-$npm_package_version-dist\"", + "release-zip-examples": "node build/zip-examples.js", "dist": "npm-run-all --parallel css js", "test": "npm-run-all lint dist js-test docs-build docs-lint", "netlify": "cross-env-shell HUGO_BASEURL=$DEPLOY_PRIME_URL npm-run-all dist release-sri docs-build", diff --git a/site/content/docs/4.3/getting-started/download.md b/site/content/docs/4.3/getting-started/download.md index c75f50cfea..767a34fb0f 100644 --- a/site/content/docs/4.3/getting-started/download.md +++ b/site/content/docs/4.3/getting-started/download.md @@ -28,6 +28,12 @@ Should you require [build tools]({{< docsref "/getting-started/build-tools#tooli }}" class="btn btn-bd-primary" onclick="ga('send', 'event', 'Getting started', 'Download', 'Download source');">Download source +## Examples + +If you want to download and examine our [examples]({{< docsref "/examples" >}}), you can grab the already built examples: + +}}" class="btn btn-bd-primary" onclick="ga('send', 'event', 'Getting started', 'Download', 'Download Examples');">Download Examples + ## BootstrapCDN Skip the download with [BootstrapCDN](https://www.bootstrapcdn.com/) to deliver cached version of Bootstrap's compiled CSS and JS to your project. diff --git a/site/layouts/_default/single.html b/site/layouts/_default/single.html index 02972c3dda..8ffbda50b7 100644 --- a/site/layouts/_default/single.html +++ b/site/layouts/_default/single.html @@ -14,6 +14,7 @@

{{ .Page.Params.Description | markdownify }}

{{ if eq .Title "Examples" }} Download source code + Download Examples {{ end }} {{ partial "ads" . }}