UNPKG

hs-cover

Version:

```bash npm i hs-cover -g ```

3 lines (2 loc) 24 kB
#! /usr/bin/env node var utils,hasRequiredUtils,cover,hasRequiredCover,diff,hasRequiredDiff,require$$0=require("fs"),require$$3=require("inquirer"),require$$2=require("chalk"),require$$1=require("path"),require$$4$1=require("figlet"),require$$6=require("commander"),require$$4=require("crypto"),bin={},version$1="2.2.0",require$$5={version:version$1};function asyncGeneratorStep(e,r,t,n,o,a,i){try{var c=e[a](i),u=c.value}catch(e){return void t(e)}c.done?r(u):Promise.resolve(u).then(n,o)}function _asyncToGenerator(c){return function(){var e=this,i=arguments;return new Promise(function(r,t){var n=c.apply(e,i);function o(e){asyncGeneratorStep(n,r,t,o,a,"next",e)}function a(e){asyncGeneratorStep(n,r,t,o,a,"throw",e)}o(void 0)})}}function _regeneratorRuntime(){_regeneratorRuntime=function(){return i};var s,i={},e=Object.prototype,u=e.hasOwnProperty,r="function"==typeof Symbol?Symbol:{},n=r.iterator||"@@iterator",t=r.asyncIterator||"@@asyncIterator",o=r.toStringTag||"@@toStringTag";function p(e,r,t,n){return Object.defineProperty(e,r,{value:t,enumerable:!n,configurable:!n,writable:!n})}try{p({},"")}catch(s){p=function(e,r,t){return e[r]=t}}function c(e,r,t,n){var o,a,i,c,r=r&&r.prototype instanceof h?r:h,r=Object.create(r.prototype);return p(r,"_invoke",(o=e,a=t,i=new _(n||[]),c=1,function(e,r){if(3===c)throw Error("Generator is already running");if(4===c){if("throw"===e)throw r;return{value:s,done:!0}}for(i.method=e,i.arg=r;;){var t=i.delegate;if(t){t=function e(r,t){var n=t.method,o=r.i[n];if(o===s)return t.delegate=null,"throw"===n&&r.i.return&&(t.method="return",t.arg=s,e(r,t),"throw"===t.method)||"return"!==n&&(t.method="throw",t.arg=new TypeError("The iterator does not provide a '"+n+"' method")),l;n=f(o,r.i,t.arg);if("throw"===n.type)return t.method="throw",t.arg=n.arg,t.delegate=null,l;o=n.arg;return o?o.done?(t[r.r]=o.value,t.next=r.n,"return"!==t.method&&(t.method="next",t.arg=s),t.delegate=null,l):o:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,l)}(t,i);if(t){if(t===l)continue;return t}}if("next"===i.method)i.sent=i._sent=i.arg;else if("throw"===i.method){if(1===c)throw c=4,i.arg;i.dispatchException(i.arg)}else"return"===i.method&&i.abrupt("return",i.arg);c=3;t=f(o,a,i);if("normal"===t.type){if(c=i.done?4:2,t.arg===l)continue;return{value:t.arg,done:i.done}}"throw"===t.type&&(c=4,i.method="throw",i.arg=t.arg)}}),!0),r}function f(e,r,t){try{return{type:"normal",arg:e.call(r,t)}}catch(e){return{type:"throw",arg:e}}}i.wrap=c;var l={};function h(){}function a(){}function m(){}var r={},d=(p(r,n,function(){return this}),Object.getPrototypeOf),d=d&&d(d(b([]))),g=(d&&d!==e&&u.call(d,n)&&(r=d),m.prototype=h.prototype=Object.create(r));function v(e){["next","throw","return"].forEach(function(r){p(e,r,function(e){return this._invoke(r,e)})})}function y(i,c){var r;p(this,"_invoke",function(t,n){function e(){return new c(function(e,r){!function r(e,t,n,o){var a,e=f(i[e],i,t);if("throw"!==e.type)return(t=(a=e.arg).value)&&"object"==typeof t&&u.call(t,"__await")?c.resolve(t.__await).then(function(e){r("next",e,n,o)},function(e){r("throw",e,n,o)}):c.resolve(t).then(function(e){a.value=e,n(a)},function(e){return r("throw",e,n,o)});o(e.arg)}(t,n,e,r)})}return r=r?r.then(e,e):e()},!0)}function w(e){this.tryEntries.push(e)}function x(e){var r=e[4]||{};r.type="normal",r.arg=s,e[4]=r}function _(e){this.tryEntries=[[-1]],e.forEach(w,this),this.reset(!0)}function b(r){if(null!=r){var t,e=r[n];if(e)return e.call(r);if("function"==typeof r.next)return r;if(!isNaN(r.length))return t=-1,(e=function e(){for(;++t<r.length;)if(u.call(r,t))return e.value=r[t],e.done=!1,e;return e.value=s,e.done=!0,e}).next=e}throw new TypeError(typeof r+" is not iterable")}return p(g,"constructor",a.prototype=m),p(m,"constructor",a),a.displayName=p(m,o,"GeneratorFunction"),i.isGeneratorFunction=function(e){e="function"==typeof e&&e.constructor;return!!e&&(e===a||"GeneratorFunction"===(e.displayName||e.name))},i.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,m):(e.__proto__=m,p(e,o,"GeneratorFunction")),e.prototype=Object.create(g),e},i.awrap=function(e){return{__await:e}},v(y.prototype),p(y.prototype,t,function(){return this}),i.AsyncIterator=y,i.async=function(e,r,t,n,o){void 0===o&&(o=Promise);var a=new y(c(e,r,t,n),o);return i.isGeneratorFunction(r)?a:a.next().then(function(e){return e.done?e.value:a.next()})},v(g),p(g,o,"Generator"),p(g,n,function(){return this}),p(g,"toString",function(){return"[object Generator]"}),i.keys=function(e){var r,t=Object(e),n=[];for(r in t)n.unshift(r);return function e(){for(;n.length;)if((r=n.pop())in t)return e.value=r,e.done=!1,e;return e.done=!0,e}},i.values=b,_.prototype={constructor:_,reset:function(e){if(this.prev=this.next=0,this.sent=this._sent=s,this.done=!1,this.delegate=null,this.method="next",this.arg=s,this.tryEntries.forEach(x),!e)for(var r in this)"t"===r.charAt(0)&&u.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=s)},stop:function(){this.done=!0;var e=this.tryEntries[0][4];if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(r){if(this.done)throw r;var t=this;function e(e){a.type="throw",a.arg=r,t.next=e}for(var n=t.tryEntries.length-1;0<=n;--n){var o=this.tryEntries[n],a=o[4],i=this.prev,c=o[1],u=o[2];if(-1===o[0])return e("end"),!1;if(!c&&!u)throw Error("try statement without catch or finally");if(null!=o[0]&&o[0]<=i){if(i<c)return this.method="next",this.arg=s,e(c),!0;if(i<u)return e(u),!1}}},abrupt:function(e,r){for(var t=this.tryEntries.length-1;0<=t;--t){var n=this.tryEntries[t];if(-1<n[0]&&n[0]<=this.prev&&this.prev<n[2]){var o=n;break}}var a=(o=o&&("break"===e||"continue"===e)&&o[0]<=r&&r<=o[2]?null:o)?o[4]:{};return a.type=e,a.arg=r,o?(this.method="next",this.next=o[2],l):this.complete(a)},complete:function(e,r){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&r&&(this.next=r),l},finish:function(e){for(var r=this.tryEntries.length-1;0<=r;--r){var t=this.tryEntries[r];if(t[2]===e)return this.complete(t[4],t[3]),x(t),l}},catch:function(e){for(var r=this.tryEntries.length-1;0<=r;--r){var t,n,o=this.tryEntries[r];if(o[0]===e)return"throw"===(t=o[4]).type&&(n=t.arg,x(o)),n}throw Error("illegal catch attempt")},delegateYield:function(e,r,t){return this.delegate={i:b(e),r:r,n:t},"next"===this.method&&(this.arg=s),l}},i}function requireUtils(){var p,f,i,c,a,s;return hasRequiredUtils||(hasRequiredUtils=1,p=require$$1,f=require$$0,i=require$$2,c=require$$3,a=require$$4,utils={getCurrentDir:m,getBaseReplace:d,validateAndGetTargetDir:function(e){return g.apply(this,arguments)},selectProjectToCover:function(e){return v.apply(this,arguments)},confirmOrInputTargetDir:function(e){return y.apply(this,arguments)},replaceFiles:l,readFilesAndDirectories:h,writeAllFiles:function(e,r,t){return u.apply(this,arguments)},getFileHash:w,compareFiles:function(e,r){return _.apply(this,arguments)},compareFilesBuffer:function(e,r){return b.apply(this,arguments)},compareFilesStream:function(e,r){return R.apply(this,arguments)},checkFileExists:function(e){return k.apply(this,arguments)},EXCLUDE_DIR:s=["-test","-uat","-sit","-prod"]}),utils;function l(e,r,t){return n.apply(this,arguments)}function n(){return(n=_asyncToGenerator(_regeneratorRuntime().mark(function e(r,t,n){var o,a,i,c,u=arguments;return _regeneratorRuntime().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(o=3<u.length&&void 0!==u[3]?u[3]:"test",c=r.replace(n,""),a=c.split("\\"),a=a[a.length-1],i=(i=p.join(t,c)).replace("-".concat(o),""),s.some(function(e){return(i||"").includes(e)}))return e.abrupt("return");e.next=8;break;case 8:return(c=[]).push({path:i,source:r,fileName:a}),e.abrupt("return",c);case 11:case"end":return e.stop()}},e)}))).apply(this,arguments)}function h(e,r,t){return o.apply(this,arguments)}function o(){return(o=_asyncToGenerator(_regeneratorRuntime().mark(function e(i,c,u){var s,r=arguments;return _regeneratorRuntime().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return s=3<r.length&&void 0!==r[3]?r[3]:"test",e.abrupt("return",new Promise(function(t,n){f.readdir(i,function(e,r){e?(console.error("无法读取目录:",e),n(e)):(e=r.map(function(e){return new Promise(function(o){var a=p.join(i,e);f.stat(a,(()=>{var t=_asyncToGenerator(_regeneratorRuntime().mark(function e(r,t){var n;return _regeneratorRuntime().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(r)return console.error("无法获取文件状态:",r),o(null),e.abrupt("return");e.next=4;break;case 4:if(t.isDirectory())return e.next=7,h(a,c,u,s);e.next=11;break;case 7:n=e.sent,o(n),e.next=15;break;case 11:return e.next=13,l(a,c,u,s);case 13:n=e.sent,o(n);case 15:case"end":return e.stop()}},e)}));return function(e,r){return t.apply(this,arguments)}})())})}),Promise.all(e).then(function(e){e=e.flat().filter(Boolean),e=Array.from(new Map(e.map(function(e){return[e.source,e]})).values());t(e)}).catch(n))})}));case 2:case"end":return e.stop()}},e)}))).apply(this,arguments)}function u(){return(u=_asyncToGenerator(_regeneratorRuntime().mark(function e(r,t,n){return _regeneratorRuntime().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:f.access(t,f.constants.F_OK,function(e){e&&f.mkdir(p.dirname(t),{recursive:!0},function(e){e?console.error(i.red("✗ 无法创建目录 ".concat(n,":")),e):f.writeFile(t,"",(()=>{var r=_asyncToGenerator(_regeneratorRuntime().mark(function e(r){return _regeneratorRuntime().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(r)return console.error(i.red("✗ 无法创建文件 ".concat(n,":")),r),e.abrupt("return");e.next=3;break;case 3:case"end":return e.stop()}},e)}));return function(e){return r.apply(this,arguments)}})())}),f.readFile(r,function(e,r){e?console.error(i.red("✗ 无法读取源文件 ".concat(n,":")),e):f.writeFile(t,r,(()=>{var r=_asyncToGenerator(_regeneratorRuntime().mark(function e(r){return _regeneratorRuntime().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(r)return console.error(i.red("✗ 无法写入目标文件 ".concat(n,":")),r),e.abrupt("return");e.next=3;break;case 3:console.log(i.green("✓ 文件已成功覆盖: ".concat(n)));case 4:case"end":return e.stop()}},e)}));return function(e){return r.apply(this,arguments)}})())})});case 1:case"end":return e.stop()}},e)}))).apply(this,arguments)}function m(e){return r.apply(this,arguments)}function r(){return(r=_asyncToGenerator(_regeneratorRuntime().mark(function e(r){var t;return _regeneratorRuntime().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,f.readdirSync(r);case 3:return t=e.sent,t=t.filter(function(e){return f.statSync(p.join(r,e)).isDirectory()}),e.abrupt("return",t);case 8:throw e.prev=8,e.t0=e.catch(0),console.error(i.red("获取目录失败: ".concat(e.t0.message))),e.t0;case 12:case"end":return e.stop()}},e,null,[[0,8]])}))).apply(this,arguments)}function d(e,r){return t.apply(this,arguments)}function t(){return(t=_asyncToGenerator(_regeneratorRuntime().mark(function e(r,t){var n,o;return _regeneratorRuntime().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,m(r);case 3:if(n=e.sent,o=n.findIndex(function(e){return["h5","html5","main"].includes(e)}),n.includes("src")&&0<n.length)return e.abrupt("return",r);e.next=9;break;case 9:if(0<n.length)return e.next=12,d(p.join(r,n[o<0?0:o]),t);e.next=13;break;case 12:return e.abrupt("return",e.sent);case 13:return e.abrupt("return","空的");case 16:throw e.prev=16,e.t0=e.catch(0),console.error(i.red("查找基础替换目录失败: ".concat(e.t0.message))),e.t0;case 20:case"end":return e.stop()}},e,null,[[0,16]])}))).apply(this,arguments)}function g(){return(g=_asyncToGenerator(_regeneratorRuntime().mark(function e(r){var t,n,o,a=arguments;return _regeneratorRuntime().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return t=1<a.length&&void 0!==a[1]?a[1]:"",e.prev=1,e.next=4,m(process.cwd());case 4:return(o=e.sent).includes(r)||(console.log(i.blue.bgRed.bold("当前目录也没有".concat(r,"啊,你是不是搞错了!"))),process.exit(1)),(n=t)||(o=o.filter(function(e){return![r,"node_modules",".git"].includes(e)}),n=o[o.length-1]),e.abrupt("return",n);case 11:throw e.prev=11,e.t0=e.catch(1),console.error(i.red("验证目标目录失败: ".concat(e.t0.message))),e.t0;case 15:case"end":return e.stop()}},e,null,[[1,11]])}))).apply(this,arguments)}function v(){return(v=_asyncToGenerator(_regeneratorRuntime().mark(function e(r){var t,n,o=arguments;return _regeneratorRuntime().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return t=1<o.length&&void 0!==o[1]?o[1]:"覆盖",e.prev=1,e.next=4,m(p.join(process.cwd(),r));case 4:return n=e.sent,e.next=7,c.prompt([{type:"list",message:"选择你要".concat(t,"的项目"),name:"cover",choices:n.map(function(e){return{name:e}})}]);case 7:return n=e.sent,e.abrupt("return",n.cover);case 11:throw e.prev=11,e.t0=e.catch(1),console.error(i.red("选择项目失败: ".concat(e.t0.message))),e.t0;case 15:case"end":return e.stop()}},e,null,[[1,11]])}))).apply(this,arguments)}function y(){return(y=_asyncToGenerator(_regeneratorRuntime().mark(function e(r){var t,n,o,a=arguments;return _regeneratorRuntime().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return t=1<a.length&&void 0!==a[1]?a[1]:"覆盖",e.prev=1,e.next=4,c.prompt([{type:"list",message:"目录【 ".concat(r," 】是你将要").concat(t,"的目录").concat("对比"===t?",对比操作不会对以[-prod]为后缀的文件进行对比":""),name:"replaceDirectory",choices:[{name:"是",value:"1"},{name:"否",value:"0"}]}]);case 4:if("1"===e.sent.replaceDirectory)return e.abrupt("return",p.join(process.cwd(),r));e.next=7;break;case 7:return e.next=9,c.prompt([{type:"input",name:"replaceDirectory",message:"请输入你要".concat(t,"的目录")}]);case 9:return n=e.sent,(n=(n.replaceDirectory||"").trim())||(console.log(i.blue.bgRed.bold("可不能输入空值啊!")),process.exit(1)),o=p.join(process.cwd(),n),f.existsSync(o)||(console.log(i.blue.bgRed.bold("能不能输入一个存在的目录!")),process.exit(1)),f.statSync(o).isDirectory()||(console.log(i.blue.bgRed.bold("能不能输入一个目录!不要文件!!")),process.exit(1)),e.abrupt("return",n);case 19:throw e.prev=19,e.t0=e.catch(1),console.error(i.red("确认目标目录失败: ".concat(e.t0.message))),e.t0;case 23:case"end":return e.stop()}},e,null,[[1,19]])}))).apply(this,arguments)}function w(e){return x.apply(this,arguments)}function x(){return(x=_asyncToGenerator(_regeneratorRuntime().mark(function e(o){return _regeneratorRuntime().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",new Promise(function(e,r){var t=a.createHash("md5"),n=f.createReadStream(o);n.on("error",function(e){return r(e)}),n.on("data",function(e){return t.update(e)}),n.on("end",function(){return e(t.digest("hex"))})}));case 1:case"end":return e.stop()}},e)}))).apply(this,arguments)}function _(){return(_=_asyncToGenerator(_regeneratorRuntime().mark(function e(r,t){var n,o,a;return _regeneratorRuntime().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(e.prev=0,a=f.statSync(r),n=f.statSync(t),a.size!==n.size)return e.abrupt("return",!1);e.next=5;break;case 5:return e.next=7,w(r);case 7:return o=e.sent,e.next=10,w(t);case 10:return a=e.sent,e.abrupt("return",o===a);case 14:throw e.prev=14,e.t0=e.catch(0),console.error(i.red("比较文件失败: ".concat(e.t0.message))),e.t0;case 18:case"end":return e.stop()}},e,null,[[0,14]])}))).apply(this,arguments)}function b(){return(b=_asyncToGenerator(_regeneratorRuntime().mark(function e(r,t){var n,o,a;return _regeneratorRuntime().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(e.prev=0,a=f.statSync(r),n=f.statSync(t),a.size!==n.size)return e.abrupt("return",!1);e.next=5;break;case 5:return e.next=7,f.promises.readFile(r);case 7:return o=e.sent,e.next=10,f.promises.readFile(t);case 10:return a=e.sent,e.abrupt("return",o.equals(a));case 14:throw e.prev=14,e.t0=e.catch(0),console.error(i.red("比较文件失败: ".concat(e.t0.message))),e.t0;case 18:case"end":return e.stop()}},e,null,[[0,14]])}))).apply(this,arguments)}function R(){return(R=_asyncToGenerator(_regeneratorRuntime().mark(function e(c,u){return _regeneratorRuntime().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",new Promise(function(e,r){var t,n,o,a=f.statSync(c),i=f.statSync(u);a.size!==i.size?e(!1):(t=f.createReadStream(c),n=f.createReadStream(u),o=!0,t.on("data",function(e){var r=n.read(e.length);r&&e.equals(r)||(o=!1,t.destroy(),n.destroy()),e.length}),t.on("end",function(){e(o)}),t.on("error",function(e){r(e)}),n.on("error",function(e){r(e)}))}));case 1:case"end":return e.stop()}},e)}))).apply(this,arguments)}function k(){return(k=_asyncToGenerator(_regeneratorRuntime().mark(function e(r){return _regeneratorRuntime().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,f.existsSync(r);case 3:return e.sent,e.abrupt("return",!0);case 7:return e.prev=7,e.t0=e.catch(0),e.abrupt("return",!1);case 10:case"end":return e.stop()}},e,null,[[0,7]])}))).apply(this,arguments)}}function requireCover(){var h,m,d,g,e,v,y,w,x,_,b,R;return hasRequiredCover||(hasRequiredCover=1,h=require$$0,m=require$$1,d=require$$2,g=require$$3,e=requireUtils(),v=e.getBaseReplace,y=e.validateAndGetTargetDir,w=e.selectProjectToCover,x=e.confirmOrInputTargetDir,_=e.readFilesAndDirectories,b=e.writeAllFiles,R=e.EXCLUDE_DIR,cover=(()=>{var e=_asyncToGenerator(_regeneratorRuntime().mark(function e(){var c,r,t,n,o,a,i,u,s,p,f,l=arguments;return _regeneratorRuntime().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return r=0<l.length&&void 0!==l[0]?l[0]:"",s=1<l.length&&void 0!==l[1]?l[1]:"",e.prev=2,c=(()=>{var r=_asyncToGenerator(_regeneratorRuntime().mark(function e(i){return _regeneratorRuntime().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",new Promise(function(t,n){h.readdir(i,function(e,r){e?(console.error("无法读取目录:",e),n(e)):(r.some(function(r){return R.some(function(e){return r.includes(e)})})?(e=r.map(function(n){var o=m.join(i,n);return new Promise(function(t){h.stat(o,function(e,r){e?(console.error("无法获取文件状态:",e),t(null)):t({path:o,isDirectory:r.isDirectory(),name:n})})})}),Promise.all(e).then(function(e){e=e.filter(Boolean);t(e)})):(e=r.map(function(e){return new Promise(function(o){var a=m.join(i,e);h.stat(a,(()=>{var t=_asyncToGenerator(_regeneratorRuntime().mark(function e(r,t){var n;return _regeneratorRuntime().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(r)return console.error("无法获取文件状态:",r),o(null),e.abrupt("return");e.next=4;break;case 4:if(t.isDirectory())return e.next=7,c(a);e.next=11;break;case 7:n=e.sent,o(n),e.next=12;break;case 11:o(null);case 12:case"end":return e.stop()}},e)}));return function(e,r){return t.apply(this,arguments)}})())})}),Promise.all(e).then(function(e){e=e.flat().filter(Boolean);0<e.length?t(e):t([])}))).catch(n)})}));case 1:case"end":return e.stop()}},e)}));return function(e){return r.apply(this,arguments)}})(),r=r||"ext",e.next=7,y(r,s);case 7:return t=e.sent,e.next=10,w(r);case 10:return n=e.sent,e.next=13,v(m.join(process.cwd(),r,n),r);case 13:return o=e.sent,e.next=16,x(t);case 16:return a=e.sent,i=m.join(process.cwd(),r,n),(u=m.parse(o).dir).includes(n)||(u=m.join(u,n)),e.next=22,c(u);case 22:return s=e.sent,p=s.filter(function(r){return R.some(function(e){return r.name.includes(e)})}).map(function(e){var r=e.name,r=r.slice(r.lastIndexOf("-")+1,-3);return{key:r,name:e.name,value:r}}),e.next=26,g.prompt({type:"list",name:"cover",message:"选择覆盖的配置项:",choices:p});case 26:return p=e.sent,f=p.cover,f=f,e.next=31,_(i,a,u,f);case 31:e.sent.forEach(function(e){b(e.source,e.path,e.fileName)}),e.next=39;break;case 35:e.prev=35,e.t0=e.catch(2),console.error(d.red("执行失败: ".concat(e.t0.message))),process.exit(1);case 39:case"end":return e.stop()}},e,null,[[2,35]])}));return function(){return e.apply(this,arguments)}})()),cover}function requireDiff(){var f,l,h,e,m,d,g,v,y,w,x;return hasRequiredDiff||(hasRequiredDiff=1,f=require$$0,l=require$$1,h=require$$2,e=requireUtils(),m=e.getBaseReplace,d=e.validateAndGetTargetDir,g=e.selectProjectToCover,v=e.confirmOrInputTargetDir,y=e.readFilesAndDirectories,w=e.EXCLUDE_DIR,x=e.compareFiles,diff=(()=>{var e=_asyncToGenerator(_regeneratorRuntime().mark(function e(){var r,t,n,o,a,i,c,u,s,p=arguments;return _regeneratorRuntime().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return t=0<p.length&&void 0!==p[0]?p[0]:"",i=1<p.length&&void 0!==p[1]?p[1]:"",console.error(h.red("正在执行文件对比中: ".concat(t," ").concat(i))),e.prev=3,r=(()=>{var n=_asyncToGenerator(_regeneratorRuntime().mark(function e(r,t,n){var o,a,i;return _regeneratorRuntime().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(o=t.replace(process.cwd(),""),i=f.existsSync(r),a=f.existsSync(t),i&&a){e.next=7;break}return console.log("在html5中",h.bgCyanBright("".concat(o," 文件不存在"))),u.push({source:r,path:t,fileName:n,isSame:!1}),e.abrupt("return");case 7:return e.next=9,x(r,t);case 9:(i=e.sent)||(u.push({source:r,path:t,fileName:n,isSame:i}),console.log(h.bgYellowBright("".concat(o," 文件不同"))));case 11:case"end":return e.stop()}},e)}));return function(e,r,t){return n.apply(this,arguments)}})(),t=t||"ext",e.next=8,d(t,i);case 8:return n=e.sent,e.next=11,g(t,"对比");case 11:return o=e.sent,e.next=14,m(l.join(process.cwd(),t,o),t);case 14:return a=e.sent,e.next=17,v(n,"对比");case 17:return i=e.sent,c=l.join(process.cwd(),t,o),(s=l.parse(a).dir).includes(o)||(s=l.join(s,o)),e.next=23,y(c,i,s);case 23:return c=e.sent,u=[],s=c.filter(function(r){return!w.some(function(e){return r.fileName.includes(e)})}).map(function(e){return r(e.source,e.path,e.fileName)}),e.next=28,Promise.all(s);case 28:console.log(h.bgGreen("共 ".concat(u.length," 文件不同"))),e.next=35;break;case 31:e.prev=31,e.t0=e.catch(3),console.error(h.red("执行diff失败: ".concat(e.t0.message))),process.exit(1);case 35:case"end":return e.stop()}},e,null,[[3,31]])}));return function(){return e.apply(this,arguments)}})()),diff}var Chalk=require$$2,figlet=require$$4$1,version="v".concat(require$$5.version),Command=require$$6.Command,program=new Command;program.name("hs-cover").description("一个来覆盖项目的文件的脚手架,即从ext中复制文件覆盖到同目录的项目中。").command("c [path...]").description("覆盖项目的文件").option("-p, --path","overwrite target directory if it exist").action(function(e,r){var t="string"==typeof e[0]?e[0]:"",e="string"==typeof e[1]?e[1]:"";requireCover()(t,e)}),program.command("cover [path...]").description("覆盖项目的文件").option("-p, --path","overwrite target directory if it exist").option("-t, --target <directory>","指定目标目录").description("cover a new project").action(function(e,r){var t="string"==typeof e[0]?e[0]:"",e="string"==typeof e[1]?e[1]:"";requireCover()(t,e)}),program.command("diff [path...]").description("diff a new project").action(function(e,r){var t="string"==typeof e[0]?e[0]:"",e="string"==typeof e[1]?e[1]:"";requireDiff()(t,e)}),program.command("d [path...]").description("diff a new project").action(function(e,r){var t="string"==typeof e[0]?e[0]:"",e="string"==typeof e[1]?e[1]:"";requireDiff()(t,e)}),program.version(version,"-v, --version").usage("<command> [option]"),program.on("--help",function(){console.log("\r\n"+figlet.textSync("h s - c o v e r",{horizontalLayout:"default",verticalLayout:"default",width:100,whitespaceBreak:!0})),console.log("\r\n版本号: ".concat(Chalk.green.bold(version),"\r\n")),console.log("\r\nRun ".concat(Chalk.cyan("hscover <command> --help")," for detailed usage of given command\r\n"))}),program.parse(process.argv),module.exports=bin;