@northflank/cli 0.4.5 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -8
- package/dist/api-helpers.js +187 -1
- package/dist/cli.js +499 -1
- package/dist/command-overview.js +93 -1
- package/dist/console-format-helpers.js +104 -1
- package/dist/context/contextCommands.js +413 -1
- package/dist/defaults.js +6157 -1
- package/dist/inquirer-helper.js +832 -1
- package/dist/port-forward/index.js +269 -0
- package/dist/utils.js +201 -1
- package/package.json +4 -6
- package/postinstall.js +1 -10
- package/dist/port-forward/client/api-helper.js +0 -1
- package/dist/port-forward/client/atomic-write.js +0 -1
- package/dist/port-forward/client/host-file-ast.js +0 -1
- package/dist/port-forward/client/host-file.js +0 -1
- package/dist/port-forward/client/index.js +0 -1
- package/dist/port-forward/client/loopback.js +0 -1
- package/dist/port-forward/client/port-forwarder.js +0 -1
- package/dist/port-forward/client/port-tunnel-tcp.js +0 -1
- package/dist/port-forward/client/port-tunnel-udp.js +0 -1
- package/dist/port-forward/client/port-tunnel.js +0 -1
- package/dist/port-forward/client/promise-mutex.js +0 -1
package/dist/inquirer-helper.js
CHANGED
|
@@ -1 +1,832 @@
|
|
|
1
|
-
'use strict';var a6U=['setPathVars','\x20Example:\x20','don\x27t\x20change','isNaN','subdomain','js-yaml','No,\x20repeat','oneOf','\x20(startedAt:\x20','askForService','message','editPayload','function','test','string','domain','9132uDCakL','description','lodash','minimum','default','body','__importStar','choices','isArray','password','whiteBright','bold','isValidJSON','type','map','__spreadArray','confirmation','trim','slice','must\x20be\x20longer\x20than\x20or\x20equal\x20to\x20','array','join','addons','__generator','editedResult','warning','No\x20projects\x20in\x20current\x20context','then','Please\x20confirm\x20following\x20configuration:\x0a','green','hasOwnProperty','Context\x20with\x20name\x20\x27','Do\x20you\x20want\x20to\x20add\x20more','bgGrey','242615zICIwU','label','3200LLgzbK','__setModuleDefault','assign','example','pattern','values','greenBright','SAVE','fetchResourceList','toString','getPathString','resultCache','Should\x20it\x20be','isFinite','set','trys','blueBright','askForProjectScopedResource','What\x20do\x20you\x20want\x20to\x20use\x20as','5qMiNQW','__importDefault','yml','stringify','No,\x20edit','integer','defaultValue','No\x20','override','loginPrompt','backups','tokenPrompt','must\x20be\x20shorter\x20than\x20or\x20equal\x20to\x20','object','must\x20be\x20smaller\x20than\x20or\x20equal\x20to\x20','get','backup','service','details','saveFile','iterator','110OFHDRz','minLength','pop','1389836YliPDu','EDIT','askForJob','safeDump','input','Context\x20name\x20already\x20exists.','unset','number','confirmationPrompt','main-context','inquirer','boolean','askForSecret','Generator\x20is\x20already\x20executing.','includes','askForJobRun','writeFileSync','red','job','propToType','safeLoad','enum','Default\x20project\x20in\x20context\x20not\x20set\x20and\x20no\x20argument\x20provided.','confirm','addon','478892GpbuGr','startedAt','toUpperCase','What\x27s\x20the\x20','split','done','Writing\x20configuration\x20failed:\x20','prompt','chalk','maxLength','tmpCmdPath','fullName','must\x20be\x20a\x20number,\x20is\x20','must\x20be\x20bigger\x20than\x20or\x20equal\x20to\x20','ABORT','properties','grey','repeat','jobs','has','concat','isObject','apiClient','choice','find','rawObject','credentials','prototype','Provide\x20a\x20file\x20path\x20to\x20write\x20the\x20configuration\x20to\x20(<name>.[json|yaml|yml])','reset','20jLtBIz','\x20type?','57923ATPZVY','Do\x20you\x20want\x20to\x20add','filter','underline','askForDomain','./utils','Something\x20unexpected\x20happened.','getType','throw','charAt','\x20and\x20it\x20','not\x20completed','items','projects','238423ytukGF','secret','token','yellowBright','__awaiter','pathVars','project','retry','subdomains','addEntry','No,\x20but\x20save\x20as\x20file','Choose\x20the\x20name\x20of\x20the\x20new\x20local\x20context:','max','runs','validate','success','maximum','response','value','deleteWarningPrompt','defineProperty','__esModule','apply','list','\x20characters,\x20is\x20','.\x20This\x20is\x20irreversible.\x20Please\x20confirm!','\x20(completedAt:\x20','askForProject','getQuestionString','__createBinding','./api-helpers','domains','InquirerHelper','\x20to\x20use:','contextProvider','fileName','yaml','ask','\x20characters','\x27\x20already\x20exists.\x20Do\x20you\x20want\x20to\x20override\x20this\x20context\x20(y)\x20or\x20enter\x20a\x20new\x20name\x20(N)?','editor','name','isEmpty','create','a\x20Northflank\x20resource','askForResource','askForAddonBackup','Go\x20to\x20editor','call','completedAt','isUndefined','return','.*\x5c.(json|yaml|yml)$','length','sent','push','must\x20be\x20a\x20valid\x20non-empty\x20json\x20string','Configuration\x20file\x20written\x20to\x20','__assign','askForCredentials','next','found','domain\x20(','getInnerType','askForAddon','services','opt','No,\x20abort','REPEAT','for\x20this\x20'];function a6k(U,k){U=U-0x133;var G=a6U[U];return G;}var a6d=a6k;(function(U,k){var b=a6k;while(!![]){try{var G=-parseInt(b(0x1de))*-parseInt(b(0x151))+-parseInt(b(0x143))+-parseInt(b(0x20f))+parseInt(b(0x1cb))*-parseInt(b(0x141))+-parseInt(b(0x1c9))+parseInt(b(0x1f6))+parseInt(b(0x1f3))*-parseInt(b(0x1a7));if(G===k)break;else U['push'](U['shift']());}catch(Q){U['push'](U['shift']());}}}(a6U,0xb3331));var __assign=this&&this[a6d(0x18b)]||function(){var Z=a6d;return __assign=Object[Z(0x1cd)]||function(U){var n=Z;for(var k,G=0x1,Q=arguments[n(0x186)];G<Q;G++){k=arguments[G];for(var f in k)if(Object['prototype'][n(0x1c5)]['call'](k,f))U[f]=k[f];}return U;},__assign['apply'](this,arguments);},__createBinding=this&&this[a6d(0x16e)]||(Object[a6d(0x17c)]?function(U,G,Q,f){if(f===undefined)f=Q;Object['defineProperty'](U,f,{'enumerable':!![],'get':function(){return G[Q];}});}:function(U,G,Q,f){if(f===undefined)f=Q;U[f]=G[Q];}),__setModuleDefault=this&&this[a6d(0x1cc)]||(Object['create']?function(U,k){var J=a6d;Object[J(0x165)](U,'default',{'enumerable':!![],'value':k});}:function(U,k){var r=a6d;U[r(0x1ab)]=k;}),__importStar=this&&this[a6d(0x1ad)]||function(U){var Y=a6d;if(U&&U[Y(0x166)])return U;var G={};if(U!=null){for(var Q in U)if(Q!=='default'&&Object[Y(0x13e)][Y(0x1c5)][Y(0x181)](U,Q))__createBinding(G,U,Q);}return __setModuleDefault(G,U),G;},__awaiter=this&&this[a6d(0x155)]||function(U,k,G,Q){function f(C){return C instanceof G?C:new G(function(y){y(C);});}return new(G||(G=Promise))(function(C,y){var a=a6k;function e(i){var z=a6k;try{s(Q[z(0x18d)](i));}catch(g){y(g);}}function p(i){var T=a6k;try{s(Q[T(0x14b)](i));}catch(g){y(g);}}function s(i){var P=a6k;i['done']?C(i['value']):f(i[P(0x163)])[P(0x1c2)](e,p);}s((Q=Q['apply'](U,k||[]))[a(0x18d)]());});},__generator=this&&this[a6d(0x1be)]||function(U,k){var K=a6d,G={'label':0x0,'sent':function(){if(e[0x0]&0x1)throw e[0x1];return e[0x1];},'trys':[],'ops':[]},Q,C,e,p;return p={'next':s(0x0),'throw':s(0x1),'return':s(0x2)},typeof Symbol===K(0x1a3)&&(p[Symbol[K(0x1f2)]]=function(){return this;}),p;function s(L){return function(H){return i([L,H]);};}function i(L){var h=K;if(Q)throw new TypeError(h(0x203));while(G)try{if(Q=0x1,C&&(e=L[0x0]&0x2?C[h(0x184)]:L[0x0]?C[h(0x14b)]||((e=C[h(0x184)])&&e[h(0x181)](C),0x0):C[h(0x18d)])&&!(e=e[h(0x181)](C,L[0x1]))[h(0x214)])return e;if(C=0x0,e)L=[L[0x0]&0x2,e['value']];switch(L[0x0]){case 0x0:case 0x1:e=L;break;case 0x4:G[h(0x1ca)]++;return{'value':L[0x1],'done':![]};case 0x5:G[h(0x1ca)]++,C=L[0x1],L=[0x0];continue;case 0x7:L=G['ops'][h(0x1f5)](),G['trys'][h(0x1f5)]();continue;default:if(!(e=G[h(0x1da)],e=e[h(0x186)]>0x0&&e[e[h(0x186)]-0x1])&&(L[0x0]===0x6||L[0x0]===0x2)){G=0x0;continue;}if(L[0x0]===0x3&&(!e||L[0x1]>e[0x0]&&L[0x1]<e[0x3])){G[h(0x1ca)]=L[0x1];break;}if(L[0x0]===0x6&&G[h(0x1ca)]<e[0x1]){G['label']=e[0x1],e=L;break;}if(e&&G[h(0x1ca)]<e[0x2]){G[h(0x1ca)]=e[0x2],G['ops'][h(0x188)](L);break;}if(e[0x2])G['ops'][h(0x1f5)]();G['trys']['pop']();continue;}L=k[h(0x181)](U,G);}catch(H){L=[0x6,H],C=0x0;}finally{Q=e=0x0;}if(L[0x0]&0x5)throw L[0x1];return{'value':L[0x0]?L[0x1]:void 0x0,'done':!![]};}},__spreadArray=this&&this[a6d(0x1b6)]||function(U,k){var V=a6d;for(var G=0x0,Q=k[V(0x186)],f=U['length'];G<Q;G++,f++)U[f]=k[G];return U;},__importDefault=this&&this[a6d(0x1df)]||function(U){var N=a6d;return U&&U[N(0x166)]?U:{'default':U};};Object[a6d(0x165)](exports,a6d(0x166),{'value':!![]}),exports[a6d(0x171)]=void 0x0;var _=__importStar(require(a6d(0x1a9))),chalk_1=__importDefault(require(a6d(0x217))),fs=__importStar(require('fs')),utils_1=require(a6d(0x148)),api_helpers_1=require(a6d(0x16f)),inquirer=require(a6d(0x200)),yaml=require(a6d(0x19c)),ConfirmChoices;(function(U){var w=a6d;U['YES']='Yes,\x20send',U[w(0x195)]=w(0x19d),U[w(0x1f7)]=w(0x1e2),U[w(0x1d2)]=w(0x15b),U[w(0x21d)]=w(0x194);}(ConfirmChoices||(ConfirmChoices={})));var InquirerHelper=function(){var Uy=a6d;function U(k){var q=a6k,G=this;this[q(0x139)]=k,this[q(0x1a2)]=function(Q){return __awaiter(G,void 0x0,void 0x0,function(){var f;return __generator(this,function(C){var O=a6k;switch(C[O(0x1ca)]){case 0x0:return[0x4,inquirer[O(0x216)]([{'type':O(0x179),'name':O(0x1bf),'message':O(0x180),'default':yaml[O(0x1f9)](Q)}])];case 0x1:f=C['sent']()[O(0x1bf)];return[0x2,yaml[O(0x20a)](f)];}});});},this[q(0x1f1)]=function(Q){return __awaiter(G,void 0x0,void 0x0,function(){function f(){return __awaiter(this,void 0x0,void 0x0,function(){return __generator(this,function(p){var j=a6k;return[0x2,inquirer[j(0x216)]([{'type':j(0x1fa),'name':j(0x174),'message':j(0x13f),'validate':function(s){var M=j;return new RegExp(M(0x185))[M(0x1a4)](s)?!![]:C(s);}}])];});});}var C,y,e;return __generator(this,function(p){var F=a6k;switch(p[F(0x1ca)]){case 0x0:C=function(s){return'Unexpected\x20file\x20type:\x20'+s+',\x20supported\x20types:\x20[json|yaml|yml]';};return[0x4,f()];case 0x1:y=p[F(0x187)]()[F(0x174)],e=y[F(0x1d4)]()[F(0x213)]('.')['pop']();try{switch(e){case'json':utils_1[F(0x160)](F(0x18a)+y);return[0x2,fs[F(0x206)](y,JSON[F(0x1e1)](Q,null,'\x20\x20'))];case F(0x175):case F(0x1e0):utils_1[F(0x160)]('Configuration\x20file\x20written\x20to\x20'+y);return[0x2,fs[F(0x206)](y,yaml[F(0x1f9)](Q))];default:utils_1[F(0x1c0)](C(e));}}catch(s){utils_1[F(0x1c0)](F(0x215)+s[F(0x1a1)]);}return[0x2,undefined];}});});},this[q(0x145)]=function(Q,f){return function(C){var u=a6k,y=typeof C===u(0x1a5)?C[u(0x1b8)]():C;if(Q===u(0x1fd)&&Number[u(0x19a)](y))return'';return f===![]&&y===u(0x199)?'':y;};},this['validate']=function(Q,f){return function(C){var A=a6k,y=[];if(C===''||C===A(0x199)){if(f!==![])y[A(0x188)]('this\x20option\x20is\x20required,\x20please\x20answer');else return!![];}Q[A(0x1b4)]===A(0x1a5)&&!_[A(0x183)](Q[A(0x1cf)])&&y[A(0x188)](new RegExp(Q['pattern'])[A(0x1a4)](C)?!![]:'doesn\x27t\x20match\x20pattern\x20\x27'+Q[A(0x1cf)]+'\x27');Q[A(0x1b4)]===A(0x1a5)&&!_[A(0x183)](Q[A(0x1f4)])&&y[A(0x188)](C[A(0x186)]>=Q[A(0x1f4)]?!![]:A(0x1ba)+Q['minLength']+A(0x169)+C['length']+'\x20characters');Q[A(0x1b4)]===A(0x1a5)&&!_[A(0x183)](Q[A(0x218)])&&y['push'](C[A(0x186)]<=Q[A(0x218)]?!![]:A(0x1ea)+Q[A(0x218)]+A(0x169)+C[A(0x186)]+A(0x177));Q[A(0x1b4)]===A(0x1e3)&&!_[A(0x1d8)](Number(C))&&y['push'](A(0x21b)+C);Q[A(0x1b4)]===A(0x1e3)&&!_['isUndefined'](Q[A(0x1aa)])&&y['push'](C>=Q[A(0x1aa)]?!![]:A(0x21c)+Q[A(0x1aa)]);Q['type']===A(0x1e3)&&!_[A(0x183)](Q[A(0x161)])&&y['push'](C<=Q[A(0x161)]?!![]:A(0x1ec)+Q[A(0x161)]);if(Q[A(0x1b4)]===A(0x13c)){var e=utils_1[A(0x1b3)](C);y[A(0x188)](e===![]||_[A(0x17b)](e)?A(0x189):!![]);}var p=y[A(0x145)](function(i){return i!==!![];}),s=(Q===null||Q===void 0x0?void 0x0:Q['example'])?'\x0a'+chalk_1[A(0x1ab)][A(0x207)]('>>')+A(0x198)+chalk_1[A(0x1ab)][A(0x1b1)](JSON[A(0x1e1)](Q[A(0x1ce)])):'';return p[A(0x186)]>0x0?p[A(0x1bc)](chalk_1[A(0x1ab)][A(0x146)](A(0x14d)))+s:!![];};},this[q(0x1d5)]=function(Q,f,C){var l=q,y=Q[Q[l(0x186)]-0x1];function e(){var o=l;return Q['slice'](0x0,-0x1)['map'](function(i){var X=a6k;return i[X(0x14c)](0x0)[X(0x211)]()+i[X(0x1b9)](0x1);})[o(0x1bc)]('>');}var p=Q[l(0x186)]>0x1?chalk_1['default'][l(0x1c8)][l(0x1b1)](e())+':\x20':'',s=C?'\x20('+chalk_1['default']['blue'](C)+')':'';return chalk_1[l(0x1ab)][l(0x140)](''+p+f+'\x20'+chalk_1[l(0x1ab)][l(0x1b2)][l(0x1d1)](y)+s+'?');},this[q(0x17e)]=function(Q,f,C){return __awaiter(G,void 0x0,void 0x0,function(){var y;return __generator(this,function(e){var S=a6k;switch(e[S(0x1ca)]){case 0x0:if(f[S(0x186)]<0x1){y=C?S(0x196)+C:S(0x18e);throw new Error(S(0x1e5)+Q+'\x20'+y+'.');}return[0x4,inquirer[S(0x216)]([{'type':S(0x168),'name':'name','message':'Choose\x20the\x20'+Q+S(0x172),'choices':f}])];case 0x1:return[0x2,e[S(0x187)]()['name']];}});});},this[q(0x1a0)]=function(Q){return function(){return __awaiter(G,void 0x0,void 0x0,function(){var f,C=this;return __generator(this,function(y){var D=a6k;return f=function(e){return __awaiter(C,void 0x0,void 0x0,function(){return __generator(this,function(p){var c=a6k;switch(p[c(0x1ca)]){case 0x0:return[0x4,this[c(0x139)]['list'][c(0x1ef)]({'parameters':{'projectId':e}})];case 0x1:return[0x2,p['sent']()[c(0x162)][c(0x192)][c(0x1b5)](function(s){return s['id'];})];}});});},[0x2,this[D(0x1dc)](D(0x1ef),f,Q)];});});};},this[q(0x1f8)]=function(Q){return function(){return __awaiter(G,void 0x0,void 0x0,function(){var f,C=this;return __generator(this,function(y){var B=a6k;return f=function(e){return __awaiter(C,void 0x0,void 0x0,function(){return __generator(this,function(p){var t=a6k;switch(p['label']){case 0x0:return[0x4,this[t(0x139)][t(0x168)][t(0x208)]({'parameters':{'projectId':e}})];case 0x1:return[0x2,p[t(0x187)]()[t(0x162)][t(0x135)][t(0x1b5)](function(s){return s['id'];})];}});});},[0x2,this[B(0x1dc)](B(0x208),f,Q)];});});};},this[q(0x205)]=function(Q,f){return function(){return __awaiter(G,void 0x0,void 0x0,function(){var C,y=this;return __generator(this,function(e){var E=a6k;return C=function(p){return __awaiter(y,void 0x0,void 0x0,function(){return __generator(this,function(s){var m=a6k;switch(s[m(0x1ca)]){case 0x0:return[0x4,this[m(0x139)][m(0x1ed)]['job'][m(0x15e)]({'parameters':{'projectId':p,'jobId':Q}})];case 0x1:return[0x2,s[m(0x187)]()[m(0x162)][m(0x15e)][m(0x1b5)](function(i){var x=m;return i['id']+x(0x19f)+i[x(0x210)]+')';})];}});});},[0x2,this['askForProjectScopedResource'](E(0x208),C,f)[E(0x1c2)](function(p){var W=E;return p[W(0x213)]('\x20')[0x0];})];});});};},this[q(0x191)]=function(Q){return function(){return __awaiter(G,void 0x0,void 0x0,function(){var f,C=this;return __generator(this,function(y){var U1=a6k;return f=function(e){return __awaiter(C,void 0x0,void 0x0,function(){return __generator(this,function(p){var U0=a6k;switch(p['label']){case 0x0:return[0x4,this[U0(0x139)][U0(0x168)][U0(0x20e)]({'parameters':{'projectId':e}})];case 0x1:return[0x2,p[U0(0x187)]()[U0(0x162)][U0(0x1bd)][U0(0x1b5)](function(s){return s['id'];})];}});});},[0x2,this['askForProjectScopedResource'](U1(0x20e),f,Q)];});});};},this[q(0x17f)]=function(Q,f){return function(){return __awaiter(G,void 0x0,void 0x0,function(){var C,y=this;return __generator(this,function(e){var U4=a6k;return C=function(p){return __awaiter(y,void 0x0,void 0x0,function(){return __generator(this,function(s){var U2=a6k;switch(s['label']){case 0x0:return[0x4,this[U2(0x139)][U2(0x1ed)][U2(0x20e)][U2(0x1e8)]({'parameters':{'projectId':p,'addonId':f}})];case 0x1:return[0x2,s[U2(0x187)]()[U2(0x162)][U2(0x1e8)]['map'](function(i){var U3=U2;return i['id']+U3(0x16b)+(i[U3(0x182)]||U3(0x14e))+')';})];}});});},[0x2,this[U4(0x1dc)](U4(0x1ee),C,Q)[U4(0x1c2)](function(p){var U5=U4;return p[U5(0x213)]('\x20')[0x0];})];});});};},this[q(0x202)]=function(Q){return function(){return __awaiter(G,void 0x0,void 0x0,function(){var f,C=this;return __generator(this,function(y){var U7=a6k;return f=function(e){return __awaiter(C,void 0x0,void 0x0,function(){return __generator(this,function(p){var U6=a6k;switch(p[U6(0x1ca)]){case 0x0:return[0x4,this[U6(0x139)][U6(0x168)][U6(0x152)]({'parameters':{'projectId':e}})];case 0x1:return[0x2,p['sent']()[U6(0x162)]['secrets'][U6(0x1b5)](function(s){return s['id'];})];}});});},[0x2,this[U7(0x1dc)](U7(0x152),f,Q)];});});};},this['askForSubdomain']=function(Q){return function(){return __awaiter(G,void 0x0,void 0x0,function(){var f,C,y;return __generator(this,function(e){var U8=a6k;switch(e[U8(0x1ca)]){case 0x0:return[0x4,this[U8(0x139)][U8(0x1ed)][U8(0x1a6)][U8(0x1f0)]({'parameters':{'domain':Q}})];case 0x1:f=e[U8(0x187)](),C=f[U8(0x162)][U8(0x159)][U8(0x1b5)](function(p){var U9=U8;return p[U9(0x17a)]+'\x20(full\x20domain:\x20'+p[U9(0x21a)]+')';}),y=U8(0x18f)+Q+')';return[0x2,this[U8(0x17e)](U8(0x19b),C,y)[U8(0x1c2)](function(p){var UU=U8;return p[UU(0x213)]('\x20')[0x0];})];}});});};},this[q(0x164)]=function(Q){return __awaiter(G,void 0x0,void 0x0,function(){return __generator(this,function(f){var Uk=a6k;switch(f[Uk(0x1ca)]){case 0x0:return[0x4,inquirer[Uk(0x216)]([{'type':Uk(0x20d),'name':'confirmation','message':chalk_1['default'][Uk(0x154)]('WARNING:\x20You\x20are\x20about\x20to\x20delete\x20'+(Q||Uk(0x17d))+Uk(0x16a)),'default':![]}])];case 0x1:return[0x2,f[Uk(0x187)]()[Uk(0x1b7)]];}});});},this[q(0x1e7)]=function(Q,f){return __awaiter(G,void 0x0,void 0x0,function(){var C,y=this;return __generator(this,function(e){var UG=a6k;switch(e[UG(0x1ca)]){case 0x0:if(!_[UG(0x183)](Q[UG(0x17a)]))return[0x3,0x3];if(!(f[UG(0x186)]<=0x0))return[0x3,0x1];_[UG(0x1d9)](Q,UG(0x17a),UG(0x1ab));return[0x3,0x3];case 0x1:return[0x4,utils_1[UG(0x158)](0xa)(function(){return __awaiter(y,void 0x0,void 0x0,function(){var p,s;return __generator(this,function(i){var UQ=a6k;switch(i[UQ(0x1ca)]){case 0x0:return[0x4,inquirer[UQ(0x216)]([{'type':UQ(0x1fa),'name':UQ(0x17a),'message':UQ(0x15c),'default':UQ(0x1ff)}])];case 0x1:p=i['sent']()[UQ(0x17a)];if(!(!Q[UQ(0x1e6)]&&f[UQ(0x13b)](function(g){var Uf=UQ;return g[Uf(0x17a)]===p;})))return[0x3,0x3];return[0x4,inquirer[UQ(0x216)]([{'type':UQ(0x20d),'name':'c','message':UQ(0x1c6)+p+UQ(0x178),'default':![]}])];case 0x2:s=i['sent']()['c'];if(s===![])throw new Error(UQ(0x1fb));_['set'](Q,UQ(0x1e6),!![]),i[UQ(0x1ca)]=0x3;case 0x3:_[UQ(0x1d9)](Q,'name',p);return[0x2];}});});})];case 0x2:e[UG(0x187)](),e[UG(0x1ca)]=0x3;case 0x3:if(!_[UG(0x183)](Q[UG(0x153)]))return[0x3,0x5];return[0x4,this[UG(0x1e9)]()];case 0x4:C=e[UG(0x187)](),_[UG(0x1d9)](Q,UG(0x153),C),e[UG(0x1ca)]=0x5;case 0x5:return[0x2,Q];}});});},this[q(0x1e9)]=function(){return __awaiter(G,void 0x0,void 0x0,function(){var Q;return __generator(this,function(f){var UC=a6k;switch(f[UC(0x1ca)]){case 0x0:return[0x4,inquirer[UC(0x216)]([{'type':UC(0x1b0),'name':'token','mask':'*','message':'Choose\x20the\x20login\x20token:'}])];case 0x1:Q=f[UC(0x187)]()[UC(0x153)];return[0x2,Q];}});});};}return U[Uy(0x13e)][Uy(0x1fe)]=function(k,G){return __awaiter(this,void 0x0,void 0x0,function(){var Q,f,C,y,e,p;return __generator(this,function(s){var Ue=a6k;switch(s['label']){case 0x0:Q=yaml[Ue(0x1f9)](k),f=_[Ue(0x15d)](Q[Ue(0x213)]('\x0a')['map'](function(i){var Up=Ue;return i[Up(0x186)];})),C=chalk_1[Ue(0x1ab)][Ue(0x133)]('-'[Ue(0x134)](f)+'\x0a');return[0x4,inquirer[Ue(0x216)]([{'type':Ue(0x168),'name':Ue(0x20d),'message':''+chalk_1['default'][Ue(0x1b2)][Ue(0x1c4)](Ue(0x1c3))+C+chalk_1[Ue(0x1ab)][Ue(0x1db)](Q)+C,'choices':Object[Ue(0x1d0)](ConfirmChoices)}])];case 0x1:y=s[Ue(0x187)]()[Ue(0x20d)],e=y;switch(e){case ConfirmChoices['YES']:return[0x3,0x2];case ConfirmChoices[Ue(0x21d)]:return[0x3,0x3];case ConfirmChoices[Ue(0x195)]:return[0x3,0x4];case ConfirmChoices[Ue(0x1f7)]:return[0x3,0x5];case ConfirmChoices[Ue(0x1d2)]:return[0x3,0x7];}return[0x3,0x9];case 0x2:return[0x2,k];case 0x3:throw new Error('Aborted.');case 0x4:return[0x2,this['retrievePayloadViaInteractiveCli'](G)];case 0x5:p=this[Ue(0x1fe)];return[0x4,this[Ue(0x1a2)](k)];case 0x6:return[0x2,p[Ue(0x167)](this,[s[Ue(0x187)](),G])];case 0x7:return[0x4,this[Ue(0x1f1)](k)];case 0x8:s[Ue(0x187)]();return[0x2,this[Ue(0x1fe)](k,G)];case 0x9:throw new Error(Ue(0x149));}});});},U['prototype']['retrievePayloadViaInteractiveCli']=function(k,G){return __awaiter(this,void 0x0,void 0x0,function(){var Q;return __generator(this,function(f){var Us=a6k;switch(f[Us(0x1ca)]){case 0x0:if((G===null||G===void 0x0?void 0x0:G[Us(0x1d6)])!==undefined)this[Us(0x1d6)]=G===null||G===void 0x0?void 0x0:G['resultCache'];this['tmpCmdPath']=G===null||G===void 0x0?void 0x0:G['cmdPath'],Q={};return[0x4,this[Us(0x209)]([],k[Us(0x193)][Us(0x1ac)],Q)];case 0x1:f[Us(0x187)](),this[Us(0x1d6)]=Q;return[0x4,this[Us(0x1fe)](Q,k)];case 0x2:return[0x2,f[Us(0x187)]()];}});});},U[Uy(0x13e)]['propToType']=function(k,G,Q,f){return __awaiter(this,void 0x0,void 0x0,function(){var C,y,e;return __generator(this,function(p){var Ui=a6k;switch(p[Ui(0x1ca)]){case 0x0:if(!(G[Ui(0x19e)]&&!_[Ui(0x136)](G,Ui(0x21e))))return[0x3,0x6];if(!(G[Ui(0x19e)][Ui(0x186)]>0x1))return[0x3,0x3];return[0x4,inquirer[Ui(0x216)]([{'type':Ui(0x168),'name':'choice','message':Ui(0x212)+(k[k[Ui(0x186)]-0x1]||'')+Ui(0x142),'choices':G[Ui(0x19e)]['map'](function(s){var Ug=Ui;return s[Ug(0x1a8)];})}])];case 0x1:y=p[Ui(0x187)]()[Ui(0x13a)];return[0x4,this['getType'](k,G[Ui(0x19e)][Ui(0x13b)](function(s){var UL=Ui;return s[UL(0x1a8)]===y;}),Q,f)];case 0x2:C=p['sent']();return[0x3,0x5];case 0x3:e=G[Ui(0x19e)][0x0],_['set'](e,'description',G[Ui(0x1a8)]);return[0x4,this['getType'](k,e,Q,f)];case 0x4:C=p[Ui(0x187)](),p['label']=0x5;case 0x5:C={};return[0x3,0x8];case 0x6:return[0x4,this[Ui(0x14a)](k,G,Q,f)];case 0x7:C=p['sent'](),p[Ui(0x1ca)]=0x8;case 0x8:return[0x2,C];}});});},U[Uy(0x13e)][Uy(0x190)]=function(k,G,Q,f){var C;return __awaiter(this,void 0x0,void 0x0,function(){var y,e,p,s,i,g,L;return __generator(this,function(H){var UH=a6k;switch(H[UH(0x1ca)]){case 0x0:if(!(f===![]))return[0x3,0x2];return[0x4,inquirer[UH(0x216)]([{'type':UH(0x20d),'name':UH(0x15a),'message':this[UH(0x1d5)](G,UH(0x144),k===null||k===void 0x0?void 0x0:k['description']),'default':![]}])];case 0x1:y=H[UH(0x187)]()[UH(0x15a)];if(!y)return[0x2,Q];H[UH(0x1ca)]=0x2;case 0x2:e=Object['keys']((C=k===null||k===void 0x0?void 0x0:k[UH(0x21e)])!==null&&C!==void 0x0?C:[]),p=k['required']||[];if(!(e[UH(0x186)]>0x0))return[0x3,0x7];s=0x0,i=e,H[UH(0x1ca)]=0x3;case 0x3:if(!(s<i[UH(0x186)]))return[0x3,0x6];g=i[s],L=G[UH(0x137)](g);if(G[UH(0x186)]>0x0&&!_['has'](Q,G[UH(0x1bc)]('.')))_['set'](Q,G[UH(0x1bc)]('.'),{});return[0x4,this[UH(0x209)](L,k['properties'][g],Q,p[UH(0x204)](g))];case 0x4:H[UH(0x187)](),H[UH(0x1ca)]=0x5;case 0x5:s++;return[0x3,0x3];case 0x6:return[0x3,0x9];case 0x7:return[0x4,this[UH(0x14a)](G,__assign(__assign({},k),{'type':UH(0x13c)}),Q,f)];case 0x8:H[UH(0x187)](),H[UH(0x1ca)]=0x9;case 0x9:return[0x2,Q];}});});},U['prototype']['askArrayEntry']=function(k,G,Q,f){return __awaiter(this,void 0x0,void 0x0,function(){var C,y;return __generator(this,function(e){var UI=a6k;switch(e[UI(0x1ca)]){case 0x0:if(G&&Q)return[0x2,!![]];C=G?UI(0x144):UI(0x1c7);return[0x4,inquirer['prompt']([{'type':UI(0x20d),'name':UI(0x15a),'message':this['getPathString'](k,C,G?f:undefined),'default':![]}])];case 0x1:y=e[UI(0x187)]()[UI(0x15a)];return[0x2,y];}});});},U[Uy(0x13e)][Uy(0x14a)]=function(k,G,Q,f){return __awaiter(this,void 0x0,void 0x0,function(){var C,y,e,p,s,i,g;return __generator(this,function(L){var Uv=a6k;switch(L['label']){case 0x0:y=k[Uv(0x1bc)]('.'),e=G===null||G===void 0x0?void 0x0:G['type'];switch(e){case Uv(0x1bb):return[0x3,0x1];case Uv(0x1eb):return[0x3,0x6];case Uv(0x13c):return[0x3,0x8];case Uv(0x1a5):return[0x3,0xa];case Uv(0x201):return[0x3,0xa];case Uv(0x1e3):return[0x3,0xa];}return[0x3,0xa];case 0x1:p=!![],L['label']=0x2;case 0x2:return[0x4,this['askArrayEntry'](k,p,f,G===null||G===void 0x0?void 0x0:G['description'])];case 0x3:if(!L[Uv(0x187)]())return[0x3,0x5];s=_[Uv(0x1ed)](Q,y),_[Uv(0x1fc)](Q,y);return[0x4,this[Uv(0x14a)](k,G[Uv(0x14f)],Q)];case 0x4:L[Uv(0x187)](),i=_['get'](Q,y);!_[Uv(0x1af)](s)?_[Uv(0x1d9)](Q,y,[i]):(s[Uv(0x188)](i),_['set'](Q,y,s));p=![];return[0x3,0x2];case 0x5:return[0x2,C||[]];case 0x6:return[0x4,this[Uv(0x190)](G,k,Q,f)];case 0x7:C=L['sent']();return[0x2,C];case 0x8:g=utils_1['isValidJSON'];return[0x4,this[Uv(0x176)](k,G,f)];case 0x9:C=g[Uv(0x167)](void 0x0,[L[Uv(0x187)]()])||undefined;return[0x3,0xc];case 0xa:return[0x4,this['ask'](k,G,f,Q)];case 0xb:C=L[Uv(0x187)]();return[0x3,0xc];case 0xc:!_[Uv(0x183)](C)&&_[Uv(0x1d9)](Q,y,C);return[0x2,C];}});});},U[Uy(0x13e)][Uy(0x176)]=function(k,G,Q,f){return __awaiter(this,void 0x0,void 0x0,function(){var C,y,e,p,s,i,g,L,H,I,v;return __generator(this,function(R){var UR=a6k;switch(R[UR(0x1ca)]){case 0x0:C=k[k[UR(0x186)]-0x1];return[0x4,api_helpers_1[UR(0x1d3)](C,this['apiClient'],this[UR(0x219)],f,this[UR(0x156)])];case 0x1:y=R[UR(0x187)](),e=y[UR(0x1e4)],p=e===void 0x0?G===null||G===void 0x0?void 0x0:G['example']:e,s=y[UR(0x1ae)],i=s===void 0x0?G===null||G===void 0x0?void 0x0:G[UR(0x20b)]:s,g=UR(0x1fa);if(!_[UR(0x183)](i))g='list';else{if((G===null||G===void 0x0?void 0x0:G[UR(0x1b4)])===UR(0x201))g=UR(0x20d);else{if((G===null||G===void 0x0?void 0x0:G['type'])===UR(0x1e3))g=UR(0x1fd);else(G===null||G===void 0x0?void 0x0:G[UR(0x1b4)])===UR(0x13c)&&(g='editor');}}L=Q!==![]?!_[UR(0x138)](p)?p:JSON['stringify'](p):UR(0x199);_[UR(0x136)](this['resultCache'],k['join']('.'))&&(L=this[UR(0x1d6)][k[UR(0x1bc)]('.')]);H=i&&Q===![]?__spreadArray(__spreadArray([],i),['don\x27t\x20change']):i,I={'type':g,'name':'id','message':this['getQuestionString'](k,G),'choices':H,'default':L,'filter':this[UR(0x145)](g,Q),'validate':this[UR(0x15f)](G,Q)};return[0x4,inquirer[UR(0x216)]([I])];case 0x2:v=R[UR(0x187)]()['id'];return[0x2,v===UR(0x199)||v===''?undefined:v];}});});},U['prototype'][Uy(0x16d)]=function(k,G){var Ub=Uy,Q=(G===null||G===void 0x0?void 0x0:G[Ub(0x1b4)])!==Ub(0x201)?Ub(0x1dd):Ub(0x1d7);return this[Ub(0x1d5)](k,Q,G===null||G===void 0x0?void 0x0:G[Ub(0x1a8)]);},U[Uy(0x13e)][Uy(0x16c)]=function(){return __awaiter(this,void 0x0,void 0x0,function(){var k,G;return __generator(this,function(Q){var Ud=a6k;switch(Q[Ud(0x1ca)]){case 0x0:return[0x4,this[Ud(0x139)]['list'][Ud(0x157)]({})];case 0x1:k=Q[Ud(0x187)](),G=k['response'][Ud(0x150)][Ud(0x1b5)](function(f){return f['id'];});if(G[Ud(0x186)]<0x1)throw new Error(Ud(0x1c1));return[0x4,inquirer[Ud(0x216)]([{'type':'list','name':Ud(0x17a),'message':'Choose\x20the\x20project\x20to\x20use:','choices':G}])];case 0x2:return[0x2,Q[Ud(0x187)]()[Ud(0x17a)]];}});});},U[Uy(0x13e)][Uy(0x1dc)]=function(k,G,Q){return __awaiter(this,void 0x0,void 0x0,function(){var f,C;return __generator(this,function(y){var UZ=a6k;switch(y[UZ(0x1ca)]){case 0x0:f=Q||this[UZ(0x139)][UZ(0x173)]['getCurrentProjectName']();if(_['isUndefined'](f))throw new Error(UZ(0x20c));return[0x4,G(f)];case 0x1:C=y[UZ(0x187)]();return[0x4,this['askForResource'](k,C,'project:\x20\x27'+f+'\x27')];case 0x2:return[0x2,y[UZ(0x187)]()];}});});},U[Uy(0x13e)][Uy(0x147)]=function(){return __awaiter(this,void 0x0,void 0x0,function(){var k,G;return __generator(this,function(Q){var Un=a6k;switch(Q[Un(0x1ca)]){case 0x0:return[0x4,this['apiClient'][Un(0x168)][Un(0x1a6)]({})];case 0x1:k=Q[Un(0x187)](),G=k[Un(0x162)][Un(0x170)][Un(0x1b5)](function(f){var UJ=Un;return f[UJ(0x17a)];});return[0x2,this['askForResource'](Un(0x1a6),G)];}});});},U[Uy(0x13e)][Uy(0x18c)]=function(){return __awaiter(this,void 0x0,void 0x0,function(){var k,G;return __generator(this,function(Q){var Ur=a6k;switch(Q[Ur(0x1ca)]){case 0x0:return[0x4,this[Ur(0x139)][Ur(0x168)]['registryCredentials']({})];case 0x1:k=Q[Ur(0x187)](),G=k[Ur(0x162)]['credentials'][Ur(0x1b5)](function(f){return f['id'];});return[0x2,this[Ur(0x17e)](Ur(0x13d),G)];}});});},U[Uy(0x13e)][Uy(0x197)]=function(k){var UY=Uy;this[UY(0x156)]=k;},U;}();exports[a6d(0x171)]=InquirerHelper;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
16
|
+
}) : (function(o, m, k, k2) {
|
|
17
|
+
if (k2 === undefined) k2 = k;
|
|
18
|
+
o[k2] = m[k];
|
|
19
|
+
}));
|
|
20
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
21
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
22
|
+
}) : function(o, v) {
|
|
23
|
+
o["default"] = v;
|
|
24
|
+
});
|
|
25
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
26
|
+
if (mod && mod.__esModule) return mod;
|
|
27
|
+
var result = {};
|
|
28
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
29
|
+
__setModuleDefault(result, mod);
|
|
30
|
+
return result;
|
|
31
|
+
};
|
|
32
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
33
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
34
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
35
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
36
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
37
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
38
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
39
|
+
});
|
|
40
|
+
};
|
|
41
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
42
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
43
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
44
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
45
|
+
function step(op) {
|
|
46
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
47
|
+
while (_) try {
|
|
48
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
49
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
50
|
+
switch (op[0]) {
|
|
51
|
+
case 0: case 1: t = op; break;
|
|
52
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
53
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
54
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
55
|
+
default:
|
|
56
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
57
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
58
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
59
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
60
|
+
if (t[2]) _.ops.pop();
|
|
61
|
+
_.trys.pop(); continue;
|
|
62
|
+
}
|
|
63
|
+
op = body.call(thisArg, _);
|
|
64
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
65
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
69
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
70
|
+
if (ar || !(i in from)) {
|
|
71
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
72
|
+
ar[i] = from[i];
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
76
|
+
};
|
|
77
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
78
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
79
|
+
};
|
|
80
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
81
|
+
exports.InquirerHelper = void 0;
|
|
82
|
+
/* eslint-disable no-await-in-loop */
|
|
83
|
+
var _ = __importStar(require("lodash"));
|
|
84
|
+
var chalk_1 = __importDefault(require("chalk"));
|
|
85
|
+
var fs = __importStar(require("fs"));
|
|
86
|
+
var utils_1 = require("./utils");
|
|
87
|
+
var api_helpers_1 = require("./api-helpers");
|
|
88
|
+
var inquirer = require('inquirer');
|
|
89
|
+
var yaml = require('js-yaml');
|
|
90
|
+
var ConfirmChoices;
|
|
91
|
+
(function (ConfirmChoices) {
|
|
92
|
+
ConfirmChoices["YES"] = "Yes, send";
|
|
93
|
+
ConfirmChoices["REPEAT"] = "No, repeat";
|
|
94
|
+
ConfirmChoices["EDIT"] = "No, edit";
|
|
95
|
+
ConfirmChoices["SAVE"] = "No, but save as file";
|
|
96
|
+
ConfirmChoices["ABORT"] = "No, abort";
|
|
97
|
+
})(ConfirmChoices || (ConfirmChoices = {}));
|
|
98
|
+
var InquirerHelper = /** @class */ (function () {
|
|
99
|
+
function InquirerHelper(apiClient) {
|
|
100
|
+
var _this = this;
|
|
101
|
+
this.apiClient = apiClient;
|
|
102
|
+
this.editPayload = function (result) { return __awaiter(_this, void 0, void 0, function () {
|
|
103
|
+
var editedResult;
|
|
104
|
+
return __generator(this, function (_a) {
|
|
105
|
+
switch (_a.label) {
|
|
106
|
+
case 0: return [4 /*yield*/, inquirer.prompt([
|
|
107
|
+
{
|
|
108
|
+
type: 'editor',
|
|
109
|
+
name: 'editedResult',
|
|
110
|
+
message: 'Go to editor',
|
|
111
|
+
default: yaml.safeDump(result),
|
|
112
|
+
},
|
|
113
|
+
])];
|
|
114
|
+
case 1:
|
|
115
|
+
editedResult = (_a.sent()).editedResult;
|
|
116
|
+
return [2 /*return*/, yaml.safeLoad(editedResult)];
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
}); };
|
|
120
|
+
this.saveFile = function (result) { return __awaiter(_this, void 0, void 0, function () {
|
|
121
|
+
function prompFileName() {
|
|
122
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
123
|
+
return __generator(this, function (_a) {
|
|
124
|
+
return [2 /*return*/, inquirer.prompt([
|
|
125
|
+
{
|
|
126
|
+
type: 'input',
|
|
127
|
+
name: 'fileName',
|
|
128
|
+
message: 'Provide a file path to write the configuration to (<name>.[json|yaml|yml])',
|
|
129
|
+
validate: function (input) {
|
|
130
|
+
return new RegExp('.*\\.(json|yaml|yml)$').test(input) ? true : fileTypeWarning(input);
|
|
131
|
+
},
|
|
132
|
+
},
|
|
133
|
+
])];
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
var fileTypeWarning, filePath, fileEnding;
|
|
138
|
+
return __generator(this, function (_a) {
|
|
139
|
+
switch (_a.label) {
|
|
140
|
+
case 0:
|
|
141
|
+
fileTypeWarning = function (fileEnding) {
|
|
142
|
+
return "Unexpected file type: " + fileEnding + ", supported types: [json|yaml|yml]";
|
|
143
|
+
};
|
|
144
|
+
return [4 /*yield*/, prompFileName()];
|
|
145
|
+
case 1:
|
|
146
|
+
filePath = (_a.sent()).fileName;
|
|
147
|
+
fileEnding = filePath.toString().split('.').pop();
|
|
148
|
+
try {
|
|
149
|
+
switch (fileEnding) {
|
|
150
|
+
case 'json':
|
|
151
|
+
(0, utils_1.success)("Configuration file written to " + filePath);
|
|
152
|
+
return [2 /*return*/, fs.writeFileSync(filePath, JSON.stringify(result, null, ' '))];
|
|
153
|
+
case 'yaml':
|
|
154
|
+
case 'yml':
|
|
155
|
+
(0, utils_1.success)("Configuration file written to " + filePath);
|
|
156
|
+
return [2 /*return*/, fs.writeFileSync(filePath, yaml.safeDump(result))];
|
|
157
|
+
default:
|
|
158
|
+
(0, utils_1.warning)(fileTypeWarning(fileEnding));
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
catch (e) {
|
|
162
|
+
(0, utils_1.warning)("Writing configuration failed: " + e.message);
|
|
163
|
+
}
|
|
164
|
+
return [2 /*return*/, undefined];
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
}); };
|
|
168
|
+
this.filter = function (type, required) { return function (input) {
|
|
169
|
+
var sanitisedInput = typeof input === 'string' ? input.trim() : input;
|
|
170
|
+
if (type === 'number' && Number.isNaN(sanitisedInput))
|
|
171
|
+
return '';
|
|
172
|
+
return required === false && sanitisedInput === "don't change" ? '' : sanitisedInput;
|
|
173
|
+
}; };
|
|
174
|
+
this.validate = function (prop, required) { return function (input) {
|
|
175
|
+
var valid = [];
|
|
176
|
+
if (input === '' || input === "don't change") {
|
|
177
|
+
if (required !== false) {
|
|
178
|
+
valid.push("this option is required, please answer");
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
return true;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
if (prop.type === 'string' && !_.isUndefined(prop.pattern)) {
|
|
185
|
+
valid.push(new RegExp(prop.pattern).test(input) ? true : "doesn't match pattern '" + prop.pattern + "'");
|
|
186
|
+
}
|
|
187
|
+
if (prop.type === 'string' && !_.isUndefined(prop.minLength)) {
|
|
188
|
+
valid.push(input.length >= prop.minLength
|
|
189
|
+
? true
|
|
190
|
+
: "must be longer than or equal to " + prop.minLength + " characters, is " + input.length + " characters");
|
|
191
|
+
}
|
|
192
|
+
if (prop.type === 'string' && !_.isUndefined(prop.maxLength)) {
|
|
193
|
+
valid.push(input.length <= prop.maxLength
|
|
194
|
+
? true
|
|
195
|
+
: "must be shorter than or equal to " + prop.maxLength + " characters, is " + input.length + " characters");
|
|
196
|
+
}
|
|
197
|
+
if (prop.type === 'integer' && !_.isFinite(Number(input))) {
|
|
198
|
+
valid.push("must be a number, is " + input);
|
|
199
|
+
}
|
|
200
|
+
if (prop.type === 'integer' && !_.isUndefined(prop.minimum)) {
|
|
201
|
+
valid.push(input >= prop.minimum ? true : "must be bigger than or equal to " + prop.minimum);
|
|
202
|
+
}
|
|
203
|
+
if (prop.type === 'integer' && !_.isUndefined(prop.maximum)) {
|
|
204
|
+
valid.push(input <= prop.maximum ? true : "must be smaller than or equal to " + prop.maximum);
|
|
205
|
+
}
|
|
206
|
+
if (prop.type === 'rawObject') {
|
|
207
|
+
var asJson = (0, utils_1.isValidJSON)(input);
|
|
208
|
+
valid.push(asJson === false || _.isEmpty(asJson) ? "must be a valid non-empty json string" : true);
|
|
209
|
+
}
|
|
210
|
+
var errors = valid.filter(function (e) { return e !== true; });
|
|
211
|
+
var example = (prop === null || prop === void 0 ? void 0 : prop.example)
|
|
212
|
+
? "\n" + chalk_1.default.red('>>') + " Example: " + chalk_1.default.whiteBright(JSON.stringify(prop.example))
|
|
213
|
+
: '';
|
|
214
|
+
return errors.length > 0 ? errors.join(chalk_1.default.underline(' and it ')) + example : true;
|
|
215
|
+
}; };
|
|
216
|
+
this.getPathString = function (propPath, question, description) {
|
|
217
|
+
var current = propPath[propPath.length - 1];
|
|
218
|
+
function stringifyPath() {
|
|
219
|
+
return propPath
|
|
220
|
+
.slice(0, -1)
|
|
221
|
+
.map(function (p) { return p.charAt(0).toUpperCase() + p.slice(1); })
|
|
222
|
+
.join('>');
|
|
223
|
+
}
|
|
224
|
+
var path = propPath.length > 1 ? chalk_1.default.bgGrey.whiteBright(stringifyPath()) + ": " : '';
|
|
225
|
+
var descr = description ? " (" + chalk_1.default.blue(description) + ")" : '';
|
|
226
|
+
return chalk_1.default.reset("" + path + question + " " + chalk_1.default.bold.greenBright(current) + descr + "?");
|
|
227
|
+
};
|
|
228
|
+
this.askForResource = function (resourceName, resourceNames, scopedBy) { return __awaiter(_this, void 0, void 0, function () {
|
|
229
|
+
var scope;
|
|
230
|
+
return __generator(this, function (_a) {
|
|
231
|
+
switch (_a.label) {
|
|
232
|
+
case 0:
|
|
233
|
+
if (resourceNames.length < 1) {
|
|
234
|
+
scope = scopedBy ? "for this " + scopedBy : 'found';
|
|
235
|
+
throw new Error("No " + resourceName + " " + scope + ".");
|
|
236
|
+
}
|
|
237
|
+
return [4 /*yield*/, inquirer.prompt([
|
|
238
|
+
{
|
|
239
|
+
type: 'list',
|
|
240
|
+
name: 'name',
|
|
241
|
+
message: "Choose the " + resourceName + " to use:",
|
|
242
|
+
choices: resourceNames,
|
|
243
|
+
},
|
|
244
|
+
])];
|
|
245
|
+
case 1: return [2 /*return*/, (_a.sent()).name];
|
|
246
|
+
}
|
|
247
|
+
});
|
|
248
|
+
}); };
|
|
249
|
+
this.askForService = function (project) { return function () { return __awaiter(_this, void 0, void 0, function () {
|
|
250
|
+
var apiCall;
|
|
251
|
+
var _this = this;
|
|
252
|
+
return __generator(this, function (_a) {
|
|
253
|
+
apiCall = function (projectName) { return __awaiter(_this, void 0, void 0, function () {
|
|
254
|
+
return __generator(this, function (_a) {
|
|
255
|
+
switch (_a.label) {
|
|
256
|
+
case 0: return [4 /*yield*/, this.apiClient.list.services({ parameters: { projectId: projectName } })];
|
|
257
|
+
case 1: return [2 /*return*/, (_a.sent()).data.services.map(function (svc) { return svc.id; })];
|
|
258
|
+
}
|
|
259
|
+
});
|
|
260
|
+
}); };
|
|
261
|
+
return [2 /*return*/, this.askForProjectScopedResource('service', apiCall, project)];
|
|
262
|
+
});
|
|
263
|
+
}); }; };
|
|
264
|
+
this.askForJob = function (project) { return function () { return __awaiter(_this, void 0, void 0, function () {
|
|
265
|
+
var apiCall;
|
|
266
|
+
var _this = this;
|
|
267
|
+
return __generator(this, function (_a) {
|
|
268
|
+
apiCall = function (projectName) { return __awaiter(_this, void 0, void 0, function () {
|
|
269
|
+
return __generator(this, function (_a) {
|
|
270
|
+
switch (_a.label) {
|
|
271
|
+
case 0: return [4 /*yield*/, this.apiClient.list.jobs({ parameters: { projectId: projectName } })];
|
|
272
|
+
case 1: return [2 /*return*/, (_a.sent()).data.jobs.map(function (job) { return job.id; })];
|
|
273
|
+
}
|
|
274
|
+
});
|
|
275
|
+
}); };
|
|
276
|
+
return [2 /*return*/, this.askForProjectScopedResource('job', apiCall, project)];
|
|
277
|
+
});
|
|
278
|
+
}); }; };
|
|
279
|
+
this.askForJobRun = function (jobName, project) { return function () { return __awaiter(_this, void 0, void 0, function () {
|
|
280
|
+
var apiCall;
|
|
281
|
+
var _this = this;
|
|
282
|
+
return __generator(this, function (_a) {
|
|
283
|
+
apiCall = function (projectName) { return __awaiter(_this, void 0, void 0, function () {
|
|
284
|
+
return __generator(this, function (_a) {
|
|
285
|
+
switch (_a.label) {
|
|
286
|
+
case 0: return [4 /*yield*/, this.apiClient.get.job.runs({
|
|
287
|
+
parameters: { projectId: projectName, jobId: jobName },
|
|
288
|
+
})];
|
|
289
|
+
case 1: return [2 /*return*/, (_a.sent()).data.runs.map(function (job) { return job.id + " (startedAt: " + job.startedAt + ")"; })];
|
|
290
|
+
}
|
|
291
|
+
});
|
|
292
|
+
}); };
|
|
293
|
+
return [2 /*return*/, this.askForProjectScopedResource('job', apiCall, project).then(function (j) { return j.split(' ')[0]; })];
|
|
294
|
+
});
|
|
295
|
+
}); }; };
|
|
296
|
+
this.askForAddon = function (project) { return function () { return __awaiter(_this, void 0, void 0, function () {
|
|
297
|
+
var apiCall;
|
|
298
|
+
var _this = this;
|
|
299
|
+
return __generator(this, function (_a) {
|
|
300
|
+
apiCall = function (projectName) { return __awaiter(_this, void 0, void 0, function () {
|
|
301
|
+
return __generator(this, function (_a) {
|
|
302
|
+
switch (_a.label) {
|
|
303
|
+
case 0: return [4 /*yield*/, this.apiClient.list.addons({ parameters: { projectId: projectName } })];
|
|
304
|
+
case 1: return [2 /*return*/, (_a.sent()).data.addons.map(function (svc) { return svc.id; })];
|
|
305
|
+
}
|
|
306
|
+
});
|
|
307
|
+
}); };
|
|
308
|
+
return [2 /*return*/, this.askForProjectScopedResource('addon', apiCall, project)];
|
|
309
|
+
});
|
|
310
|
+
}); }; };
|
|
311
|
+
this.askForAddonBackup = function (project, addon) { return function () { return __awaiter(_this, void 0, void 0, function () {
|
|
312
|
+
var apiCall;
|
|
313
|
+
var _this = this;
|
|
314
|
+
return __generator(this, function (_a) {
|
|
315
|
+
apiCall = function (projectName) { return __awaiter(_this, void 0, void 0, function () {
|
|
316
|
+
return __generator(this, function (_a) {
|
|
317
|
+
switch (_a.label) {
|
|
318
|
+
case 0: return [4 /*yield*/, this.apiClient.get.addon.backups({
|
|
319
|
+
parameters: {
|
|
320
|
+
projectId: projectName,
|
|
321
|
+
addonId: addon,
|
|
322
|
+
},
|
|
323
|
+
})];
|
|
324
|
+
case 1: return [2 /*return*/, (_a.sent()).data.backups.map(function (job) { return job.id + " (completedAt: " + (job.completedAt || 'not completed') + ")"; })];
|
|
325
|
+
}
|
|
326
|
+
});
|
|
327
|
+
}); };
|
|
328
|
+
return [2 /*return*/, this.askForProjectScopedResource('backup', apiCall, project).then(function (j) { return j.split(' ')[0]; })];
|
|
329
|
+
});
|
|
330
|
+
}); }; };
|
|
331
|
+
this.askForSecret = function (project) { return function () { return __awaiter(_this, void 0, void 0, function () {
|
|
332
|
+
var apiCall;
|
|
333
|
+
var _this = this;
|
|
334
|
+
return __generator(this, function (_a) {
|
|
335
|
+
apiCall = function (projectName) { return __awaiter(_this, void 0, void 0, function () {
|
|
336
|
+
return __generator(this, function (_a) {
|
|
337
|
+
switch (_a.label) {
|
|
338
|
+
case 0: return [4 /*yield*/, this.apiClient.list.secrets({ parameters: { projectId: projectName } })];
|
|
339
|
+
case 1: return [2 /*return*/, (_a.sent()).data.secrets.map(function (svc) { return svc.id; })];
|
|
340
|
+
}
|
|
341
|
+
});
|
|
342
|
+
}); };
|
|
343
|
+
return [2 /*return*/, this.askForProjectScopedResource('secret', apiCall, project)];
|
|
344
|
+
});
|
|
345
|
+
}); }; };
|
|
346
|
+
this.askForSubdomain = function (domain) { return function () { return __awaiter(_this, void 0, void 0, function () {
|
|
347
|
+
var getDomainResponse, subdomains, scopedBy;
|
|
348
|
+
return __generator(this, function (_a) {
|
|
349
|
+
switch (_a.label) {
|
|
350
|
+
case 0: return [4 /*yield*/, this.apiClient.get.domain({
|
|
351
|
+
parameters: { domain: domain },
|
|
352
|
+
})];
|
|
353
|
+
case 1:
|
|
354
|
+
getDomainResponse = _a.sent();
|
|
355
|
+
subdomains = getDomainResponse.data.subdomains.map(function (d) { return d.name + " (full domain: " + d.fullName + ")"; });
|
|
356
|
+
scopedBy = "domain (" + domain + ")";
|
|
357
|
+
return [2 /*return*/, this.askForResource('subdomain', subdomains, scopedBy).then(function (j) { return j.split(' ')[0]; })];
|
|
358
|
+
}
|
|
359
|
+
});
|
|
360
|
+
}); }; };
|
|
361
|
+
this.deleteWarningPrompt = function (resourceString) { return __awaiter(_this, void 0, void 0, function () {
|
|
362
|
+
return __generator(this, function (_a) {
|
|
363
|
+
switch (_a.label) {
|
|
364
|
+
case 0: return [4 /*yield*/, inquirer.prompt([
|
|
365
|
+
{
|
|
366
|
+
type: 'confirm',
|
|
367
|
+
name: 'confirmation',
|
|
368
|
+
message: chalk_1.default.yellowBright("WARNING: You are about to delete " + (resourceString || 'a Northflank resource') + ". This is irreversible. Please confirm!"),
|
|
369
|
+
default: false,
|
|
370
|
+
},
|
|
371
|
+
])];
|
|
372
|
+
case 1: return [2 /*return*/, (_a.sent()).confirmation];
|
|
373
|
+
}
|
|
374
|
+
});
|
|
375
|
+
}); };
|
|
376
|
+
this.loginPrompt = function (options, existingContexts) { return __awaiter(_this, void 0, void 0, function () {
|
|
377
|
+
var token;
|
|
378
|
+
var _this = this;
|
|
379
|
+
return __generator(this, function (_a) {
|
|
380
|
+
switch (_a.label) {
|
|
381
|
+
case 0:
|
|
382
|
+
if (!_.isUndefined(options.name)) return [3 /*break*/, 3];
|
|
383
|
+
if (!(existingContexts.length <= 0)) return [3 /*break*/, 1];
|
|
384
|
+
_.set(options, 'name', 'default');
|
|
385
|
+
return [3 /*break*/, 3];
|
|
386
|
+
case 1: return [4 /*yield*/, (0, utils_1.retry)(10)(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
387
|
+
var name, c;
|
|
388
|
+
return __generator(this, function (_a) {
|
|
389
|
+
switch (_a.label) {
|
|
390
|
+
case 0: return [4 /*yield*/, inquirer.prompt([
|
|
391
|
+
{
|
|
392
|
+
type: 'input',
|
|
393
|
+
name: 'name',
|
|
394
|
+
message: 'Choose the name of the new local context:',
|
|
395
|
+
default: 'main-context',
|
|
396
|
+
},
|
|
397
|
+
])];
|
|
398
|
+
case 1:
|
|
399
|
+
name = (_a.sent()).name;
|
|
400
|
+
if (!(!options.override && existingContexts.find(function (ctx) { return ctx.name === name; }))) return [3 /*break*/, 3];
|
|
401
|
+
return [4 /*yield*/, inquirer.prompt([
|
|
402
|
+
{
|
|
403
|
+
type: 'confirm',
|
|
404
|
+
name: 'c',
|
|
405
|
+
message: "Context with name '" + name + "' already exists. Do you want to override this context (y) or enter a new name (N)?",
|
|
406
|
+
default: false,
|
|
407
|
+
},
|
|
408
|
+
])];
|
|
409
|
+
case 2:
|
|
410
|
+
c = (_a.sent()).c;
|
|
411
|
+
if (c === false)
|
|
412
|
+
throw new Error('Context name already exists.');
|
|
413
|
+
_.set(options, 'override', true);
|
|
414
|
+
_a.label = 3;
|
|
415
|
+
case 3:
|
|
416
|
+
_.set(options, 'name', name);
|
|
417
|
+
return [2 /*return*/];
|
|
418
|
+
}
|
|
419
|
+
});
|
|
420
|
+
}); })];
|
|
421
|
+
case 2:
|
|
422
|
+
_a.sent();
|
|
423
|
+
_a.label = 3;
|
|
424
|
+
case 3:
|
|
425
|
+
if (!_.isUndefined(options.token)) return [3 /*break*/, 5];
|
|
426
|
+
return [4 /*yield*/, this.tokenPrompt()];
|
|
427
|
+
case 4:
|
|
428
|
+
token = _a.sent();
|
|
429
|
+
_.set(options, 'token', token);
|
|
430
|
+
_a.label = 5;
|
|
431
|
+
case 5: return [2 /*return*/, options];
|
|
432
|
+
}
|
|
433
|
+
});
|
|
434
|
+
}); };
|
|
435
|
+
this.tokenPrompt = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
436
|
+
var token;
|
|
437
|
+
return __generator(this, function (_a) {
|
|
438
|
+
switch (_a.label) {
|
|
439
|
+
case 0: return [4 /*yield*/, inquirer.prompt([
|
|
440
|
+
{
|
|
441
|
+
type: 'password',
|
|
442
|
+
name: 'token',
|
|
443
|
+
mask: '*',
|
|
444
|
+
message: 'Choose the login token:',
|
|
445
|
+
},
|
|
446
|
+
])];
|
|
447
|
+
case 1:
|
|
448
|
+
token = (_a.sent()).token;
|
|
449
|
+
return [2 /*return*/, token];
|
|
450
|
+
}
|
|
451
|
+
});
|
|
452
|
+
}); };
|
|
453
|
+
}
|
|
454
|
+
InquirerHelper.prototype.confirmationPrompt = function (result, defaultOpt) {
|
|
455
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
456
|
+
var resultDump, length, divider, confirm, _a, _b;
|
|
457
|
+
return __generator(this, function (_c) {
|
|
458
|
+
switch (_c.label) {
|
|
459
|
+
case 0:
|
|
460
|
+
resultDump = yaml.safeDump(result);
|
|
461
|
+
length = _.max(resultDump.split('\n').map(function (l) { return l.length; }));
|
|
462
|
+
divider = chalk_1.default.grey('-'.repeat(length) + "\n");
|
|
463
|
+
return [4 /*yield*/, inquirer.prompt([
|
|
464
|
+
{
|
|
465
|
+
type: 'list',
|
|
466
|
+
name: 'confirm',
|
|
467
|
+
message: "" + chalk_1.default.bold.green('Please confirm following configuration:\n') + divider + chalk_1.default.blueBright(resultDump) + divider,
|
|
468
|
+
choices: Object.values(ConfirmChoices),
|
|
469
|
+
},
|
|
470
|
+
])];
|
|
471
|
+
case 1:
|
|
472
|
+
confirm = (_c.sent()).confirm;
|
|
473
|
+
_a = confirm;
|
|
474
|
+
switch (_a) {
|
|
475
|
+
case ConfirmChoices.YES: return [3 /*break*/, 2];
|
|
476
|
+
case ConfirmChoices.ABORT: return [3 /*break*/, 3];
|
|
477
|
+
case ConfirmChoices.REPEAT: return [3 /*break*/, 4];
|
|
478
|
+
case ConfirmChoices.EDIT: return [3 /*break*/, 5];
|
|
479
|
+
case ConfirmChoices.SAVE: return [3 /*break*/, 7];
|
|
480
|
+
}
|
|
481
|
+
return [3 /*break*/, 9];
|
|
482
|
+
case 2: return [2 /*return*/, result];
|
|
483
|
+
case 3: throw new Error('Aborted.');
|
|
484
|
+
case 4: return [2 /*return*/, this.retrievePayloadViaInteractiveCli(defaultOpt)];
|
|
485
|
+
case 5:
|
|
486
|
+
_b = this.confirmationPrompt;
|
|
487
|
+
return [4 /*yield*/, this.editPayload(result)];
|
|
488
|
+
case 6: return [2 /*return*/, _b.apply(this, [_c.sent(), defaultOpt])];
|
|
489
|
+
case 7: return [4 /*yield*/, this.saveFile(result)];
|
|
490
|
+
case 8:
|
|
491
|
+
_c.sent();
|
|
492
|
+
return [2 /*return*/, this.confirmationPrompt(result, defaultOpt)];
|
|
493
|
+
case 9: throw new Error('Something unexpected happened.');
|
|
494
|
+
}
|
|
495
|
+
});
|
|
496
|
+
});
|
|
497
|
+
};
|
|
498
|
+
InquirerHelper.prototype.retrievePayloadViaInteractiveCli = function (defaultOpt, ctx) {
|
|
499
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
500
|
+
var result;
|
|
501
|
+
return __generator(this, function (_a) {
|
|
502
|
+
switch (_a.label) {
|
|
503
|
+
case 0:
|
|
504
|
+
if ((ctx === null || ctx === void 0 ? void 0 : ctx.resultCache) !== undefined)
|
|
505
|
+
this.resultCache = ctx === null || ctx === void 0 ? void 0 : ctx.resultCache;
|
|
506
|
+
this.tmpCmdPath = ctx === null || ctx === void 0 ? void 0 : ctx.cmdPath;
|
|
507
|
+
result = {};
|
|
508
|
+
return [4 /*yield*/, this.propToType([], defaultOpt.opt.body, result)];
|
|
509
|
+
case 1:
|
|
510
|
+
_a.sent();
|
|
511
|
+
this.resultCache = result;
|
|
512
|
+
return [4 /*yield*/, this.confirmationPrompt(result, defaultOpt)];
|
|
513
|
+
case 2: return [2 /*return*/, _a.sent()];
|
|
514
|
+
}
|
|
515
|
+
});
|
|
516
|
+
});
|
|
517
|
+
};
|
|
518
|
+
InquirerHelper.prototype.propToType = function (propPath, prop, obj, required) {
|
|
519
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
520
|
+
var type, choice_1, oneOfProp;
|
|
521
|
+
return __generator(this, function (_a) {
|
|
522
|
+
switch (_a.label) {
|
|
523
|
+
case 0:
|
|
524
|
+
if (!(prop.oneOf && !_.has(prop, 'properties'))) return [3 /*break*/, 6];
|
|
525
|
+
if (!(prop.oneOf.length > 1)) return [3 /*break*/, 3];
|
|
526
|
+
return [4 /*yield*/, inquirer.prompt([
|
|
527
|
+
{
|
|
528
|
+
type: 'list',
|
|
529
|
+
name: 'choice',
|
|
530
|
+
message: "What's the " + (propPath[propPath.length - 1] || '') + " type?",
|
|
531
|
+
choices: prop.oneOf.map(function (p) { return p.description; }),
|
|
532
|
+
},
|
|
533
|
+
])];
|
|
534
|
+
case 1:
|
|
535
|
+
choice_1 = (_a.sent()).choice;
|
|
536
|
+
return [4 /*yield*/, this.getType(propPath, prop.oneOf.find(function (p) { return p.description === choice_1; }), obj, required)];
|
|
537
|
+
case 2:
|
|
538
|
+
type = _a.sent();
|
|
539
|
+
return [3 /*break*/, 5];
|
|
540
|
+
case 3:
|
|
541
|
+
oneOfProp = prop.oneOf[0];
|
|
542
|
+
_.set(oneOfProp, 'description', prop.description);
|
|
543
|
+
return [4 /*yield*/, this.getType(propPath, oneOfProp, obj, required)];
|
|
544
|
+
case 4:
|
|
545
|
+
type = _a.sent();
|
|
546
|
+
_a.label = 5;
|
|
547
|
+
case 5:
|
|
548
|
+
type = {};
|
|
549
|
+
return [3 /*break*/, 8];
|
|
550
|
+
case 6: return [4 /*yield*/, this.getType(propPath, prop, obj, required)];
|
|
551
|
+
case 7:
|
|
552
|
+
type = _a.sent();
|
|
553
|
+
_a.label = 8;
|
|
554
|
+
case 8: return [2 /*return*/, type];
|
|
555
|
+
}
|
|
556
|
+
});
|
|
557
|
+
});
|
|
558
|
+
};
|
|
559
|
+
InquirerHelper.prototype.getInnerType = function (prop, path, obj, required) {
|
|
560
|
+
var _a;
|
|
561
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
562
|
+
var addEntry, propertyKeys, requiredProps, _i, propertyKeys_1, propNameInner, innerPath;
|
|
563
|
+
return __generator(this, function (_b) {
|
|
564
|
+
switch (_b.label) {
|
|
565
|
+
case 0:
|
|
566
|
+
if (!(required === false)) return [3 /*break*/, 2];
|
|
567
|
+
return [4 /*yield*/, inquirer.prompt([
|
|
568
|
+
{
|
|
569
|
+
type: 'confirm',
|
|
570
|
+
name: 'addEntry',
|
|
571
|
+
message: this.getPathString(path, "Do you want to add", prop === null || prop === void 0 ? void 0 : prop.description),
|
|
572
|
+
default: false,
|
|
573
|
+
},
|
|
574
|
+
])];
|
|
575
|
+
case 1:
|
|
576
|
+
addEntry = (_b.sent()).addEntry;
|
|
577
|
+
if (!addEntry)
|
|
578
|
+
return [2 /*return*/, obj];
|
|
579
|
+
_b.label = 2;
|
|
580
|
+
case 2:
|
|
581
|
+
propertyKeys = Object.keys((_a = prop === null || prop === void 0 ? void 0 : prop.properties) !== null && _a !== void 0 ? _a : []);
|
|
582
|
+
requiredProps = prop.required || [];
|
|
583
|
+
if (!(propertyKeys.length > 0)) return [3 /*break*/, 7];
|
|
584
|
+
_i = 0, propertyKeys_1 = propertyKeys;
|
|
585
|
+
_b.label = 3;
|
|
586
|
+
case 3:
|
|
587
|
+
if (!(_i < propertyKeys_1.length)) return [3 /*break*/, 6];
|
|
588
|
+
propNameInner = propertyKeys_1[_i];
|
|
589
|
+
innerPath = path.concat(propNameInner);
|
|
590
|
+
// innerPath.concat(propNameInner);
|
|
591
|
+
// eslint-disable-next-line no-await-in-loop
|
|
592
|
+
if (path.length > 0 && !_.has(obj, path.join('.')))
|
|
593
|
+
_.set(obj, path.join('.'), {});
|
|
594
|
+
return [4 /*yield*/, this.propToType(innerPath, prop.properties[propNameInner], obj, requiredProps.includes(propNameInner))];
|
|
595
|
+
case 4:
|
|
596
|
+
_b.sent();
|
|
597
|
+
_b.label = 5;
|
|
598
|
+
case 5:
|
|
599
|
+
_i++;
|
|
600
|
+
return [3 /*break*/, 3];
|
|
601
|
+
case 6: return [3 /*break*/, 9];
|
|
602
|
+
case 7: return [4 /*yield*/, this.getType(path, __assign(__assign({}, prop), { type: 'rawObject' }), obj, required)];
|
|
603
|
+
case 8:
|
|
604
|
+
_b.sent();
|
|
605
|
+
_b.label = 9;
|
|
606
|
+
case 9: return [2 /*return*/, obj];
|
|
607
|
+
}
|
|
608
|
+
});
|
|
609
|
+
});
|
|
610
|
+
};
|
|
611
|
+
InquirerHelper.prototype.askArrayEntry = function (propPath, firstTime, required, description) {
|
|
612
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
613
|
+
var message, addEntry;
|
|
614
|
+
return __generator(this, function (_a) {
|
|
615
|
+
switch (_a.label) {
|
|
616
|
+
case 0:
|
|
617
|
+
if (firstTime && required) {
|
|
618
|
+
return [2 /*return*/, true];
|
|
619
|
+
}
|
|
620
|
+
message = firstTime ? "Do you want to add" : "Do you want to add more";
|
|
621
|
+
return [4 /*yield*/, inquirer.prompt([
|
|
622
|
+
{
|
|
623
|
+
type: 'confirm',
|
|
624
|
+
name: 'addEntry',
|
|
625
|
+
message: this.getPathString(propPath, message, firstTime ? description : undefined),
|
|
626
|
+
default: false,
|
|
627
|
+
},
|
|
628
|
+
])];
|
|
629
|
+
case 1:
|
|
630
|
+
addEntry = (_a.sent()).addEntry;
|
|
631
|
+
return [2 /*return*/, addEntry];
|
|
632
|
+
}
|
|
633
|
+
});
|
|
634
|
+
});
|
|
635
|
+
};
|
|
636
|
+
InquirerHelper.prototype.getType = function (propPath, prop, obj, required) {
|
|
637
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
638
|
+
var result, path, _a, firstTime, current, newEntry, _b;
|
|
639
|
+
return __generator(this, function (_c) {
|
|
640
|
+
switch (_c.label) {
|
|
641
|
+
case 0:
|
|
642
|
+
path = propPath.join('.');
|
|
643
|
+
_a = prop === null || prop === void 0 ? void 0 : prop.type;
|
|
644
|
+
switch (_a) {
|
|
645
|
+
case 'array': return [3 /*break*/, 1];
|
|
646
|
+
case 'object': return [3 /*break*/, 6];
|
|
647
|
+
case 'rawObject': return [3 /*break*/, 8];
|
|
648
|
+
case 'string': return [3 /*break*/, 10];
|
|
649
|
+
case 'boolean': return [3 /*break*/, 10];
|
|
650
|
+
case 'integer': return [3 /*break*/, 10];
|
|
651
|
+
}
|
|
652
|
+
return [3 /*break*/, 10];
|
|
653
|
+
case 1:
|
|
654
|
+
firstTime = true;
|
|
655
|
+
_c.label = 2;
|
|
656
|
+
case 2: return [4 /*yield*/, this.askArrayEntry(propPath, firstTime, required, prop === null || prop === void 0 ? void 0 : prop.description)];
|
|
657
|
+
case 3:
|
|
658
|
+
if (!_c.sent()) return [3 /*break*/, 5];
|
|
659
|
+
current = _.get(obj, path);
|
|
660
|
+
_.unset(obj, path);
|
|
661
|
+
return [4 /*yield*/, this.getType(propPath, prop.items, obj)];
|
|
662
|
+
case 4:
|
|
663
|
+
_c.sent();
|
|
664
|
+
newEntry = _.get(obj, path);
|
|
665
|
+
if (!_.isArray(current)) {
|
|
666
|
+
_.set(obj, path, [newEntry]);
|
|
667
|
+
}
|
|
668
|
+
else {
|
|
669
|
+
current.push(newEntry);
|
|
670
|
+
_.set(obj, path, current);
|
|
671
|
+
}
|
|
672
|
+
firstTime = false;
|
|
673
|
+
return [3 /*break*/, 2];
|
|
674
|
+
case 5:
|
|
675
|
+
// @ts-ignore
|
|
676
|
+
return [2 /*return*/, result || []];
|
|
677
|
+
case 6: return [4 /*yield*/, this.getInnerType(prop, propPath, obj, required)];
|
|
678
|
+
case 7:
|
|
679
|
+
result = _c.sent();
|
|
680
|
+
return [2 /*return*/, result];
|
|
681
|
+
case 8:
|
|
682
|
+
_b = utils_1.isValidJSON;
|
|
683
|
+
return [4 /*yield*/, this.ask(propPath, prop, required)];
|
|
684
|
+
case 9:
|
|
685
|
+
result = _b.apply(void 0, [_c.sent()]) || undefined;
|
|
686
|
+
return [3 /*break*/, 12];
|
|
687
|
+
case 10: return [4 /*yield*/, this.ask(propPath, prop, required, obj)];
|
|
688
|
+
case 11:
|
|
689
|
+
result = _c.sent();
|
|
690
|
+
return [3 /*break*/, 12];
|
|
691
|
+
case 12:
|
|
692
|
+
if (!_.isUndefined(result)) {
|
|
693
|
+
_.set(obj, path, result);
|
|
694
|
+
}
|
|
695
|
+
return [2 /*return*/, result];
|
|
696
|
+
}
|
|
697
|
+
});
|
|
698
|
+
});
|
|
699
|
+
};
|
|
700
|
+
InquirerHelper.prototype.ask = function (propPath, prop, required, currentObj) {
|
|
701
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
702
|
+
var parentPropertyPath, _a, _b, defaultValue, _c, choices, type, defaultStr, requiredAdjustedChoices, questionConfig, result;
|
|
703
|
+
return __generator(this, function (_d) {
|
|
704
|
+
switch (_d.label) {
|
|
705
|
+
case 0:
|
|
706
|
+
parentPropertyPath = propPath[propPath.length - 1];
|
|
707
|
+
return [4 /*yield*/, (0, api_helpers_1.fetchResourceList)(parentPropertyPath, this.apiClient, this.tmpCmdPath, currentObj, this.pathVars)];
|
|
708
|
+
case 1:
|
|
709
|
+
_a = _d.sent(), _b = _a.defaultValue, defaultValue = _b === void 0 ? prop === null || prop === void 0 ? void 0 : prop.example : _b, _c = _a.choices, choices = _c === void 0 ? prop === null || prop === void 0 ? void 0 : prop.enum : _c;
|
|
710
|
+
type = 'input';
|
|
711
|
+
if (!_.isUndefined(choices)) {
|
|
712
|
+
type = 'list';
|
|
713
|
+
}
|
|
714
|
+
else if ((prop === null || prop === void 0 ? void 0 : prop.type) === 'boolean') {
|
|
715
|
+
type = 'confirm';
|
|
716
|
+
}
|
|
717
|
+
else if ((prop === null || prop === void 0 ? void 0 : prop.type) === 'integer') {
|
|
718
|
+
type = 'number';
|
|
719
|
+
}
|
|
720
|
+
else if ((prop === null || prop === void 0 ? void 0 : prop.type) === 'rawObject') {
|
|
721
|
+
type = 'editor';
|
|
722
|
+
}
|
|
723
|
+
defaultStr =
|
|
724
|
+
// eslint-disable-next-line no-nested-ternary
|
|
725
|
+
required !== false
|
|
726
|
+
? !_.isObject(defaultValue)
|
|
727
|
+
? defaultValue
|
|
728
|
+
: JSON.stringify(defaultValue)
|
|
729
|
+
: "don't change";
|
|
730
|
+
if (_.has(this.resultCache, propPath.join('.'))) {
|
|
731
|
+
defaultStr = this.resultCache[propPath.join('.')];
|
|
732
|
+
}
|
|
733
|
+
requiredAdjustedChoices = choices && required === false ? __spreadArray(__spreadArray([], choices, true), ["don't change"], false) : choices;
|
|
734
|
+
questionConfig = {
|
|
735
|
+
type: type,
|
|
736
|
+
name: 'id',
|
|
737
|
+
message: this.getQuestionString(propPath, prop),
|
|
738
|
+
choices: requiredAdjustedChoices,
|
|
739
|
+
default: defaultStr,
|
|
740
|
+
filter: this.filter(type, required),
|
|
741
|
+
validate: this.validate(prop, required),
|
|
742
|
+
};
|
|
743
|
+
return [4 /*yield*/, inquirer.prompt([questionConfig])];
|
|
744
|
+
case 2:
|
|
745
|
+
result = (_d.sent()).id;
|
|
746
|
+
return [2 /*return*/, result === "don't change" || result === '' ? undefined : result];
|
|
747
|
+
}
|
|
748
|
+
});
|
|
749
|
+
});
|
|
750
|
+
};
|
|
751
|
+
InquirerHelper.prototype.getQuestionString = function (propPath, prop) {
|
|
752
|
+
var question = (prop === null || prop === void 0 ? void 0 : prop.type) !== 'boolean' ? "What do you want to use as" : 'Should it be';
|
|
753
|
+
return this.getPathString(propPath, question, prop === null || prop === void 0 ? void 0 : prop.description);
|
|
754
|
+
};
|
|
755
|
+
InquirerHelper.prototype.askForProject = function () {
|
|
756
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
757
|
+
var projects, projectNames;
|
|
758
|
+
return __generator(this, function (_a) {
|
|
759
|
+
switch (_a.label) {
|
|
760
|
+
case 0: return [4 /*yield*/, this.apiClient.list.projects({})];
|
|
761
|
+
case 1:
|
|
762
|
+
projects = _a.sent();
|
|
763
|
+
projectNames = projects.data.projects.map(function (prj) { return prj.id; });
|
|
764
|
+
if (projectNames.length < 1) {
|
|
765
|
+
throw new Error("No projects in current context");
|
|
766
|
+
}
|
|
767
|
+
return [4 /*yield*/, inquirer.prompt([
|
|
768
|
+
{
|
|
769
|
+
type: 'list',
|
|
770
|
+
name: 'name',
|
|
771
|
+
message: "Choose the project to use:",
|
|
772
|
+
choices: projectNames,
|
|
773
|
+
},
|
|
774
|
+
])];
|
|
775
|
+
case 2: return [2 /*return*/, (_a.sent()).name];
|
|
776
|
+
}
|
|
777
|
+
});
|
|
778
|
+
});
|
|
779
|
+
};
|
|
780
|
+
InquirerHelper.prototype.askForProjectScopedResource = function (resourceName, apiCall, project) {
|
|
781
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
782
|
+
var projectName, resourceNames;
|
|
783
|
+
return __generator(this, function (_a) {
|
|
784
|
+
switch (_a.label) {
|
|
785
|
+
case 0:
|
|
786
|
+
projectName = project || this.apiClient.contextProvider.getCurrentProjectName();
|
|
787
|
+
if (_.isUndefined(projectName)) {
|
|
788
|
+
throw new Error('Default project in context not set and no argument provided.');
|
|
789
|
+
}
|
|
790
|
+
return [4 /*yield*/, apiCall(projectName)];
|
|
791
|
+
case 1:
|
|
792
|
+
resourceNames = _a.sent();
|
|
793
|
+
return [4 /*yield*/, this.askForResource(resourceName, resourceNames, "project: '" + projectName + "'")];
|
|
794
|
+
case 2: return [2 /*return*/, _a.sent()];
|
|
795
|
+
}
|
|
796
|
+
});
|
|
797
|
+
});
|
|
798
|
+
};
|
|
799
|
+
InquirerHelper.prototype.askForDomain = function () {
|
|
800
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
801
|
+
var listDomainsResponse, domains;
|
|
802
|
+
return __generator(this, function (_a) {
|
|
803
|
+
switch (_a.label) {
|
|
804
|
+
case 0: return [4 /*yield*/, this.apiClient.list.domains({})];
|
|
805
|
+
case 1:
|
|
806
|
+
listDomainsResponse = _a.sent();
|
|
807
|
+
domains = listDomainsResponse.data.domains.map(function (d) { return d.name; });
|
|
808
|
+
return [2 /*return*/, this.askForResource('domain', domains)];
|
|
809
|
+
}
|
|
810
|
+
});
|
|
811
|
+
});
|
|
812
|
+
};
|
|
813
|
+
InquirerHelper.prototype.askForCredentials = function () {
|
|
814
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
815
|
+
var listCredentialsResponse, credentials;
|
|
816
|
+
return __generator(this, function (_a) {
|
|
817
|
+
switch (_a.label) {
|
|
818
|
+
case 0: return [4 /*yield*/, this.apiClient.list.registryCredentials({})];
|
|
819
|
+
case 1:
|
|
820
|
+
listCredentialsResponse = _a.sent();
|
|
821
|
+
credentials = listCredentialsResponse.data.credentials.map(function (d) { return d.id; });
|
|
822
|
+
return [2 /*return*/, this.askForResource('credentials', credentials)];
|
|
823
|
+
}
|
|
824
|
+
});
|
|
825
|
+
});
|
|
826
|
+
};
|
|
827
|
+
InquirerHelper.prototype.setPathVars = function (opt) {
|
|
828
|
+
this.pathVars = opt;
|
|
829
|
+
};
|
|
830
|
+
return InquirerHelper;
|
|
831
|
+
}());
|
|
832
|
+
exports.InquirerHelper = InquirerHelper;
|