Skip to content

Commit 1003d34

Browse files
authored
Add issues/11256 behavior to track the version of extension (#67)
1 parent cc645b2 commit 1003d34

File tree

4 files changed

+25
-1
lines changed

4 files changed

+25
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ web/.classpath
99
web/.project
1010
backend/.classpath
1111
backend/.project
12+
assets/index.json.tmp

assets/index.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"plugins": [
33
{
44
"name": "SampleExtension",
5+
"version": "@@VERSION@@",
56
"dependencies": [
67
"Toolbar"
78
]

build/extension/prod-webpack.config.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,34 @@
11

22
const path = require("path");
3+
const fs = require("fs");
34

45
const createExtensionWebpackConfig = require('../../MapStore2/build/createExtensionWebpackConfig');
56
const CopyPlugin = require('copy-webpack-plugin');
67
const ZipPlugin = require('zip-webpack-plugin');
8+
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
79
const {name} = require('../../config');
810
const commons = require('./commons');
911

12+
// read version and produce a temporary updated index.json
13+
const { version: versionText } = require('../../package.json');
14+
const indexSrc = path.resolve(__dirname, "..", "..", "assets", "index.json");
15+
const tmpIndex = path.resolve(__dirname, "..", "..", "assets", "index.json.tmp");
16+
try {
17+
const indexContent = JSON.parse(fs.readFileSync(indexSrc, 'utf8'));
18+
if (Array.isArray(indexContent.plugins)) {
19+
indexContent.plugins = indexContent.plugins.map(p => p && p.name === name ? { ...p, version: versionText } : p);
20+
}
21+
fs.writeFileSync(tmpIndex, JSON.stringify(indexContent, null, 4), 'utf8');
22+
} catch (e) {
23+
// keep behavior silent here; build will fail later if necessary
24+
console.error('Error updating index.json from version.txt:', e);
25+
}
26+
1027
// the build configuration for production allow to create the final zip file, compressed accordingly
1128
const plugins = [
1229
new CopyPlugin([
1330
{ from: path.resolve(__dirname, "..", "..", "assets", "translations"), to: "translations" },
14-
{ from: path.resolve(__dirname, "..", "..", "assets", "index.json"), to: "index.json" }
31+
{ from: tmpIndex, to: 'index.json' }
1532
]),
1633
new ZipPlugin({
1734
filename: `${name}.zip`,
@@ -22,6 +39,10 @@ const plugins = [
2239
// other files have to be placed in the root, with the same name
2340
return path.basename(assetPath);
2441
}
42+
}),
43+
new CleanWebpackPlugin({
44+
cleanOnceBeforeBuildPatterns: [],
45+
cleanAfterEveryBuildPatterns: [tmpIndex]
2546
})
2647
];
2748
module.exports = createExtensionWebpackConfig({ prod: true, name, ...commons, plugins});

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
"babel-plugin-object-assign": "1.2.1",
5454
"babel-plugin-react-transform": "2.0.2",
5555
"babel-plugin-transform-imports": "2.0.0",
56+
"clean-webpack-plugin": "^4.0.0",
5657
"copy-webpack-plugin": "5.0.2",
5758
"css-loader": "5.1.2",
5859
"css-minimizer-webpack-plugin": "3.0.2",

0 commit comments

Comments
 (0)