aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/twbs/bootstrap/build/build-plugins.js
diff options
context:
space:
mode:
authorMario <mario@mariovavti.com>2022-08-19 13:15:48 +0000
committerMario <mario@mariovavti.com>2022-08-19 13:15:48 +0000
commit185ddf1eaf82e08586be6c7689507ee924d9dd47 (patch)
tree218ff6da6fb1511a1b2823729607c7c4b13e30e9 /vendor/twbs/bootstrap/build/build-plugins.js
parent7dee47183d05b6e1f7d5c5588e2df9993fb294dd (diff)
downloadvolse-hubzilla-185ddf1eaf82e08586be6c7689507ee924d9dd47.tar.gz
volse-hubzilla-185ddf1eaf82e08586be6c7689507ee924d9dd47.tar.bz2
volse-hubzilla-185ddf1eaf82e08586be6c7689507ee924d9dd47.zip
update to bootstrap 5.2 and fixes
Diffstat (limited to 'vendor/twbs/bootstrap/build/build-plugins.js')
-rw-r--r--vendor/twbs/bootstrap/build/build-plugins.js207
1 files changed, 64 insertions, 143 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()
+})()