ci-file
Version:
2 lines (1 loc) • 19.2 kB
JavaScript
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(require("fs-extra"),require("chalk"),require("path"),require("url"),require("inquirer"),require("ora")):"function"==typeof define&&define.amd?define(["fs-extra","chalk","path","url","inquirer","ora"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).fs,t.chalk,t.path,t.url,t.inquirer,t.ora)}(this,(function(t,e,r,n,o,a){"use strict";function i(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,n)}return r}function u(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?i(Object(r),!0).forEach((function(e){l(t,e,r[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):i(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}function c(){c=function(){return t};var t={},e=Object.prototype,r=e.hasOwnProperty,n=Object.defineProperty||function(t,e,r){t[e]=r.value},o="function"==typeof Symbol?Symbol:{},a=o.iterator||"@@iterator",i=o.asyncIterator||"@@asyncIterator",u=o.toStringTag||"@@toStringTag";function s(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{s({},"")}catch(t){s=function(t,e,r){return t[e]=r}}function f(t,e,r,o){var a=e&&e.prototype instanceof h?e:h,i=Object.create(a.prototype),u=new S(o||[]);return n(i,"_invoke",{value:O(t,r,u)}),i}function l(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}t.wrap=f;var p={};function h(){}function v(){}function d(){}var y={};s(y,a,(function(){return this}));var m=Object.getPrototypeOf,g=m&&m(m(P([])));g&&g!==e&&r.call(g,a)&&(y=g);var b=d.prototype=h.prototype=Object.create(y);function x(t){["next","throw","return"].forEach((function(e){s(t,e,(function(t){return this._invoke(e,t)}))}))}function w(t,e){function o(n,a,i,u){var c=l(t[n],t,a);if("throw"!==c.type){var s=c.arg,f=s.value;return f&&"object"==typeof f&&r.call(f,"__await")?e.resolve(f.__await).then((function(t){o("next",t,i,u)}),(function(t){o("throw",t,i,u)})):e.resolve(f).then((function(t){s.value=t,i(s)}),(function(t){return o("throw",t,i,u)}))}u(c.arg)}var a;n(this,"_invoke",{value:function(t,r){function n(){return new e((function(e,n){o(t,r,e,n)}))}return a=a?a.then(n,n):n()}})}function O(t,e,r){var n="suspendedStart";return function(o,a){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===o)throw a;return E()}for(r.method=o,r.arg=a;;){var i=r.delegate;if(i){var u=j(i,r);if(u){if(u===p)continue;return u}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var c=l(t,e,r);if("normal"===c.type){if(n=r.done?"completed":"suspendedYield",c.arg===p)continue;return{value:c.arg,done:r.done}}"throw"===c.type&&(n="completed",r.method="throw",r.arg=c.arg)}}}function j(t,e){var r=e.method,n=t.iterator[r];if(void 0===n)return e.delegate=null,"throw"===r&&t.iterator.return&&(e.method="return",e.arg=void 0,j(t,e),"throw"===e.method)||"return"!==r&&(e.method="throw",e.arg=new TypeError("The iterator does not provide a '"+r+"' method")),p;var o=l(n,t.iterator,e.arg);if("throw"===o.type)return e.method="throw",e.arg=o.arg,e.delegate=null,p;var a=o.arg;return a?a.done?(e[t.resultName]=a.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=void 0),e.delegate=null,p):a:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,p)}function k(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function L(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function S(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(k,this),this.reset(!0)}function P(t){if(t){var e=t[a];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var n=-1,o=function e(){for(;++n<t.length;)if(r.call(t,n))return e.value=t[n],e.done=!1,e;return e.value=void 0,e.done=!0,e};return o.next=o}}return{next:E}}function E(){return{value:void 0,done:!0}}return v.prototype=d,n(b,"constructor",{value:d,configurable:!0}),n(d,"constructor",{value:v,configurable:!0}),v.displayName=s(d,u,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===v||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,d):(t.__proto__=d,s(t,u,"GeneratorFunction")),t.prototype=Object.create(b),t},t.awrap=function(t){return{__await:t}},x(w.prototype),s(w.prototype,i,(function(){return this})),t.AsyncIterator=w,t.async=function(e,r,n,o,a){void 0===a&&(a=Promise);var i=new w(f(e,r,n,o),a);return t.isGeneratorFunction(r)?i:i.next().then((function(t){return t.done?t.value:i.next()}))},x(b),s(b,u,"Generator"),s(b,a,(function(){return this})),s(b,"toString",(function(){return"[object Generator]"})),t.keys=function(t){var e=Object(t),r=[];for(var n in e)r.push(n);return r.reverse(),function t(){for(;r.length;){var n=r.pop();if(n in e)return t.value=n,t.done=!1,t}return t.done=!0,t}},t.values=P,S.prototype={constructor:S,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(L),!t)for(var e in this)"t"===e.charAt(0)&&r.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=void 0)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var e=this;function n(r,n){return i.type="throw",i.arg=t,e.next=r,n&&(e.method="next",e.arg=void 0),!!n}for(var o=this.tryEntries.length-1;o>=0;--o){var a=this.tryEntries[o],i=a.completion;if("root"===a.tryLoc)return n("end");if(a.tryLoc<=this.prev){var u=r.call(a,"catchLoc"),c=r.call(a,"finallyLoc");if(u&&c){if(this.prev<a.catchLoc)return n(a.catchLoc,!0);if(this.prev<a.finallyLoc)return n(a.finallyLoc)}else if(u){if(this.prev<a.catchLoc)return n(a.catchLoc,!0)}else{if(!c)throw new Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return n(a.finallyLoc)}}}},abrupt:function(t,e){for(var n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var a=o;break}}a&&("break"===t||"continue"===t)&&a.tryLoc<=e&&e<=a.finallyLoc&&(a=null);var i=a?a.completion:{};return i.type=t,i.arg=e,a?(this.method="next",this.next=a.finallyLoc,p):this.complete(i)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),p},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),L(r),p}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;L(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:P(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=void 0),p}},t}function s(t,e,r,n,o,a,i){try{var u=t[a](i),c=u.value}catch(t){return void r(t)}u.done?e(c):Promise.resolve(c).then(n,o)}function f(t){return function(){var e=this,r=arguments;return new Promise((function(n,o){var a=t.apply(e,r);function i(t){s(a,n,o,i,u,"next",t)}function u(t){s(a,n,o,i,u,"throw",t)}i(void 0)}))}}function l(t,e,r){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.call(t,e||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function p(t,e){if(null==t)return{};var r,n,o=function(t,e){if(null==t)return{};var r,n,o={},a=Object.keys(t);for(n=0;n<a.length;n++)r=a[n],e.indexOf(r)>=0||(o[r]=t[r]);return o}(t,e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(t);for(n=0;n<a.length;n++)r=a[n],e.indexOf(r)>=0||Object.prototype.propertyIsEnumerable.call(t,r)&&(o[r]=t[r])}return o}function h(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}function v(t,e){var r="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!r){if(Array.isArray(t)||(r=function(t,e){if(t){if("string"==typeof t)return h(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?h(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){r&&(t=r);var n=0,o=function(){};return{s:o,n:function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,i=!0,u=!1;return{s:function(){r=r.call(t)},n:function(){var t=r.next();return i=t.done,t},e:function(t){u=!0,a=t},f:function(){try{i||null==r.return||r.return()}finally{if(u)throw a}}}}e.__proto__.error=function(t){return console.error(e.red(t))},e.__proto__.success=function(t){return console.log(e.greenBright(t))},e.__proto__.warn=function(t){return console.log(e.yellow(t))};var d={react:"\nimport React from 'react';\n\nexport default function({name}) {\n\n return <div>{name}</div>;\n};\n","react-ts":"\nimport React from 'react';\n\ninterface Props {\n name:string\n}\n\nconst ComponentReact = ((props: Props = {name:\"\"})) => {\n\n return <div>{name}</div>;\n};\n\nexport default ComponentReact\n",vue2:"\n<template>\n <div class=\"\">\n \n </div>\n</template>\n\n<script>\n\nexport default {\n name: '',\n components: {\n },\n props: {\n },\n data() {\n return {};\n }\n};\n<\/script>\n\n<style lang='less' scoped>\n</style>\n",vue3:"\n<template>\n <div class=\"\">\n \n </div>\n</template>\n\n<script setup lang=\"ts\"> \nimport { PropType } from 'vue'; \n\nconst props = defineProps({\n stringArray: {\n type: Array as PropType<String[]>,\n required: true,\n default: [],\n },\n});\n<\/script>\n\n<style lang='less' scoped>\n</style>\n"};function y(){return m.apply(this,arguments)}function m(){return m=f(c().mark((function t(){var e,r,n,o=arguments;return c().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return e=o.length>0&&void 0!==o[0]?o[0]:"",r=["vue2","vue3","react","react-ts"],t.next=4,A({text:"请选择模版",list:r.filter((function(t){return-1!==t.indexOf(e)}))});case 4:return n=t.sent,t.abrupt("return",d[n.value]||"");case 6:case"end":return t.stop()}}),t)}))),m.apply(this,arguments)}var g=["type","text","color","list"],b=["message"],x=["自定义",".js",".ts",".d.ts",".vue",".jsx",".tsx",".json",".css",".less",".sass",".styl",".html",".yml"],w=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",e=n.fileURLToPath("undefined"==typeof document&&"undefined"==typeof location?new(require("url").URL)("file:"+e).href:"undefined"==typeof document?location.href:document.currentScript&&document.currentScript.src||new URL("index.js",document.baseURI).href),o=r.dirname(e);return r.resolve(o,t)},O=function(){var r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",n=process.cwd(),o=r.startsWith("/")?r:"/".concat(r);-1===o.indexOf(n)&&(o+=n);var a=t.existsSync(o);return a&&e.error("".concat(o," 已存在")),a};function j(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";if(!t||!t.trim())return e.error("不能为空"),!1;if(/[\u4e00-\u9fa5|\u3002|\uff1f|\uff01|\uff0c|\u3001|\uff1b|\uff1a|\u201c|\u201d|\u2018|\u2019|\uff08|\uff09|\u300a|\u300b|\u3008|\u3009|\u3010|\u3011|\u300e|\u300f|\u300c|\u300d|\ufe43|\ufe44|\u3014|\u3015|\u2026|\u2014|\uff5e|\ufe4f|\uffe5]/.test(t))return e.error("名称不应该包含中文"),!1;var r=t.substring(0,1);return!!/^[a-zA-Z]+$/.test(r)||(e.error("首写字母必须是英文"),!1)}function k(){return L.apply(this,arguments)}function L(){return L=f(c().mark((function t(){var r,n,a,i,s,f=arguments;return c().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return n=(r=f.length>0&&void 0!==f[0]?f[0]:{message:"请输入文件名称"}).message,a=p(r,b),t.next=4,o.prompt([u({type:"input",name:"value",message:e.blueBright(n)},a)]);case 4:if((i=t.sent).value){t.next=12;break}return t.next=8,k(r);case 8:if(s=t.sent){t.next=11;break}return t.abrupt("return",k(r));case 11:return t.abrupt("return",s);case 12:return t.abrupt("return",i.value);case 13:case"end":return t.stop()}}),t)}))),L.apply(this,arguments)}var S,P,E,_=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"/";return["当前目录"].concat(t.readdirSync(e).filter((function(t){var e=t.lastIndexOf(".");return e<0&&t.substring(e+1)})))},A=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=t.type,n=void 0===r?"list":r,a=t.text,i=void 0===a?"选择":a,c=t.color,s=void 0===c?"green":c,f=t.list,l=void 0===f?[]:f,h=p(t,g);return o.prompt([u({type:n,name:"value",message:e[s](i),choices:l},h)])};function T(t){return q.apply(this,arguments)}function q(){return q=f(c().mark((function t(e){var r,n,o,a,i,u,s=arguments;return c().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return a=function(){return a=f(c().mark((function t(e){var r,a,i,u,s;return c().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,A({text:"选择文件夾",list:e});case 2:if(r=t.sent,"当前目录"!==(a=r.value)){t.next=6;break}return t.abrupt("return",{value:n});case 6:if(n+="/".concat(a),!((i=_(n)).length>1||"当前目录"!==i[0])){t.next=14;break}return t.next=11,o(i);case 11:return u=t.sent,s="当前目录"===u.value?n:u.value,t.abrupt("return",{value:s});case 14:return t.abrupt("return",{value:n});case 15:case"end":return t.stop()}}),t)}))),a.apply(this,arguments)},o=function(t){return a.apply(this,arguments)},r=s.length>1&&void 0!==s[1]?s[1]:[],n=e,t.next=6,o(r);case 6:return i=t.sent,u=i.value,t.abrupt("return",u);case 9:case"end":return t.stop()}}),t)}))),q.apply(this,arguments)}function N(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";if(r.split("/").length>1){var n,o=r.split("/").filter((function(t){return t&&"/"!==t})),a=o[o.length-1],i=e,u=v(o);try{for(u.s();!(n=u.n()).done;){var c=n.value;if(c===a)break;i=i+"/"+c,t.existsSync(i)||c===a||t.mkdirSync(i)}}catch(t){u.e(t)}finally{u.f()}}}function F(){return I.apply(this,arguments)}function I(){return(I=f(c().mark((function t(){var e,r;return c().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,A({text:"选择文件类型",list:x});case 2:if("自定义"!==(e=t.sent).value){t.next=9;break}return t.next=6,k({message:"输入文件类型"});case 6:return(r=t.sent)&&!r.startsWith(".")&&(r=".".concat(r)),t.abrupt("return",r);case 9:return t.abrupt("return",e.value);case 10:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function D(){return G.apply(this,arguments)}function G(){return G=f(c().mark((function t(){var r,n,a,i,u,s=arguments;return c().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(n=(r=s.length>0&&void 0!==s[0]?s[0]:"").substring(0,1),a=n.toUpperCase(),i=r,n===a){t.next=10;break}return u={type:"list",name:"value",message:e.green("你好, 建议使用大驼峰命名,请问需要把首字母转为大写吗"),choices:["转换","不用"]},t.next=8,o.prompt([u]);case 8:t.sent.value===u.choices[0]&&(i=r.replace(n,a));case 10:return t.abrupt("return",i);case 11:case"end":return t.stop()}}),t)}))),G.apply(this,arguments)}function R(){return U.apply(this,arguments)}function U(){return(U=f(c().mark((function t(){var e,r,n,o;return c().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return e=["D/i模式 [A]/index.[js]","F模式 [A].[js]"],t.next=3,A({text:"请选择创建文件模式",list:e,default:e[0]});case 3:return r=t.sent,n=r.value,o=-1===n.indexOf("D/i")?"File":"Dir",t.abrupt("return",o);case 7:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function B(){var r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";if(!O(r)){var o=a(e.yellow("创建中..."));o.clear(),o.start(),t.writeFileSync(r,n),o.succeed(),e.success("创建成功!请查看:".concat(e.blueBright(r)))}}function C(t,e){return W.apply(this,arguments)}function W(){return W=f(c().mark((function e(n,o){var a,i,u,s,f,l,p,h,v,d,m=arguments;return c().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return a=m.length>2&&void 0!==m[2]?m[2]:"",i=_(n),e.next=4,T(n,i);case 4:if(u=e.sent,!O(u+"/"+o)){e.next=8;break}return e.abrupt("return");case 8:return e.next=10,N(u,o);case 10:return s=o.startsWith("/")?o:"/".concat(o),f=s.split("/")[s.split("/").length-1],e.next=14,D(f);case 14:if(l=e.sent,f!==l&&(s=s.replace(f,l)),p=u+s,h=r.extname(s),v=a,h){e.next=24;break}return e.next=22,F();case 22:h=e.sent,p="".concat(p).concat(h);case 24:if(v||".vue"!==h&&".react"!==h){e.next=28;break}return e.next=27,y(h.replace(".",""));case 27:v=e.sent;case 28:return e.next=30,R();case 30:if("Dir"!==e.sent){e.next=38;break}if(d=p.replace(h,""),!O(d)){e.next=36;break}return e.abrupt("return");case 36:t.mkdirSync(d),p=p.replace(s,"".concat(s,"/index"));case 38:B(p,v);case 39:case"end":return e.stop()}}),e)}))),W.apply(this,arguments)}S=w("."),P=t.readFileSync(S+"/package.json","utf8"),E=JSON.parse(P),program.option("-d,--debug","whether to enable debug mode?",!1),program.on("option:debug",(function(){console.log("开启了debug模式")})),program.on("command:*",(function(t){console.error(e.redBright("未知命令:".concat(t[0])))})),program.on("--help",(function(){console.log("\n","输入 ".concat(e.cyan("cli <command> --help")," 查看命令详情."),"\n")})),program.command("create ").alias("c").description("创建文件").argument("[name]","文件名称").usage("[name]").action(function(){var e=f(c().mark((function e(r){var n,o;return c().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n=t.existsSync(r),!r||!n){e.next=3;break}return e.abrupt("return");case 3:if(e.t1=r,e.t1){e.next=8;break}return e.next=7,k();case 7:e.t1=e.sent;case 8:if(e.t0=e.t1,e.t0){e.next=11;break}e.t0="";case 11:if(j(o=e.t0)){e.next=14;break}return e.abrupt("return");case 14:C(process.cwd(),o);case 16:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}()),program.version(E.version),program.parse(process.argv),program}));