1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- #!/usr/bin/env node
-
- 'use strict';
-
-
-
- var crypto = require('crypto');
- var fs = require('fs');
- var path = require('path');
- var replace = require('replace-in-file');
-
- var configFile = path.join(__dirname, '../_config.yml');
-
-
-
-
- var files = [
- {
- file: 'dist/css/bootstrap.min.css',
- configPropertyName: 'css_hash'
- },
- {
- file: 'dist/css/bootstrap-theme.min.css',
- configPropertyName: 'css_theme_hash'
- },
- {
- file: 'dist/js/bootstrap.min.js',
- configPropertyName: 'js_hash'
- }
- ];
-
- files.forEach(function (file) {
- fs.readFile(file.file, 'utf8', function (err, data) {
- if (err) {
- throw err;
- }
-
- var algo = 'sha384';
- var hash = crypto.createHash(algo).update(data, 'utf8').digest('base64');
- var integrity = algo + '-' + hash;
-
- console.log(file.configPropertyName + ': ' + integrity);
-
- try {
- replace.sync({
- files: configFile,
- from: new RegExp('(\\s' + file.configPropertyName + ':\\s+"|\')(\\S+)("|\')'),
- to: '$1' + integrity + '$3'
- });
- } catch (error) {
- console.error('Error occurred:', error);
- }
- });
- });
|