diff --git a/website/GenerateResultsJsonPlugin.js b/website/GenerateResultsJsonPlugin.js new file mode 100644 index 0000000000..790b2e2bc6 --- /dev/null +++ b/website/GenerateResultsJsonPlugin.js @@ -0,0 +1,32 @@ +const fs = require('fs'); +const path = require('path'); + +class GenerateResultsJsonPlugin { + apply(compiler) { + compiler.hooks.thisCompilation.tap('GenerateResultsJsonPlugin', (compilation) => { + compilation.hooks.processAssets.tapAsync( + { + name: 'GenerateResultsJsonPlugin', + stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL, + }, + (assets, callback) => { + const resultsDir = path.resolve(__dirname, 'public/result'); + const results = fs.readdirSync(resultsDir).filter(file => fs.statSync(path.join(resultsDir, file)).isDirectory()); + const newJsonContent = JSON.stringify({ results }, null, 2); + const jsonFilePath = path.resolve(__dirname, 'src/assets/results.json'); + if (fs.existsSync(jsonFilePath)) { + const existingJsonContent = fs.readFileSync(jsonFilePath, 'utf-8'); + if (existingJsonContent !== newJsonContent) { + fs.writeFileSync(jsonFilePath, newJsonContent); + } + } else { + fs.writeFileSync(jsonFilePath, newJsonContent); + } + callback(); + } + ); + }); + } +} + +module.exports = GenerateResultsJsonPlugin; diff --git a/website/generateResults.js b/website/generateResults.js deleted file mode 100644 index dc58fbd9ff..0000000000 --- a/website/generateResults.js +++ /dev/null @@ -1,22 +0,0 @@ -const fs = require('fs'); -const path = require('path'); - -const resultsDir = path.join(__dirname, 'public', 'result'); -const outputFilePath = path.join(__dirname, 'src', 'assets', 'results.json'); - -console.log('Running generateResults.js...'); - -fs.readdir(resultsDir, { withFileTypes: true }, (err, files) => { - if (err) { - console.error(`Failed to read directory ${resultsDir}:`, err); - process.exit(1); - } - const results = { results: files.filter(file => file.isDirectory()).map(file => file.name) }; - fs.writeFile(outputFilePath, JSON.stringify(results, null, 2), (err) => { - if (err) { - console.error(`Failed to write ${outputFilePath}:`, err); - process.exit(1); - } - console.log(`${outputFilePath} has been generated successfully.`); - }); -}); diff --git a/website/package.json b/website/package.json index 10e451e20e..6d9e445ee6 100644 --- a/website/package.json +++ b/website/package.json @@ -2,9 +2,8 @@ "name": "buildkit-bench-website", "private": true, "scripts": { - "serve": "yarn run prebuild && vue-cli-service serve", - "prebuild": "node generateResults.js", - "build": "yarn run prebuild && vue-cli-service build" + "serve": "vue-cli-service serve", + "build": "vue-cli-service build" }, "repository": { "type": "git", diff --git a/website/src/components/ResultsList.vue b/website/src/components/ResultsList.vue index 75b68032bd..a1932dbac1 100644 --- a/website/src/components/ResultsList.vue +++ b/website/src/components/ResultsList.vue @@ -11,16 +11,16 @@