-
-
Notifications
You must be signed in to change notification settings - Fork 23
/
generateCasbinVersionPlugin.js
33 lines (29 loc) · 1.07 KB
/
generateCasbinVersionPlugin.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
const fs = require('fs');
const path = require('path');
class GenerateCasbinVersionPlugin {
apply(compiler) {
compiler.hooks.emit.tapAsync('GenerateCasbinVersionPlugin', (compilation, callback) => {
const packageJsonPath = path.resolve(__dirname, 'node_modules/casbin/package.json');
fs.readFile(packageJsonPath, 'utf-8', (err, data) => {
if (err) {
console.error('Error reading package.json:', err);
callback();
return;
}
const packageJson = JSON.parse(data);
const casbinVersion = packageJson.version;
const outputPath = path.resolve(__dirname, 'public/casbin-version.json');
const jsonContent = JSON.stringify({ casbinVersion });
fs.writeFile(outputPath, jsonContent, (err) => {
if (err) {
console.error('Error writing casbin-version.json:', err);
} else {
console.log('Casbin version generated:', casbinVersion);
}
callback();
});
});
});
}
}
module.exports = GenerateCasbinVersionPlugin;