-
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: show Node-Casbin version in top-right corner (#106)
* feat: Add function to fetch and display Casbin version * refactor: Remove redundant code for fetching casbin version * build: Add GenerateCasbinVersionPlugin to next.config.mjs
- Loading branch information
1 parent
9b80a83
commit 7c4a7f4
Showing
4 changed files
with
58 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ | |
# next.js | ||
/.next/ | ||
/out/ | ||
/public/casbin-version.json | ||
|
||
# production | ||
/build | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters