talos

Форк
0
66 строк · 1.7 Кб
1
#!/usr/bin/env node
2

3
/*!
4
 * Script to generate SRI hashes for use in our docs.
5
 * Remember to use the same vendor files as the CDN ones,
6
 * otherwise the hashes won't match!
7
 *
8
 * Copyright 2017-2021 The Bootstrap Authors
9
 * Copyright 2017-2021 Twitter, Inc.
10
 * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
11
 */
12

13
'use strict'
14

15
const crypto = require('crypto')
16
const fs = require('fs')
17
const path = require('path')
18
const sh = require('shelljs')
19

20
const pkg = require('../package.json')
21

22
sh.config.fatal = true
23

24
const configFile = path.join(__dirname, '../config.yml')
25

26
// Array of objects which holds the files to generate SRI hashes for.
27
// `file` is the path from the root folder
28
// `configPropertyName` is the config.yml variable's name of the file
29
const files = [
30
  {
31
    file: 'dist/css/bootstrap.min.css',
32
    configPropertyName: 'css_hash'
33
  },
34
  {
35
    file: 'dist/js/bootstrap.min.js',
36
    configPropertyName: 'js_hash'
37
  },
38
  {
39
    file: 'dist/js/bootstrap.bundle.min.js',
40
    configPropertyName: 'js_bundle_hash'
41
  },
42
  {
43
    file: `site/static/docs/${pkg.config.version_short}/assets/js/vendor/jquery.slim.min.js`,
44
    configPropertyName: 'jquery_hash'
45
  },
46
  {
47
    file: 'node_modules/popper.js/dist/umd/popper.min.js',
48
    configPropertyName: 'popper_hash'
49
  }
50
]
51

52
files.forEach(file => {
53
  fs.readFile(file.file, 'utf8', (err, data) => {
54
    if (err) {
55
      throw err
56
    }
57

58
    const algo = 'sha384'
59
    const hash = crypto.createHash(algo).update(data, 'utf8').digest('base64')
60
    const integrity = `${algo}-${hash}`
61

62
    console.log(`${file.configPropertyName}: ${integrity}`)
63

64
    sh.sed('-i', new RegExp(`^(\\s+${file.configPropertyName}:\\s+["'])\\S*(["'])`), `$1${integrity}$2`, configFile)
65
  })
66
})
67

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.