2019-12-06 22:53:09 +01:00
|
|
|
const gitRevSync = require('git-rev-sync');
|
2018-07-12 22:13:49 +02:00
|
|
|
const pkg = require('../package.json');
|
|
|
|
|
2019-12-06 22:53:09 +01:00
|
|
|
let commit = 'unknown';
|
|
|
|
|
|
|
|
try {
|
|
|
|
commit = gitRevSync.short();
|
|
|
|
} catch (e) {
|
|
|
|
console.warn('Error fetching current git commit: ' + e);
|
|
|
|
}
|
|
|
|
|
2018-07-12 22:13:49 +02:00
|
|
|
const version = JSON.stringify({
|
|
|
|
commit,
|
|
|
|
source: pkg.homepage,
|
|
|
|
version: process.env.CIRCLE_TAG || `v${pkg.version}`
|
|
|
|
});
|
|
|
|
|
|
|
|
class VersionPlugin {
|
|
|
|
apply(compiler) {
|
|
|
|
compiler.hooks.emit.tap('VersionPlugin', compilation => {
|
|
|
|
compilation.assets['version.json'] = {
|
|
|
|
source() {
|
|
|
|
return version;
|
|
|
|
},
|
|
|
|
size() {
|
2018-07-27 15:11:46 +02:00
|
|
|
return version.length;
|
2018-07-12 22:13:49 +02:00
|
|
|
}
|
2018-07-27 15:11:46 +02:00
|
|
|
};
|
|
|
|
});
|
2018-07-12 22:13:49 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = VersionPlugin;
|