diff --git a/bin/generate.js b/bin/generate.js index dcb5a31..a7dcf8b 100755 --- a/bin/generate.js +++ b/bin/generate.js @@ -57,6 +57,9 @@ if (args.h || args.help || args._.length > 1) { const baseURL = args.b || 'https://query.linkeddatafragments.org/'; const webpackConfig = require(args.w ? path.resolve(process.cwd(), args.w) : '../webpack.config.js'); + // Remove the location of queries.json which shouldn't be present in the build configuration. + webpackConfig[0].entry=webpackConfig[0].entry.filter(x => !x.endsWith('queries.json')); + // Override the baseURL in the webpack config webpackConfig.baseURL.replace = baseURL; @@ -69,6 +72,7 @@ if (args.h || args.help || args._.length > 1) { entry.output.path = path.resolve(process.cwd(), destinationPath); } } + webpack(webpackConfig, (err, stats) => { if (err) { console.error(err.stack || err); @@ -85,4 +89,8 @@ if (args.h || args.help || args._.length > 1) { fs.unlinkSync('.tmp-comunica-engine.js'); }); + + if (fs.existsSync(path.join(process.cwd(), 'queries.json'))) { + fs.renameSync(path.join(process.cwd(), 'queries.json'), path.join(process.cwd(), `${destinationPath}/queries.json`)); + }; })(); diff --git a/plugins/MoveFilePlugin.js b/plugins/MoveFilePlugin.js deleted file mode 100644 index 6da8023..0000000 --- a/plugins/MoveFilePlugin.js +++ /dev/null @@ -1,25 +0,0 @@ -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; diff --git a/webpack.config.js b/webpack.config.js index 42ed7e5..45c365e 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,6 +1,5 @@ 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; @@ -48,6 +47,7 @@ module.exports = [ path.join(__dirname, './images/sparql.png'), path.join(__dirname, './favicon.ico'), path.join(__dirname, './solid-client-id.jsonld'), + path.join(__dirname, './queries.json'), ], output: { filename: 'scripts/ldf-client-ui.min.js', @@ -59,11 +59,6 @@ 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: [