Skip to content

Commit edafa99

Browse files
committed
build: update build tools and scripts
1 parent 600fe7f commit edafa99

File tree

9 files changed

+398
-8343
lines changed

9 files changed

+398
-8343
lines changed

build/banner.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
'use strict'
22

33
const pkg = require('../package.json')
4+
45
const year = new Date().getFullYear()
56

67
function getBanner(pluginFilename) {
78
return `/*!
89
* CoreUI${pluginFilename ? ` ${pluginFilename}` : ''} v${pkg.version} (${pkg.homepage})
910
* Copyright ${year} ${pkg.author}
10-
* Licensed under MIT (${pkg.homepage})
11+
* Licensed under MIT (https://github.com/coreui/coreui/blob/main/LICENSE)
1112
*/`
1213
}
1314

build/build-plugins.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
/*!
44
* Script to build our plugins to use them separately.
5-
* Copyright 2020-2022 The Bootstrap Authors
6-
* Copyright 2020-2022 Twitter, Inc.
5+
* Copyright 2020-2023 The Bootstrap Authors
76
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
87
*/
98

build/change-version.js

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
/*!
44
* Script to update version number references in the project.
5-
* Copyright 2017-2022 The Bootstrap Authors
6-
* Copyright 2017-2022 Twitter, Inc.
5+
* Copyright 2017-2023 The Bootstrap Authors
76
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
87
*/
98

@@ -24,9 +23,6 @@ const GLOBBY_OPTIONS = {
2423
cwd: path.join(__dirname, '..'),
2524
gitignore: true
2625
}
27-
const EXCLUDED_FILES = [
28-
'CHANGELOG.md'
29-
]
3026

3127
// Blame TC39... https://github.com/benjamingr/RegExp.escape/issues/37
3228
function regExpQuote(string) {
@@ -39,9 +35,17 @@ function regExpQuoteReplacement(string) {
3935

4036
async function replaceRecursively(file, oldVersion, newVersion) {
4137
const originalString = await fs.readFile(file, 'utf8')
42-
const newString = originalString.replace(
43-
new RegExp(regExpQuote(oldVersion), 'g'), regExpQuoteReplacement(newVersion)
44-
)
38+
const newString = originalString
39+
.replace(
40+
new RegExp(regExpQuote(oldVersion), 'g'),
41+
regExpQuoteReplacement(newVersion)
42+
)
43+
// Also replace the version used by the rubygem,
44+
// which is using periods (`.`) instead of hyphens (`-`)
45+
.replace(
46+
new RegExp(regExpQuote(oldVersion.replace(/-/g, '.')), 'g'),
47+
regExpQuoteReplacement(newVersion.replace(/-/g, '.'))
48+
)
4549

4650
// No need to move any further if the strings are identical
4751
if (originalString === newString) {
@@ -59,22 +63,35 @@ async function replaceRecursively(file, oldVersion, newVersion) {
5963
await fs.writeFile(file, newString, 'utf8')
6064
}
6165

66+
function showUsage(args) {
67+
console.error('USAGE: change-version old_version new_version [--verbose] [--dry[-run]]')
68+
console.error('Got arguments:', args)
69+
process.exit(1)
70+
}
71+
6272
async function main(args) {
6373
let [oldVersion, newVersion] = args
6474

6575
if (!oldVersion || !newVersion) {
66-
console.error('USAGE: change-version old_version new_version [--verbose] [--dry[-run]]')
67-
console.error('Got arguments:', args)
68-
process.exit(1)
76+
showUsage(args)
6977
}
7078

71-
// Strip any leading `v` from arguments because otherwise we will end up with duplicate `v`s
72-
[oldVersion, newVersion] = [oldVersion, newVersion].map(arg => arg.startsWith('v') ? arg.slice(1) : arg)
79+
// Strip any leading `v` from arguments because
80+
// otherwise we will end up with duplicate `v`s
81+
[oldVersion, newVersion] = [oldVersion, newVersion].map(arg => {
82+
return arg.startsWith('v') ? arg.slice(1) : arg
83+
})
84+
85+
if (oldVersion === newVersion) {
86+
showUsage(args)
87+
}
7388

7489
try {
75-
const files = await globby(GLOB, GLOBBY_OPTIONS, EXCLUDED_FILES)
90+
const files = await globby(GLOB, GLOBBY_OPTIONS)
7691

77-
await Promise.all(files.map(file => replaceRecursively(file, oldVersion, newVersion)))
92+
await Promise.all(
93+
files.map(file => replaceRecursively(file, oldVersion, newVersion))
94+
)
7895
} catch (error) {
7996
console.error(error)
8097
process.exit(1)

build/generate-sri.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
* Remember to use the same vendor files as the CDN ones,
66
* otherwise the hashes won't match!
77
*
8-
* Copyright 2017-2022 The Bootstrap Authors
9-
* Copyright 2017-2022 Twitter, Inc.
8+
* Copyright 2017-2023 The Bootstrap Authors
109
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
1110
*/
1211

@@ -19,11 +18,11 @@ const sh = require('shelljs')
1918

2019
sh.config.fatal = true
2120

22-
const configFile = path.join(__dirname, '../config.yml')
21+
const configFile = path.join(__dirname, '../hugo.yml')
2322

2423
// Array of objects which holds the files to generate SRI hashes for.
2524
// `file` is the path from the root folder
26-
// `configPropertyName` is the config.yml variable's name of the file
25+
// `configPropertyName` is the hugo.yml variable's name of the file
2726
const files = [
2827
{
2928
file: 'dist/css/coreui.min.css',
@@ -47,8 +46,8 @@ const files = [
4746
}
4847
]
4948

50-
for (const file of files) {
51-
fs.readFile(file.file, 'utf8', (error, data) => {
49+
for (const { file, configPropertyName } of files) {
50+
fs.readFile(file, 'utf8', (error, data) => {
5251
if (error) {
5352
throw error
5453
}
@@ -57,8 +56,8 @@ for (const file of files) {
5756
const hash = crypto.createHash(algo).update(data, 'utf8').digest('base64')
5857
const integrity = `${algo}-${hash}`
5958

60-
console.log(`${file.configPropertyName}: ${integrity}`)
59+
console.log(`${configPropertyName}: ${integrity}`)
6160

62-
sh.sed('-i', new RegExp(`^(\\s+${file.configPropertyName}:\\s+["'])\\S*(["'])`), `$1${integrity}$2`, configFile)
61+
sh.sed('-i', new RegExp(`^(\\s+${configPropertyName}:\\s+["'])\\S*(["'])`), `$1${integrity}$2`, configFile)
6362
})
6463
}

build/rollup.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ if (BUNDLE) {
4040
const rollupConfig = {
4141
input: path.resolve(__dirname, `../js/index.${ESM ? 'esm' : 'umd'}.js`),
4242
output: {
43-
banner,
43+
banner: banner(),
4444
file: path.resolve(__dirname, `../dist/js/${fileDestination}.js`),
4545
format: ESM ? 'esm' : 'umd',
4646
globals,

build/vnu-jar.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
/*!
44
* Script to run vnu-jar if Java is available.
5-
* Copyright 2017-2022 The Bootstrap Authors
6-
* Copyright 2017-2022 Twitter, Inc.
5+
* Copyright 2017-2023 The Bootstrap Authors
76
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
87
*/
98

@@ -14,10 +13,13 @@ const vnu = require('vnu-jar')
1413

1514
execFile('java', ['-version'], (error, stdout, stderr) => {
1615
if (error) {
17-
console.error('Skipping vnu-jar test; Java is missing.')
16+
console.error('Skipping vnu-jar test; Java is probably missing.')
17+
console.error(error)
1818
return
1919
}
2020

21+
console.log('Running vnu-jar validation...')
22+
2123
const is32bitJava = !/64-Bit/.test(stderr)
2224

2325
// vnu-jar accepts multiple ignores joined with a `|`.
@@ -40,7 +42,7 @@ execFile('java', ['-version'], (error, stdout, stderr) => {
4042
'--skip-non-html',
4143
'--Werror',
4244
`--filterpattern "${ignores}"`,
43-
'_gh_pages/',
45+
'_site/',
4446
'js/tests/'
4547
]
4648

@@ -49,6 +51,8 @@ execFile('java', ['-version'], (error, stdout, stderr) => {
4951
args.splice(0, 0, '-Xss512k')
5052
}
5153

54+
console.log(`command used: java ${args.join(' ')}`)
55+
5256
return spawn('java', args, {
5357
shell: true,
5458
stdio: 'inherit'

config.yml renamed to hugo.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,12 @@ params:
7676
cdn:
7777
# See https://www.srihash.org for info on how to generate the hashes
7878
css: "https://cdn.jsdelivr.net/npm/@coreui/coreui@4.2.6/dist/css/coreui.min.css"
79-
css_hash: "sha384-aDYjet8+3D1zE9FwvXAZGj/ValcG1CpTh2JStsGO9qAOWQKIlwrRF2zlau3NtEW6"
79+
css_hash: "sha384-ZfCwsOdmbHF3XqoqhRHviIzl7Kp3sNV6h0w6KAGt6/CE579SuoMkO9e9Cv36zrZb"
8080
css_rtl: "https://cdn.jsdelivr.net/npm/@coreui/coreui@4.2.6/dist/css/coreui.rtl.min.css"
81-
css_rtl_hash: "sha384-TmaP/Hx3htA3zM9hV9rL5Vimgt0LA14ZSBOx5kykS/ifU61qZ/i1WbKB1kFsvM+u"
81+
css_rtl_hash: "sha384-kCouuV807XIU9BIqR2HKA+Lf+sU+LOYLvBpTvNp6AJ7A/Gl1DeLoRRfZ6UFU7eTq"
8282
js: "https://cdn.jsdelivr.net/npm/@coreui/coreui@4.2.6/dist/js/coreui.min.js"
83-
js_hash: "sha384-7z/8kRsWn+JzUhcmd/7if4xTkhFHSa91GbgPGNPuOACOF6hhbxLeSAX0OhEy5ug9"
83+
js_hash: "sha384-dtAjcJI0LEY1lF2SIzuX/l9MN2fXLJSwuRlPIs7FQdIdKtkM/5xZKDLeT4lTG+Ks"
8484
js_bundle: "https://cdn.jsdelivr.net/npm/@coreui/coreui@4.2.6/dist/js/coreui.bundle.min.js"
85-
js_bundle_hash: "sha384-J90s3AWCoKGcK4pNZC9vcTdx9Qpy6AySGN9dsRnCSX/UtQlYwEvZ5W09yowP0ICe"
85+
js_bundle_hash: "sha384-zB2pfzmBfPbMyNTA/VC1TBdnztOVi4B2ROvMzS5l+tz3msltCVlYt7uBXd66F1nG"
8686
popper: "https://cdn.jsdelivr.net/npm/@popperjs/core@2.11.5/dist/umd/popper.min.js"
87-
popper_hash: "sha384-oBqDVmMz9ATKxIep9tiCxS/Z9fNfEXiDAYTujMAeBAsjFuCZSmKbSSUnQlmh/jp3"
87+
popper_hash: "sha384-I7E8VVD/ismYTF4hNIPjVp/Zjvgyol6VFvRkX/vR+Vc4jQkC+hVqc2pM8ODewa9r"

0 commit comments

Comments
 (0)