15
const crypto = require('crypto')
16
const fs = require('fs')
17
const path = require('path')
18
const sh = require('shelljs')
20
const pkg = require('../package.json')
24
const configFile = path.join(__dirname, '../config.yml')
31
file: 'dist/css/bootstrap.min.css',
32
configPropertyName: 'css_hash'
35
file: 'dist/js/bootstrap.min.js',
36
configPropertyName: 'js_hash'
39
file: 'dist/js/bootstrap.bundle.min.js',
40
configPropertyName: 'js_bundle_hash'
43
file: `site/static/docs/${pkg.config.version_short}/assets/js/vendor/jquery.slim.min.js`,
44
configPropertyName: 'jquery_hash'
47
file: 'node_modules/popper.js/dist/umd/popper.min.js',
48
configPropertyName: 'popper_hash'
52
files.forEach(file => {
53
fs.readFile(file.file, 'utf8', (err, data) => {
59
const hash = crypto.createHash(algo).update(data, 'utf8').digest('base64')
60
const integrity = `${algo}-${hash}`
62
console.log(`${file.configPropertyName}: ${integrity}`)
64
sh.sed('-i', new RegExp(`^(\\s+${file.configPropertyName}:\\s+["'])\\S*(["'])`), `$1${integrity}$2`, configFile)