Skip to content

Commit d4b2598

Browse files
committed
feat(plugin-tab): pivot to using hook functions
BREAKING CHANGE: event based listeners replaced with functions
1 parent fc966d6 commit d4b2598

File tree

3 files changed

+14
-21
lines changed

3 files changed

+14
-21
lines changed

packages/plugin-tab/index.js

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ const glob = require('glob');
1010
const tab_loader = require('./src/tab-loader');
1111

1212
const pluginName = '@pattern-lab/plugin-tab';
13+
//remove the forward-slash, which can accidentally result in directories being written in the output
14+
const safePluginName = '@pattern-lab-plugin-tab';
1315

1416
function writeConfigToOutput(patternlab, pluginConfig) {
1517
try {
@@ -21,7 +23,7 @@ function writeConfigToOutput(patternlab, pluginConfig) {
2123
patternlab.config.paths.public.root,
2224
'patternlab-components',
2325
'packages',
24-
`/${pluginName}.json`
26+
`/${safePluginName}.json`
2527
),
2628
JSON.stringify(pluginConfig, null, 2)
2729
);
@@ -39,16 +41,12 @@ async function onPatternIterate(patternlab, pattern) {
3941
}
4042

4143
/**
42-
* Define what events you wish to listen to here
43-
* For a full list of events - check out https://github.com/pattern-lab/patternlab-node/wiki/Creating-Plugins#events
44-
* @param patternlab - global data store which has the handle to the event emitter
44+
* Define what hooks you wish to invoke to here
45+
* //todo change link
46+
* For a full list of hooks - check out https://github.com/pattern-lab/patternlab-node/wiki/Creating-Plugins#events
47+
* @param patternlab - global data store which has the handle to hooks
4548
*/
46-
function registerEvents(patternlab) {
47-
//register our handler at the appropriate time of execution
48-
patternlab.events.on('patternlab-pattern-write-end', onPatternIterate);
49-
}
50-
51-
function registerEventHandlers(patternlab) {
49+
function registerHooks(patternlab) {
5250
patternlab.hooks['patternlab-pattern-write-end'].push(onPatternIterate);
5351
}
5452

@@ -63,11 +61,7 @@ function getPluginFrontendConfig() {
6361
templates: [],
6462
stylesheets: [],
6563
javascripts: [
66-
'patternlab-components/pattern-lab/' +
67-
pluginName +
68-
'/js/' +
69-
pluginName +
70-
'.js',
64+
`patternlab-components/pattern-lab/${safePluginName}/js/${safePluginName}.js`,
7165
],
7266
onready: 'PluginTab.init()',
7367
callback: '',
@@ -116,7 +110,7 @@ function pluginInit(patternlab) {
116110
patternlab.config.paths.public.root,
117111
'patternlab-components',
118112
'pattern-lab',
119-
pluginName,
113+
safePluginName,
120114
relativePath
121115
);
122116

@@ -166,15 +160,14 @@ function pluginInit(patternlab) {
166160
patternlab.config.plugins = {};
167161
}
168162

169-
//attempt to only register events once
163+
//attempt to only register hooks once
170164
if (
171165
patternlab.config.plugins[pluginName] !== undefined &&
172166
patternlab.config.plugins[pluginName].enabled &&
173167
!patternlab.config.plugins[pluginName].initialized
174168
) {
175-
//register events
176-
//registerEvents(patternlab);
177-
registerEventHandlers(patternlab);
169+
//register hooks
170+
registerHooks(patternlab);
178171

179172
//set the plugin initialized flag to true to indicate it is installed and ready
180173
patternlab.config.plugins[pluginName].initialized = true;

packages/plugin-tab/src/snippet.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* global Panels */
22

3-
Panels.add({
3+
window.patternlab.panels.add({
44
id: 'sg-panel-<<type>>',
55
name: '<<typeUC>>',
66
default: false,

0 commit comments

Comments
 (0)