@sprit/pretty-console-webpack-plugin
Version:
## Usage ```typescript import { PrettyConsoleWebpackPlugin } from '@sprit/pretty-console-webpack-plugin'; ```
3 lines (2 loc) • 3.4 kB
JavaScript
;function t(t){return t&&"object"==typeof t&&"default"in t?t.default:t}Object.defineProperty(exports,"__esModule",{value:!0});var e=t(require("safe-require")),o=require("child_process"),r=t(require("path")),i="pretty-console-webpack-plugin",n={NODE_ENV:!0},a={keyBgColor:"#363636",valBgColor:"#175e9c"},s=function(t,e,o){void 0===o&&(o=a);var r=o.keyBgColor,i=o.valBgColor;return["%c "+t+" %c"+e,"padding: 2px 4px;font-size: 12px;background:"+(void 0===r?"#363636":r)+";color:white;border-radius: 4px 0 0 4px;","padding: 2px 4px;font-size: 12px;background:"+(void 0===i?"#175e9c":i)+";color:white;border-radius: 0 4px 4px 0;"]},c=function(t){return t.replace(/[\s\r\n]+$/,"")};function u(t,e,i){var n=t?["git","--git-dir="+r.join(t,".git"),"--work-tree="+t,e].join(" "):["git",e].join(" ");if(i)return o.exec(n,(function(t,e){if(t)return i(t,"");i(null,c(e))})),null;try{return c(""+o.execSync(n))}catch(t){return console.error(t.message),"-"}}var m=function(){function t(t){var e;if(void 0===t&&(t={}),this.gitWorkTree=t.gitWorkTree,this.commithashCommand=t.commithashCommand||"rev-parse HEAD",this.versionCommand=t.versionCommand||"describe --always"+(null!=(e=t)&&e.lightweightTags?" --tags":""),this.createBranchFile=t.branch||!1,this.branchCommand=t.branchCommand||"rev-parse --abbrev-ref HEAD",this.lastCommitDateTimeCommand=t.lastCommitDateTimeCommand||"log -1 --format=%cI",t.versionCommand&&t.lightweightTags)throw new Error("lightweightTags can't be used together versionCommand")}var e=t.prototype;return e.commithash=function(){return u(this.gitWorkTree,this.commithashCommand)},e.version=function(){return u(this.gitWorkTree,this.versionCommand)},e.branch=function(){return u(this.gitWorkTree,this.branchCommand)},e.lastcommitdatetime=function(){return u(this.gitWorkTree,this.lastCommitDateTimeCommand)},t}(),l=function(t){return null!=t?t:"-"},h=e("html-webpack-plugin");console.log("%c ["+i+"] "+JSON.stringify("检测到 html-webpack-plugin 主版本号: "+h.version),"color: red");var p=function(){function t(t){this.option=Object.assign(n,t)}var e=t.prototype;return e.getCompilationHook=function(t,e){return t.hooks[e]},e.apply=function(t){var e=this;t.hooks.compilation.tap(i,(function(t){var o,r=e.getCompilationHook(t,"htmlWebpackPluginBeforeHtmlProcessing"),n=e.getCompilationHook(t,"html-webpack-plugin-before-html-processing"),a=null!=(o=null!=r?r:n)?o:h.getHooks(t).alterAssetTagGroups;a&&a.tap(i,(function(t){var o="\n ;"+function(t){var e=[];if(t.NODE_ENV){var o=process.env.NODE_ENV;e.push(s("NODE_ENV",l(o),{keyBgColor:"#20e014"}))}if(t.git){var r=t.git,i=new m;if(r.branch){var n=i.branch();e.push(s("git 分支",l(n)))}if(r.hash){var a=i.commithash();e.push(s("git hash",l(null==a?void 0:a.slice(0,r.hash))))}if(r.version){var c=i.version();e.push(s("git 版本",l(c)))}if(r.lastCommitDateTime){var u=i.lastcommitdatetime();e.push(s("git 最近提交时间",l(u)))}}if(t.custom)for(var h=t.custom(),p=0,g=Object.entries(h);p<g.length;p++){var f=g[p];e.push(s(f[0],l(f[1])))}return e}(e.option).map((function(t){return"console.log.apply(this, ["+t.map((function(t){return"'"+t+"'"}))+"])"})).join(";")+";\n ",r=h.createHtmlTagObject("script",void 0,o);t.headTags.unshift(r)}))}))},t}();exports.Git=m,exports.PrettyConsoleWebpackPlugin=p,exports.getConsole=s;
//# sourceMappingURL=pretty-console-webpack-plugin.cjs.production.min.js.map