11import { SitespeedioPlugin } from '@sitespeed.io/plugin' ;
22import { HarAnalyzer } from './harAnalyzer.js' ;
3+ import path from 'node:path' ;
4+ import { fileURLToPath } from 'node:url' ;
5+ import fs from 'node:fs' ;
6+ const fsp = fs . promises ;
37
48// https://www.sitespeed.io/documentation/sitespeed.io/plugins/#create-your-own-plugin
59// node bin\sitespeed.js -b edge -n 1 --plugins.add analysisstorer --plugins.add ../../../plugin-javascript/lib/index.js --browsertime.chrome.includeResponseBodies all https://webperf.se
@@ -11,17 +15,41 @@ export default class JavascriptPlugin extends SitespeedioPlugin {
1115 super ( { name : pluginname , options, context, queue } ) ;
1216 }
1317
14- open ( context , options ) {
18+ async open ( context , options ) {
1519 this . make = context . messageMaker ( pluginname ) . make ;
1620 this . harAnalyzer = new HarAnalyzer ( ) ;
21+ const libFolder = fileURLToPath ( new URL ( '..' , import . meta. url ) ) ;
22+ this . pluginFolder = path . resolve ( libFolder ) ;
23+
24+ this . pug = await fsp . readFile (
25+ path . resolve ( this . pluginFolder , 'pug' , 'index.pug' ) ,
26+ 'utf8'
27+ ) ;
1728 }
1829
1930 async processMessage ( message , queue ) {
2031 // const filterRegistry = this.filterRegistry;
2132 switch ( message . type ) {
2233 case 'sitespeedio.setup' : {
2334 // Let other plugins know that the pagenotfound plugin is alive
24- super . sendMessage ( 'browsertime.setup' ) ;
35+ // queue.postMessage(this.make(pluginname + '.setup'));
36+ // Add the HTML pugs
37+ queue . postMessage (
38+ this . make ( 'html.pug' , {
39+ id : pluginname ,
40+ name : 'Javascript' ,
41+ pug : this . pug ,
42+ type : 'pageSummary'
43+ } )
44+ ) ;
45+ queue . postMessage (
46+ this . make ( 'html.pug' , {
47+ id : pluginname ,
48+ name : 'Javascript' ,
49+ pug : this . pug ,
50+ type : 'run'
51+ } )
52+ ) ;
2553 break ;
2654 }
2755 case 'browsertime.har' : {
0 commit comments