Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

website: use webpack to generate results list #145

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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: 32 additions & 0 deletions website/GenerateResultsJsonPlugin.js
Original file line number Diff line number Diff line change
@@ -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;
22 changes: 0 additions & 22 deletions website/generateResults.js

This file was deleted.

5 changes: 2 additions & 3 deletions website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 4 additions & 4 deletions website/src/components/ResultsList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@
</template>

<script>
import resultsData from '@/assets/results.json';

export default {
data() {
return {
results: [],
results: resultsData.results.sort((a, b) => b.localeCompare(a)),
selectedResult: null
};
},
async created() {
const resultsData = await import(`../assets/results.json`);
this.results = resultsData.results.sort((a, b) => b.localeCompare(a));
created() {
this.updateSelectedResult();
},
watch: {
Expand Down
6 changes: 5 additions & 1 deletion website/vue.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const path = require('path');
const GenerateResultsJsonPlugin = require('./GenerateResultsJsonPlugin');

module.exports = {
publicPath: process.env.WEBSITE_PUBLIC_PATH || '/',
Expand All @@ -7,7 +8,10 @@ module.exports = {
alias: {
'@': path.resolve(__dirname, 'src')
}
}
},
plugins: [
new GenerateResultsJsonPlugin()
]
},
chainWebpack: config => {
config.module.rule('text').test(/\.txt$/).type('asset/source');
Expand Down
Loading