mirror of https://github.com/twbs/bootstrap.git
Add a simple script to generate SRI hashes for our assets. (#24814)
This commit is contained in:
parent
dcb761350c
commit
cdab56d940
|
@ -0,0 +1,61 @@
|
||||||
|
#!/usr/bin/env node
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* Script to generate SRI hashes for use in our docs.
|
||||||
|
* Remember to use the same vendor files as the CDN ones,
|
||||||
|
* otherwise the hashes won't match!
|
||||||
|
*
|
||||||
|
* Copyright 2017 The Bootstrap Authors
|
||||||
|
* Copyright 2017 Twitter, Inc.
|
||||||
|
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
|
||||||
|
*/
|
||||||
|
|
||||||
|
'use strict'
|
||||||
|
|
||||||
|
const fs = require('fs')
|
||||||
|
const path = require('path')
|
||||||
|
const sriToolbox = require('sri-toolbox')
|
||||||
|
const sh = require('shelljs')
|
||||||
|
const sed = sh.sed
|
||||||
|
|
||||||
|
sh.config.fatal = true
|
||||||
|
|
||||||
|
const configFile = path.join(__dirname, '..', '_config.yml')
|
||||||
|
|
||||||
|
// Array of objects which holds the files to generate SRI hashes for.
|
||||||
|
// `file` is the path from the root folder
|
||||||
|
// `configPropertyName` is the _config.yml variable's name of the file
|
||||||
|
const files = [
|
||||||
|
{
|
||||||
|
file: 'dist/css/bootstrap.min.css',
|
||||||
|
configPropertyName: 'css_hash'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
file: 'dist/js/bootstrap.min.js',
|
||||||
|
configPropertyName: 'js_hash'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
file: 'assets/js/vendor/jquery-slim.min.js',
|
||||||
|
configPropertyName: 'jquery_hash'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
file: 'assets/js/vendor/popper.min.js',
|
||||||
|
configPropertyName: 'popper_hash'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
files.forEach((file) => {
|
||||||
|
fs.readFile(file.file, 'utf8', (err, data) => {
|
||||||
|
if (err) {
|
||||||
|
throw err
|
||||||
|
}
|
||||||
|
|
||||||
|
const integrity = sriToolbox.generate({
|
||||||
|
algorithms: ['sha384']
|
||||||
|
}, data)
|
||||||
|
|
||||||
|
console.log(`${file.configPropertyName}: ${integrity}`)
|
||||||
|
|
||||||
|
sed('-i', new RegExp(`(\\s${file.configPropertyName}:\\s+"|')(\\S+)("|')`), '$1' + integrity + '$3', configFile)
|
||||||
|
})
|
||||||
|
})
|
|
@ -40,6 +40,12 @@ printf "\n${magenta}Compile latest CSS and JS...${end}"
|
||||||
printf "\n${magenta}=======================================================\n${end}"
|
printf "\n${magenta}=======================================================\n${end}"
|
||||||
npm run dist
|
npm run dist
|
||||||
|
|
||||||
|
# Generate the SRI hashes
|
||||||
|
printf "\n${magenta}=======================================================${end}"
|
||||||
|
printf "\n${magenta}Generate the SRI hashes...${end}"
|
||||||
|
printf "\n${magenta}=======================================================\n${end}"
|
||||||
|
npm run release-sri
|
||||||
|
|
||||||
# Compress the dist files
|
# Compress the dist files
|
||||||
printf "\n${magenta}=======================================================${end}"
|
printf "\n${magenta}=======================================================${end}"
|
||||||
printf "\n${magenta}Compressing the dist files...${end}"
|
printf "\n${magenta}Compressing the dist files...${end}"
|
||||||
|
|
|
@ -6182,6 +6182,12 @@
|
||||||
"integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=",
|
"integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"sri-toolbox": {
|
||||||
|
"version": "0.2.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/sri-toolbox/-/sri-toolbox-0.2.0.tgz",
|
||||||
|
"integrity": "sha1-p/6lw/3lXmdc8cjAbz67XCk1g14=",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
"sshpk": {
|
"sshpk": {
|
||||||
"version": "1.13.1",
|
"version": "1.13.1",
|
||||||
"resolved": "https://registry.npmjs.org/sshpk/-/sshpk-1.13.1.tgz",
|
"resolved": "https://registry.npmjs.org/sshpk/-/sshpk-1.13.1.tgz",
|
||||||
|
|
|
@ -55,6 +55,7 @@
|
||||||
"docs-upload-preview": "build/upload-preview.sh",
|
"docs-upload-preview": "build/upload-preview.sh",
|
||||||
"docs-workbox-precache": "node build/workbox.js",
|
"docs-workbox-precache": "node build/workbox.js",
|
||||||
"maintenance-dependencies": "ncu -a -x jquery && npm update && bundle update && shx echo \"Manually update assets/js/vendor/*, js/tests/vendor/* and .travis.yml\"",
|
"maintenance-dependencies": "ncu -a -x jquery && npm update && bundle update && shx echo \"Manually update assets/js/vendor/*, js/tests/vendor/* and .travis.yml\"",
|
||||||
|
"release-sri": "node build/generate-sri.js",
|
||||||
"release-version": "node build/change-version.js",
|
"release-version": "node build/change-version.js",
|
||||||
"release-zip": "cd dist/ && zip -r9 bootstrap-$npm_package_version-dist.zip * && shx mv bootstrap-$npm_package_version-dist.zip ..",
|
"release-zip": "cd dist/ && zip -r9 bootstrap-$npm_package_version-dist.zip * && shx mv bootstrap-$npm_package_version-dist.zip ..",
|
||||||
"dist": "npm-run-all --parallel css js",
|
"dist": "npm-run-all --parallel css js",
|
||||||
|
@ -106,6 +107,7 @@
|
||||||
"rollup-plugin-node-resolve": "^3.0.0",
|
"rollup-plugin-node-resolve": "^3.0.0",
|
||||||
"shelljs": "^0.7.8",
|
"shelljs": "^0.7.8",
|
||||||
"shx": "^0.2.2",
|
"shx": "^0.2.2",
|
||||||
|
"sri-toolbox": "^0.2.0",
|
||||||
"stylelint": "^8.2.0",
|
"stylelint": "^8.2.0",
|
||||||
"stylelint-config-recommended-scss": "^2.0.0",
|
"stylelint-config-recommended-scss": "^2.0.0",
|
||||||
"stylelint-config-standard": "^17.0.0",
|
"stylelint-config-standard": "^17.0.0",
|
||||||
|
|
Loading…
Reference in New Issue