Skip to content
Open
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
18 changes: 12 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as fs from 'node:fs';
import { execSync, exec } from 'node:child_process';
import * as chromeLauncher from "chrome-launcher";
import lighthouse from "lighthouse";
import { sortResult } from './resultSort.js';
import { report } from './report.js';

function install(project) {
console.log('Installing: ', project.name);
Expand Down Expand Up @@ -86,23 +86,23 @@ async function main() {
const args = process.argv.length <= 2 ? [] : process.argv.slice(2, process.argv.length);
const projects = JSON.parse(fs.readFileSync("projectList.json"));
// install
if (args.length == 0 || args.includes("--install")) {
if (args.length == 0 || args.includes("--all") || args.includes("--install")) {
for (const project of projects) {
if (project.name) {
install(project);
}
}
}
// build
if (args.length == 0 || args.includes("--build")) {
if (args.length == 0 || args.includes("--all") || args.includes("--build")) {
for (const project of projects) {
if (project.name) {
build(project);
}
}
}
// lighthouse benchmark
if (args.length == 0 || args.includes("--bench")) {
if (args.length == 0 || args.includes("--all") || args.includes("--bench")) {
let port = 5000;
if (!fs.existsSync('./results')) {
fs.mkdirSync('./results');
Expand All @@ -112,14 +112,20 @@ async function main() {
console.log(`Start testing ${project.name}...`)
let serve = preview(project, port);
const result = await runLighthouse(`http://localhost:${port}/`);
fs.writeFileSync(`./results/${project.name}.json`, JSON.stringify(result));
if (args.includes("--upload")) {
report(project.name, result);
} else {
fs.writeFileSync(`./results/${project.name}.json`, JSON.stringify(result));
}
if (serve) {
serve.kill('SIGINT');
}
port++;
}
}
sortResult('./results');
if (!args.includes("--upload")) {
sortResult('./results');
}
}
// generate result

Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
"main": "index.js",
"scripts": {
"preinstall": "npx only-allow pnpm",
"bench": "node index.js"
"bench": "node index.js",
"report": "node index.js --upload"
},
"author": "@originjs",
"license": "MulanPSL-2.0",
"dependencies": {
"axios": "^1.6.8",
"chrome-launcher": "^1.1.0",
"lighthouse": "^11.4.0",
"serve": "^14.2.1",
Expand Down
48 changes: 48 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions projectList.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[
{
"name":"vue3",
"name":"vue",
"path":"app/vue3-realworld-app"
},
{
Expand Down Expand Up @@ -38,7 +38,7 @@
"preview":"\"node_modules/.bin/vite\" preview"
},
{
"name":"ember",
"name":"ember.js",
"path":"app/ember-realworld",
"build":"set NODE_OPTIONS=--openssl-legacy-provider && \"node_modules/.bin/ember\" build --environment=production"
},
Expand Down Expand Up @@ -78,5 +78,10 @@
"install":"cargo install wasm-pack && cargo install --locked trunk",
"build":"cd crates/conduit-wasm && trunk build",
"dist":"crates/conduit-wasm/dist"
},
{
"name":"million",
"path":"app/million-realworld-example-app",
"dist":"build"
}
]
54 changes: 54 additions & 0 deletions report.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { platform as _platform } from "os";
import axios from "axios";

const techStack = "前端框架";
const REPORT_URL='http://8.134.178.105:3000';
const url = REPORT_URL;
const BOOST_PERFORMANCE = Object.freeze([
'first-contentful-paint',
'largest-contentful-paint',
'total-blocking-time',
'cumulative-layout-shift',
'speed-index'])

export async function report(project, jsonData) {
const patchId = await getPatchId();
const res = dealdata(project, jsonData, patchId.toString());
await postData(res);
}

async function getPatchId() {
const { data: patchId } = await axios.post(
`${url}/sync/benchmark/getPatchId`,
{},
);
console.log("patchId: ", patchId);
return patchId.toString();
}

function dealdata(projectName, jsonData, patchId) {
const res = [];
for (let bench of BOOST_PERFORMANCE) {
res.push({
projectName,
benchmark: bench,
techStack,
rawValue: jsonData.audits[bench].numericValue,
patchId,
platform: _platform(),
})
}
return res;
}

async function postData(res) {
for (let data of res) {
try {
console.log(data);
const response = await axios.post(`${url}/sync/benchmark`, data);
console.log(response.data);
} catch (error) {
console.error(error);
}
}
}