diff --git a/index.js b/index.js index ec39b3d..ed6071a 100644 --- a/index.js +++ b/index.js @@ -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); @@ -86,7 +86,7 @@ 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); @@ -94,7 +94,7 @@ async function main() { } } // 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); @@ -102,7 +102,7 @@ async function main() { } } // 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'); @@ -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 diff --git a/package.json b/package.json index 167ffc7..9297a40 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 68fc2d3..5eb30c9 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -5,6 +5,9 @@ settings: excludeLinksFromLockfile: false dependencies: + axios: + specifier: ^1.6.8 + version: 1.6.8 chrome-launcher: specifier: ^1.1.0 version: 1.1.0 @@ -238,11 +241,25 @@ packages: tslib: 2.6.2 dev: false + /asynckit@0.4.0: + resolution: {integrity: sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==} + dev: false + /axe-core@4.8.3: resolution: {integrity: sha512-d5ZQHPSPkF9Tw+yfyDcRoUOc4g/8UloJJe5J8m4L5+c7AtDdjDLRxew/knnI4CxvtdxEUVgWz4x3OIQUIFiMfw==} engines: {node: '>=4'} dev: false + /axios@1.6.8: + resolution: {integrity: sha512-v/ZHtJDU39mDpyBoFVkETcd/uNdxrWRrg3bKpOKzXFA6Bvqopts6ALSMU3y6ijYxbw2B+wPrIv46egTzJXCLGQ==} + dependencies: + follow-redirects: 1.15.6 + form-data: 4.0.0 + proxy-from-env: 1.1.0 + transitivePeerDependencies: + - debug + dev: false + /b4a@1.6.4: resolution: {integrity: sha512-fpWrvyVHEKyeEvbKZTVOeZF3VSKKWtJxFIxX/jaVPf+cLbGUSitjb49pHLqPV2BUNNZ0LcoeEGfE/YCpyDYHIw==} dev: false @@ -392,6 +409,13 @@ packages: resolution: {integrity: sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==} dev: false + /combined-stream@1.0.8: + resolution: {integrity: sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==} + engines: {node: '>= 0.8'} + dependencies: + delayed-stream: 1.0.0 + dev: false + /compressible@2.0.18: resolution: {integrity: sha512-AF3r7P5dWxL8MxyITRMlORQNaOA2IkAFaTr4k7BUumjPtRpGDTZpl0Pb1XCO6JeDCBdp126Cgs9sMxqSjgYyRg==} engines: {node: '>= 0.6'} @@ -519,6 +543,11 @@ packages: esprima: 4.0.1 dev: false + /delayed-stream@1.0.0: + resolution: {integrity: sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==} + engines: {node: '>=0.4.0'} + dev: false + /devtools-protocol@0.0.1203626: resolution: {integrity: sha512-nEzHZteIUZfGCZtTiS1fRpC8UZmsfD1SiyPvaUNvS13dvKf666OAm8YTi0+Ca3n1nLEyu49Cy4+dPWpaHFJk9g==} dev: false @@ -647,6 +676,25 @@ packages: pend: 1.2.0 dev: false + /follow-redirects@1.15.6: + resolution: {integrity: sha512-wWN62YITEaOpSK584EZXJafH1AGpO8RVgElfkuXbTOrPX4fIfOyEpW/CsiNd8JdYrAoOvafRTOEnvsO++qCqFA==} + engines: {node: '>=4.0'} + peerDependencies: + debug: '*' + peerDependenciesMeta: + debug: + optional: true + dev: false + + /form-data@4.0.0: + resolution: {integrity: sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==} + engines: {node: '>= 6'} + dependencies: + asynckit: 0.4.0 + combined-stream: 1.0.8 + mime-types: 2.1.35 + dev: false + /frac@1.1.2: resolution: {integrity: sha512-w/XBfkibaTl3YDqASwfDUqkna4Z2p9cFSr1aHDt0WoMTECnRfBOv2WArlZILlqgWlmdIlALXGpM2AOhEk5W3IA==} engines: {node: '>=0.8'} diff --git a/projectList.json b/projectList.json index a8ac7c6..ee71f2e 100644 --- a/projectList.json +++ b/projectList.json @@ -1,6 +1,6 @@ [ { - "name":"vue3", + "name":"vue", "path":"app/vue3-realworld-app" }, { @@ -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" }, @@ -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" } ] \ No newline at end of file diff --git a/report.js b/report.js new file mode 100644 index 0000000..2056713 --- /dev/null +++ b/report.js @@ -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); + } + } +} \ No newline at end of file