git-revision-webpack-plugin
Version:
[](https://badge.fury.io/js/git-revision-webpack-plugin) [](https://www.npmjs.com/package/
3 lines (2 loc) • 2.67 kB
JavaScript
Object.defineProperty(exports,"__esModule",{value:!0});var e,t=require("child_process"),i=(e=require("path"))&&"object"==typeof e&&"default"in e?e.default:e;function r(e){return e.replace(/[\s\r\n]+$/,"")}function n(e,n,o){var a=e?["git","--git-dir="+i.join(e,".git"),"--work-tree="+e,n].join(" "):["git",n].join(" ");return o?(t.exec(a,(function(e,t){if(e)return o(e,"");o(null,r(t))})),null):r(""+t.execSync(a))}function o(e){var t=e.gitWorkTree,i=e.command,r=e.replacePattern,o=e.asset,a="";e.compiler.hooks.compilation.tap("GitRevisionWebpackPlugin",(function(e){e.hooks.optimizeTree.tapAsync("optimize-tree",(function(e,r,o){n(t,i,(function(e,t){if(e)return o(e);a=t,o()}))})),e.hooks.assetPath.tap("GitRevisionWebpackPlugin",(function(e,t){var i="function"==typeof e?e(t):e;return a?i.replace(r,a):i})),e.hooks.processAssets.tap("GitRevisionWebpackPlugin",(function(e){e[o]={source:function(){return a},size:function(){return a?a.length:0},buffer:function(){return Buffer.from(a)},map:function(){return{}},sourceAndMap:function(){return{source:a,map:{}}},updateHash:function(){}}}))}))}exports.GitRevisionPlugin=function(){function e(e){if(void 0===e&&(e={}),this.gitWorkTree=e.gitWorkTree,this.commithashCommand=e.commithashCommand||"rev-parse HEAD",this.versionCommand=e.versionCommand||"describe --always"+(e.lightweightTags?" --tags":""),this.createBranchFile=e.branch||!1,this.branchCommand=e.branchCommand||"rev-parse --abbrev-ref HEAD",this.lastCommitDateTimeCommand=e.lastCommitDateTimeCommand||"log -1 --format=%cI",e.versionCommand&&e.lightweightTags)throw new Error("lightweightTags can't be used together versionCommand")}var t=e.prototype;return t.commithash=function(){return n(this.gitWorkTree,this.commithashCommand)},t.version=function(){return n(this.gitWorkTree,this.versionCommand)},t.branch=function(){return n(this.gitWorkTree,this.branchCommand)},t.lastcommitdatetime=function(){return n(this.gitWorkTree,this.lastCommitDateTimeCommand)},t.apply=function(e){o({compiler:e,gitWorkTree:this.gitWorkTree,command:this.commithashCommand,replacePattern:/\[git-revision-hash\]/gi,asset:"COMMITHASH"}),o({compiler:e,gitWorkTree:this.gitWorkTree,command:this.versionCommand,replacePattern:/\[git-revision-version\]/gi,asset:"VERSION"}),o({compiler:e,gitWorkTree:this.gitWorkTree,command:this.lastCommitDateTimeCommand,replacePattern:/\[git-revision-last-commit-datetime\]/gi,asset:"LASTCOMMITDATETIME"}),this.createBranchFile&&o({compiler:e,gitWorkTree:this.gitWorkTree,command:this.branchCommand,replacePattern:/\[git-revision-branch\]/gi,asset:"BRANCH"})},e}();
//# sourceMappingURL=git-revision-webpack-plugin.cjs.production.min.js.map
;