UNPKG

@sprit/console-tag

Version:
3 lines (2 loc) 3.64 kB
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t,o=require("child_process"),i=(t=require("path"))&&"object"==typeof t&&"default"in t?t.default:t,n=function(t){return t.replace(/[\s\r\n]+$/,"")};function e(t,e,r){var a=t?["git","--git-dir="+i.join(t,".git"),"--work-tree="+t,e].join(" "):["git",e].join(" ");if(r)return o.exec(a,(function(t,o){if(t)return r(t,"");r(null,n(o))})),null;try{return n(""+o.execSync(a))}catch(t){return console.error(t.message),"-"}}var r=function(){function t(t){var o;if(void 0===t&&(t={}),this.gitWorkTree=t.gitWorkTree,this.commithashCommand=t.commithashCommand||"rev-parse HEAD",this.versionCommand=t.versionCommand||"describe --always"+(null!=(o=t)&&o.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 o=t.prototype;return o.commithash=function(){return e(this.gitWorkTree,this.commithashCommand)},o.version=function(){return e(this.gitWorkTree,this.versionCommand)},o.branch=function(){return e(this.gitWorkTree,this.branchCommand)},o.lastcommitdatetime=function(){return e(this.gitWorkTree,this.lastCommitDateTimeCommand)},t}(),a={keyBgColor:"#363636",valBgColor:"#175e9c"},s=function(t,o,i){void 0===i&&(i=a);var n=i.keyBgColor,e=i.valBgColor;return["%c "+t+" %c"+o,"padding: 2px 4px;font-size: 12px;background:"+(void 0===n?"#363636":n)+";color:white;border-radius: 4px 0 0 4px;","padding: 2px 4px;font-size: 12px;background:"+(void 0===e?"#175e9c":e)+";color:white;border-radius: 0 4px 4px 0;"]},u="console-tag-plugin",c={NODE_ENV:!0},l=function(t){return null!=t?t:"-"},m=function(t){return"\n ;"+function(t){var o=[];if(t.NODE_ENV){var i=process.env.NODE_ENV;o.push(s("NODE_ENV",l(i),{keyBgColor:"#20e014"}))}if(t.git){var n=t.git,e=new r;if(n.branch){var a=e.branch();o.push(s("git 分支",l(a)))}if(n.hash){var u=e.commithash();o.push(s("git hash",l(null==u?void 0:u.slice(0,n.hash))))}if(n.version){var c=e.version();o.push(s("git 版本",l(c)))}if(n.lastCommitDateTime){var m=e.lastcommitdatetime();o.push(s("git 最近提交时间",l(m)))}}if(t.custom)for(var p=t.custom(),h=0,g=Object.entries(p);h<g.length;h++){var f=g[h];o.push(s(f[0],l(f[1])))}return o}(t).map((function(t){return"console.log.apply(this, ["+t.map((function(t){return"'"+t+"'"}))+"])"})).join(";")+";\n "},p=function(){function t(t){this.option=Object.assign(c,t)}var o=t.prototype;return o.getCompilationHook=function(t,o){return t.hooks[o]},o.apply=function(t){var o=this;t.hooks.compilation.tap(u,(function(t){var i,n=o.getCompilationHook(t,"htmlWebpackPluginBeforeHtmlProcessing"),e=o.getCompilationHook(t,"html-webpack-plugin-before-html-processing"),r=null!=(i=null!=n?n:e)?i:o.option.HtmlPlugin.getHooks(t).alterAssetTagGroups;r&&r.tap(u,(function(t){var i=o.option.HtmlPlugin.createHtmlTagObject("script",void 0,m(o.option));return t.headTags.unshift(i),t}))}))},t}();exports.ConsoleTagRspackPlugin=function(){function t(t){this.option=Object.assign(c,t)}return t.prototype.apply=function(t){var o=this;t.hooks.compilation.tap(u,(function(t){var i;(null!=(i=o.option.HtmlPlugin.getCompilationHooks)?i:o.option.HtmlPlugin.getHooks)(t).alterAssetTagGroups.tap(u,(function(t){return t.headTags.push(o.option.HtmlPlugin.createHtmlTagObject("script",void 0,m(o.option))),t}))}))},t}(),exports.ConsoleTagWebpackPlugin=p,exports.Git=r,exports.getConsole=s; //# sourceMappingURL=console-tag-plugin.cjs.production.min.js.map