@@ -10,6 +10,8 @@ const glob = require('glob');
10
10
const tab_loader = require ( './src/tab-loader' ) ;
11
11
12
12
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' ;
13
15
14
16
function writeConfigToOutput ( patternlab , pluginConfig ) {
15
17
try {
@@ -21,7 +23,7 @@ function writeConfigToOutput(patternlab, pluginConfig) {
21
23
patternlab . config . paths . public . root ,
22
24
'patternlab-components' ,
23
25
'packages' ,
24
- `/${ pluginName } .json`
26
+ `/${ safePluginName } .json`
25
27
) ,
26
28
JSON . stringify ( pluginConfig , null , 2 )
27
29
) ;
@@ -39,16 +41,12 @@ async function onPatternIterate(patternlab, pattern) {
39
41
}
40
42
41
43
/**
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
45
48
*/
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 ) {
52
50
patternlab . hooks [ 'patternlab-pattern-write-end' ] . push ( onPatternIterate ) ;
53
51
}
54
52
@@ -63,11 +61,7 @@ function getPluginFrontendConfig() {
63
61
templates : [ ] ,
64
62
stylesheets : [ ] ,
65
63
javascripts : [
66
- 'patternlab-components/pattern-lab/' +
67
- pluginName +
68
- '/js/' +
69
- pluginName +
70
- '.js' ,
64
+ `patternlab-components/pattern-lab/${ safePluginName } /js/${ safePluginName } .js` ,
71
65
] ,
72
66
onready : 'PluginTab.init()' ,
73
67
callback : '' ,
@@ -116,7 +110,7 @@ function pluginInit(patternlab) {
116
110
patternlab . config . paths . public . root ,
117
111
'patternlab-components' ,
118
112
'pattern-lab' ,
119
- pluginName ,
113
+ safePluginName ,
120
114
relativePath
121
115
) ;
122
116
@@ -166,15 +160,14 @@ function pluginInit(patternlab) {
166
160
patternlab . config . plugins = { } ;
167
161
}
168
162
169
- //attempt to only register events once
163
+ //attempt to only register hooks once
170
164
if (
171
165
patternlab . config . plugins [ pluginName ] !== undefined &&
172
166
patternlab . config . plugins [ pluginName ] . enabled &&
173
167
! patternlab . config . plugins [ pluginName ] . initialized
174
168
) {
175
- //register events
176
- //registerEvents(patternlab);
177
- registerEventHandlers ( patternlab ) ;
169
+ //register hooks
170
+ registerHooks ( patternlab ) ;
178
171
179
172
//set the plugin initialized flag to true to indicate it is installed and ready
180
173
patternlab . config . plugins [ pluginName ] . initialized = true ;
0 commit comments