source: trip-planner-front/node_modules/bootstrap/grunt/generate-sri.js@ eed0bf8

Last change on this file since eed0bf8 was fa375fe, checked in by Ema <ema_spirova@…>, 3 years ago

adding new components

  • Property mode set to 100644
File size: 1.6 KB
Line 
1#!/usr/bin/env node
2
3'use strict';
4
5/*!
6 * Script to generate SRI hashes for use in our docs.
7 * Remember to use the same vendor files as the CDN ones,
8 * otherwise the hashes won't match!
9 *
10 * Copyright 2017-2019 The Bootstrap Authors
11 * Copyright 2017-2019 Twitter, Inc.
12 * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
13 */
14
15var crypto = require('crypto');
16var fs = require('fs');
17var path = require('path');
18var replace = require('replace-in-file');
19
20var configFile = path.join(__dirname, '../_config.yml');
21
22// Array of objects which holds the files to generate SRI hashes for.
23// `file` is the path from the root folder
24// `configPropertyName` is the _config.yml variable's name of the file
25var files = [
26 {
27 file: 'dist/css/bootstrap.min.css',
28 configPropertyName: 'css_hash'
29 },
30 {
31 file: 'dist/css/bootstrap-theme.min.css',
32 configPropertyName: 'css_theme_hash'
33 },
34 {
35 file: 'dist/js/bootstrap.min.js',
36 configPropertyName: 'js_hash'
37 }
38];
39
40files.forEach(function (file) {
41 fs.readFile(file.file, 'utf8', function (err, data) {
42 if (err) {
43 throw err;
44 }
45
46 var algo = 'sha384';
47 var hash = crypto.createHash(algo).update(data, 'utf8').digest('base64');
48 var integrity = algo + '-' + hash;
49
50 console.log(file.configPropertyName + ': ' + integrity);
51
52 try {
53 replace.sync({
54 files: configFile,
55 from: new RegExp('(\\s' + file.configPropertyName + ':\\s+"|\')(\\S+)("|\')'),
56 to: '$1' + integrity + '$3'
57 });
58 } catch (error) {
59 console.error('Error occurred:', error);
60 }
61 });
62});
Note: See TracBrowser for help on using the repository browser.