1
0
Fork 0
freesewing/plugins/plugin-bundle/src/index.mjs

76 lines
2.2 KiB
JavaScript
Raw Normal View History

2022-09-15 13:49:55 +02:00
import { bannerPlugin } from '../../plugin-banner/src/index.mjs'
import { bartackPlugin } from '../../plugin-bartack/src/index.mjs'
import { buttonsPlugin } from '../../plugin-buttons/src/index.mjs'
2022-08-28 14:44:17 +02:00
import { cutonfoldPlugin } from '../../plugin-cutonfold/src/index.mjs'
import { dimensionPlugin } from '../../plugin-dimension/src/index.mjs'
import { grainlinePlugin } from '../../plugin-grainline/src/index.mjs'
2022-09-15 13:49:55 +02:00
import { logoPlugin } from '../../plugin-logo/src/index.mjs'
import { measurementsPlugin } from '../../plugin-measurements/src/index.mjs'
2022-09-15 13:49:55 +02:00
import { mirrorPlugin } from '../../plugin-mirror/src/index.mjs'
import { notchesPlugin } from '../../plugin-notches/src/index.mjs'
import { roundPlugin } from '../../plugin-round/src/index.mjs'
import { scaleboxPlugin } from '../../plugin-scalebox/src/index.mjs'
2022-08-28 14:44:17 +02:00
import { sprinklePlugin } from '../../plugin-sprinkle/src/index.mjs'
import { titlePlugin } from '../../plugin-title/src/index.mjs'
import { pluginCutlist } from '../../plugin-cutlist/src/index.mjs'
import { name, version } from '../data.mjs'
2022-08-28 14:44:17 +02:00
const bundledPlugins = [
bannerPlugin,
bartackPlugin,
buttonsPlugin,
cutonfoldPlugin,
dimensionPlugin,
grainlinePlugin,
logoPlugin,
measurementsPlugin,
2022-08-28 14:44:17 +02:00
mirrorPlugin,
notchesPlugin,
roundPlugin,
scaleboxPlugin,
2022-08-28 14:44:17 +02:00
sprinklePlugin,
titlePlugin,
pluginCutlist,
2022-08-28 14:44:17 +02:00
]
const hooks = {}
const macros = {}
const store = []
function bundleHooks(plugin) {
for (const i in plugin.hooks) {
if (typeof hooks[i] === 'undefined') hooks[i] = []
const hook = plugin.hooks[i]
if (typeof hook === 'function') hooks[i].push(hook)
else if (typeof hook === 'object') {
for (let method of hook) hooks[i].push(method)
2022-08-28 14:44:17 +02:00
}
}
}
2022-08-28 14:44:17 +02:00
function bundleMacros(plugin) {
for (const i in plugin.macros) macros[i] = plugin.macros[i]
2022-08-28 14:44:17 +02:00
}
function bundleStore(plugin) {
if (plugin.store) store.push(...plugin.store)
}
2022-08-28 14:44:17 +02:00
for (const plugin of bundledPlugins) {
bundleHooks(plugin, hooks)
bundleMacros(plugin, macros)
bundleStore(plugin, store)
2022-08-28 14:44:17 +02:00
}
export const plugin = {
name,
version,
hooks,
macros,
store,
2022-08-28 14:44:17 +02:00
}
// More specifically named exports
export const bundlePlugin = plugin
export const pluginBundle = plugin