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

fix: duplicate queries.json file generation #159

Merged
merged 1 commit into from
May 29, 2024
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
3 changes: 3 additions & 0 deletions bin/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ if (args.h || args.help || args._.length > 1) {
// Override the baseURL in the webpack config
webpackConfig.baseURL.replace = baseURL;

// Override the buildContext in the webpack config
webpackConfig.buildContext.dir = destinationPath;
rubensworks marked this conversation as resolved.
Show resolved Hide resolved

for (const entry of webpackConfig) {
entry.mode = mode;
if (entry.output) {
Expand Down
25 changes: 25 additions & 0 deletions plugins/MoveFilePlugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const fs = require('fs');

class MoveFilePlugin {

/**
* Create a new instance of the MoveFilePlugin.
* This plugin expects two functions as arguments, because the paths will be different at runtime.
* @param getSource method to retrieve the source file path
* @param getDestination method to retrieve the destination file path
*/
constructor(getSource, getDestination) {
this.getSource = getSource;
this.getDestination = getDestination;
}

apply(compiler) {
compiler.hooks.afterEmit.tap('MoveFilePlugin', (compilation) => {
if (fs.existsSync(this.getSource())) {
fs.renameSync(this.getSource(), this.getDestination());
}
});
}
}

module.exports = MoveFilePlugin;
19 changes: 15 additions & 4 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const path = require('path');
const webpack = require('webpack');
const MoveFilePlugin = require('./plugins/MoveFilePlugin');

// First check if we can load Comunica form cwd, if not, fallback to the default
let pathToComunica;
Expand All @@ -13,7 +14,7 @@ catch {
comunicaOverride = false;
}

// Make this an object so we can mutate it from the top level of the config
// Make this an object, so we can mutate it from the top level of the config
// and have the options propagated to the plugins
const baseURL = {
search: '<%= baseURL %>',
Expand All @@ -23,6 +24,12 @@ const baseURL = {
flags: 'g'
}

// Make this an object, so we can mutate it from the top level of the config
// and have the options propagated to the plugins
const buildContext = {
dir: 'build',
}

module.exports = [
{
entry: [
Expand All @@ -41,7 +48,6 @@ module.exports = [
path.join(__dirname, './images/sparql.png'),
path.join(__dirname, './favicon.ico'),
path.join(__dirname, './solid-client-id.jsonld'),
path.join(process.cwd(), './queries.json'),
],
output: {
filename: 'scripts/ldf-client-ui.min.js',
Expand All @@ -53,6 +59,11 @@ module.exports = [
jQuery: path.join(__dirname, '/deps/jquery-2.1.0.js'),
}),
new webpack.NormalModuleReplacementPlugin(/^comunica-packagejson$/, (process.platform === 'win32' ? '' : '!!json-loader!') + path.join(pathToComunica, '../../package.json')),
// Include the generated queries.json file by moving it from the current working directory (where it was generated) to the build path.
new MoveFilePlugin(
() => path.join(process.cwd(), 'queries.json'),
() => path.join(__dirname, `${buildContext.dir}/queries.json`)
),
],
module: {
rules: [
Expand Down Expand Up @@ -155,6 +166,6 @@ module.exports = [
},
];

// Export the baseURL object so we can mutated it
// in the generate script
// Export the baseURL and buildContext objects, so we can mutate it in the generate script
module.exports.baseURL = baseURL;
module.exports.buildContext = buildContext;
Loading