diff options
Diffstat (limited to 'vendor/twbs/bootstrap/build')
-rw-r--r-- | vendor/twbs/bootstrap/build/build-plugins.js | 207 | ||||
-rw-r--r-- | vendor/twbs/bootstrap/build/change-version.js | 8 | ||||
-rw-r--r-- | vendor/twbs/bootstrap/build/generate-sri.js | 14 | ||||
-rw-r--r-- | vendor/twbs/bootstrap/build/postcss.config.js | 18 | ||||
-rw-r--r-- | vendor/twbs/bootstrap/build/rollup.config.js | 6 | ||||
-rw-r--r-- | vendor/twbs/bootstrap/build/svgo.yml | 59 | ||||
-rw-r--r-- | vendor/twbs/bootstrap/build/vnu-jar.js | 4 | ||||
-rw-r--r-- | vendor/twbs/bootstrap/build/zip-examples.js | 18 |
8 files changed, 98 insertions, 236 deletions
diff --git a/vendor/twbs/bootstrap/build/build-plugins.js b/vendor/twbs/bootstrap/build/build-plugins.js index 2e16e4f03..4c68edcd1 100644 --- a/vendor/twbs/bootstrap/build/build-plugins.js +++ b/vendor/twbs/bootstrap/build/build-plugins.js @@ -2,8 +2,8 @@ /*! * Script to build our plugins to use them separately. - * Copyright 2020-2021 The Bootstrap Authors - * Copyright 2020-2021 Twitter, Inc. + * Copyright 2020-2022 The Bootstrap Authors + * Copyright 2020-2022 Twitter, Inc. * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) */ @@ -11,173 +11,94 @@ const path = require('path') const rollup = require('rollup') +const globby = require('globby') const { babel } = require('@rollup/plugin-babel') const banner = require('./banner.js') -const rootPath = path.resolve(__dirname, '../js/dist/') -const plugins = [ - babel({ - // Only transpile our source code - exclude: 'node_modules/**', - // Include the helpers in each file, at most one copy of each - babelHelpers: 'bundled' - }) -] -const bsPlugins = { - Data: path.resolve(__dirname, '../js/src/dom/data.js'), - EventHandler: path.resolve(__dirname, '../js/src/dom/event-handler.js'), - Manipulator: path.resolve(__dirname, '../js/src/dom/manipulator.js'), - SelectorEngine: path.resolve(__dirname, '../js/src/dom/selector-engine.js'), - Alert: path.resolve(__dirname, '../js/src/alert.js'), - Base: path.resolve(__dirname, '../js/src/base-component.js'), - Button: path.resolve(__dirname, '../js/src/button.js'), - Carousel: path.resolve(__dirname, '../js/src/carousel.js'), - Collapse: path.resolve(__dirname, '../js/src/collapse.js'), - Dropdown: path.resolve(__dirname, '../js/src/dropdown.js'), - Modal: path.resolve(__dirname, '../js/src/modal.js'), - Offcanvas: path.resolve(__dirname, '../js/src/offcanvas.js'), - Popover: path.resolve(__dirname, '../js/src/popover.js'), - ScrollSpy: path.resolve(__dirname, '../js/src/scrollspy.js'), - Tab: path.resolve(__dirname, '../js/src/tab.js'), - Toast: path.resolve(__dirname, '../js/src/toast.js'), - Tooltip: path.resolve(__dirname, '../js/src/tooltip.js') -} - -const defaultPluginConfig = { - external: [ - bsPlugins.Data, - bsPlugins.Base, - bsPlugins.EventHandler, - bsPlugins.SelectorEngine - ], - globals: { - [bsPlugins.Data]: 'Data', - [bsPlugins.Base]: 'Base', - [bsPlugins.EventHandler]: 'EventHandler', - [bsPlugins.SelectorEngine]: 'SelectorEngine' - } -} +const sourcePath = path.resolve(__dirname, '../js/src/').replace(/\\/g, '/') +const jsFiles = globby.sync(sourcePath + '/**/*.js') -const getConfigByPluginKey = pluginKey => { - switch (pluginKey) { - case 'Alert': - case 'Offcanvas': - case 'Tab': - return defaultPluginConfig - - case 'Base': - case 'Button': - case 'Carousel': - case 'Collapse': - case 'Modal': - case 'ScrollSpy': { - const config = Object.assign(defaultPluginConfig) - config.external.push(bsPlugins.Manipulator) - config.globals[bsPlugins.Manipulator] = 'Manipulator' - return config - } +// Array which holds the resolved plugins +const resolvedPlugins = [] - case 'Dropdown': - case 'Tooltip': { - const config = Object.assign(defaultPluginConfig) - config.external.push(bsPlugins.Manipulator, '@popperjs/core') - config.globals[bsPlugins.Manipulator] = 'Manipulator' - config.globals['@popperjs/core'] = 'Popper' - return config - } +// Trims the "js" extension and uppercases => first letter, hyphens, backslashes & slashes +const filenameToEntity = filename => filename.replace('.js', '') + .replace(/(?:^|-|\/|\\)[a-z]/g, str => str.slice(-1).toUpperCase()) - case 'Popover': - return { - external: [ - bsPlugins.Data, - bsPlugins.SelectorEngine, - bsPlugins.Tooltip - ], - globals: { - [bsPlugins.Data]: 'Data', - [bsPlugins.SelectorEngine]: 'SelectorEngine', - [bsPlugins.Tooltip]: 'Tooltip' - } - } - - case 'Toast': - return { - external: [ - bsPlugins.Data, - bsPlugins.Base, - bsPlugins.EventHandler, - bsPlugins.Manipulator - ], - globals: { - [bsPlugins.Data]: 'Data', - [bsPlugins.Base]: 'Base', - [bsPlugins.EventHandler]: 'EventHandler', - [bsPlugins.Manipulator]: 'Manipulator' - } - } - - default: - return { - external: [] - } - } +for (const file of jsFiles) { + resolvedPlugins.push({ + src: file.replace('.js', ''), + dist: file.replace('src', 'dist'), + fileName: path.basename(file), + className: filenameToEntity(path.basename(file)) + // safeClassName: filenameToEntity(path.relative(sourcePath, file)) + }) } -const utilObjects = new Set([ - 'Util', - 'Sanitizer', - 'Backdrop' -]) - -const domObjects = new Set([ - 'Data', - 'EventHandler', - 'Manipulator', - 'SelectorEngine' -]) - const build = async plugin => { - console.log(`Building ${plugin} plugin...`) + const globals = {} - const { external, globals } = getConfigByPluginKey(plugin) - const pluginFilename = path.basename(bsPlugins[plugin]) - let pluginPath = rootPath + const bundle = await rollup.rollup({ + input: plugin.src, + plugins: [ + babel({ + // Only transpile our source code + exclude: 'node_modules/**', + // Include the helpers in each file, at most one copy of each + babelHelpers: 'bundled' + }) + ], + external(source) { + // Pattern to identify local files + const pattern = /^(\.{1,2})\// + + // It's not a local file, e.g a Node.js package + if (!pattern.test(source)) { + globals[source] = source + return true + } - if (utilObjects.has(plugin)) { - pluginPath = `${rootPath}/util/` - } + const usedPlugin = resolvedPlugins.find(plugin => { + return plugin.src.includes(source.replace(pattern, '')) + }) - if (domObjects.has(plugin)) { - pluginPath = `${rootPath}/dom/` - } + if (!usedPlugin) { + throw new Error(`Source ${source} is not mapped!`) + } - const bundle = await rollup.rollup({ - input: bsPlugins[plugin], - plugins, - external + // We can change `Index` with `UtilIndex` etc if we use + // `safeClassName` instead of `className` everywhere + globals[path.normalize(usedPlugin.src)] = usedPlugin.className + return true + } }) await bundle.write({ - banner: banner(pluginFilename), + banner: banner(plugin.fileName), format: 'umd', - name: plugin, + name: plugin.className, sourcemap: true, globals, generatedCode: 'es2015', - file: path.resolve(__dirname, `${pluginPath}/${pluginFilename}`) + file: plugin.dist }) - console.log(`Building ${plugin} plugin... Done!`) + console.log(`Built ${plugin.className}`) } -const main = async () => { +(async () => { try { - await Promise.all(Object.keys(bsPlugins).map(plugin => build(plugin))) + const basename = path.basename(__filename) + const timeLabel = `[${basename}] finished` + + console.log('Building individual plugins...') + console.time(timeLabel) + + await Promise.all(Object.values(resolvedPlugins).map(plugin => build(plugin))) + + console.timeEnd(timeLabel) } catch (error) { console.error(error) - process.exit(1) } -} - -main() +})() diff --git a/vendor/twbs/bootstrap/build/change-version.js b/vendor/twbs/bootstrap/build/change-version.js index 63f231ea2..6d85441a9 100644 --- a/vendor/twbs/bootstrap/build/change-version.js +++ b/vendor/twbs/bootstrap/build/change-version.js @@ -2,8 +2,8 @@ /*! * Script to update version number references in the project. - * Copyright 2017-2021 The Bootstrap Authors - * Copyright 2017-2021 Twitter, Inc. + * Copyright 2017-2022 The Bootstrap Authors + * Copyright 2017-2022 Twitter, Inc. * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) */ @@ -57,7 +57,7 @@ async function replaceRecursively(file, oldVersion, newVersion) { } async function main(args) { - const [oldVersion, newVersion] = args + let [oldVersion, newVersion] = args if (!oldVersion || !newVersion) { console.error('USAGE: change-version old_version new_version [--verbose] [--dry[-run]]') @@ -66,7 +66,7 @@ async function main(args) { } // Strip any leading `v` from arguments because otherwise we will end up with duplicate `v`s - [oldVersion, newVersion].map(arg => arg.startsWith('v') ? arg.slice(1) : arg) + [oldVersion, newVersion] = [oldVersion, newVersion].map(arg => arg.startsWith('v') ? arg.slice(1) : arg) try { const files = await globby(GLOB, GLOBBY_OPTIONS) diff --git a/vendor/twbs/bootstrap/build/generate-sri.js b/vendor/twbs/bootstrap/build/generate-sri.js index 221873b8f..cde818e09 100644 --- a/vendor/twbs/bootstrap/build/generate-sri.js +++ b/vendor/twbs/bootstrap/build/generate-sri.js @@ -5,8 +5,8 @@ * Remember to use the same vendor files as the CDN ones, * otherwise the hashes won't match! * - * Copyright 2017-2021 The Bootstrap Authors - * Copyright 2017-2021 Twitter, Inc. + * Copyright 2017-2022 The Bootstrap Authors + * Copyright 2017-2022 Twitter, Inc. * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) */ @@ -47,10 +47,10 @@ const files = [ } ] -files.forEach(file => { - fs.readFile(file.file, 'utf8', (err, data) => { - if (err) { - throw err +for (const file of files) { + fs.readFile(file.file, 'utf8', (error, data) => { + if (error) { + throw error } const algo = 'sha384' @@ -61,4 +61,4 @@ files.forEach(file => { sh.sed('-i', new RegExp(`^(\\s+${file.configPropertyName}:\\s+["'])\\S*(["'])`), `$1${integrity}$2`, configFile) }) -}) +} diff --git a/vendor/twbs/bootstrap/build/postcss.config.js b/vendor/twbs/bootstrap/build/postcss.config.js index b179a0e77..7f8186d10 100644 --- a/vendor/twbs/bootstrap/build/postcss.config.js +++ b/vendor/twbs/bootstrap/build/postcss.config.js @@ -1,19 +1,19 @@ 'use strict' -module.exports = ctx => { +const mapConfig = { + inline: false, + annotation: true, + sourcesContent: true +} + +module.exports = context => { return { - map: ctx.file.dirname.includes('examples') ? - false : - { - inline: false, - annotation: true, - sourcesContent: true - }, + map: context.file.dirname.includes('examples') ? false : mapConfig, plugins: { autoprefixer: { cascade: false }, - rtlcss: ctx.env === 'RTL' ? {} : false + rtlcss: context.env === 'RTL' } } } diff --git a/vendor/twbs/bootstrap/build/rollup.config.js b/vendor/twbs/bootstrap/build/rollup.config.js index c00438de2..2d2920fd5 100644 --- a/vendor/twbs/bootstrap/build/rollup.config.js +++ b/vendor/twbs/bootstrap/build/rollup.config.js @@ -9,7 +9,7 @@ const banner = require('./banner.js') const BUNDLE = process.env.BUNDLE === 'true' const ESM = process.env.ESM === 'true' -let fileDest = `bootstrap${ESM ? '.esm' : ''}` +let fileDestination = `bootstrap${ESM ? '.esm' : ''}` const external = ['@popperjs/core'] const plugins = [ babel({ @@ -24,7 +24,7 @@ const globals = { } if (BUNDLE) { - fileDest += '.bundle' + fileDestination += '.bundle' // Remove last entry in external array to bundle Popper external.pop() delete globals['@popperjs/core'] @@ -41,7 +41,7 @@ const rollupConfig = { input: path.resolve(__dirname, `../js/index.${ESM ? 'esm' : 'umd'}.js`), output: { banner, - file: path.resolve(__dirname, `../dist/js/${fileDest}.js`), + file: path.resolve(__dirname, `../dist/js/${fileDestination}.js`), format: ESM ? 'esm' : 'umd', globals, generatedCode: 'es2015' diff --git a/vendor/twbs/bootstrap/build/svgo.yml b/vendor/twbs/bootstrap/build/svgo.yml deleted file mode 100644 index 67940d393..000000000 --- a/vendor/twbs/bootstrap/build/svgo.yml +++ /dev/null @@ -1,59 +0,0 @@ -# Usage: -# install svgo globally: `npm i -g svgo` -# svgo --config=build/svgo.yml --input=foo.svg - -# https://github.com/svg/svgo/blob/master/docs/how-it-works/en.md -# replace default config - -multipass: true -#full: true - -# https://github.com/svg/svgo/blob/master/lib/svgo/js2svg.js#L6 for more config options - -js2svg: - pretty: true - indent: 2 - -plugins: -# - addAttributesToSVGElement: -# attributes: -# - focusable: false - - cleanupAttrs: true - - cleanupEnableBackground: true - - cleanupIDs: true - - cleanupListOfValues: true - - cleanupNumericValues: true - - collapseGroups: true - - convertColors: true - - convertPathData: true - - convertShapeToPath: true - - convertStyleToAttrs: true - - convertTransform: true - - inlineStyles: true - - mergePaths: true - - minifyStyles: true - - moveElemsAttrsToGroup: true - - moveGroupAttrsToElems: true - - removeAttrs: - attrs: - - "data-name" - - removeComments: true - - removeDesc: true - - removeDoctype: true - - removeEditorsNSData: true - - removeEmptyAttrs: true - - removeEmptyContainers: true - - removeEmptyText: true - - removeHiddenElems: true - - removeMetadata: true - - removeNonInheritableGroupAttrs: true - - removeTitle: false - - removeUnknownsAndDefaults: - keepRoleAttr: true - - removeUnusedNS: true - - removeUselessDefs: true - - removeUselessStrokeAndFill: true - - removeViewBox: false - - removeXMLNS: false - - removeXMLProcInst: true - - sortAttrs: true diff --git a/vendor/twbs/bootstrap/build/vnu-jar.js b/vendor/twbs/bootstrap/build/vnu-jar.js index 2d5cc8b55..df4192e24 100644 --- a/vendor/twbs/bootstrap/build/vnu-jar.js +++ b/vendor/twbs/bootstrap/build/vnu-jar.js @@ -2,8 +2,8 @@ /*! * Script to run vnu-jar if Java is available. - * Copyright 2017-2021 The Bootstrap Authors - * Copyright 2017-2021 Twitter, Inc. + * Copyright 2017-2022 The Bootstrap Authors + * Copyright 2017-2022 Twitter, Inc. * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) */ diff --git a/vendor/twbs/bootstrap/build/zip-examples.js b/vendor/twbs/bootstrap/build/zip-examples.js index 312548e8a..759dd817d 100644 --- a/vendor/twbs/bootstrap/build/zip-examples.js +++ b/vendor/twbs/bootstrap/build/zip-examples.js @@ -3,7 +3,7 @@ /*! * Script to create the built examples zip archive; * requires the `zip` command to be present! - * Copyright 2020-2021 The Bootstrap Authors + * Copyright 2020-2022 The Bootstrap Authors * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) */ @@ -57,22 +57,22 @@ sh.mkdir('-p', [ sh.cp('-Rf', `${docsDir}/examples/*`, distFolder) -cssFiles.forEach(file => { +for (const file of cssFiles) { sh.cp('-f', `${docsDir}/dist/css/${file}`, `${distFolder}/assets/dist/css/`) -}) +} -jsFiles.forEach(file => { +for (const file of jsFiles) { sh.cp('-f', `${docsDir}/dist/js/${file}`, `${distFolder}/assets/dist/js/`) -}) +} -imgFiles.forEach(file => { +for (const file of imgFiles) { sh.cp('-f', `${docsDir}/assets/brand/${file}`, `${distFolder}/assets/brand/`) -}) +} sh.rm(`${distFolder}/index.html`) // get all examples' HTML files -sh.find(`${distFolder}/**/*.html`).forEach(file => { +for (const file of sh.find(`${distFolder}/**/*.html`)) { const fileContents = sh.cat(file) .toString() .replace(new RegExp(`"/docs/${versionShort}/`, 'g'), '"../') @@ -81,7 +81,7 @@ sh.find(`${distFolder}/**/*.html`).forEach(file => { .replace(/(<script src="\.\.\/.*) integrity=".*>/g, '$1></script>') .replace(/( +)<!-- favicons(.|\n)+<style>/i, ' <style>') new sh.ShellString(fileContents).to(file) -}) +} // create the zip file sh.exec(`zip -r9 "${distFolder}.zip" "${distFolder}"`) |