mirror of
https://github.com/ComfortablyCoding/strapi-plugin-website-builder.git
synced 2025-12-18 00:04:52 -05:00
47 lines
1.1 KiB
JavaScript
47 lines
1.1 KiB
JavaScript
'use strict';
|
|
|
|
const { getService } = require('../utils/common');
|
|
const { FILE_UID, EMIT_ACTIONS } = require('../utils/constants');
|
|
|
|
function bootstrapEvents({ strapi, build }) {
|
|
// build valid events
|
|
const events = new Map();
|
|
build.trigger.events.forEach((event) => {
|
|
// setup actions
|
|
let actions = new Set();
|
|
if (event.actions === '*') {
|
|
EMIT_ACTIONS.forEach((action) => actions.add(action));
|
|
} else {
|
|
event.actions.forEach((action) => actions.add(action));
|
|
}
|
|
|
|
// setup events
|
|
if (event.uid === '*') {
|
|
Object.keys(strapi.contentTypes)
|
|
.filter((uid) => /^api::/.test(uid) || uid === FILE_UID)
|
|
.forEach((uid) => {
|
|
events.set(uid, actions);
|
|
});
|
|
} else {
|
|
events.set(event.uid, actions);
|
|
}
|
|
});
|
|
|
|
EMIT_ACTIONS.forEach((action) => {
|
|
strapi.eventHub.on(`entry.${action}`, ({ uid, entry: record }) => {
|
|
const entry = events.get(uid);
|
|
if (entry && entry.has(action)) {
|
|
getService({ strapi, name: 'build' }).trigger({
|
|
name: build.name,
|
|
record,
|
|
trigger: { type: 'event' },
|
|
});
|
|
}
|
|
});
|
|
});
|
|
}
|
|
|
|
module.exports = {
|
|
bootstrapEvents,
|
|
};
|