UNPKG

appbir

Version:

常用脚手架库 -【app-lib-cli】

2 lines 7.58 kB
(()=>{var e={17:(e,t,r)=>{const{log:o}=r(115),n={ERROR:-1,WARN:1,SUCESS:0};let i=[];for(let e in n)i.push(n[e]);const s={[n.ERROR]:"e",[n.WARN]:"w",[n.SUCESS]:"s"};e.exports={AppError:class{constructor(e,t=n.WARN,r={}){if(!i.includes(t))throw o.me(`create AppError code [${t}] is no't in ERROR_CODE [${i}] `);let s=Array.isArray(e)?e:null==e?[]:[e],a={trace:!1,module:!0,data:void 0,print:!0,...r};this.options={message:s,code:t,config:a},a.print&&this.print()}print(e={}){let{message:t,code:r,config:n}={...this.options,...e},{trace:i,module:a}=n;if(t&&t.length){let e=[a&&"m",s[r],i?"":"n"].join(""),n=o[e];if(!n)throw o.me(`log no exist ${e} function`);n.apply(o,t)}}isError(){return this.options.code===n.ERROR}noError(){return this.options.code===n.SUCESS}},ERROR_CODE:n}},585:(e,t,r)=>{const{LANGUAGE:o}=r(598),n={language:e=>["[language]",`[${o.join("/")}] default(${o[0]})`,t=>{if(!o.includes(t))throw log.en("error",`command-argument value '${t}' is invalid for argument 'language' , please choice right language in [${o.join(",")}]`),new e.commander.InvalidArgumentError;return t},o[0]]};e.exports={ARGUMENTS:n}},598:e=>{const t={umd:{key:"umd"},commonjs:{key:"commonjs"},window:{key:"window"}};let r=(()=>{let e=[];for(prop in t)e.push(t[prop].key);return e})();e.exports={TARGET:["server","doc","build","process"],LANGUAGE:["es","node","bin","react","vue","static"],LIBRARY_TARGET_OBJ:t,LIBRARY_TARGET:r}},919:(e,t,r)=>{const{TARGET:o,LIBRARY_TARGET:n}=r(598),i={target:({Option:e})=>new e("-t, --target [string]","server target module").choices(o),debug:({Option:e})=>new e("-d, --debug","show debug log"),libraryTarget:({Option:e})=>new e("-t, --libraryTarget [string]","output libraryTarget").choices(n).default(n[0],"default is umd"),message:({Option:e})=>new e("-msg, --message [string]","git submit or change log message")};e.exports=i},783:e=>{const t=(e,t)=>{let r=1*t;if(isNaN(r))throw new e;return r},r=t;e.exports={int:t,port:r}},174:(e,t,r)=>{const{log:o}=r(115),{ERROR_CODE:n,AppError:i}=r(17),{getRootPath:s,resolve:a}=r(32),{autoRequire:p}=r(718),l=r(783),c=(e="")=>a(s(),"./static/",e),u=(e,t=!0)=>p(t?a(s(),e):a(e));e.exports={praseOpt:e=>{let{options:t}=e,r=t.slice(t.length-2,t.length-1)[0];return{arg:t.slice(0,t.length-2),option:r}},action:async(e,...t)=>{let{commond:r,start:s,...a}=e,p=t.slice(0,t.length-1);const l="string"==typeof t[0]?t[0]:"";o.md(`${r} ${l}::BEGAIN`,{...a,options:p});let c=await s({commond:r,...a,options:t});return void 0===c?new i(`[./plugins/${r}.commong.js] function need return `,n.ERROR):("object"!=typeof c&&(c=new i("",c,{print:!1})),c.noError()?o.md(`${r} ${t[0]}::SUCCESS`):(o.md(`execute [${r} ${l}] result is not 0, confirm is execute success`,`exexute file is [./plugins/${r}.commong.js]`),c.isError()?o.men(`execute [${r} ${l}] result is error!`):o.mwn(`execute [${r} ${l}] is not complete!`)),c)},optionsToArray:(e={},t=[])=>{let r=[];for(key in e)t.includes(key)||(r.push(`--${key}`),r.push(e[key]));return r},bindArg:(e,t)=>{let r={};for(key in e)r[key]=e[key].bind(null,t);return r},prase:l,transEnv:(e,t=[])=>{let r=[];for(let i in e)t.includes(i)&&r.push(`${o=i,n=void 0,(n=o,n.replace(/([A-Z])/g,"_$1").toLowerCase()).toUpperCase()}=${e[i]}`);var o,n;return r},getConfigPath:e=>{let{opt:t,append:r}=e,{commond:o,options:n}=t,i=[o,n[0]].concat(r||[]).concat(["config.js"]).join(".");return a(s(),"./static/config",i)},getStaticPath:c,autoRequireFile:u,autoRequireStaticFile:e=>u(c(e))}},625:e=>{const t={umd:{key:"umd"},commonjs:{key:"commonjs"},window:{key:"window"}};let r=(()=>{let e=[];for(prop in t)e.push(t[prop].key);return e})();e.exports={TARGET:["server","doc","build","process"],LANGUAGE:["es","bin","node","react","vue"],LIBRARY_TARGET_OBJ:t,LIBRARY_TARGET:r}},424:(e,t,r)=>{const o=r(177);e.exports={initCommond:e=>{let{STATIC:{jsonToFile:t},utils:{autoRequireStaticFile:r}}=e;t(o);let n=r("plugin.config.json"),i=((e,t)=>{let{program:r,commander:o,utils:{autoRequireStaticFile:n,action:i},OPTIONS:s,noBuild:{appRequire:a}}=t;const p=[];e.forEach((e=>{if(e?.enable){let l=e.path,c=e.name;try{let u="local"==e?.type?n(`plugin/${l}`):a(l);const m=u?.start(t);if(!m.init)return log.me("need init method export in "+l);if(!m.start)return log.me("need start method export in "+l);let d=r.command(c);m.init(d,t),d.addOption(s.debug(o)).action(i.bind(null,{start:m.start,commond:c})),d.addOption(s.message(o)),p.push(e)}catch(e){log.me(`regiter ${c} commond error,please check [${l}] file`,e)}}})),log.md(`already success register ${p.length} commonds`);let l=p.map((e=>({commond:e.name,"see commond help":`appbir ${e.name} --help`,enable:e.enable,type:e.type,discription:e.discription})));return process.argv.includes("--debug")&&log.T(l),l})(n,e);return{commonds:n,registerCommond:i}}}},555:(e,t,r)=>{const{log:o}=r(115),n=r(933),i=r(32),s=r(802),{exec:a}=r(194),p=r(174),l=r(718),c=r(919),{ARGUMENTS:u}=r(585),m=r(17),d=r(625);e.exports={nodeUtils:i,utils:p,exec:a,commander:n,log:o,noBuild:l,OPTIONS:c,ARGUMENTS:u,Error:m,STATIC:s,CONSTANT:d}},933:e=>{"use strict";e.exports=require("app-lib-commander")},194:e=>{"use strict";e.exports=require("app-lib-exec")},115:e=>{"use strict";e.exports=require("app-lib-log")},718:e=>{"use strict";e.exports=require("app-lib-nobuild")},32:e=>{"use strict";e.exports=require("app-lib-node")},802:e=>{"use strict";e.exports=require("app-lib-trans-storage")},177:e=>{"use strict";e.exports=JSON.parse('[{"name":"plugin.config.json","content":"[\\r\\n {\\"name\\":\\"plugin\\",\\"enable\\":true,\\"type\\":\\"package\\",\\"path\\":\\"app-lib-cli-plugin-plugin\\",\\"discription\\":\\"//TODO 插件管理\\"},\\r\\n {\\"name\\":\\"git\\",\\"enable\\":true,\\"type\\":\\"package\\",\\"path\\":\\"app-lib-cli-plugin-git\\",\\"discription\\":\\"GIT操作\\"},\\r\\n {\\"name\\":\\"build\\",\\"enable\\":true,\\"type\\":\\"package\\",\\"path\\":\\"app-lib-cli-plugin-build\\",\\"discription\\":\\"构建编译\\"},\\r\\n {\\"name\\":\\"md\\",\\"enable\\":true,\\"type\\":\\"package\\",\\"path\\":\\"app-lib-cli-plugin-md\\",\\"discription\\":\\"markdown编译\\"},\\r\\n {\\"name\\":\\"run\\",\\"enable\\":true,\\"type\\":\\"package\\",\\"path\\":\\"app-lib-cli-plugin-run\\",\\"discription\\":\\"自定义命令\\"},\\r\\n {\\"name\\":\\"server\\",\\"enable\\":true,\\"type\\":\\"package\\",\\"path\\":\\"app-lib-cli-plugin-server\\",\\"discription\\":\\"启动服务\\"},\\r\\n {\\"name\\":\\"init\\",\\"enable\\":true,\\"type\\":\\"package\\",\\"path\\":\\"app-lib-cli-plugin-init\\",\\"discription\\":\\"初始工程\\"},\\r\\n {\\"name\\":\\"doc\\",\\"enable\\":true,\\"type\\":\\"package\\",\\"path\\":\\"app-lib-cli-plugin-doc\\",\\"discription\\":\\"API文档\\"}\\r\\n]"}]')}},t={};function r(o){var n=t[o];if(void 0!==n)return n.exports;var i=t[o]={exports:{}};return e[o](i,i.exports,r),i.exports}var o={};(()=>{const{initCommond:e}=r(424),t=r(555);let{log:o,commander:{Command:n},utils:{action:i,autoRequireFile:s}}=t;const a=new n;o.auotLevel();let{registerCommond:p}=e({...t,program:a});const l=s("package.json");a.version(`v${l.version}`,"-v,--version","the current version").description("appbir personal cli tool for speed work, you can connection email for appbir@163.com").action(i.bind(null,{start:async()=>(o.mi("usage [ appbir --help ] , show support commond >"),o.T(p),0),commond:l.name})),o.md("run.argv",JSON.stringify(process.argv.slice(2))),a.parse(process.argv)})();var n=exports;for(var i in o)n[i]=o[i];o.__esModule&&Object.defineProperty(n,"__esModule",{value:!0})})(); //# sourceMappingURL=cli-min.js.map