-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
58 lines (51 loc) · 2.21 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
const plugin = {
name: 'elderjs-plugin-your-plugin',
description: `[copy and paste the start of your readme]`,
minimumElderjsVersion: "1.4.13", // you can leave blank.
init: (plugin) => {
// this is a sync function that runs on plugin initialization.
// if you need async, it is recommended that you extract the async logic to run on the 'bootstrap' hook.
// Plugins have their own closure scope. This means that if you set:
// plugin.init = true
// you will have access to plugin.init in all of your hooks.
// this data can be updated in hooks and will be persistent between page loads.
// IMPORTANT: It is important to note that since builds are run across child processes,
// the 'plugin' object is not consistent across all processes.
// Plugins also get the build settings (plugin.settings) and the config (plugin.config) settings.
return plugin;
},
hooks: [
{
hook: 'bootstrap',
name: 'yourFirstHook',
description: `A description of what this hook does.`,
priority: 50,
run: async ({ plugin, routes }) => {
// all props and mutations are detailed here: https://github.com/Elderjs/elderjs/blob/master/src/hooks/hookInterface.ts
// if you are looking for details on what a prop or mutation represents you can read this: https://github.com/Elderjs/elderjs/blob/master/src/hooks/hookEntityDefinitions.ts
// here is how you'd read the init property set in the init() function
plugin.bootstrapRan = true;
return {
plugin,
};
}
},
{
hook: 'request',
name: 'yourSecondHook',
description: `A description of what this hook does.`,
priority: 50,
run: async ({ plugin, routes }) => {
// plugin.bootstrapRan will alaways be true in this example because `bootstrap` runs before `request`.
return {
plugin,
};
}
},
],
config: { // here is where you set the default configs for your plugin. These are merged with the configs found in the user's elder.config.js file.
doMagic: true,
},
anotherProp: {} // this will be available as a named export. :) Useful for exposing plugin internals.
};
module.exports = plugin;