123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- #!/usr/bin/env node
- 'use strict'
- import crypto from 'crypto'
- import { readFileSync, writeFileSync } from 'fs'
- import path from 'path'
- import { fileURLToPath } from 'node:url'
- const __dirname = path.dirname(fileURLToPath(import.meta.url))
- const configFile = path.join(__dirname, '../pages/_data/site.json')
- console.log(configFile)
- const files = [
- {
- file: 'dist/css/tabler.min.css',
- configPropertyName: 'css_hash'
- },
- {
- file: 'dist/css/tabler.rtl.min.css',
- configPropertyName: 'css_rtl_hash'
- },
- {
- file: 'dist/css/tabler-flags.min.css',
- configPropertyName: 'css_flags_hash'
- },
- {
- file: 'dist/css/tabler-payments.min.css',
- configPropertyName: 'css_payments_hash'
- },
- {
- file: 'dist/css/tabler-social.min.css',
- configPropertyName: 'css_social_hash'
- },
- {
- file: 'dist/css/tabler-vendors.min.css',
- configPropertyName: 'css_vendors_hash'
- },
- {
- file: 'dist/js/tabler.min.js',
- configPropertyName: 'js_hash'
- },
- {
- file: 'dist/js/tabler.bundle.min.js',
- configPropertyName: 'js_bundle_hash'
- }
- ]
- files.forEach((file) => {
- const data = readFileSync(path.join(__dirname, '..', file.file), 'utf8')
- const algo = 'sha384'
- const hash = crypto.createHash(algo).update(data, 'utf8').digest('base64')
- const integrity = `${algo}-${hash}`
- let config = readFileSync(configFile, 'utf8')
- const regex = new RegExp(`"${file.configPropertyName}"\\:\\s+("|')(\\S+)(\\1)`, 'gm')
- config = config.replace(regex, function() {
- return `"${file.configPropertyName}": ${arguments[1]}${integrity}${arguments[3]}`
- })
- writeFileSync(configFile, config, 'utf8')
- })
|