Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { SitespeedioPlugin } from '@sitespeed.io/plugin';
import { HarAnalyzer } from './harAnalyzer.js';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import fs from 'node:fs';
const fsp = fs.promises;

// https://www.sitespeed.io/documentation/sitespeed.io/plugins/#create-your-own-plugin
// 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
Expand All @@ -11,17 +15,41 @@ export default class JavascriptPlugin extends SitespeedioPlugin {
super({ name: pluginname, options, context, queue });
}

open(context, options) {
async open(context, options) {
this.make = context.messageMaker(pluginname).make;
this.harAnalyzer = new HarAnalyzer();
const libFolder = fileURLToPath(new URL('..', import.meta.url));
this.pluginFolder = path.resolve(libFolder);

this.pug = await fsp.readFile(
path.resolve(this.pluginFolder, 'pug', 'index.pug'),
'utf8'
);
}

async processMessage(message, queue) {
// const filterRegistry = this.filterRegistry;
switch (message.type) {
case 'sitespeedio.setup': {
// Let other plugins know that the pagenotfound plugin is alive
super.sendMessage('browsertime.setup');
// queue.postMessage(this.make(pluginname + '.setup'));
// Add the HTML pugs
queue.postMessage(
this.make('html.pug', {
id: pluginname,
name: 'Javascript',
pug: this.pug,
type: 'pageSummary'
})
);
queue.postMessage(
this.make('html.pug', {
id: pluginname,
name: 'Javascript',
pug: this.pug,
type: 'run'
})
);
break;
}
case 'browsertime.har': {
Expand Down
31 changes: 31 additions & 0 deletions pug/index.pug
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

- let pluginData = pageInfo.data['webperf-plugin-javascript'].run ? pageInfo.data['webperf-plugin-javascript'].run : pageInfo.data['webperf-plugin-javascript'].pageSummary

h1 Issues
if pluginData.knowledgeData && pluginData.knowledgeData.issues && pluginData.knowledgeData.issues.length > 0
table
thead
tr
th URL
th Rule
th Category
th Severity
th Text
th Line
th Column
tbody
each issue in pluginData.knowledgeData.issues
tr
td= issue.url
td= issue.rule
td= issue.category
td= issue.severity
td= issue.text
td= issue.line
td= issue.column
else
p No issues found.

h2 Debug: Plugin Data
pre
code= JSON.stringify(pluginData, null, 3)
Loading