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 -n 1 --plugins.add analysisstorer --plugins.add ../../../plugin-css/lib/index.js --browsertime.chrome.includeResponseBodies all https://webperf.se
@@ -11,17 +15,38 @@ export default class CssPlugin 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' : {
23- // Let other plugins know that the pagenotfound plugin is alive
24- super . sendMessage ( 'browsertime.setup' ) ;
34+ queue . postMessage (
35+ this . make ( 'html.pug' , {
36+ id : pluginname ,
37+ name : 'CSS' ,
38+ pug : this . pug ,
39+ type : 'pageSummary'
40+ } )
41+ ) ;
42+ queue . postMessage (
43+ this . make ( 'html.pug' , {
44+ id : pluginname ,
45+ name : 'CSS' ,
46+ pug : this . pug ,
47+ type : 'run'
48+ } )
49+ ) ;
2550 break ;
2651 }
2752 case 'browsertime.har' : {
0 commit comments