hs-cover
Version:
```bash npm i hs-cover -g ```
3 lines (2 loc) • 32 kB
JavaScript
#! /usr/bin/env node
var 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");function _arrayLikeToArray(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,n=Array(r);t<r;t++)n[t]=e[t];return n}function asyncGeneratorStep(e,r,t,n,o,a,i){try{var c=e[a](i),s=c.value}catch(e){return void t(e)}c.done?r(s):Promise.resolve(s).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 _createForOfIteratorHelper(e,r){var t,n,o,a,i="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(i)return o=!(n=!0),{s:function(){i=i.call(e)},n:function(){var e=i.next();return n=e.done,e},e:function(e){o=!0,t=e},f:function(){try{n||null==i.return||i.return()}finally{if(o)throw t}}};if(Array.isArray(e)||(i=_unsupportedIterableToArray(e))||r)return i&&(e=i),a=0,{s:r=function(){},n:function(){return a>=e.length?{done:!0}:{done:!1,value:e[a++]}},e:function(e){throw e},f:r};throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _regeneratorRuntime(){_regeneratorRuntime=function(){return i};var u,i={},e=Object.prototype,s=e.hasOwnProperty,r="function"==typeof Symbol?Symbol:{},n=r.iterator||"@@iterator",t=r.asyncIterator||"@@asyncIterator",o=r.toStringTag||"@@toStringTag";function l(e,r,t,n){return Object.defineProperty(e,r,{value:t,enumerable:!n,configurable:!n,writable:!n})}try{l({},"")}catch(u){l=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 l(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:u,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===u)return t.delegate=null,"throw"===n&&r.i.return&&(t.method="return",t.arg=u,e(r,t),"throw"===t.method)||"return"!==n&&(t.method="throw",t.arg=new TypeError("The iterator does not provide a '"+n+"' method")),f;n=p(o,r.i,t.arg);if("throw"===n.type)return t.method="throw",t.arg=n.arg,t.delegate=null,f;o=n.arg;return o?o.done?(t[r.r]=o.value,t.next=r.n,"return"!==t.method&&(t.method="next",t.arg=u),t.delegate=null,f):o:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,f)}(t,i);if(t){if(t===f)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=p(o,a,i);if("normal"===t.type){if(c=i.done?4:2,t.arg===f)continue;return{value:t.arg,done:i.done}}"throw"===t.type&&(c=4,i.method="throw",i.arg=t.arg)}}),!0),r}function p(e,r,t){try{return{type:"normal",arg:e.call(r,t)}}catch(e){return{type:"throw",arg:e}}}i.wrap=c;var f={};function h(){}function a(){}function m(){}var r={},d=(l(r,n,function(){return this}),Object.getPrototypeOf),d=d&&d(d(b([]))),y=(d&&d!==e&&s.call(d,n)&&(r=d),m.prototype=h.prototype=Object.create(r));function v(e){["next","throw","return"].forEach(function(r){l(e,r,function(e){return this._invoke(r,e)})})}function g(i,c){var r;l(this,"_invoke",function(t,n){function e(){return new c(function(e,r){!function r(e,t,n,o){var a,e=p(i[e],i,t);if("throw"!==e.type)return(t=(a=e.arg).value)&&"object"==typeof t&&s.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 x(e){this.tryEntries.push(e)}function w(e){var r=e[4]||{};r.type="normal",r.arg=u,e[4]=r}function _(e){this.tryEntries=[[-1]],e.forEach(x,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(s.call(r,t))return e.value=r[t],e.done=!1,e;return e.value=u,e.done=!0,e}).next=e}throw new TypeError(typeof r+" is not iterable")}return l(y,"constructor",a.prototype=m),l(m,"constructor",a),a.displayName=l(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,l(e,o,"GeneratorFunction")),e.prototype=Object.create(y),e},i.awrap=function(e){return{__await:e}},v(g.prototype),l(g.prototype,t,function(){return this}),i.AsyncIterator=g,i.async=function(e,r,t,n,o){void 0===o&&(o=Promise);var a=new g(c(e,r,t,n),o);return i.isGeneratorFunction(r)?a:a.next().then(function(e){return e.done?e.value:a.next()})},v(y),l(y,o,"Generator"),l(y,n,function(){return this}),l(y,"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=u,this.done=!1,this.delegate=null,this.method="next",this.arg=u,this.tryEntries.forEach(w),!e)for(var r in this)"t"===r.charAt(0)&&s.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=u)},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],s=o[2];if(-1===o[0])return e("end"),!1;if(!c&&!s)throw Error("try statement without catch or finally");if(null!=o[0]&&o[0]<=i){if(i<c)return this.method="next",this.arg=u,e(c),!0;if(i<s)return e(s),!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],f):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),f},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]),w(t),f}},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,w(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=u),f}},i}function _unsupportedIterableToArray(e,r){var t;if(e)return"string"==typeof e?_arrayLikeToArray(e,r):"Map"===(t="Object"===(t={}.toString.call(e).slice(8,-1))&&e.constructor?e.constructor.name:t)||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?_arrayLikeToArray(e,r):void 0}var utils,hasRequiredUtils,cover,hasRequiredCover,diff,hasRequiredDiff,analyse_1,hasRequiredAnalyse,bin={},version$1="2.5.0",require$$5={version:version$1};function requireUtils(){var f,h,c,i,a,r,s,u,l;return hasRequiredUtils||(hasRequiredUtils=1,f=require$$1,h=require$$0,c=require$$2,i=require$$3,a=require$$4,s=["h5","html5","main"],utils={getCurrentDir:y,getBaseReplace:v,validateAndGetTargetDir:function(e){return x.apply(this,arguments)},selectProjectToCover:function(e){return w.apply(this,arguments)},confirmOrInputTargetDir:function(e){return _.apply(this,arguments)},replaceFiles:m,readFilesAndDirectories:d,writeAllFiles:function(e,r,t){return p.apply(this,arguments)},getFileHash:b,compareFiles:function(e,r){return S.apply(this,arguments)},compareFilesBuffer:function(e,r){return k.apply(this,arguments)},compareFilesStream:function(e,r){return q.apply(this,arguments)},checkFileExists:function(e){return T.apply(this,arguments)},EXCLUDE_DIR:r=["-test","-uat","-sit","-prod"],extractDynamicPart:function(e){return(e=e.match(/-([^.-]+)\./))?e[1]:null},shouldExcludeFile:$,IMAGE_EXTENSIONS:u=[".jpg",".jpeg",".png",".gif",".bmp",".webp",".tiff",".tif",".ico",".svg",".heic",".heif",".raw",".psd",".ai",".eps",".xcf"],FONT_EXTENSIONS:l=[".ttf",".otf",".woff",".woff2",".eot",".sfnt"]}),utils;function m(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=arguments;return _regeneratorRuntime().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(i=3<c.length&&void 0!==c[3]?c[3]:"test",a=r.replace(n,""),o=a.split("\\"),o=o[o.length-1],$(a=(a=f.join(t,a)).replace("-".concat(i),"")))return e.abrupt("return");e.next=8;break;case 8:return(i=[]).push({path:a,source:r,fileName:o}),e.abrupt("return",i);case 11:case"end":return e.stop()}},e)}))).apply(this,arguments)}function d(e,r,t){return o.apply(this,arguments)}function o(){return(o=_asyncToGenerator(_regeneratorRuntime().mark(function e(o,u,l){var p,r=arguments;return _regeneratorRuntime().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return p=3<r.length&&void 0!==r[3]?r[3]:"test",e.abrupt("return",new Promise(function(t,n){h.readdir(o,function(e,r){e?(console.error("无法读取目录:",e),n(e)):(e=r.map(function(s){return new Promise(function(i){var c=f.join(o,s);h.stat(c,(()=>{var t=_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(r)return console.error("无法获取文件状态:",r),i(null),e.abrupt("return");e.next=4;break;case 4:if(t.isDirectory()){if(n="node_modules"===s||c.includes(f.sep+"node_modules"+f.sep)||c.endsWith(f.sep+"node_modules"),o="dist"===s||c.includes(f.sep+"dist"+f.sep)||c.endsWith(f.sep+"dist"),n||o)return i(null),e.abrupt("return");e.next=10}else e.next=19;break;case 10:if(n)return i(null),e.abrupt("return");e.next=13;break;case 13:return e.next=15,d(c,u,l,p);case 15:o=e.sent,i(o),e.next=23;break;case 19:return e.next=21,m(c,u,l,p);case 21:a=e.sent,i(a);case 23: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 p(){return(p=_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:return e.prev=0,o=f.dirname(t),e.next=4,h.promises.mkdir(o,{recursive:!0});case 4:if(o=u.some(function(e){return n.toLowerCase().endsWith(e)}),a=l.some(function(e){return n.toLowerCase().endsWith(e)}),o||a)return e.next=10,h.promises.readFile(r);e.next=15;break;case 10:return a=e.sent,e.next=13,h.promises.writeFile(t,a);case 13:e.next=20;break;case 15:return e.next=17,h.promises.readFile(r,"utf8");case 17:return i=e.sent,e.next=20,h.promises.writeFile(t,i,"utf8");case 20:console.log(c.green("✓ 文件已成功覆盖: ".concat(n))),e.next=26;break;case 23:e.prev=23,e.t0=e.catch(0),"ENOENT"===e.t0.code?console.error(c.red("✗ 无法读取源文件 ".concat(n,":")),e.t0.message):console.error(c.red("✗ 无法写入目标文件 ".concat(n,":")),e.t0.message);case 26:case"end":return e.stop()}},e,null,[[0,23]])}))).apply(this,arguments)}function y(e){return t.apply(this,arguments)}function t(){return(t=_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,h.readdirSync(r);case 3:return t=e.sent,t=t.filter(function(e){return h.statSync(f.join(r,e)).isDirectory()}),e.abrupt("return",t);case 8:throw e.prev=8,e.t0=e.catch(0),console.error(c.red("获取目录失败: ".concat(e.t0.message))),e.t0;case 12:case"end":return e.stop()}},e,null,[[0,8]])}))).apply(this,arguments)}function v(e,r){return g.apply(this,arguments)}function g(){return(g=_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,y(r);case 3:if(n=e.sent,o=n.findIndex(function(e){return s.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,v(f.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(c.red("查找基础替换目录失败: ".concat(e.t0.message))),e.t0;case 20:case"end":return e.stop()}},e,null,[[0,16]])}))).apply(this,arguments)}function x(){return(x=_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,y(process.cwd());case 4:return(o=e.sent).includes(r)||(console.log(c.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(c.red("验证目标目录失败: ".concat(e.t0.message))),e.t0;case 15:case"end":return e.stop()}},e,null,[[1,11]])}))).apply(this,arguments)}function w(){return(w=_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,y(f.join(process.cwd(),r));case 4:return n=e.sent,e.next=7,i.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(c.red("选择项目失败: ".concat(e.t0.message))),e.t0;case 15:case"end":return e.stop()}},e,null,[[1,11]])}))).apply(this,arguments)}function _(){return(_=_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,i.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",f.join(process.cwd(),r));e.next=7;break;case 7:return e.next=9,i.prompt([{type:"input",name:"replaceDirectory",message:"请输入你要".concat(t,"的目录")}]);case 9:return n=e.sent,(n=(n.replaceDirectory||"").trim())||(console.log(c.blue.bgRed.bold("可不能输入空值啊!")),process.exit(1)),o=f.join(process.cwd(),n),h.existsSync(o)||(console.log(c.blue.bgRed.bold("能不能输入一个存在的目录!")),process.exit(1)),h.statSync(o).isDirectory()||(console.log(c.blue.bgRed.bold("能不能输入一个目录!不要文件!!")),process.exit(1)),e.abrupt("return",n);case 19:throw e.prev=19,e.t0=e.catch(1),console.error(c.red("确认目标目录失败: ".concat(e.t0.message))),e.t0;case 23:case"end":return e.stop()}},e,null,[[1,19]])}))).apply(this,arguments)}function b(e){return R.apply(this,arguments)}function R(){return(R=_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=h.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 S(){return(S=_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=h.statSync(r),n=h.statSync(t),a.size!==n.size)return e.abrupt("return",!1);e.next=5;break;case 5:return e.next=7,b(r);case 7:return o=e.sent,e.next=10,b(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(c.red("比较文件失败: ".concat(e.t0.message))),e.t0;case 18:case"end":return e.stop()}},e,null,[[0,14]])}))).apply(this,arguments)}function k(){return(k=_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=h.statSync(r),n=h.statSync(t),a.size!==n.size)return e.abrupt("return",!1);e.next=5;break;case 5:return e.next=7,h.promises.readFile(r);case 7:return o=e.sent,e.next=10,h.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(c.red("比较文件失败: ".concat(e.t0.message))),e.t0;case 18:case"end":return e.stop()}},e,null,[[0,14]])}))).apply(this,arguments)}function q(){return(q=_asyncToGenerator(_regeneratorRuntime().mark(function e(c,s){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=h.statSync(c),i=h.statSync(s);a.size!==i.size?e(!1):(t=h.createReadStream(c),n=h.createReadStream(s),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 T(){return(T=_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,h.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 $(e){var t;return!!e&&(t=e.toLowerCase(),r.some(function(e){var r;return!!t.includes(e)&&(r=t.indexOf(e),t.substring(r+e.length).startsWith("."))}))}}function requireCover(){var h,m,d,y,e,v,g,x,w,_,b,R,S,k,q,T;return hasRequiredCover||(hasRequiredCover=1,h=require$$0,m=require$$1,d=require$$2,y=require$$3,e=requireUtils(),v=e.getBaseReplace,g=e.validateAndGetTargetDir,x=e.selectProjectToCover,w=e.confirmOrInputTargetDir,_=e.readFilesAndDirectories,b=e.writeAllFiles,R=e.EXCLUDE_DIR,S=e.IMAGE_EXTENSIONS,k=e.FONT_EXTENSIONS,q=e.extractDynamicPart,T=e.shouldExcludeFile,cover=(()=>{var e=_asyncToGenerator(_regeneratorRuntime().mark(function e(){var c,r,t,n,o,a,i,s,u,l,p,f=arguments;return _regeneratorRuntime().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return r=0<f.length&&void 0!==f[0]?f[0]:"",u=1<f.length&&void 0!==f[1]?f[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(e){var r=e.toLowerCase();return T(e)&&!S.some(function(e){return r.endsWith(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,g(r,u);case 7:return t=e.sent,e.next=10,x(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,w(t);case 16:return a=e.sent,i=m.join(process.cwd(),r,n),(s=m.parse(o).dir).includes(n)||(s=m.join(s,n)),e.next=22,c(s);case 22:return u=e.sent,l=u.filter(function(r){return!S.some(function(e){return r.name.includes(e)})&&!k.some(function(e){return r.name.includes(e)})}).filter(function(r){return R.some(function(e){return r.name.includes(e)})}).map(function(e){var r=e.name,r=q(r);return{key:r,name:e.name,value:r}}),e.next=26,y.prompt({type:"list",name:"cover",message:"选择覆盖的配置项:",choices:l});case 26:return l=e.sent,p=l.cover,p=p,e.next=31,_(i,a,s,p);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 j,E,D,e,F,G,I,O,A,N,C;return hasRequiredDiff||(hasRequiredDiff=1,j=require$$0,E=require$$1,D=require$$2,e=requireUtils(),F=e.getBaseReplace,G=e.validateAndGetTargetDir,I=e.selectProjectToCover,O=e.confirmOrInputTargetDir,A=e.readFilesAndDirectories,N=e.compareFiles,C=e.shouldExcludeFile,diff=(()=>{var e=_asyncToGenerator(_regeneratorRuntime().mark(function e(){var g,x,w,_,b,R,S,k,q,T,$=arguments;return _regeneratorRuntime().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return w=0<$.length&&void 0!==$[0]?$[0]:"",S=1<$.length&&void 0!==$[1]?$[1]:"",g=2<$.length&&void 0!==$[2]?$[2]:"",console.error(D.red("正在执行文件对比中: ".concat(w," ").concat(S))),e.prev=4,x=(()=>{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=j.existsSync(r),a=j.existsSync(t),i&&a){e.next=7;break}return console.log("在html5中",D.bgCyanBright("".concat(o," 文件不存在"))),q.push({source:r,path:t,fileName:n,isSame:!1}),e.abrupt("return");case 7:return e.next=9,N(r,t);case 9:(i=e.sent)||(q.push({source:r,path:t,fileName:n,isSame:i}),console.log(D.bgYellowBright("".concat(o," 文件不同"))));case 11:case"end":return e.stop()}},e)}));return function(e,r,t){return n.apply(this,arguments)}})(),w=w||"ext",e.next=9,G(w,S);case 9:return _=e.sent,e.next=12,I(w,"对比");case 12:return b=e.sent,e.next=15,F(E.join(process.cwd(),w,b),w);case 15:return R=e.sent,e.next=18,O(_,"对比");case 18:return S=e.sent,k=E.join(process.cwd(),w,b),(T=E.parse(R).dir).includes(b)||(T=E.join(T,b)),e.next=24,A(k,S,T);case 24:return k=e.sent,q=[],T=k.filter(function(e){return!C(e.fileName)}).map(function(e){return x(e.source,e.path,e.fileName)}),e.next=29,Promise.all(T);case 29:if(console.log(D.bgGreen("共 ".concat(q.length," 文件不同"))),g&&g.trim()){v=y=d=m=h=l=f=p=u=s=c=n=i=a=o=t=r=void 0;var r=q,t=E.resolve(process.cwd(),g);if(r&&0!==r.length&&t&&t.trim()){var n,o=E.resolve(t),a=E.resolve(E.dirname(r[0].source)),i=_createForOfIteratorHelper(r);try{for(i.s();!(n=i.n()).done;)for(var c=n.value,s=E.resolve(c.source),u=E.relative(a,s);u.startsWith("..");)a=E.dirname(a),u=E.relative(a,s)}catch(e){i.e(e)}finally{i.f()}var l,p=0,f=_createForOfIteratorHelper(r);try{for(f.s();!(l=f.n()).done;){var h=l.value,m=E.resolve(h.source);if(j.existsSync(m)){var d=E.relative(a,m),y=E.join(o,d);try{var v=E.dirname(y);j.existsSync(v)||j.mkdirSync(v,{recursive:!0}),j.copyFileSync(m,y)}catch(e){console.error(D.red("复制失败 ".concat(m,": ").concat(e.message))),p++}}else console.error(D.red("源文件不存在,跳过: ".concat(m))),p++}}catch(e){f.e(e)}finally{f.f()}0<p?console.error(D.yellow("导出完成,".concat(p," 个文件失败"))):console.log(D.green("已导出 ".concat(r.length," 个文件到 ").concat(o)))}}return e.abrupt("return",q);case 34:e.prev=34,e.t0=e.catch(4),console.error(D.red("执行diff失败: ".concat(e.t0.message))),process.exit(1);case 38:case"end":return e.stop()}},e,null,[[4,34]])}));return function(){return e.apply(this,arguments)}})()),diff}function requireAnalyse(){var h,m,p,o,a;return hasRequiredAnalyse||(hasRequiredAnalyse=1,h=require$$1,m=require$$0,p=["h5","html5","main"],o=["metalhola","hola","html5"],a=["assets","ext","node_modules",".git"],analyse_1=function(e){return r.apply(this,arguments)}),analyse_1;function d(){return process.cwd()}function y(e){if(m.existsSync(e)&&m.statSync(e).isDirectory()){var r=h.join(e,"src");if(m.existsSync(r)&&m.statSync(r).isDirectory())return e;var t,n=_createForOfIteratorHelper(m.readdirSync(e,{withFileTypes:!0}).filter(function(e){return e.isDirectory()&&p.includes(e.name)}));try{for(n.s();!(t=n.n()).done;){var o=t.value,a=h.join(e,o.name),i=m.readdirSync(a,{withFileTypes:!0});if(i.some(function(e){return e.isDirectory()&&"src"===e.name}))return a;var c,s=_createForOfIteratorHelper(i);try{for(s.s();!(c=s.n()).done;){var u=c.value;if(u.isDirectory()){var l=h.join(a,u.name);if(m.readdirSync(l,{withFileTypes:!0}).some(function(e){return e.isDirectory()&&"src"===e.name}))return l}}}catch(e){s.e(e)}finally{s.f()}}}catch(e){n.e(e)}finally{n.f()}}return null}function v(e,r){e=h.join(e,r.split("/").join(h.sep));return m.existsSync(e)&&m.statSync(e).isFile()?e:null}function g(r){var e,t,n;return e=r,n=h.join(e,"ext"),e=h.join(e,"html5"),t=h.join(e,"src"),m.existsSync(n)&&m.statSync(n).isDirectory()&&m.existsSync(e)&&m.statSync(e).isDirectory()&&m.existsSync(t)&&m.statSync(t).isDirectory()?[h.join(r,"html5")]:0<(n=o.filter(function(e){e=h.join(r,e);return m.existsSync(e)&&m.statSync(e).isDirectory()}).map(function(e){return h.join(r,e)})).length?n:m.readdirSync(r,{withFileTypes:!0}).filter(function(e){return e.isDirectory()&&!e.name.startsWith(".")&&!a.includes(e.name)}).map(function(e){return h.join(r,e.name)})}function r(){return(r=_asyncToGenerator(_regeneratorRuntime().mark(function e(n){var o,a,i;return _regeneratorRuntime().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(n&&"string"==typeof n){e.next=2;break}return e.abrupt("return",{sameNameAndRelativeInExamples:[],sameRelativeInExt:[]});case 2:return o=h.basename(n),r=n,t=void 0,-1!==(t=(r=h.normalize(r).replace(/^(\.\.(\/|\\))*/,"").split(h.sep).join("/")).indexOf("src/"))?r=r.slice(t):r.startsWith("src/")||(r="src/"+r),i=r.replace(/\\/g,"/"),a=((e,r)=>{var t,n=[],o=d(),a=h.join(o,"ext"),i=_createForOfIteratorHelper(g(o));try{for(i.s();!(t=i.n()).done;){var c,s=y(t.value);s&&(c=v(s,e))&&h.basename(c)===r&&n.push(c)}}catch(e){i.e(e)}finally{i.f()}if(m.existsSync(a)&&m.statSync(a).isDirectory()){var u,l=_createForOfIteratorHelper(m.readdirSync(a,{withFileTypes:!0}).filter(function(e){return e.isDirectory()&&!e.name.startsWith(".")}).map(function(e){return h.join(a,e.name)}));try{for(l.s();!(u=l.n()).done;){var p,f=y(u.value);f&&(p=v(f,e))&&h.basename(p)===r&&n.push(p)}}catch(e){l.e(e)}finally{l.f()}}return n})(i,o),i=((e,r)=>{var t=[],n=h.join(d(),"ext");if(m.existsSync(n)&&m.statSync(n).isDirectory()){var o,a=_createForOfIteratorHelper(m.readdirSync(n,{withFileTypes:!0}).filter(function(e){return e.isDirectory()&&!e.name.startsWith(".")}).map(function(e){return h.join(n,e.name)}));try{for(a.s();!(o=a.n()).done;){var i=o.value,c=h.basename(i),s=y(i),u=s?v(s,e):null,l=u&&h.basename(u)===r?u:null;t.push({dirName:c,filePath:l})}}catch(e){a.e(e)}finally{a.f()}}return t})(i,o),e.abrupt("return",{sameNameAndRelativeInExamples:a,sameRelativeInExt:i});case 7:case"end":return e.stop()}var r,t},e)}))).apply(this,arguments)}}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").option("--export-dir <path>","将不同文件的 source 副本导出到指定目录(保持相对结构)").action((()=>{var 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 n="string"==typeof r[0]?r[0]:"",o="string"==typeof r[1]?r[1]:"",e.next=4,requireDiff()(n,o,t.exportDir||"");case 4:e.sent;case 5:case"end":return e.stop()}},e)}));return function(e,r){return t.apply(this,arguments)}})()),program.command("d [path...]").description("diff a new project").option("--export-dir <path>","将不同文件的 source 副本导出到指定目录(保持相对结构)").action((()=>{var 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 n="string"==typeof r[0]?r[0]:"",o="string"==typeof r[1]?r[1]:"",e.next=4,requireDiff()(n,o,t.exportDir||"");case 4:e.sent;case 5:case"end":return e.stop()}},e)}));return function(e,r){return t.apply(this,arguments)}})()),program.command("a [path...]").description("analyse a file").action((()=>{var 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 n="string"==typeof r[0]?r[0]:"",o="string"==typeof r[1]?r[1]:"",e.next=4,requireAnalyse()(n,o);case 4:n=e.sent,console.log(Chalk.yellowBright.bgRed.bold("当前修改的文件可能影响到的文件列表:")),o=n.sameNameAndRelativeInExamples.map(function(e){return e.replace(process.cwd(),"")}),console.log(o.join("\n")),console.log(Chalk.cyan("当前目录 ext 中相对路径同名(每个 ext 子项目均列出):")),n.sameRelativeInExt.forEach(function(e){var r=e.dirName,e=e.filePath,e=e?e.replace(process.cwd(),""):"[".concat(r,"] 无匹配,请检查是否遗漏或者使用主线文件");console.log(Chalk.hex("#a0c4ff").bold(" ".concat(r,":")),e)});case 10:case"end":return e.stop()}},e)}));return function(e,r){return t.apply(this,arguments)}})()),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;