index.cjs 132 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086
  1. /*!
  2. Stencil CLI (CommonJS) v4.20.0 | MIT Licensed | https://stenciljs.com
  3. */
  4. "use strict";
  5. var __create = Object.create;
  6. var __defProp = Object.defineProperty;
  7. var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
  8. var __getOwnPropNames = Object.getOwnPropertyNames;
  9. var __getProtoOf = Object.getPrototypeOf;
  10. var __hasOwnProp = Object.prototype.hasOwnProperty;
  11. var __commonJS = (cb, mod) => function __require() {
  12. return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
  13. };
  14. var __export = (target, all) => {
  15. for (var name in all)
  16. __defProp(target, name, { get: all[name], enumerable: true });
  17. };
  18. var __copyProps = (to, from, except, desc) => {
  19. if (from && typeof from === "object" || typeof from === "function") {
  20. for (let key of __getOwnPropNames(from))
  21. if (!__hasOwnProp.call(to, key) && key !== except)
  22. __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  23. }
  24. return to;
  25. };
  26. var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  27. // If the importer is in node compatibility mode or this is not an ESM
  28. // file that has been converted to a CommonJS file using a Babel-
  29. // compatible transform (i.e. "__esModule" has not been set), then set
  30. // "default" to the CommonJS "module.exports" for node compatibility.
  31. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  32. mod
  33. ));
  34. var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
  35. // node_modules/kleur/index.js
  36. var require_kleur = __commonJS({
  37. "node_modules/kleur/index.js"(exports2, module2) {
  38. "use strict";
  39. var { FORCE_COLOR, NODE_DISABLE_COLORS, TERM } = process.env;
  40. var $ = {
  41. enabled: !NODE_DISABLE_COLORS && TERM !== "dumb" && FORCE_COLOR !== "0",
  42. // modifiers
  43. reset: init(0, 0),
  44. bold: init(1, 22),
  45. dim: init(2, 22),
  46. italic: init(3, 23),
  47. underline: init(4, 24),
  48. inverse: init(7, 27),
  49. hidden: init(8, 28),
  50. strikethrough: init(9, 29),
  51. // colors
  52. black: init(30, 39),
  53. red: init(31, 39),
  54. green: init(32, 39),
  55. yellow: init(33, 39),
  56. blue: init(34, 39),
  57. magenta: init(35, 39),
  58. cyan: init(36, 39),
  59. white: init(37, 39),
  60. gray: init(90, 39),
  61. grey: init(90, 39),
  62. // background colors
  63. bgBlack: init(40, 49),
  64. bgRed: init(41, 49),
  65. bgGreen: init(42, 49),
  66. bgYellow: init(43, 49),
  67. bgBlue: init(44, 49),
  68. bgMagenta: init(45, 49),
  69. bgCyan: init(46, 49),
  70. bgWhite: init(47, 49)
  71. };
  72. function run2(arr, str) {
  73. let i = 0, tmp, beg = "", end = "";
  74. for (; i < arr.length; i++) {
  75. tmp = arr[i];
  76. beg += tmp.open;
  77. end += tmp.close;
  78. if (str.includes(tmp.close)) {
  79. str = str.replace(tmp.rgx, tmp.close + tmp.open);
  80. }
  81. }
  82. return beg + str + end;
  83. }
  84. function chain(has, keys) {
  85. let ctx = { has, keys };
  86. ctx.reset = $.reset.bind(ctx);
  87. ctx.bold = $.bold.bind(ctx);
  88. ctx.dim = $.dim.bind(ctx);
  89. ctx.italic = $.italic.bind(ctx);
  90. ctx.underline = $.underline.bind(ctx);
  91. ctx.inverse = $.inverse.bind(ctx);
  92. ctx.hidden = $.hidden.bind(ctx);
  93. ctx.strikethrough = $.strikethrough.bind(ctx);
  94. ctx.black = $.black.bind(ctx);
  95. ctx.red = $.red.bind(ctx);
  96. ctx.green = $.green.bind(ctx);
  97. ctx.yellow = $.yellow.bind(ctx);
  98. ctx.blue = $.blue.bind(ctx);
  99. ctx.magenta = $.magenta.bind(ctx);
  100. ctx.cyan = $.cyan.bind(ctx);
  101. ctx.white = $.white.bind(ctx);
  102. ctx.gray = $.gray.bind(ctx);
  103. ctx.grey = $.grey.bind(ctx);
  104. ctx.bgBlack = $.bgBlack.bind(ctx);
  105. ctx.bgRed = $.bgRed.bind(ctx);
  106. ctx.bgGreen = $.bgGreen.bind(ctx);
  107. ctx.bgYellow = $.bgYellow.bind(ctx);
  108. ctx.bgBlue = $.bgBlue.bind(ctx);
  109. ctx.bgMagenta = $.bgMagenta.bind(ctx);
  110. ctx.bgCyan = $.bgCyan.bind(ctx);
  111. ctx.bgWhite = $.bgWhite.bind(ctx);
  112. return ctx;
  113. }
  114. function init(open, close) {
  115. let blk = {
  116. open: `\x1B[${open}m`,
  117. close: `\x1B[${close}m`,
  118. rgx: new RegExp(`\\x1b\\[${close}m`, "g")
  119. };
  120. return function(txt) {
  121. if (this !== void 0 && this.has !== void 0) {
  122. this.has.includes(open) || (this.has.push(open), this.keys.push(blk));
  123. return txt === void 0 ? this : $.enabled ? run2(this.keys, txt + "") : txt + "";
  124. }
  125. return txt === void 0 ? chain([open], [blk]) : $.enabled ? run2([blk], txt + "") : txt + "";
  126. };
  127. }
  128. module2.exports = $;
  129. }
  130. });
  131. // node_modules/prompts/lib/util/action.js
  132. var require_action = __commonJS({
  133. "node_modules/prompts/lib/util/action.js"(exports2, module2) {
  134. "use strict";
  135. module2.exports = (key, isSelect) => {
  136. if (key.meta && key.name !== "escape") return;
  137. if (key.ctrl) {
  138. if (key.name === "a") return "first";
  139. if (key.name === "c") return "abort";
  140. if (key.name === "d") return "abort";
  141. if (key.name === "e") return "last";
  142. if (key.name === "g") return "reset";
  143. }
  144. if (isSelect) {
  145. if (key.name === "j") return "down";
  146. if (key.name === "k") return "up";
  147. }
  148. if (key.name === "return") return "submit";
  149. if (key.name === "enter") return "submit";
  150. if (key.name === "backspace") return "delete";
  151. if (key.name === "delete") return "deleteForward";
  152. if (key.name === "abort") return "abort";
  153. if (key.name === "escape") return "exit";
  154. if (key.name === "tab") return "next";
  155. if (key.name === "pagedown") return "nextPage";
  156. if (key.name === "pageup") return "prevPage";
  157. if (key.name === "home") return "home";
  158. if (key.name === "end") return "end";
  159. if (key.name === "up") return "up";
  160. if (key.name === "down") return "down";
  161. if (key.name === "right") return "right";
  162. if (key.name === "left") return "left";
  163. return false;
  164. };
  165. }
  166. });
  167. // node_modules/prompts/lib/util/strip.js
  168. var require_strip = __commonJS({
  169. "node_modules/prompts/lib/util/strip.js"(exports2, module2) {
  170. "use strict";
  171. module2.exports = (str) => {
  172. const pattern = [
  173. "[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)",
  174. "(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PRZcf-ntqry=><~]))"
  175. ].join("|");
  176. const RGX = new RegExp(pattern, "g");
  177. return typeof str === "string" ? str.replace(RGX, "") : str;
  178. };
  179. }
  180. });
  181. // node_modules/sisteransi/src/index.js
  182. var require_src = __commonJS({
  183. "node_modules/sisteransi/src/index.js"(exports2, module2) {
  184. "use strict";
  185. var ESC = "\x1B";
  186. var CSI = `${ESC}[`;
  187. var beep = "\x07";
  188. var cursor = {
  189. to(x, y) {
  190. if (!y) return `${CSI}${x + 1}G`;
  191. return `${CSI}${y + 1};${x + 1}H`;
  192. },
  193. move(x, y) {
  194. let ret = "";
  195. if (x < 0) ret += `${CSI}${-x}D`;
  196. else if (x > 0) ret += `${CSI}${x}C`;
  197. if (y < 0) ret += `${CSI}${-y}A`;
  198. else if (y > 0) ret += `${CSI}${y}B`;
  199. return ret;
  200. },
  201. up: (count = 1) => `${CSI}${count}A`,
  202. down: (count = 1) => `${CSI}${count}B`,
  203. forward: (count = 1) => `${CSI}${count}C`,
  204. backward: (count = 1) => `${CSI}${count}D`,
  205. nextLine: (count = 1) => `${CSI}E`.repeat(count),
  206. prevLine: (count = 1) => `${CSI}F`.repeat(count),
  207. left: `${CSI}G`,
  208. hide: `${CSI}?25l`,
  209. show: `${CSI}?25h`,
  210. save: `${ESC}7`,
  211. restore: `${ESC}8`
  212. };
  213. var scroll = {
  214. up: (count = 1) => `${CSI}S`.repeat(count),
  215. down: (count = 1) => `${CSI}T`.repeat(count)
  216. };
  217. var erase = {
  218. screen: `${CSI}2J`,
  219. up: (count = 1) => `${CSI}1J`.repeat(count),
  220. down: (count = 1) => `${CSI}J`.repeat(count),
  221. line: `${CSI}2K`,
  222. lineEnd: `${CSI}K`,
  223. lineStart: `${CSI}1K`,
  224. lines(count) {
  225. let clear = "";
  226. for (let i = 0; i < count; i++)
  227. clear += this.line + (i < count - 1 ? cursor.up() : "");
  228. if (count)
  229. clear += cursor.left;
  230. return clear;
  231. }
  232. };
  233. module2.exports = { cursor, scroll, erase, beep };
  234. }
  235. });
  236. // node_modules/prompts/lib/util/clear.js
  237. var require_clear = __commonJS({
  238. "node_modules/prompts/lib/util/clear.js"(exports2, module2) {
  239. "use strict";
  240. var strip = require_strip();
  241. var { erase, cursor } = require_src();
  242. var width = (str) => [...strip(str)].length;
  243. module2.exports = function(prompt, perLine) {
  244. if (!perLine) return erase.line + cursor.to(0);
  245. let rows = 0;
  246. const lines = prompt.split(/\r?\n/);
  247. for (let line of lines) {
  248. rows += 1 + Math.floor(Math.max(width(line) - 1, 0) / perLine);
  249. }
  250. return erase.lines(rows);
  251. };
  252. }
  253. });
  254. // node_modules/prompts/lib/util/figures.js
  255. var require_figures = __commonJS({
  256. "node_modules/prompts/lib/util/figures.js"(exports2, module2) {
  257. "use strict";
  258. var main = {
  259. arrowUp: "\u2191",
  260. arrowDown: "\u2193",
  261. arrowLeft: "\u2190",
  262. arrowRight: "\u2192",
  263. radioOn: "\u25C9",
  264. radioOff: "\u25EF",
  265. tick: "\u2714",
  266. cross: "\u2716",
  267. ellipsis: "\u2026",
  268. pointerSmall: "\u203A",
  269. line: "\u2500",
  270. pointer: "\u276F"
  271. };
  272. var win = {
  273. arrowUp: main.arrowUp,
  274. arrowDown: main.arrowDown,
  275. arrowLeft: main.arrowLeft,
  276. arrowRight: main.arrowRight,
  277. radioOn: "(*)",
  278. radioOff: "( )",
  279. tick: "\u221A",
  280. cross: "\xD7",
  281. ellipsis: "...",
  282. pointerSmall: "\xBB",
  283. line: "\u2500",
  284. pointer: ">"
  285. };
  286. var figures = process.platform === "win32" ? win : main;
  287. module2.exports = figures;
  288. }
  289. });
  290. // node_modules/prompts/lib/util/style.js
  291. var require_style = __commonJS({
  292. "node_modules/prompts/lib/util/style.js"(exports2, module2) {
  293. "use strict";
  294. var c = require_kleur();
  295. var figures = require_figures();
  296. var styles = Object.freeze({
  297. password: { scale: 1, render: (input) => "*".repeat(input.length) },
  298. emoji: { scale: 2, render: (input) => "\u{1F603}".repeat(input.length) },
  299. invisible: { scale: 0, render: (input) => "" },
  300. default: { scale: 1, render: (input) => `${input}` }
  301. });
  302. var render = (type) => styles[type] || styles.default;
  303. var symbols = Object.freeze({
  304. aborted: c.red(figures.cross),
  305. done: c.green(figures.tick),
  306. exited: c.yellow(figures.cross),
  307. default: c.cyan("?")
  308. });
  309. var symbol = (done, aborted, exited) => aborted ? symbols.aborted : exited ? symbols.exited : done ? symbols.done : symbols.default;
  310. var delimiter = (completing) => c.gray(completing ? figures.ellipsis : figures.pointerSmall);
  311. var item = (expandable, expanded) => c.gray(expandable ? expanded ? figures.pointerSmall : "+" : figures.line);
  312. module2.exports = {
  313. styles,
  314. render,
  315. symbols,
  316. symbol,
  317. delimiter,
  318. item
  319. };
  320. }
  321. });
  322. // node_modules/prompts/lib/util/lines.js
  323. var require_lines = __commonJS({
  324. "node_modules/prompts/lib/util/lines.js"(exports2, module2) {
  325. "use strict";
  326. var strip = require_strip();
  327. module2.exports = function(msg, perLine) {
  328. let lines = String(strip(msg) || "").split(/\r?\n/);
  329. if (!perLine) return lines.length;
  330. return lines.map((l) => Math.ceil(l.length / perLine)).reduce((a, b) => a + b);
  331. };
  332. }
  333. });
  334. // node_modules/prompts/lib/util/wrap.js
  335. var require_wrap = __commonJS({
  336. "node_modules/prompts/lib/util/wrap.js"(exports2, module2) {
  337. "use strict";
  338. module2.exports = (msg, opts = {}) => {
  339. const tab = Number.isSafeInteger(parseInt(opts.margin)) ? new Array(parseInt(opts.margin)).fill(" ").join("") : opts.margin || "";
  340. const width = opts.width;
  341. return (msg || "").split(/\r?\n/g).map((line) => line.split(/\s+/g).reduce((arr, w) => {
  342. if (w.length + tab.length >= width || arr[arr.length - 1].length + w.length + 1 < width)
  343. arr[arr.length - 1] += ` ${w}`;
  344. else arr.push(`${tab}${w}`);
  345. return arr;
  346. }, [tab]).join("\n")).join("\n");
  347. };
  348. }
  349. });
  350. // node_modules/prompts/lib/util/entriesToDisplay.js
  351. var require_entriesToDisplay = __commonJS({
  352. "node_modules/prompts/lib/util/entriesToDisplay.js"(exports2, module2) {
  353. "use strict";
  354. module2.exports = (cursor, total, maxVisible) => {
  355. maxVisible = maxVisible || total;
  356. let startIndex = Math.min(total - maxVisible, cursor - Math.floor(maxVisible / 2));
  357. if (startIndex < 0) startIndex = 0;
  358. let endIndex = Math.min(startIndex + maxVisible, total);
  359. return { startIndex, endIndex };
  360. };
  361. }
  362. });
  363. // node_modules/prompts/lib/util/index.js
  364. var require_util = __commonJS({
  365. "node_modules/prompts/lib/util/index.js"(exports2, module2) {
  366. "use strict";
  367. module2.exports = {
  368. action: require_action(),
  369. clear: require_clear(),
  370. style: require_style(),
  371. strip: require_strip(),
  372. figures: require_figures(),
  373. lines: require_lines(),
  374. wrap: require_wrap(),
  375. entriesToDisplay: require_entriesToDisplay()
  376. };
  377. }
  378. });
  379. // node_modules/prompts/lib/elements/prompt.js
  380. var require_prompt = __commonJS({
  381. "node_modules/prompts/lib/elements/prompt.js"(exports2, module2) {
  382. "use strict";
  383. var readline = require("readline");
  384. var { action } = require_util();
  385. var EventEmitter = require("events");
  386. var { beep, cursor } = require_src();
  387. var color = require_kleur();
  388. var Prompt = class extends EventEmitter {
  389. constructor(opts = {}) {
  390. super();
  391. this.firstRender = true;
  392. this.in = opts.stdin || process.stdin;
  393. this.out = opts.stdout || process.stdout;
  394. this.onRender = (opts.onRender || (() => void 0)).bind(this);
  395. const rl = readline.createInterface({ input: this.in, escapeCodeTimeout: 50 });
  396. readline.emitKeypressEvents(this.in, rl);
  397. if (this.in.isTTY) this.in.setRawMode(true);
  398. const isSelect = ["SelectPrompt", "MultiselectPrompt"].indexOf(this.constructor.name) > -1;
  399. const keypress = (str, key) => {
  400. let a = action(key, isSelect);
  401. if (a === false) {
  402. this._ && this._(str, key);
  403. } else if (typeof this[a] === "function") {
  404. this[a](key);
  405. } else {
  406. this.bell();
  407. }
  408. };
  409. this.close = () => {
  410. this.out.write(cursor.show);
  411. this.in.removeListener("keypress", keypress);
  412. if (this.in.isTTY) this.in.setRawMode(false);
  413. rl.close();
  414. this.emit(this.aborted ? "abort" : this.exited ? "exit" : "submit", this.value);
  415. this.closed = true;
  416. };
  417. this.in.on("keypress", keypress);
  418. }
  419. fire() {
  420. this.emit("state", {
  421. value: this.value,
  422. aborted: !!this.aborted,
  423. exited: !!this.exited
  424. });
  425. }
  426. bell() {
  427. this.out.write(beep);
  428. }
  429. render() {
  430. this.onRender(color);
  431. if (this.firstRender) this.firstRender = false;
  432. }
  433. };
  434. module2.exports = Prompt;
  435. }
  436. });
  437. // node_modules/prompts/lib/elements/text.js
  438. var require_text = __commonJS({
  439. "node_modules/prompts/lib/elements/text.js"(exports2, module2) {
  440. var color = require_kleur();
  441. var Prompt = require_prompt();
  442. var { erase, cursor } = require_src();
  443. var { style, clear, lines, figures } = require_util();
  444. var TextPrompt = class extends Prompt {
  445. constructor(opts = {}) {
  446. super(opts);
  447. this.transform = style.render(opts.style);
  448. this.scale = this.transform.scale;
  449. this.msg = opts.message;
  450. this.initial = opts.initial || ``;
  451. this.validator = opts.validate || (() => true);
  452. this.value = ``;
  453. this.errorMsg = opts.error || `Please Enter A Valid Value`;
  454. this.cursor = Number(!!this.initial);
  455. this.cursorOffset = 0;
  456. this.clear = clear(``, this.out.columns);
  457. this.render();
  458. }
  459. set value(v) {
  460. if (!v && this.initial) {
  461. this.placeholder = true;
  462. this.rendered = color.gray(this.transform.render(this.initial));
  463. } else {
  464. this.placeholder = false;
  465. this.rendered = this.transform.render(v);
  466. }
  467. this._value = v;
  468. this.fire();
  469. }
  470. get value() {
  471. return this._value;
  472. }
  473. reset() {
  474. this.value = ``;
  475. this.cursor = Number(!!this.initial);
  476. this.cursorOffset = 0;
  477. this.fire();
  478. this.render();
  479. }
  480. exit() {
  481. this.abort();
  482. }
  483. abort() {
  484. this.value = this.value || this.initial;
  485. this.done = this.aborted = true;
  486. this.error = false;
  487. this.red = false;
  488. this.fire();
  489. this.render();
  490. this.out.write("\n");
  491. this.close();
  492. }
  493. async validate() {
  494. let valid = await this.validator(this.value);
  495. if (typeof valid === `string`) {
  496. this.errorMsg = valid;
  497. valid = false;
  498. }
  499. this.error = !valid;
  500. }
  501. async submit() {
  502. this.value = this.value || this.initial;
  503. this.cursorOffset = 0;
  504. this.cursor = this.rendered.length;
  505. await this.validate();
  506. if (this.error) {
  507. this.red = true;
  508. this.fire();
  509. this.render();
  510. return;
  511. }
  512. this.done = true;
  513. this.aborted = false;
  514. this.fire();
  515. this.render();
  516. this.out.write("\n");
  517. this.close();
  518. }
  519. next() {
  520. if (!this.placeholder) return this.bell();
  521. this.value = this.initial;
  522. this.cursor = this.rendered.length;
  523. this.fire();
  524. this.render();
  525. }
  526. moveCursor(n) {
  527. if (this.placeholder) return;
  528. this.cursor = this.cursor + n;
  529. this.cursorOffset += n;
  530. }
  531. _(c, key) {
  532. let s1 = this.value.slice(0, this.cursor);
  533. let s2 = this.value.slice(this.cursor);
  534. this.value = `${s1}${c}${s2}`;
  535. this.red = false;
  536. this.cursor = this.placeholder ? 0 : s1.length + 1;
  537. this.render();
  538. }
  539. delete() {
  540. if (this.isCursorAtStart()) return this.bell();
  541. let s1 = this.value.slice(0, this.cursor - 1);
  542. let s2 = this.value.slice(this.cursor);
  543. this.value = `${s1}${s2}`;
  544. this.red = false;
  545. if (this.isCursorAtStart()) {
  546. this.cursorOffset = 0;
  547. } else {
  548. this.cursorOffset++;
  549. this.moveCursor(-1);
  550. }
  551. this.render();
  552. }
  553. deleteForward() {
  554. if (this.cursor * this.scale >= this.rendered.length || this.placeholder) return this.bell();
  555. let s1 = this.value.slice(0, this.cursor);
  556. let s2 = this.value.slice(this.cursor + 1);
  557. this.value = `${s1}${s2}`;
  558. this.red = false;
  559. if (this.isCursorAtEnd()) {
  560. this.cursorOffset = 0;
  561. } else {
  562. this.cursorOffset++;
  563. }
  564. this.render();
  565. }
  566. first() {
  567. this.cursor = 0;
  568. this.render();
  569. }
  570. last() {
  571. this.cursor = this.value.length;
  572. this.render();
  573. }
  574. left() {
  575. if (this.cursor <= 0 || this.placeholder) return this.bell();
  576. this.moveCursor(-1);
  577. this.render();
  578. }
  579. right() {
  580. if (this.cursor * this.scale >= this.rendered.length || this.placeholder) return this.bell();
  581. this.moveCursor(1);
  582. this.render();
  583. }
  584. isCursorAtStart() {
  585. return this.cursor === 0 || this.placeholder && this.cursor === 1;
  586. }
  587. isCursorAtEnd() {
  588. return this.cursor === this.rendered.length || this.placeholder && this.cursor === this.rendered.length + 1;
  589. }
  590. render() {
  591. if (this.closed) return;
  592. if (!this.firstRender) {
  593. if (this.outputError)
  594. this.out.write(cursor.down(lines(this.outputError, this.out.columns) - 1) + clear(this.outputError, this.out.columns));
  595. this.out.write(clear(this.outputText, this.out.columns));
  596. }
  597. super.render();
  598. this.outputError = "";
  599. this.outputText = [
  600. style.symbol(this.done, this.aborted),
  601. color.bold(this.msg),
  602. style.delimiter(this.done),
  603. this.red ? color.red(this.rendered) : this.rendered
  604. ].join(` `);
  605. if (this.error) {
  606. this.outputError += this.errorMsg.split(`
  607. `).reduce((a, l, i) => a + `
  608. ${i ? " " : figures.pointerSmall} ${color.red().italic(l)}`, ``);
  609. }
  610. this.out.write(erase.line + cursor.to(0) + this.outputText + cursor.save + this.outputError + cursor.restore + cursor.move(this.cursorOffset, 0));
  611. }
  612. };
  613. module2.exports = TextPrompt;
  614. }
  615. });
  616. // node_modules/prompts/lib/elements/select.js
  617. var require_select = __commonJS({
  618. "node_modules/prompts/lib/elements/select.js"(exports2, module2) {
  619. "use strict";
  620. var color = require_kleur();
  621. var Prompt = require_prompt();
  622. var { style, clear, figures, wrap, entriesToDisplay } = require_util();
  623. var { cursor } = require_src();
  624. var SelectPrompt = class extends Prompt {
  625. constructor(opts = {}) {
  626. super(opts);
  627. this.msg = opts.message;
  628. this.hint = opts.hint || "- Use arrow-keys. Return to submit.";
  629. this.warn = opts.warn || "- This option is disabled";
  630. this.cursor = opts.initial || 0;
  631. this.choices = opts.choices.map((ch, idx) => {
  632. if (typeof ch === "string")
  633. ch = { title: ch, value: idx };
  634. return {
  635. title: ch && (ch.title || ch.value || ch),
  636. value: ch && (ch.value === void 0 ? idx : ch.value),
  637. description: ch && ch.description,
  638. selected: ch && ch.selected,
  639. disabled: ch && ch.disabled
  640. };
  641. });
  642. this.optionsPerPage = opts.optionsPerPage || 10;
  643. this.value = (this.choices[this.cursor] || {}).value;
  644. this.clear = clear("", this.out.columns);
  645. this.render();
  646. }
  647. moveCursor(n) {
  648. this.cursor = n;
  649. this.value = this.choices[n].value;
  650. this.fire();
  651. }
  652. reset() {
  653. this.moveCursor(0);
  654. this.fire();
  655. this.render();
  656. }
  657. exit() {
  658. this.abort();
  659. }
  660. abort() {
  661. this.done = this.aborted = true;
  662. this.fire();
  663. this.render();
  664. this.out.write("\n");
  665. this.close();
  666. }
  667. submit() {
  668. if (!this.selection.disabled) {
  669. this.done = true;
  670. this.aborted = false;
  671. this.fire();
  672. this.render();
  673. this.out.write("\n");
  674. this.close();
  675. } else
  676. this.bell();
  677. }
  678. first() {
  679. this.moveCursor(0);
  680. this.render();
  681. }
  682. last() {
  683. this.moveCursor(this.choices.length - 1);
  684. this.render();
  685. }
  686. up() {
  687. if (this.cursor === 0) {
  688. this.moveCursor(this.choices.length - 1);
  689. } else {
  690. this.moveCursor(this.cursor - 1);
  691. }
  692. this.render();
  693. }
  694. down() {
  695. if (this.cursor === this.choices.length - 1) {
  696. this.moveCursor(0);
  697. } else {
  698. this.moveCursor(this.cursor + 1);
  699. }
  700. this.render();
  701. }
  702. next() {
  703. this.moveCursor((this.cursor + 1) % this.choices.length);
  704. this.render();
  705. }
  706. _(c, key) {
  707. if (c === " ") return this.submit();
  708. }
  709. get selection() {
  710. return this.choices[this.cursor];
  711. }
  712. render() {
  713. if (this.closed) return;
  714. if (this.firstRender) this.out.write(cursor.hide);
  715. else this.out.write(clear(this.outputText, this.out.columns));
  716. super.render();
  717. let { startIndex, endIndex } = entriesToDisplay(this.cursor, this.choices.length, this.optionsPerPage);
  718. this.outputText = [
  719. style.symbol(this.done, this.aborted),
  720. color.bold(this.msg),
  721. style.delimiter(false),
  722. this.done ? this.selection.title : this.selection.disabled ? color.yellow(this.warn) : color.gray(this.hint)
  723. ].join(" ");
  724. if (!this.done) {
  725. this.outputText += "\n";
  726. for (let i = startIndex; i < endIndex; i++) {
  727. let title, prefix, desc = "", v = this.choices[i];
  728. if (i === startIndex && startIndex > 0) {
  729. prefix = figures.arrowUp;
  730. } else if (i === endIndex - 1 && endIndex < this.choices.length) {
  731. prefix = figures.arrowDown;
  732. } else {
  733. prefix = " ";
  734. }
  735. if (v.disabled) {
  736. title = this.cursor === i ? color.gray().underline(v.title) : color.strikethrough().gray(v.title);
  737. prefix = (this.cursor === i ? color.bold().gray(figures.pointer) + " " : " ") + prefix;
  738. } else {
  739. title = this.cursor === i ? color.cyan().underline(v.title) : v.title;
  740. prefix = (this.cursor === i ? color.cyan(figures.pointer) + " " : " ") + prefix;
  741. if (v.description && this.cursor === i) {
  742. desc = ` - ${v.description}`;
  743. if (prefix.length + title.length + desc.length >= this.out.columns || v.description.split(/\r?\n/).length > 1) {
  744. desc = "\n" + wrap(v.description, { margin: 3, width: this.out.columns });
  745. }
  746. }
  747. }
  748. this.outputText += `${prefix} ${title}${color.gray(desc)}
  749. `;
  750. }
  751. }
  752. this.out.write(this.outputText);
  753. }
  754. };
  755. module2.exports = SelectPrompt;
  756. }
  757. });
  758. // node_modules/prompts/lib/elements/toggle.js
  759. var require_toggle = __commonJS({
  760. "node_modules/prompts/lib/elements/toggle.js"(exports2, module2) {
  761. var color = require_kleur();
  762. var Prompt = require_prompt();
  763. var { style, clear } = require_util();
  764. var { cursor, erase } = require_src();
  765. var TogglePrompt = class extends Prompt {
  766. constructor(opts = {}) {
  767. super(opts);
  768. this.msg = opts.message;
  769. this.value = !!opts.initial;
  770. this.active = opts.active || "on";
  771. this.inactive = opts.inactive || "off";
  772. this.initialValue = this.value;
  773. this.render();
  774. }
  775. reset() {
  776. this.value = this.initialValue;
  777. this.fire();
  778. this.render();
  779. }
  780. exit() {
  781. this.abort();
  782. }
  783. abort() {
  784. this.done = this.aborted = true;
  785. this.fire();
  786. this.render();
  787. this.out.write("\n");
  788. this.close();
  789. }
  790. submit() {
  791. this.done = true;
  792. this.aborted = false;
  793. this.fire();
  794. this.render();
  795. this.out.write("\n");
  796. this.close();
  797. }
  798. deactivate() {
  799. if (this.value === false) return this.bell();
  800. this.value = false;
  801. this.render();
  802. }
  803. activate() {
  804. if (this.value === true) return this.bell();
  805. this.value = true;
  806. this.render();
  807. }
  808. delete() {
  809. this.deactivate();
  810. }
  811. left() {
  812. this.deactivate();
  813. }
  814. right() {
  815. this.activate();
  816. }
  817. down() {
  818. this.deactivate();
  819. }
  820. up() {
  821. this.activate();
  822. }
  823. next() {
  824. this.value = !this.value;
  825. this.fire();
  826. this.render();
  827. }
  828. _(c, key) {
  829. if (c === " ") {
  830. this.value = !this.value;
  831. } else if (c === "1") {
  832. this.value = true;
  833. } else if (c === "0") {
  834. this.value = false;
  835. } else return this.bell();
  836. this.render();
  837. }
  838. render() {
  839. if (this.closed) return;
  840. if (this.firstRender) this.out.write(cursor.hide);
  841. else this.out.write(clear(this.outputText, this.out.columns));
  842. super.render();
  843. this.outputText = [
  844. style.symbol(this.done, this.aborted),
  845. color.bold(this.msg),
  846. style.delimiter(this.done),
  847. this.value ? this.inactive : color.cyan().underline(this.inactive),
  848. color.gray("/"),
  849. this.value ? color.cyan().underline(this.active) : this.active
  850. ].join(" ");
  851. this.out.write(erase.line + cursor.to(0) + this.outputText);
  852. }
  853. };
  854. module2.exports = TogglePrompt;
  855. }
  856. });
  857. // node_modules/prompts/lib/dateparts/datepart.js
  858. var require_datepart = __commonJS({
  859. "node_modules/prompts/lib/dateparts/datepart.js"(exports2, module2) {
  860. "use strict";
  861. var DatePart = class _DatePart {
  862. constructor({ token, date, parts, locales }) {
  863. this.token = token;
  864. this.date = date || /* @__PURE__ */ new Date();
  865. this.parts = parts || [this];
  866. this.locales = locales || {};
  867. }
  868. up() {
  869. }
  870. down() {
  871. }
  872. next() {
  873. const currentIdx = this.parts.indexOf(this);
  874. return this.parts.find((part, idx) => idx > currentIdx && part instanceof _DatePart);
  875. }
  876. setTo(val) {
  877. }
  878. prev() {
  879. let parts = [].concat(this.parts).reverse();
  880. const currentIdx = parts.indexOf(this);
  881. return parts.find((part, idx) => idx > currentIdx && part instanceof _DatePart);
  882. }
  883. toString() {
  884. return String(this.date);
  885. }
  886. };
  887. module2.exports = DatePart;
  888. }
  889. });
  890. // node_modules/prompts/lib/dateparts/meridiem.js
  891. var require_meridiem = __commonJS({
  892. "node_modules/prompts/lib/dateparts/meridiem.js"(exports2, module2) {
  893. "use strict";
  894. var DatePart = require_datepart();
  895. var Meridiem = class extends DatePart {
  896. constructor(opts = {}) {
  897. super(opts);
  898. }
  899. up() {
  900. this.date.setHours((this.date.getHours() + 12) % 24);
  901. }
  902. down() {
  903. this.up();
  904. }
  905. toString() {
  906. let meridiem = this.date.getHours() > 12 ? "pm" : "am";
  907. return /\A/.test(this.token) ? meridiem.toUpperCase() : meridiem;
  908. }
  909. };
  910. module2.exports = Meridiem;
  911. }
  912. });
  913. // node_modules/prompts/lib/dateparts/day.js
  914. var require_day = __commonJS({
  915. "node_modules/prompts/lib/dateparts/day.js"(exports2, module2) {
  916. "use strict";
  917. var DatePart = require_datepart();
  918. var pos = (n) => {
  919. n = n % 10;
  920. return n === 1 ? "st" : n === 2 ? "nd" : n === 3 ? "rd" : "th";
  921. };
  922. var Day = class extends DatePart {
  923. constructor(opts = {}) {
  924. super(opts);
  925. }
  926. up() {
  927. this.date.setDate(this.date.getDate() + 1);
  928. }
  929. down() {
  930. this.date.setDate(this.date.getDate() - 1);
  931. }
  932. setTo(val) {
  933. this.date.setDate(parseInt(val.substr(-2)));
  934. }
  935. toString() {
  936. let date = this.date.getDate();
  937. let day = this.date.getDay();
  938. return this.token === "DD" ? String(date).padStart(2, "0") : this.token === "Do" ? date + pos(date) : this.token === "d" ? day + 1 : this.token === "ddd" ? this.locales.weekdaysShort[day] : this.token === "dddd" ? this.locales.weekdays[day] : date;
  939. }
  940. };
  941. module2.exports = Day;
  942. }
  943. });
  944. // node_modules/prompts/lib/dateparts/hours.js
  945. var require_hours = __commonJS({
  946. "node_modules/prompts/lib/dateparts/hours.js"(exports2, module2) {
  947. "use strict";
  948. var DatePart = require_datepart();
  949. var Hours = class extends DatePart {
  950. constructor(opts = {}) {
  951. super(opts);
  952. }
  953. up() {
  954. this.date.setHours(this.date.getHours() + 1);
  955. }
  956. down() {
  957. this.date.setHours(this.date.getHours() - 1);
  958. }
  959. setTo(val) {
  960. this.date.setHours(parseInt(val.substr(-2)));
  961. }
  962. toString() {
  963. let hours = this.date.getHours();
  964. if (/h/.test(this.token))
  965. hours = hours % 12 || 12;
  966. return this.token.length > 1 ? String(hours).padStart(2, "0") : hours;
  967. }
  968. };
  969. module2.exports = Hours;
  970. }
  971. });
  972. // node_modules/prompts/lib/dateparts/milliseconds.js
  973. var require_milliseconds = __commonJS({
  974. "node_modules/prompts/lib/dateparts/milliseconds.js"(exports2, module2) {
  975. "use strict";
  976. var DatePart = require_datepart();
  977. var Milliseconds = class extends DatePart {
  978. constructor(opts = {}) {
  979. super(opts);
  980. }
  981. up() {
  982. this.date.setMilliseconds(this.date.getMilliseconds() + 1);
  983. }
  984. down() {
  985. this.date.setMilliseconds(this.date.getMilliseconds() - 1);
  986. }
  987. setTo(val) {
  988. this.date.setMilliseconds(parseInt(val.substr(-this.token.length)));
  989. }
  990. toString() {
  991. return String(this.date.getMilliseconds()).padStart(4, "0").substr(0, this.token.length);
  992. }
  993. };
  994. module2.exports = Milliseconds;
  995. }
  996. });
  997. // node_modules/prompts/lib/dateparts/minutes.js
  998. var require_minutes = __commonJS({
  999. "node_modules/prompts/lib/dateparts/minutes.js"(exports2, module2) {
  1000. "use strict";
  1001. var DatePart = require_datepart();
  1002. var Minutes = class extends DatePart {
  1003. constructor(opts = {}) {
  1004. super(opts);
  1005. }
  1006. up() {
  1007. this.date.setMinutes(this.date.getMinutes() + 1);
  1008. }
  1009. down() {
  1010. this.date.setMinutes(this.date.getMinutes() - 1);
  1011. }
  1012. setTo(val) {
  1013. this.date.setMinutes(parseInt(val.substr(-2)));
  1014. }
  1015. toString() {
  1016. let m = this.date.getMinutes();
  1017. return this.token.length > 1 ? String(m).padStart(2, "0") : m;
  1018. }
  1019. };
  1020. module2.exports = Minutes;
  1021. }
  1022. });
  1023. // node_modules/prompts/lib/dateparts/month.js
  1024. var require_month = __commonJS({
  1025. "node_modules/prompts/lib/dateparts/month.js"(exports2, module2) {
  1026. "use strict";
  1027. var DatePart = require_datepart();
  1028. var Month = class extends DatePart {
  1029. constructor(opts = {}) {
  1030. super(opts);
  1031. }
  1032. up() {
  1033. this.date.setMonth(this.date.getMonth() + 1);
  1034. }
  1035. down() {
  1036. this.date.setMonth(this.date.getMonth() - 1);
  1037. }
  1038. setTo(val) {
  1039. val = parseInt(val.substr(-2)) - 1;
  1040. this.date.setMonth(val < 0 ? 0 : val);
  1041. }
  1042. toString() {
  1043. let month = this.date.getMonth();
  1044. let tl = this.token.length;
  1045. return tl === 2 ? String(month + 1).padStart(2, "0") : tl === 3 ? this.locales.monthsShort[month] : tl === 4 ? this.locales.months[month] : String(month + 1);
  1046. }
  1047. };
  1048. module2.exports = Month;
  1049. }
  1050. });
  1051. // node_modules/prompts/lib/dateparts/seconds.js
  1052. var require_seconds = __commonJS({
  1053. "node_modules/prompts/lib/dateparts/seconds.js"(exports2, module2) {
  1054. "use strict";
  1055. var DatePart = require_datepart();
  1056. var Seconds = class extends DatePart {
  1057. constructor(opts = {}) {
  1058. super(opts);
  1059. }
  1060. up() {
  1061. this.date.setSeconds(this.date.getSeconds() + 1);
  1062. }
  1063. down() {
  1064. this.date.setSeconds(this.date.getSeconds() - 1);
  1065. }
  1066. setTo(val) {
  1067. this.date.setSeconds(parseInt(val.substr(-2)));
  1068. }
  1069. toString() {
  1070. let s = this.date.getSeconds();
  1071. return this.token.length > 1 ? String(s).padStart(2, "0") : s;
  1072. }
  1073. };
  1074. module2.exports = Seconds;
  1075. }
  1076. });
  1077. // node_modules/prompts/lib/dateparts/year.js
  1078. var require_year = __commonJS({
  1079. "node_modules/prompts/lib/dateparts/year.js"(exports2, module2) {
  1080. "use strict";
  1081. var DatePart = require_datepart();
  1082. var Year = class extends DatePart {
  1083. constructor(opts = {}) {
  1084. super(opts);
  1085. }
  1086. up() {
  1087. this.date.setFullYear(this.date.getFullYear() + 1);
  1088. }
  1089. down() {
  1090. this.date.setFullYear(this.date.getFullYear() - 1);
  1091. }
  1092. setTo(val) {
  1093. this.date.setFullYear(val.substr(-4));
  1094. }
  1095. toString() {
  1096. let year = String(this.date.getFullYear()).padStart(4, "0");
  1097. return this.token.length === 2 ? year.substr(-2) : year;
  1098. }
  1099. };
  1100. module2.exports = Year;
  1101. }
  1102. });
  1103. // node_modules/prompts/lib/dateparts/index.js
  1104. var require_dateparts = __commonJS({
  1105. "node_modules/prompts/lib/dateparts/index.js"(exports2, module2) {
  1106. "use strict";
  1107. module2.exports = {
  1108. DatePart: require_datepart(),
  1109. Meridiem: require_meridiem(),
  1110. Day: require_day(),
  1111. Hours: require_hours(),
  1112. Milliseconds: require_milliseconds(),
  1113. Minutes: require_minutes(),
  1114. Month: require_month(),
  1115. Seconds: require_seconds(),
  1116. Year: require_year()
  1117. };
  1118. }
  1119. });
  1120. // node_modules/prompts/lib/elements/date.js
  1121. var require_date = __commonJS({
  1122. "node_modules/prompts/lib/elements/date.js"(exports2, module2) {
  1123. "use strict";
  1124. var color = require_kleur();
  1125. var Prompt = require_prompt();
  1126. var { style, clear, figures } = require_util();
  1127. var { erase, cursor } = require_src();
  1128. var { DatePart, Meridiem, Day, Hours, Milliseconds, Minutes, Month, Seconds, Year } = require_dateparts();
  1129. var regex = /\\(.)|"((?:\\["\\]|[^"])+)"|(D[Do]?|d{3,4}|d)|(M{1,4})|(YY(?:YY)?)|([aA])|([Hh]{1,2})|(m{1,2})|(s{1,2})|(S{1,4})|./g;
  1130. var regexGroups = {
  1131. 1: ({ token }) => token.replace(/\\(.)/g, "$1"),
  1132. 2: (opts) => new Day(opts),
  1133. // Day // TODO
  1134. 3: (opts) => new Month(opts),
  1135. // Month
  1136. 4: (opts) => new Year(opts),
  1137. // Year
  1138. 5: (opts) => new Meridiem(opts),
  1139. // AM/PM // TODO (special)
  1140. 6: (opts) => new Hours(opts),
  1141. // Hours
  1142. 7: (opts) => new Minutes(opts),
  1143. // Minutes
  1144. 8: (opts) => new Seconds(opts),
  1145. // Seconds
  1146. 9: (opts) => new Milliseconds(opts)
  1147. // Fractional seconds
  1148. };
  1149. var dfltLocales = {
  1150. months: "January,February,March,April,May,June,July,August,September,October,November,December".split(","),
  1151. monthsShort: "Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec".split(","),
  1152. weekdays: "Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday".split(","),
  1153. weekdaysShort: "Sun,Mon,Tue,Wed,Thu,Fri,Sat".split(",")
  1154. };
  1155. var DatePrompt = class extends Prompt {
  1156. constructor(opts = {}) {
  1157. super(opts);
  1158. this.msg = opts.message;
  1159. this.cursor = 0;
  1160. this.typed = "";
  1161. this.locales = Object.assign(dfltLocales, opts.locales);
  1162. this._date = opts.initial || /* @__PURE__ */ new Date();
  1163. this.errorMsg = opts.error || "Please Enter A Valid Value";
  1164. this.validator = opts.validate || (() => true);
  1165. this.mask = opts.mask || "YYYY-MM-DD HH:mm:ss";
  1166. this.clear = clear("", this.out.columns);
  1167. this.render();
  1168. }
  1169. get value() {
  1170. return this.date;
  1171. }
  1172. get date() {
  1173. return this._date;
  1174. }
  1175. set date(date) {
  1176. if (date) this._date.setTime(date.getTime());
  1177. }
  1178. set mask(mask) {
  1179. let result;
  1180. this.parts = [];
  1181. while (result = regex.exec(mask)) {
  1182. let match = result.shift();
  1183. let idx = result.findIndex((gr) => gr != null);
  1184. this.parts.push(idx in regexGroups ? regexGroups[idx]({ token: result[idx] || match, date: this.date, parts: this.parts, locales: this.locales }) : result[idx] || match);
  1185. }
  1186. let parts = this.parts.reduce((arr, i) => {
  1187. if (typeof i === "string" && typeof arr[arr.length - 1] === "string")
  1188. arr[arr.length - 1] += i;
  1189. else arr.push(i);
  1190. return arr;
  1191. }, []);
  1192. this.parts.splice(0);
  1193. this.parts.push(...parts);
  1194. this.reset();
  1195. }
  1196. moveCursor(n) {
  1197. this.typed = "";
  1198. this.cursor = n;
  1199. this.fire();
  1200. }
  1201. reset() {
  1202. this.moveCursor(this.parts.findIndex((p) => p instanceof DatePart));
  1203. this.fire();
  1204. this.render();
  1205. }
  1206. exit() {
  1207. this.abort();
  1208. }
  1209. abort() {
  1210. this.done = this.aborted = true;
  1211. this.error = false;
  1212. this.fire();
  1213. this.render();
  1214. this.out.write("\n");
  1215. this.close();
  1216. }
  1217. async validate() {
  1218. let valid = await this.validator(this.value);
  1219. if (typeof valid === "string") {
  1220. this.errorMsg = valid;
  1221. valid = false;
  1222. }
  1223. this.error = !valid;
  1224. }
  1225. async submit() {
  1226. await this.validate();
  1227. if (this.error) {
  1228. this.color = "red";
  1229. this.fire();
  1230. this.render();
  1231. return;
  1232. }
  1233. this.done = true;
  1234. this.aborted = false;
  1235. this.fire();
  1236. this.render();
  1237. this.out.write("\n");
  1238. this.close();
  1239. }
  1240. up() {
  1241. this.typed = "";
  1242. this.parts[this.cursor].up();
  1243. this.render();
  1244. }
  1245. down() {
  1246. this.typed = "";
  1247. this.parts[this.cursor].down();
  1248. this.render();
  1249. }
  1250. left() {
  1251. let prev = this.parts[this.cursor].prev();
  1252. if (prev == null) return this.bell();
  1253. this.moveCursor(this.parts.indexOf(prev));
  1254. this.render();
  1255. }
  1256. right() {
  1257. let next = this.parts[this.cursor].next();
  1258. if (next == null) return this.bell();
  1259. this.moveCursor(this.parts.indexOf(next));
  1260. this.render();
  1261. }
  1262. next() {
  1263. let next = this.parts[this.cursor].next();
  1264. this.moveCursor(next ? this.parts.indexOf(next) : this.parts.findIndex((part) => part instanceof DatePart));
  1265. this.render();
  1266. }
  1267. _(c) {
  1268. if (/\d/.test(c)) {
  1269. this.typed += c;
  1270. this.parts[this.cursor].setTo(this.typed);
  1271. this.render();
  1272. }
  1273. }
  1274. render() {
  1275. if (this.closed) return;
  1276. if (this.firstRender) this.out.write(cursor.hide);
  1277. else this.out.write(clear(this.outputText, this.out.columns));
  1278. super.render();
  1279. this.outputText = [
  1280. style.symbol(this.done, this.aborted),
  1281. color.bold(this.msg),
  1282. style.delimiter(false),
  1283. this.parts.reduce((arr, p, idx) => arr.concat(idx === this.cursor && !this.done ? color.cyan().underline(p.toString()) : p), []).join("")
  1284. ].join(" ");
  1285. if (this.error) {
  1286. this.outputText += this.errorMsg.split("\n").reduce(
  1287. (a, l, i) => a + `
  1288. ${i ? ` ` : figures.pointerSmall} ${color.red().italic(l)}`,
  1289. ``
  1290. );
  1291. }
  1292. this.out.write(erase.line + cursor.to(0) + this.outputText);
  1293. }
  1294. };
  1295. module2.exports = DatePrompt;
  1296. }
  1297. });
  1298. // node_modules/prompts/lib/elements/number.js
  1299. var require_number = __commonJS({
  1300. "node_modules/prompts/lib/elements/number.js"(exports2, module2) {
  1301. var color = require_kleur();
  1302. var Prompt = require_prompt();
  1303. var { cursor, erase } = require_src();
  1304. var { style, figures, clear, lines } = require_util();
  1305. var isNumber = /[0-9]/;
  1306. var isDef = (any) => any !== void 0;
  1307. var round = (number, precision) => {
  1308. let factor = Math.pow(10, precision);
  1309. return Math.round(number * factor) / factor;
  1310. };
  1311. var NumberPrompt = class extends Prompt {
  1312. constructor(opts = {}) {
  1313. super(opts);
  1314. this.transform = style.render(opts.style);
  1315. this.msg = opts.message;
  1316. this.initial = isDef(opts.initial) ? opts.initial : "";
  1317. this.float = !!opts.float;
  1318. this.round = opts.round || 2;
  1319. this.inc = opts.increment || 1;
  1320. this.min = isDef(opts.min) ? opts.min : -Infinity;
  1321. this.max = isDef(opts.max) ? opts.max : Infinity;
  1322. this.errorMsg = opts.error || `Please Enter A Valid Value`;
  1323. this.validator = opts.validate || (() => true);
  1324. this.color = `cyan`;
  1325. this.value = ``;
  1326. this.typed = ``;
  1327. this.lastHit = 0;
  1328. this.render();
  1329. }
  1330. set value(v) {
  1331. if (!v && v !== 0) {
  1332. this.placeholder = true;
  1333. this.rendered = color.gray(this.transform.render(`${this.initial}`));
  1334. this._value = ``;
  1335. } else {
  1336. this.placeholder = false;
  1337. this.rendered = this.transform.render(`${round(v, this.round)}`);
  1338. this._value = round(v, this.round);
  1339. }
  1340. this.fire();
  1341. }
  1342. get value() {
  1343. return this._value;
  1344. }
  1345. parse(x) {
  1346. return this.float ? parseFloat(x) : parseInt(x);
  1347. }
  1348. valid(c) {
  1349. return c === `-` || c === `.` && this.float || isNumber.test(c);
  1350. }
  1351. reset() {
  1352. this.typed = ``;
  1353. this.value = ``;
  1354. this.fire();
  1355. this.render();
  1356. }
  1357. exit() {
  1358. this.abort();
  1359. }
  1360. abort() {
  1361. let x = this.value;
  1362. this.value = x !== `` ? x : this.initial;
  1363. this.done = this.aborted = true;
  1364. this.error = false;
  1365. this.fire();
  1366. this.render();
  1367. this.out.write(`
  1368. `);
  1369. this.close();
  1370. }
  1371. async validate() {
  1372. let valid = await this.validator(this.value);
  1373. if (typeof valid === `string`) {
  1374. this.errorMsg = valid;
  1375. valid = false;
  1376. }
  1377. this.error = !valid;
  1378. }
  1379. async submit() {
  1380. await this.validate();
  1381. if (this.error) {
  1382. this.color = `red`;
  1383. this.fire();
  1384. this.render();
  1385. return;
  1386. }
  1387. let x = this.value;
  1388. this.value = x !== `` ? x : this.initial;
  1389. this.done = true;
  1390. this.aborted = false;
  1391. this.error = false;
  1392. this.fire();
  1393. this.render();
  1394. this.out.write(`
  1395. `);
  1396. this.close();
  1397. }
  1398. up() {
  1399. this.typed = ``;
  1400. if (this.value === "") {
  1401. this.value = this.min - this.inc;
  1402. }
  1403. if (this.value >= this.max) return this.bell();
  1404. this.value += this.inc;
  1405. this.color = `cyan`;
  1406. this.fire();
  1407. this.render();
  1408. }
  1409. down() {
  1410. this.typed = ``;
  1411. if (this.value === "") {
  1412. this.value = this.min + this.inc;
  1413. }
  1414. if (this.value <= this.min) return this.bell();
  1415. this.value -= this.inc;
  1416. this.color = `cyan`;
  1417. this.fire();
  1418. this.render();
  1419. }
  1420. delete() {
  1421. let val = this.value.toString();
  1422. if (val.length === 0) return this.bell();
  1423. this.value = this.parse(val = val.slice(0, -1)) || ``;
  1424. if (this.value !== "" && this.value < this.min) {
  1425. this.value = this.min;
  1426. }
  1427. this.color = `cyan`;
  1428. this.fire();
  1429. this.render();
  1430. }
  1431. next() {
  1432. this.value = this.initial;
  1433. this.fire();
  1434. this.render();
  1435. }
  1436. _(c, key) {
  1437. if (!this.valid(c)) return this.bell();
  1438. const now = Date.now();
  1439. if (now - this.lastHit > 1e3) this.typed = ``;
  1440. this.typed += c;
  1441. this.lastHit = now;
  1442. this.color = `cyan`;
  1443. if (c === `.`) return this.fire();
  1444. this.value = Math.min(this.parse(this.typed), this.max);
  1445. if (this.value > this.max) this.value = this.max;
  1446. if (this.value < this.min) this.value = this.min;
  1447. this.fire();
  1448. this.render();
  1449. }
  1450. render() {
  1451. if (this.closed) return;
  1452. if (!this.firstRender) {
  1453. if (this.outputError)
  1454. this.out.write(cursor.down(lines(this.outputError, this.out.columns) - 1) + clear(this.outputError, this.out.columns));
  1455. this.out.write(clear(this.outputText, this.out.columns));
  1456. }
  1457. super.render();
  1458. this.outputError = "";
  1459. this.outputText = [
  1460. style.symbol(this.done, this.aborted),
  1461. color.bold(this.msg),
  1462. style.delimiter(this.done),
  1463. !this.done || !this.done && !this.placeholder ? color[this.color]().underline(this.rendered) : this.rendered
  1464. ].join(` `);
  1465. if (this.error) {
  1466. this.outputError += this.errorMsg.split(`
  1467. `).reduce((a, l, i) => a + `
  1468. ${i ? ` ` : figures.pointerSmall} ${color.red().italic(l)}`, ``);
  1469. }
  1470. this.out.write(erase.line + cursor.to(0) + this.outputText + cursor.save + this.outputError + cursor.restore);
  1471. }
  1472. };
  1473. module2.exports = NumberPrompt;
  1474. }
  1475. });
  1476. // node_modules/prompts/lib/elements/multiselect.js
  1477. var require_multiselect = __commonJS({
  1478. "node_modules/prompts/lib/elements/multiselect.js"(exports2, module2) {
  1479. "use strict";
  1480. var color = require_kleur();
  1481. var { cursor } = require_src();
  1482. var Prompt = require_prompt();
  1483. var { clear, figures, style, wrap, entriesToDisplay } = require_util();
  1484. var MultiselectPrompt = class extends Prompt {
  1485. constructor(opts = {}) {
  1486. super(opts);
  1487. this.msg = opts.message;
  1488. this.cursor = opts.cursor || 0;
  1489. this.scrollIndex = opts.cursor || 0;
  1490. this.hint = opts.hint || "";
  1491. this.warn = opts.warn || "- This option is disabled -";
  1492. this.minSelected = opts.min;
  1493. this.showMinError = false;
  1494. this.maxChoices = opts.max;
  1495. this.instructions = opts.instructions;
  1496. this.optionsPerPage = opts.optionsPerPage || 10;
  1497. this.value = opts.choices.map((ch, idx) => {
  1498. if (typeof ch === "string")
  1499. ch = { title: ch, value: idx };
  1500. return {
  1501. title: ch && (ch.title || ch.value || ch),
  1502. description: ch && ch.description,
  1503. value: ch && (ch.value === void 0 ? idx : ch.value),
  1504. selected: ch && ch.selected,
  1505. disabled: ch && ch.disabled
  1506. };
  1507. });
  1508. this.clear = clear("", this.out.columns);
  1509. if (!opts.overrideRender) {
  1510. this.render();
  1511. }
  1512. }
  1513. reset() {
  1514. this.value.map((v) => !v.selected);
  1515. this.cursor = 0;
  1516. this.fire();
  1517. this.render();
  1518. }
  1519. selected() {
  1520. return this.value.filter((v) => v.selected);
  1521. }
  1522. exit() {
  1523. this.abort();
  1524. }
  1525. abort() {
  1526. this.done = this.aborted = true;
  1527. this.fire();
  1528. this.render();
  1529. this.out.write("\n");
  1530. this.close();
  1531. }
  1532. submit() {
  1533. const selected = this.value.filter((e) => e.selected);
  1534. if (this.minSelected && selected.length < this.minSelected) {
  1535. this.showMinError = true;
  1536. this.render();
  1537. } else {
  1538. this.done = true;
  1539. this.aborted = false;
  1540. this.fire();
  1541. this.render();
  1542. this.out.write("\n");
  1543. this.close();
  1544. }
  1545. }
  1546. first() {
  1547. this.cursor = 0;
  1548. this.render();
  1549. }
  1550. last() {
  1551. this.cursor = this.value.length - 1;
  1552. this.render();
  1553. }
  1554. next() {
  1555. this.cursor = (this.cursor + 1) % this.value.length;
  1556. this.render();
  1557. }
  1558. up() {
  1559. if (this.cursor === 0) {
  1560. this.cursor = this.value.length - 1;
  1561. } else {
  1562. this.cursor--;
  1563. }
  1564. this.render();
  1565. }
  1566. down() {
  1567. if (this.cursor === this.value.length - 1) {
  1568. this.cursor = 0;
  1569. } else {
  1570. this.cursor++;
  1571. }
  1572. this.render();
  1573. }
  1574. left() {
  1575. this.value[this.cursor].selected = false;
  1576. this.render();
  1577. }
  1578. right() {
  1579. if (this.value.filter((e) => e.selected).length >= this.maxChoices) return this.bell();
  1580. this.value[this.cursor].selected = true;
  1581. this.render();
  1582. }
  1583. handleSpaceToggle() {
  1584. const v = this.value[this.cursor];
  1585. if (v.selected) {
  1586. v.selected = false;
  1587. this.render();
  1588. } else if (v.disabled || this.value.filter((e) => e.selected).length >= this.maxChoices) {
  1589. return this.bell();
  1590. } else {
  1591. v.selected = true;
  1592. this.render();
  1593. }
  1594. }
  1595. toggleAll() {
  1596. if (this.maxChoices !== void 0 || this.value[this.cursor].disabled) {
  1597. return this.bell();
  1598. }
  1599. const newSelected = !this.value[this.cursor].selected;
  1600. this.value.filter((v) => !v.disabled).forEach((v) => v.selected = newSelected);
  1601. this.render();
  1602. }
  1603. _(c, key) {
  1604. if (c === " ") {
  1605. this.handleSpaceToggle();
  1606. } else if (c === "a") {
  1607. this.toggleAll();
  1608. } else {
  1609. return this.bell();
  1610. }
  1611. }
  1612. renderInstructions() {
  1613. if (this.instructions === void 0 || this.instructions) {
  1614. if (typeof this.instructions === "string") {
  1615. return this.instructions;
  1616. }
  1617. return `
  1618. Instructions:
  1619. ${figures.arrowUp}/${figures.arrowDown}: Highlight option
  1620. ${figures.arrowLeft}/${figures.arrowRight}/[space]: Toggle selection
  1621. ` + (this.maxChoices === void 0 ? ` a: Toggle all
  1622. ` : "") + ` enter/return: Complete answer`;
  1623. }
  1624. return "";
  1625. }
  1626. renderOption(cursor2, v, i, arrowIndicator) {
  1627. const prefix = (v.selected ? color.green(figures.radioOn) : figures.radioOff) + " " + arrowIndicator + " ";
  1628. let title, desc;
  1629. if (v.disabled) {
  1630. title = cursor2 === i ? color.gray().underline(v.title) : color.strikethrough().gray(v.title);
  1631. } else {
  1632. title = cursor2 === i ? color.cyan().underline(v.title) : v.title;
  1633. if (cursor2 === i && v.description) {
  1634. desc = ` - ${v.description}`;
  1635. if (prefix.length + title.length + desc.length >= this.out.columns || v.description.split(/\r?\n/).length > 1) {
  1636. desc = "\n" + wrap(v.description, { margin: prefix.length, width: this.out.columns });
  1637. }
  1638. }
  1639. }
  1640. return prefix + title + color.gray(desc || "");
  1641. }
  1642. // shared with autocompleteMultiselect
  1643. paginateOptions(options) {
  1644. if (options.length === 0) {
  1645. return color.red("No matches for this query.");
  1646. }
  1647. let { startIndex, endIndex } = entriesToDisplay(this.cursor, options.length, this.optionsPerPage);
  1648. let prefix, styledOptions = [];
  1649. for (let i = startIndex; i < endIndex; i++) {
  1650. if (i === startIndex && startIndex > 0) {
  1651. prefix = figures.arrowUp;
  1652. } else if (i === endIndex - 1 && endIndex < options.length) {
  1653. prefix = figures.arrowDown;
  1654. } else {
  1655. prefix = " ";
  1656. }
  1657. styledOptions.push(this.renderOption(this.cursor, options[i], i, prefix));
  1658. }
  1659. return "\n" + styledOptions.join("\n");
  1660. }
  1661. // shared with autocomleteMultiselect
  1662. renderOptions(options) {
  1663. if (!this.done) {
  1664. return this.paginateOptions(options);
  1665. }
  1666. return "";
  1667. }
  1668. renderDoneOrInstructions() {
  1669. if (this.done) {
  1670. return this.value.filter((e) => e.selected).map((v) => v.title).join(", ");
  1671. }
  1672. const output = [color.gray(this.hint), this.renderInstructions()];
  1673. if (this.value[this.cursor].disabled) {
  1674. output.push(color.yellow(this.warn));
  1675. }
  1676. return output.join(" ");
  1677. }
  1678. render() {
  1679. if (this.closed) return;
  1680. if (this.firstRender) this.out.write(cursor.hide);
  1681. super.render();
  1682. let prompt = [
  1683. style.symbol(this.done, this.aborted),
  1684. color.bold(this.msg),
  1685. style.delimiter(false),
  1686. this.renderDoneOrInstructions()
  1687. ].join(" ");
  1688. if (this.showMinError) {
  1689. prompt += color.red(`You must select a minimum of ${this.minSelected} choices.`);
  1690. this.showMinError = false;
  1691. }
  1692. prompt += this.renderOptions(this.value);
  1693. this.out.write(this.clear + prompt);
  1694. this.clear = clear(prompt, this.out.columns);
  1695. }
  1696. };
  1697. module2.exports = MultiselectPrompt;
  1698. }
  1699. });
  1700. // node_modules/prompts/lib/elements/autocomplete.js
  1701. var require_autocomplete = __commonJS({
  1702. "node_modules/prompts/lib/elements/autocomplete.js"(exports2, module2) {
  1703. "use strict";
  1704. var color = require_kleur();
  1705. var Prompt = require_prompt();
  1706. var { erase, cursor } = require_src();
  1707. var { style, clear, figures, wrap, entriesToDisplay } = require_util();
  1708. var getVal = (arr, i) => arr[i] && (arr[i].value || arr[i].title || arr[i]);
  1709. var getTitle = (arr, i) => arr[i] && (arr[i].title || arr[i].value || arr[i]);
  1710. var getIndex = (arr, valOrTitle) => {
  1711. const index = arr.findIndex((el) => el.value === valOrTitle || el.title === valOrTitle);
  1712. return index > -1 ? index : void 0;
  1713. };
  1714. var AutocompletePrompt = class extends Prompt {
  1715. constructor(opts = {}) {
  1716. super(opts);
  1717. this.msg = opts.message;
  1718. this.suggest = opts.suggest;
  1719. this.choices = opts.choices;
  1720. this.initial = typeof opts.initial === "number" ? opts.initial : getIndex(opts.choices, opts.initial);
  1721. this.select = this.initial || opts.cursor || 0;
  1722. this.i18n = { noMatches: opts.noMatches || "no matches found" };
  1723. this.fallback = opts.fallback || this.initial;
  1724. this.clearFirst = opts.clearFirst || false;
  1725. this.suggestions = [];
  1726. this.input = "";
  1727. this.limit = opts.limit || 10;
  1728. this.cursor = 0;
  1729. this.transform = style.render(opts.style);
  1730. this.scale = this.transform.scale;
  1731. this.render = this.render.bind(this);
  1732. this.complete = this.complete.bind(this);
  1733. this.clear = clear("", this.out.columns);
  1734. this.complete(this.render);
  1735. this.render();
  1736. }
  1737. set fallback(fb) {
  1738. this._fb = Number.isSafeInteger(parseInt(fb)) ? parseInt(fb) : fb;
  1739. }
  1740. get fallback() {
  1741. let choice;
  1742. if (typeof this._fb === "number")
  1743. choice = this.choices[this._fb];
  1744. else if (typeof this._fb === "string")
  1745. choice = { title: this._fb };
  1746. return choice || this._fb || { title: this.i18n.noMatches };
  1747. }
  1748. moveSelect(i) {
  1749. this.select = i;
  1750. if (this.suggestions.length > 0)
  1751. this.value = getVal(this.suggestions, i);
  1752. else this.value = this.fallback.value;
  1753. this.fire();
  1754. }
  1755. async complete(cb) {
  1756. const p = this.completing = this.suggest(this.input, this.choices);
  1757. const suggestions = await p;
  1758. if (this.completing !== p) return;
  1759. this.suggestions = suggestions.map((s, i, arr) => ({ title: getTitle(arr, i), value: getVal(arr, i), description: s.description }));
  1760. this.completing = false;
  1761. const l = Math.max(suggestions.length - 1, 0);
  1762. this.moveSelect(Math.min(l, this.select));
  1763. cb && cb();
  1764. }
  1765. reset() {
  1766. this.input = "";
  1767. this.complete(() => {
  1768. this.moveSelect(this.initial !== void 0 ? this.initial : 0);
  1769. this.render();
  1770. });
  1771. this.render();
  1772. }
  1773. exit() {
  1774. if (this.clearFirst && this.input.length > 0) {
  1775. this.reset();
  1776. } else {
  1777. this.done = this.exited = true;
  1778. this.aborted = false;
  1779. this.fire();
  1780. this.render();
  1781. this.out.write("\n");
  1782. this.close();
  1783. }
  1784. }
  1785. abort() {
  1786. this.done = this.aborted = true;
  1787. this.exited = false;
  1788. this.fire();
  1789. this.render();
  1790. this.out.write("\n");
  1791. this.close();
  1792. }
  1793. submit() {
  1794. this.done = true;
  1795. this.aborted = this.exited = false;
  1796. this.fire();
  1797. this.render();
  1798. this.out.write("\n");
  1799. this.close();
  1800. }
  1801. _(c, key) {
  1802. let s1 = this.input.slice(0, this.cursor);
  1803. let s2 = this.input.slice(this.cursor);
  1804. this.input = `${s1}${c}${s2}`;
  1805. this.cursor = s1.length + 1;
  1806. this.complete(this.render);
  1807. this.render();
  1808. }
  1809. delete() {
  1810. if (this.cursor === 0) return this.bell();
  1811. let s1 = this.input.slice(0, this.cursor - 1);
  1812. let s2 = this.input.slice(this.cursor);
  1813. this.input = `${s1}${s2}`;
  1814. this.complete(this.render);
  1815. this.cursor = this.cursor - 1;
  1816. this.render();
  1817. }
  1818. deleteForward() {
  1819. if (this.cursor * this.scale >= this.rendered.length) return this.bell();
  1820. let s1 = this.input.slice(0, this.cursor);
  1821. let s2 = this.input.slice(this.cursor + 1);
  1822. this.input = `${s1}${s2}`;
  1823. this.complete(this.render);
  1824. this.render();
  1825. }
  1826. first() {
  1827. this.moveSelect(0);
  1828. this.render();
  1829. }
  1830. last() {
  1831. this.moveSelect(this.suggestions.length - 1);
  1832. this.render();
  1833. }
  1834. up() {
  1835. if (this.select === 0) {
  1836. this.moveSelect(this.suggestions.length - 1);
  1837. } else {
  1838. this.moveSelect(this.select - 1);
  1839. }
  1840. this.render();
  1841. }
  1842. down() {
  1843. if (this.select === this.suggestions.length - 1) {
  1844. this.moveSelect(0);
  1845. } else {
  1846. this.moveSelect(this.select + 1);
  1847. }
  1848. this.render();
  1849. }
  1850. next() {
  1851. if (this.select === this.suggestions.length - 1) {
  1852. this.moveSelect(0);
  1853. } else this.moveSelect(this.select + 1);
  1854. this.render();
  1855. }
  1856. nextPage() {
  1857. this.moveSelect(Math.min(this.select + this.limit, this.suggestions.length - 1));
  1858. this.render();
  1859. }
  1860. prevPage() {
  1861. this.moveSelect(Math.max(this.select - this.limit, 0));
  1862. this.render();
  1863. }
  1864. left() {
  1865. if (this.cursor <= 0) return this.bell();
  1866. this.cursor = this.cursor - 1;
  1867. this.render();
  1868. }
  1869. right() {
  1870. if (this.cursor * this.scale >= this.rendered.length) return this.bell();
  1871. this.cursor = this.cursor + 1;
  1872. this.render();
  1873. }
  1874. renderOption(v, hovered, isStart, isEnd) {
  1875. let desc;
  1876. let prefix = isStart ? figures.arrowUp : isEnd ? figures.arrowDown : " ";
  1877. let title = hovered ? color.cyan().underline(v.title) : v.title;
  1878. prefix = (hovered ? color.cyan(figures.pointer) + " " : " ") + prefix;
  1879. if (v.description) {
  1880. desc = ` - ${v.description}`;
  1881. if (prefix.length + title.length + desc.length >= this.out.columns || v.description.split(/\r?\n/).length > 1) {
  1882. desc = "\n" + wrap(v.description, { margin: 3, width: this.out.columns });
  1883. }
  1884. }
  1885. return prefix + " " + title + color.gray(desc || "");
  1886. }
  1887. render() {
  1888. if (this.closed) return;
  1889. if (this.firstRender) this.out.write(cursor.hide);
  1890. else this.out.write(clear(this.outputText, this.out.columns));
  1891. super.render();
  1892. let { startIndex, endIndex } = entriesToDisplay(this.select, this.choices.length, this.limit);
  1893. this.outputText = [
  1894. style.symbol(this.done, this.aborted, this.exited),
  1895. color.bold(this.msg),
  1896. style.delimiter(this.completing),
  1897. this.done && this.suggestions[this.select] ? this.suggestions[this.select].title : this.rendered = this.transform.render(this.input)
  1898. ].join(" ");
  1899. if (!this.done) {
  1900. const suggestions = this.suggestions.slice(startIndex, endIndex).map((item, i) => this.renderOption(
  1901. item,
  1902. this.select === i + startIndex,
  1903. i === 0 && startIndex > 0,
  1904. i + startIndex === endIndex - 1 && endIndex < this.choices.length
  1905. )).join("\n");
  1906. this.outputText += `
  1907. ` + (suggestions || color.gray(this.fallback.title));
  1908. }
  1909. this.out.write(erase.line + cursor.to(0) + this.outputText);
  1910. }
  1911. };
  1912. module2.exports = AutocompletePrompt;
  1913. }
  1914. });
  1915. // node_modules/prompts/lib/elements/autocompleteMultiselect.js
  1916. var require_autocompleteMultiselect = __commonJS({
  1917. "node_modules/prompts/lib/elements/autocompleteMultiselect.js"(exports2, module2) {
  1918. "use strict";
  1919. var color = require_kleur();
  1920. var { cursor } = require_src();
  1921. var MultiselectPrompt = require_multiselect();
  1922. var { clear, style, figures } = require_util();
  1923. var AutocompleteMultiselectPrompt = class extends MultiselectPrompt {
  1924. constructor(opts = {}) {
  1925. opts.overrideRender = true;
  1926. super(opts);
  1927. this.inputValue = "";
  1928. this.clear = clear("", this.out.columns);
  1929. this.filteredOptions = this.value;
  1930. this.render();
  1931. }
  1932. last() {
  1933. this.cursor = this.filteredOptions.length - 1;
  1934. this.render();
  1935. }
  1936. next() {
  1937. this.cursor = (this.cursor + 1) % this.filteredOptions.length;
  1938. this.render();
  1939. }
  1940. up() {
  1941. if (this.cursor === 0) {
  1942. this.cursor = this.filteredOptions.length - 1;
  1943. } else {
  1944. this.cursor--;
  1945. }
  1946. this.render();
  1947. }
  1948. down() {
  1949. if (this.cursor === this.filteredOptions.length - 1) {
  1950. this.cursor = 0;
  1951. } else {
  1952. this.cursor++;
  1953. }
  1954. this.render();
  1955. }
  1956. left() {
  1957. this.filteredOptions[this.cursor].selected = false;
  1958. this.render();
  1959. }
  1960. right() {
  1961. if (this.value.filter((e) => e.selected).length >= this.maxChoices) return this.bell();
  1962. this.filteredOptions[this.cursor].selected = true;
  1963. this.render();
  1964. }
  1965. delete() {
  1966. if (this.inputValue.length) {
  1967. this.inputValue = this.inputValue.substr(0, this.inputValue.length - 1);
  1968. this.updateFilteredOptions();
  1969. }
  1970. }
  1971. updateFilteredOptions() {
  1972. const currentHighlight = this.filteredOptions[this.cursor];
  1973. this.filteredOptions = this.value.filter((v) => {
  1974. if (this.inputValue) {
  1975. if (typeof v.title === "string") {
  1976. if (v.title.toLowerCase().includes(this.inputValue.toLowerCase())) {
  1977. return true;
  1978. }
  1979. }
  1980. if (typeof v.value === "string") {
  1981. if (v.value.toLowerCase().includes(this.inputValue.toLowerCase())) {
  1982. return true;
  1983. }
  1984. }
  1985. return false;
  1986. }
  1987. return true;
  1988. });
  1989. const newHighlightIndex = this.filteredOptions.findIndex((v) => v === currentHighlight);
  1990. this.cursor = newHighlightIndex < 0 ? 0 : newHighlightIndex;
  1991. this.render();
  1992. }
  1993. handleSpaceToggle() {
  1994. const v = this.filteredOptions[this.cursor];
  1995. if (v.selected) {
  1996. v.selected = false;
  1997. this.render();
  1998. } else if (v.disabled || this.value.filter((e) => e.selected).length >= this.maxChoices) {
  1999. return this.bell();
  2000. } else {
  2001. v.selected = true;
  2002. this.render();
  2003. }
  2004. }
  2005. handleInputChange(c) {
  2006. this.inputValue = this.inputValue + c;
  2007. this.updateFilteredOptions();
  2008. }
  2009. _(c, key) {
  2010. if (c === " ") {
  2011. this.handleSpaceToggle();
  2012. } else {
  2013. this.handleInputChange(c);
  2014. }
  2015. }
  2016. renderInstructions() {
  2017. if (this.instructions === void 0 || this.instructions) {
  2018. if (typeof this.instructions === "string") {
  2019. return this.instructions;
  2020. }
  2021. return `
  2022. Instructions:
  2023. ${figures.arrowUp}/${figures.arrowDown}: Highlight option
  2024. ${figures.arrowLeft}/${figures.arrowRight}/[space]: Toggle selection
  2025. [a,b,c]/delete: Filter choices
  2026. enter/return: Complete answer
  2027. `;
  2028. }
  2029. return "";
  2030. }
  2031. renderCurrentInput() {
  2032. return `
  2033. Filtered results for: ${this.inputValue ? this.inputValue : color.gray("Enter something to filter")}
  2034. `;
  2035. }
  2036. renderOption(cursor2, v, i) {
  2037. let title;
  2038. if (v.disabled) title = cursor2 === i ? color.gray().underline(v.title) : color.strikethrough().gray(v.title);
  2039. else title = cursor2 === i ? color.cyan().underline(v.title) : v.title;
  2040. return (v.selected ? color.green(figures.radioOn) : figures.radioOff) + " " + title;
  2041. }
  2042. renderDoneOrInstructions() {
  2043. if (this.done) {
  2044. return this.value.filter((e) => e.selected).map((v) => v.title).join(", ");
  2045. }
  2046. const output = [color.gray(this.hint), this.renderInstructions(), this.renderCurrentInput()];
  2047. if (this.filteredOptions.length && this.filteredOptions[this.cursor].disabled) {
  2048. output.push(color.yellow(this.warn));
  2049. }
  2050. return output.join(" ");
  2051. }
  2052. render() {
  2053. if (this.closed) return;
  2054. if (this.firstRender) this.out.write(cursor.hide);
  2055. super.render();
  2056. let prompt = [
  2057. style.symbol(this.done, this.aborted),
  2058. color.bold(this.msg),
  2059. style.delimiter(false),
  2060. this.renderDoneOrInstructions()
  2061. ].join(" ");
  2062. if (this.showMinError) {
  2063. prompt += color.red(`You must select a minimum of ${this.minSelected} choices.`);
  2064. this.showMinError = false;
  2065. }
  2066. prompt += this.renderOptions(this.filteredOptions);
  2067. this.out.write(this.clear + prompt);
  2068. this.clear = clear(prompt, this.out.columns);
  2069. }
  2070. };
  2071. module2.exports = AutocompleteMultiselectPrompt;
  2072. }
  2073. });
  2074. // node_modules/prompts/lib/elements/confirm.js
  2075. var require_confirm = __commonJS({
  2076. "node_modules/prompts/lib/elements/confirm.js"(exports2, module2) {
  2077. var color = require_kleur();
  2078. var Prompt = require_prompt();
  2079. var { style, clear } = require_util();
  2080. var { erase, cursor } = require_src();
  2081. var ConfirmPrompt = class extends Prompt {
  2082. constructor(opts = {}) {
  2083. super(opts);
  2084. this.msg = opts.message;
  2085. this.value = opts.initial;
  2086. this.initialValue = !!opts.initial;
  2087. this.yesMsg = opts.yes || "yes";
  2088. this.yesOption = opts.yesOption || "(Y/n)";
  2089. this.noMsg = opts.no || "no";
  2090. this.noOption = opts.noOption || "(y/N)";
  2091. this.render();
  2092. }
  2093. reset() {
  2094. this.value = this.initialValue;
  2095. this.fire();
  2096. this.render();
  2097. }
  2098. exit() {
  2099. this.abort();
  2100. }
  2101. abort() {
  2102. this.done = this.aborted = true;
  2103. this.fire();
  2104. this.render();
  2105. this.out.write("\n");
  2106. this.close();
  2107. }
  2108. submit() {
  2109. this.value = this.value || false;
  2110. this.done = true;
  2111. this.aborted = false;
  2112. this.fire();
  2113. this.render();
  2114. this.out.write("\n");
  2115. this.close();
  2116. }
  2117. _(c, key) {
  2118. if (c.toLowerCase() === "y") {
  2119. this.value = true;
  2120. return this.submit();
  2121. }
  2122. if (c.toLowerCase() === "n") {
  2123. this.value = false;
  2124. return this.submit();
  2125. }
  2126. return this.bell();
  2127. }
  2128. render() {
  2129. if (this.closed) return;
  2130. if (this.firstRender) this.out.write(cursor.hide);
  2131. else this.out.write(clear(this.outputText, this.out.columns));
  2132. super.render();
  2133. this.outputText = [
  2134. style.symbol(this.done, this.aborted),
  2135. color.bold(this.msg),
  2136. style.delimiter(this.done),
  2137. this.done ? this.value ? this.yesMsg : this.noMsg : color.gray(this.initialValue ? this.yesOption : this.noOption)
  2138. ].join(" ");
  2139. this.out.write(erase.line + cursor.to(0) + this.outputText);
  2140. }
  2141. };
  2142. module2.exports = ConfirmPrompt;
  2143. }
  2144. });
  2145. // node_modules/prompts/lib/elements/index.js
  2146. var require_elements = __commonJS({
  2147. "node_modules/prompts/lib/elements/index.js"(exports2, module2) {
  2148. "use strict";
  2149. module2.exports = {
  2150. TextPrompt: require_text(),
  2151. SelectPrompt: require_select(),
  2152. TogglePrompt: require_toggle(),
  2153. DatePrompt: require_date(),
  2154. NumberPrompt: require_number(),
  2155. MultiselectPrompt: require_multiselect(),
  2156. AutocompletePrompt: require_autocomplete(),
  2157. AutocompleteMultiselectPrompt: require_autocompleteMultiselect(),
  2158. ConfirmPrompt: require_confirm()
  2159. };
  2160. }
  2161. });
  2162. // node_modules/prompts/lib/prompts.js
  2163. var require_prompts = __commonJS({
  2164. "node_modules/prompts/lib/prompts.js"(exports2) {
  2165. "use strict";
  2166. var $ = exports2;
  2167. var el = require_elements();
  2168. var noop = (v) => v;
  2169. function toPrompt(type, args, opts = {}) {
  2170. return new Promise((res, rej) => {
  2171. const p = new el[type](args);
  2172. const onAbort = opts.onAbort || noop;
  2173. const onSubmit = opts.onSubmit || noop;
  2174. const onExit = opts.onExit || noop;
  2175. p.on("state", args.onState || noop);
  2176. p.on("submit", (x) => res(onSubmit(x)));
  2177. p.on("exit", (x) => res(onExit(x)));
  2178. p.on("abort", (x) => rej(onAbort(x)));
  2179. });
  2180. }
  2181. $.text = (args) => toPrompt("TextPrompt", args);
  2182. $.password = (args) => {
  2183. args.style = "password";
  2184. return $.text(args);
  2185. };
  2186. $.invisible = (args) => {
  2187. args.style = "invisible";
  2188. return $.text(args);
  2189. };
  2190. $.number = (args) => toPrompt("NumberPrompt", args);
  2191. $.date = (args) => toPrompt("DatePrompt", args);
  2192. $.confirm = (args) => toPrompt("ConfirmPrompt", args);
  2193. $.list = (args) => {
  2194. const sep = args.separator || ",";
  2195. return toPrompt("TextPrompt", args, {
  2196. onSubmit: (str) => str.split(sep).map((s) => s.trim())
  2197. });
  2198. };
  2199. $.toggle = (args) => toPrompt("TogglePrompt", args);
  2200. $.select = (args) => toPrompt("SelectPrompt", args);
  2201. $.multiselect = (args) => {
  2202. args.choices = [].concat(args.choices || []);
  2203. const toSelected = (items) => items.filter((item) => item.selected).map((item) => item.value);
  2204. return toPrompt("MultiselectPrompt", args, {
  2205. onAbort: toSelected,
  2206. onSubmit: toSelected
  2207. });
  2208. };
  2209. $.autocompleteMultiselect = (args) => {
  2210. args.choices = [].concat(args.choices || []);
  2211. const toSelected = (items) => items.filter((item) => item.selected).map((item) => item.value);
  2212. return toPrompt("AutocompleteMultiselectPrompt", args, {
  2213. onAbort: toSelected,
  2214. onSubmit: toSelected
  2215. });
  2216. };
  2217. var byTitle = (input, choices) => Promise.resolve(
  2218. choices.filter((item) => item.title.slice(0, input.length).toLowerCase() === input.toLowerCase())
  2219. );
  2220. $.autocomplete = (args) => {
  2221. args.suggest = args.suggest || byTitle;
  2222. args.choices = [].concat(args.choices || []);
  2223. return toPrompt("AutocompletePrompt", args);
  2224. };
  2225. }
  2226. });
  2227. // node_modules/prompts/lib/index.js
  2228. var require_lib = __commonJS({
  2229. "node_modules/prompts/lib/index.js"(exports2, module2) {
  2230. "use strict";
  2231. var prompts = require_prompts();
  2232. var passOn = ["suggest", "format", "onState", "validate", "onRender", "type"];
  2233. var noop = () => {
  2234. };
  2235. async function prompt(questions = [], { onSubmit = noop, onCancel = noop } = {}) {
  2236. const answers = {};
  2237. const override2 = prompt._override || {};
  2238. questions = [].concat(questions);
  2239. let answer, question, quit, name, type, lastPrompt;
  2240. const getFormattedAnswer = async (question2, answer2, skipValidation = false) => {
  2241. if (!skipValidation && question2.validate && question2.validate(answer2) !== true) {
  2242. return;
  2243. }
  2244. return question2.format ? await question2.format(answer2, answers) : answer2;
  2245. };
  2246. for (question of questions) {
  2247. ({ name, type } = question);
  2248. if (typeof type === "function") {
  2249. type = await type(answer, { ...answers }, question);
  2250. question["type"] = type;
  2251. }
  2252. if (!type) continue;
  2253. for (let key in question) {
  2254. if (passOn.includes(key)) continue;
  2255. let value = question[key];
  2256. question[key] = typeof value === "function" ? await value(answer, { ...answers }, lastPrompt) : value;
  2257. }
  2258. lastPrompt = question;
  2259. if (typeof question.message !== "string") {
  2260. throw new Error("prompt message is required");
  2261. }
  2262. ({ name, type } = question);
  2263. if (prompts[type] === void 0) {
  2264. throw new Error(`prompt type (${type}) is not defined`);
  2265. }
  2266. if (override2[question.name] !== void 0) {
  2267. answer = await getFormattedAnswer(question, override2[question.name]);
  2268. if (answer !== void 0) {
  2269. answers[name] = answer;
  2270. continue;
  2271. }
  2272. }
  2273. try {
  2274. answer = prompt._injected ? getInjectedAnswer(prompt._injected, question.initial) : await prompts[type](question);
  2275. answers[name] = answer = await getFormattedAnswer(question, answer, true);
  2276. quit = await onSubmit(question, answer, answers);
  2277. } catch (err2) {
  2278. quit = !await onCancel(question, answers);
  2279. }
  2280. if (quit) return answers;
  2281. }
  2282. return answers;
  2283. }
  2284. function getInjectedAnswer(injected, deafultValue) {
  2285. const answer = injected.shift();
  2286. if (answer instanceof Error) {
  2287. throw answer;
  2288. }
  2289. return answer === void 0 ? deafultValue : answer;
  2290. }
  2291. function inject(answers) {
  2292. prompt._injected = (prompt._injected || []).concat(answers);
  2293. }
  2294. function override(answers) {
  2295. prompt._override = Object.assign({}, answers);
  2296. }
  2297. module2.exports = Object.assign(prompt, { prompt, prompts, inject, override });
  2298. }
  2299. });
  2300. // src/cli/index.ts
  2301. var cli_exports = {};
  2302. __export(cli_exports, {
  2303. BOOLEAN_CLI_FLAGS: () => BOOLEAN_CLI_FLAGS,
  2304. parseFlags: () => parseFlags,
  2305. run: () => run,
  2306. runTask: () => runTask
  2307. });
  2308. module.exports = __toCommonJS(cli_exports);
  2309. // src/cli/config-flags.ts
  2310. var BOOLEAN_CLI_FLAGS = [
  2311. "build",
  2312. "cache",
  2313. "checkVersion",
  2314. "ci",
  2315. "compare",
  2316. "debug",
  2317. "dev",
  2318. "devtools",
  2319. "docs",
  2320. "e2e",
  2321. "es5",
  2322. "esm",
  2323. "help",
  2324. "log",
  2325. "open",
  2326. "prerender",
  2327. "prerenderExternal",
  2328. "prod",
  2329. "profile",
  2330. "serviceWorker",
  2331. "screenshot",
  2332. "serve",
  2333. "skipNodeCheck",
  2334. "spec",
  2335. "ssr",
  2336. "stats",
  2337. "updateScreenshot",
  2338. "verbose",
  2339. "version",
  2340. "watch",
  2341. // JEST CLI OPTIONS
  2342. "all",
  2343. "automock",
  2344. "bail",
  2345. // 'cache', Stencil already supports this argument
  2346. "changedFilesWithAncestor",
  2347. // 'ci', Stencil already supports this argument
  2348. "clearCache",
  2349. "clearMocks",
  2350. "collectCoverage",
  2351. "color",
  2352. "colors",
  2353. "coverage",
  2354. // 'debug', Stencil already supports this argument
  2355. "detectLeaks",
  2356. "detectOpenHandles",
  2357. "errorOnDeprecated",
  2358. "expand",
  2359. "findRelatedTests",
  2360. "forceExit",
  2361. "init",
  2362. "injectGlobals",
  2363. "json",
  2364. "lastCommit",
  2365. "listTests",
  2366. "logHeapUsage",
  2367. "noStackTrace",
  2368. "notify",
  2369. "onlyChanged",
  2370. "onlyFailures",
  2371. "passWithNoTests",
  2372. "resetMocks",
  2373. "resetModules",
  2374. "restoreMocks",
  2375. "runInBand",
  2376. "runTestsByPath",
  2377. "showConfig",
  2378. "silent",
  2379. "skipFilter",
  2380. "testLocationInResults",
  2381. "updateSnapshot",
  2382. "useStderr",
  2383. // 'verbose', Stencil already supports this argument
  2384. // 'version', Stencil already supports this argument
  2385. // 'watch', Stencil already supports this argument
  2386. "watchAll",
  2387. "watchman"
  2388. ];
  2389. var NUMBER_CLI_FLAGS = [
  2390. "port",
  2391. // JEST CLI ARGS
  2392. "maxConcurrency",
  2393. "testTimeout"
  2394. ];
  2395. var STRING_CLI_FLAGS = [
  2396. "address",
  2397. "config",
  2398. "docsApi",
  2399. "docsJson",
  2400. "emulate",
  2401. "root",
  2402. "screenshotConnector",
  2403. // JEST CLI ARGS
  2404. "cacheDirectory",
  2405. "changedSince",
  2406. "collectCoverageFrom",
  2407. // 'config', Stencil already supports this argument
  2408. "coverageDirectory",
  2409. "coverageThreshold",
  2410. "env",
  2411. "filter",
  2412. "globalSetup",
  2413. "globalTeardown",
  2414. "globals",
  2415. "haste",
  2416. "moduleNameMapper",
  2417. "notifyMode",
  2418. "outputFile",
  2419. "preset",
  2420. "prettierPath",
  2421. "resolver",
  2422. "rootDir",
  2423. "runner",
  2424. "testEnvironment",
  2425. "testEnvironmentOptions",
  2426. "testFailureExitCode",
  2427. "testNamePattern",
  2428. "testResultsProcessor",
  2429. "testRunner",
  2430. "testSequencer",
  2431. "testURL",
  2432. "timers",
  2433. "transform"
  2434. ];
  2435. var STRING_ARRAY_CLI_FLAGS = [
  2436. "collectCoverageOnlyFrom",
  2437. "coveragePathIgnorePatterns",
  2438. "coverageReporters",
  2439. "moduleDirectories",
  2440. "moduleFileExtensions",
  2441. "modulePathIgnorePatterns",
  2442. "modulePaths",
  2443. "projects",
  2444. "reporters",
  2445. "roots",
  2446. "selectProjects",
  2447. "setupFiles",
  2448. "setupFilesAfterEnv",
  2449. "snapshotSerializers",
  2450. "testMatch",
  2451. "testPathIgnorePatterns",
  2452. "testPathPattern",
  2453. "testRegex",
  2454. "transformIgnorePatterns",
  2455. "unmockedModulePathPatterns",
  2456. "watchPathIgnorePatterns"
  2457. ];
  2458. var STRING_NUMBER_CLI_FLAGS = ["maxWorkers"];
  2459. var BOOLEAN_STRING_CLI_FLAGS = [
  2460. /**
  2461. * `headless` is an argument passed through to Puppeteer (which is passed to Chrome) for end-to-end testing.
  2462. * Prior to Chrome v112, `headless` was treated like a boolean flag. Starting with Chrome v112, 'new' is an accepted
  2463. * option to support Chrome's new headless mode. In order to support this option in Stencil, both the boolean and
  2464. * string versions of the flag must be accepted.
  2465. *
  2466. * {@see https://developer.chrome.com/articles/new-headless/}
  2467. */
  2468. "headless"
  2469. ];
  2470. var LOG_LEVEL_CLI_FLAGS = ["logLevel"];
  2471. var CLI_FLAG_ALIASES = {
  2472. c: "config",
  2473. h: "help",
  2474. p: "port",
  2475. v: "version",
  2476. // JEST SPECIFIC CLI FLAGS
  2477. // these are defined in
  2478. // https://github.com/facebook/jest/blob/4156f86/packages/jest-cli/src/args.ts
  2479. b: "bail",
  2480. e: "expand",
  2481. f: "onlyFailures",
  2482. i: "runInBand",
  2483. o: "onlyChanged",
  2484. t: "testNamePattern",
  2485. u: "updateSnapshot",
  2486. w: "maxWorkers"
  2487. };
  2488. var CLI_FLAG_REGEX = new RegExp(`^-[chpvbewofitu]{1}$`);
  2489. var createConfigFlags = (init = {}) => {
  2490. const flags = {
  2491. task: null,
  2492. args: [],
  2493. knownArgs: [],
  2494. unknownArgs: [],
  2495. ...init
  2496. };
  2497. return flags;
  2498. };
  2499. // src/utils/constants.ts
  2500. var DIST_HYDRATE_SCRIPT = "dist-hydrate-script";
  2501. var DOCS_CUSTOM = "docs-custom";
  2502. var DOCS_JSON = "docs-json";
  2503. var DOCS_README = "docs-readme";
  2504. var DOCS_VSCODE = "docs-vscode";
  2505. var WWW = "www";
  2506. // src/utils/helpers.ts
  2507. var dashToPascalCase = (str) => str.toLowerCase().split("-").map((segment) => segment.charAt(0).toUpperCase() + segment.slice(1)).join("");
  2508. var toCamelCase = (str) => {
  2509. const pascalCase = dashToPascalCase(str);
  2510. return pascalCase.charAt(0).toLowerCase() + pascalCase.slice(1);
  2511. };
  2512. var isFunction = (v) => typeof v === "function";
  2513. var isString = (v) => typeof v === "string";
  2514. // src/utils/message-utils.ts
  2515. var buildError = (diagnostics) => {
  2516. const diagnostic = {
  2517. level: "error",
  2518. type: "build",
  2519. header: "Build Error",
  2520. messageText: "build error",
  2521. relFilePath: void 0,
  2522. absFilePath: void 0,
  2523. lines: []
  2524. };
  2525. if (diagnostics) {
  2526. diagnostics.push(diagnostic);
  2527. }
  2528. return diagnostic;
  2529. };
  2530. var catchError = (diagnostics, err2, msg) => {
  2531. const diagnostic = {
  2532. level: "error",
  2533. type: "build",
  2534. header: "Build Error",
  2535. messageText: "build error",
  2536. lines: []
  2537. };
  2538. if (isString(msg)) {
  2539. diagnostic.messageText = msg.length ? msg : "UNKNOWN ERROR";
  2540. } else if (err2 != null) {
  2541. if (err2.stack != null) {
  2542. diagnostic.messageText = err2.stack.toString();
  2543. } else {
  2544. if (err2.message != null) {
  2545. diagnostic.messageText = err2.message.length ? err2.message : "UNKNOWN ERROR";
  2546. } else {
  2547. diagnostic.messageText = err2.toString();
  2548. }
  2549. }
  2550. }
  2551. if (diagnostics != null && !shouldIgnoreError(diagnostic.messageText)) {
  2552. diagnostics.push(diagnostic);
  2553. }
  2554. return diagnostic;
  2555. };
  2556. var hasError = (diagnostics) => {
  2557. if (diagnostics == null || diagnostics.length === 0) {
  2558. return false;
  2559. }
  2560. return diagnostics.some((d) => d.level === "error" && d.type !== "runtime");
  2561. };
  2562. var shouldIgnoreError = (msg) => {
  2563. return msg === TASK_CANCELED_MSG;
  2564. };
  2565. var TASK_CANCELED_MSG = `task canceled`;
  2566. // src/utils/path.ts
  2567. var normalizePath = (path, relativize = true) => {
  2568. if (typeof path !== "string") {
  2569. throw new Error(`invalid path to normalize`);
  2570. }
  2571. path = normalizeSlashes(path.trim());
  2572. const components = pathComponents(path, getRootLength(path));
  2573. const reducedComponents = reducePathComponents(components);
  2574. const rootPart = reducedComponents[0];
  2575. const secondPart = reducedComponents[1];
  2576. const normalized = rootPart + reducedComponents.slice(1).join("/");
  2577. if (normalized === "") {
  2578. return ".";
  2579. }
  2580. if (rootPart === "" && secondPart && path.includes("/") && !secondPart.startsWith(".") && !secondPart.startsWith("@") && relativize) {
  2581. return "./" + normalized;
  2582. }
  2583. return normalized;
  2584. };
  2585. var normalizeSlashes = (path) => path.replace(backslashRegExp, "/");
  2586. var altDirectorySeparator = "\\";
  2587. var urlSchemeSeparator = "://";
  2588. var backslashRegExp = /\\/g;
  2589. var reducePathComponents = (components) => {
  2590. if (!Array.isArray(components) || components.length === 0) {
  2591. return [];
  2592. }
  2593. const reduced = [components[0]];
  2594. for (let i = 1; i < components.length; i++) {
  2595. const component = components[i];
  2596. if (!component) continue;
  2597. if (component === ".") continue;
  2598. if (component === "..") {
  2599. if (reduced.length > 1) {
  2600. if (reduced[reduced.length - 1] !== "..") {
  2601. reduced.pop();
  2602. continue;
  2603. }
  2604. } else if (reduced[0]) continue;
  2605. }
  2606. reduced.push(component);
  2607. }
  2608. return reduced;
  2609. };
  2610. var getRootLength = (path) => {
  2611. const rootLength = getEncodedRootLength(path);
  2612. return rootLength < 0 ? ~rootLength : rootLength;
  2613. };
  2614. var getEncodedRootLength = (path) => {
  2615. if (!path) return 0;
  2616. const ch0 = path.charCodeAt(0);
  2617. if (ch0 === 47 /* slash */ || ch0 === 92 /* backslash */) {
  2618. if (path.charCodeAt(1) !== ch0) return 1;
  2619. const p1 = path.indexOf(ch0 === 47 /* slash */ ? "/" : altDirectorySeparator, 2);
  2620. if (p1 < 0) return path.length;
  2621. return p1 + 1;
  2622. }
  2623. if (isVolumeCharacter(ch0) && path.charCodeAt(1) === 58 /* colon */) {
  2624. const ch2 = path.charCodeAt(2);
  2625. if (ch2 === 47 /* slash */ || ch2 === 92 /* backslash */) return 3;
  2626. if (path.length === 2) return 2;
  2627. }
  2628. const schemeEnd = path.indexOf(urlSchemeSeparator);
  2629. if (schemeEnd !== -1) {
  2630. const authorityStart = schemeEnd + urlSchemeSeparator.length;
  2631. const authorityEnd = path.indexOf("/", authorityStart);
  2632. if (authorityEnd !== -1) {
  2633. const scheme = path.slice(0, schemeEnd);
  2634. const authority = path.slice(authorityStart, authorityEnd);
  2635. if (scheme === "file" && (authority === "" || authority === "localhost") && isVolumeCharacter(path.charCodeAt(authorityEnd + 1))) {
  2636. const volumeSeparatorEnd = getFileUrlVolumeSeparatorEnd(path, authorityEnd + 2);
  2637. if (volumeSeparatorEnd !== -1) {
  2638. if (path.charCodeAt(volumeSeparatorEnd) === 47 /* slash */) {
  2639. return ~(volumeSeparatorEnd + 1);
  2640. }
  2641. if (volumeSeparatorEnd === path.length) {
  2642. return ~volumeSeparatorEnd;
  2643. }
  2644. }
  2645. }
  2646. return ~(authorityEnd + 1);
  2647. }
  2648. return ~path.length;
  2649. }
  2650. return 0;
  2651. };
  2652. var isVolumeCharacter = (charCode) => charCode >= 97 /* a */ && charCode <= 122 /* z */ || charCode >= 65 /* A */ && charCode <= 90 /* Z */;
  2653. var getFileUrlVolumeSeparatorEnd = (url, start) => {
  2654. const ch0 = url.charCodeAt(start);
  2655. if (ch0 === 58 /* colon */) return start + 1;
  2656. if (ch0 === 37 /* percent */ && url.charCodeAt(start + 1) === 51 /* _3 */) {
  2657. const ch2 = url.charCodeAt(start + 2);
  2658. if (ch2 === 97 /* a */ || ch2 === 65 /* A */) return start + 3;
  2659. }
  2660. return -1;
  2661. };
  2662. var pathComponents = (path, rootLength) => {
  2663. const root = path.substring(0, rootLength);
  2664. const rest = path.substring(rootLength).split("/");
  2665. const restLen = rest.length;
  2666. if (restLen > 0 && !rest[restLen - 1]) {
  2667. rest.pop();
  2668. }
  2669. return [root, ...rest];
  2670. };
  2671. // src/utils/output-target.ts
  2672. var isOutputTargetHydrate = (o) => o.type === DIST_HYDRATE_SCRIPT;
  2673. var isOutputTargetDocs = (o) => o.type === DOCS_README || o.type === DOCS_JSON || o.type === DOCS_CUSTOM || o.type === DOCS_VSCODE;
  2674. // src/utils/result.ts
  2675. var result_exports = {};
  2676. __export(result_exports, {
  2677. err: () => err,
  2678. map: () => map,
  2679. ok: () => ok,
  2680. unwrap: () => unwrap,
  2681. unwrapErr: () => unwrapErr
  2682. });
  2683. var ok = (value) => ({
  2684. isOk: true,
  2685. isErr: false,
  2686. value
  2687. });
  2688. var err = (value) => ({
  2689. isOk: false,
  2690. isErr: true,
  2691. value
  2692. });
  2693. function map(result, fn) {
  2694. if (result.isOk) {
  2695. const val = fn(result.value);
  2696. if (val instanceof Promise) {
  2697. return val.then((newVal) => ok(newVal));
  2698. } else {
  2699. return ok(val);
  2700. }
  2701. }
  2702. if (result.isErr) {
  2703. const value = result.value;
  2704. return err(value);
  2705. }
  2706. throw "should never get here";
  2707. }
  2708. var unwrap = (result) => {
  2709. if (result.isOk) {
  2710. return result.value;
  2711. } else {
  2712. throw result.value;
  2713. }
  2714. };
  2715. var unwrapErr = (result) => {
  2716. if (result.isErr) {
  2717. return result.value;
  2718. } else {
  2719. throw result.value;
  2720. }
  2721. };
  2722. // src/utils/util.ts
  2723. var readOnlyArrayHasStringMember = (readOnlyArray, maybeMember) => readOnlyArray.includes(maybeMember);
  2724. // src/utils/validation.ts
  2725. var validateComponentTag = (tag) => {
  2726. if (typeof tag !== "string") {
  2727. return `Tag "${tag}" must be a string type`;
  2728. }
  2729. if (tag !== tag.trim()) {
  2730. return `Tag can not contain white spaces`;
  2731. }
  2732. if (tag !== tag.toLowerCase()) {
  2733. return `Tag can not contain upper case characters`;
  2734. }
  2735. if (tag.length === 0) {
  2736. return `Received empty tag value`;
  2737. }
  2738. if (tag.indexOf(" ") > -1) {
  2739. return `"${tag}" tag cannot contain a space`;
  2740. }
  2741. if (tag.indexOf(",") > -1) {
  2742. return `"${tag}" tag cannot be used for multiple tags`;
  2743. }
  2744. const invalidChars = tag.replace(/\w|-/g, "");
  2745. if (invalidChars !== "") {
  2746. return `"${tag}" tag contains invalid characters: ${invalidChars}`;
  2747. }
  2748. if (tag.indexOf("-") === -1) {
  2749. return `"${tag}" tag must contain a dash (-) to work as a valid web component`;
  2750. }
  2751. if (tag.indexOf("--") > -1) {
  2752. return `"${tag}" tag cannot contain multiple dashes (--) next to each other`;
  2753. }
  2754. if (tag.indexOf("-") === 0) {
  2755. return `"${tag}" tag cannot start with a dash (-)`;
  2756. }
  2757. if (tag.lastIndexOf("-") === tag.length - 1) {
  2758. return `"${tag}" tag cannot end with a dash (-)`;
  2759. }
  2760. return void 0;
  2761. };
  2762. // src/declarations/stencil-public-compiler.ts
  2763. var LOG_LEVELS = ["debug", "info", "warn", "error"];
  2764. // src/cli/parse-flags.ts
  2765. var parseFlags = (args) => {
  2766. const flags = createConfigFlags();
  2767. flags.args = Array.isArray(args) ? args.slice() : [];
  2768. if (flags.args.length > 0 && flags.args[0] && !flags.args[0].startsWith("-")) {
  2769. flags.task = flags.args[0];
  2770. parseArgs(flags, args.slice(1));
  2771. } else {
  2772. parseArgs(flags, flags.args);
  2773. }
  2774. if (flags.task != null) {
  2775. const i = flags.args.indexOf(flags.task);
  2776. if (i > -1) {
  2777. flags.args.splice(i, 1);
  2778. }
  2779. }
  2780. return flags;
  2781. };
  2782. var parseArgs = (flags, args) => {
  2783. const argsCopy = args.concat();
  2784. while (argsCopy.length > 0) {
  2785. parseCLITerm(flags, argsCopy);
  2786. }
  2787. };
  2788. var parseCLITerm = (flags, args) => {
  2789. const arg = args.shift();
  2790. if (arg === void 0) return;
  2791. const isNegatedBoolean = !readOnlyArrayHasStringMember(BOOLEAN_CLI_FLAGS, normalizeFlagName(arg)) && readOnlyArrayHasStringMember(BOOLEAN_CLI_FLAGS, normalizeNegativeFlagName(arg));
  2792. const isNegatedBooleanOrString = !readOnlyArrayHasStringMember(BOOLEAN_STRING_CLI_FLAGS, normalizeFlagName(arg)) && readOnlyArrayHasStringMember(BOOLEAN_STRING_CLI_FLAGS, normalizeNegativeFlagName(arg));
  2793. if (arg.startsWith("--") && arg.includes("=")) {
  2794. const [originalArg, value] = parseEqualsArg(arg);
  2795. setCLIArg(flags, arg.split("=")[0], normalizeFlagName(originalArg), value);
  2796. } else if (arg.startsWith("-") && arg.includes("=")) {
  2797. const [originalArg, value] = parseEqualsArg(arg);
  2798. setCLIArg(flags, desugarRawAlias(originalArg), normalizeFlagName(originalArg), value);
  2799. } else if (CLI_FLAG_REGEX.test(arg)) {
  2800. setCLIArg(flags, desugarRawAlias(arg), normalizeFlagName(arg), parseCLIValue(args));
  2801. } else if (arg.startsWith("--no-") && arg.length > "--no-".length) {
  2802. const normalized = normalizeNegativeFlagName(arg);
  2803. setCLIArg(flags, arg, normalized, "");
  2804. } else if (arg.startsWith("--no") && (isNegatedBoolean || isNegatedBooleanOrString)) {
  2805. setCLIArg(flags, arg, normalizeNegativeFlagName(arg), "");
  2806. } else if (arg.startsWith("--") && arg.length > "--".length) {
  2807. setCLIArg(flags, arg, normalizeFlagName(arg), parseCLIValue(args));
  2808. } else {
  2809. flags.unknownArgs.push(arg);
  2810. }
  2811. };
  2812. var normalizeNegativeFlagName = (flagName) => {
  2813. const trimmed = flagName.replace(/^--no[-]?/, "");
  2814. return normalizeFlagName(trimmed.charAt(0).toLowerCase() + trimmed.slice(1));
  2815. };
  2816. var normalizeFlagName = (flagName) => {
  2817. const trimmed = flagName.replace(/^-+/, "");
  2818. return trimmed.includes("-") ? toCamelCase(trimmed) : trimmed;
  2819. };
  2820. var setCLIArg = (flags, rawArg, normalizedArg, value) => {
  2821. normalizedArg = desugarAlias(normalizedArg);
  2822. if (readOnlyArrayHasStringMember(BOOLEAN_CLI_FLAGS, normalizedArg)) {
  2823. const parsed = typeof value === "string" ? (
  2824. // check if the value is `'true'`
  2825. value === "true"
  2826. ) : (
  2827. // no value was supplied, default to true
  2828. true
  2829. );
  2830. flags[normalizedArg] = parsed;
  2831. flags.knownArgs.push(rawArg);
  2832. if (typeof value === "string" && value !== "") {
  2833. flags.knownArgs.push(value);
  2834. }
  2835. } else if (readOnlyArrayHasStringMember(STRING_CLI_FLAGS, normalizedArg)) {
  2836. if (typeof value === "string") {
  2837. flags[normalizedArg] = value;
  2838. flags.knownArgs.push(rawArg);
  2839. flags.knownArgs.push(value);
  2840. } else {
  2841. throwCLIParsingError(rawArg, "expected a string argument but received nothing");
  2842. }
  2843. } else if (readOnlyArrayHasStringMember(STRING_ARRAY_CLI_FLAGS, normalizedArg)) {
  2844. if (typeof value === "string") {
  2845. if (!Array.isArray(flags[normalizedArg])) {
  2846. flags[normalizedArg] = [];
  2847. }
  2848. const targetArray = flags[normalizedArg];
  2849. if (Array.isArray(targetArray)) {
  2850. targetArray.push(value);
  2851. flags.knownArgs.push(rawArg);
  2852. flags.knownArgs.push(value);
  2853. }
  2854. } else {
  2855. throwCLIParsingError(rawArg, "expected a string argument but received nothing");
  2856. }
  2857. } else if (readOnlyArrayHasStringMember(NUMBER_CLI_FLAGS, normalizedArg)) {
  2858. if (typeof value === "string") {
  2859. const parsed = parseInt(value, 10);
  2860. if (isNaN(parsed)) {
  2861. throwNumberParsingError(rawArg, value);
  2862. } else {
  2863. flags[normalizedArg] = parsed;
  2864. flags.knownArgs.push(rawArg);
  2865. flags.knownArgs.push(value);
  2866. }
  2867. } else {
  2868. throwCLIParsingError(rawArg, "expected a number argument but received nothing");
  2869. }
  2870. } else if (readOnlyArrayHasStringMember(STRING_NUMBER_CLI_FLAGS, normalizedArg)) {
  2871. if (typeof value === "string") {
  2872. if (CLI_ARG_STRING_REGEX.test(value)) {
  2873. flags[normalizedArg] = value;
  2874. } else {
  2875. const parsed = Number(value);
  2876. if (isNaN(parsed)) {
  2877. throwNumberParsingError(rawArg, value);
  2878. } else {
  2879. flags[normalizedArg] = parsed;
  2880. }
  2881. }
  2882. flags.knownArgs.push(rawArg);
  2883. flags.knownArgs.push(value);
  2884. } else {
  2885. throwCLIParsingError(rawArg, "expected a string or a number but received nothing");
  2886. }
  2887. } else if (readOnlyArrayHasStringMember(BOOLEAN_STRING_CLI_FLAGS, normalizedArg)) {
  2888. const derivedValue = typeof value === "string" ? value ? value : false : true;
  2889. flags[normalizedArg] = derivedValue;
  2890. flags.knownArgs.push(rawArg);
  2891. if (typeof derivedValue === "string" && derivedValue) {
  2892. flags.knownArgs.push(derivedValue);
  2893. }
  2894. } else if (readOnlyArrayHasStringMember(LOG_LEVEL_CLI_FLAGS, normalizedArg)) {
  2895. if (typeof value === "string") {
  2896. if (isLogLevel(value)) {
  2897. flags[normalizedArg] = value;
  2898. flags.knownArgs.push(rawArg);
  2899. flags.knownArgs.push(value);
  2900. } else {
  2901. throwCLIParsingError(rawArg, `expected to receive a valid log level but received "${String(value)}"`);
  2902. }
  2903. } else {
  2904. throwCLIParsingError(rawArg, "expected to receive a valid log level but received nothing");
  2905. }
  2906. } else {
  2907. flags.unknownArgs.push(rawArg);
  2908. if (typeof value === "string") {
  2909. flags.unknownArgs.push(value);
  2910. }
  2911. }
  2912. };
  2913. var CLI_ARG_STRING_REGEX = /[^\d\.Ee\+\-]+/g;
  2914. var Empty = Symbol("Empty");
  2915. var parseCLIValue = (args) => {
  2916. if (args[0] === void 0) {
  2917. return Empty;
  2918. }
  2919. if (!args[0].startsWith("-")) {
  2920. const value = args.shift();
  2921. if (typeof value === "string") {
  2922. return value;
  2923. }
  2924. }
  2925. return Empty;
  2926. };
  2927. var parseEqualsArg = (arg) => {
  2928. const [originalArg, ...splitSections] = arg.split("=");
  2929. const value = splitSections.join("=");
  2930. return [originalArg, value === "" ? Empty : value];
  2931. };
  2932. var isLogLevel = (maybeLogLevel) => readOnlyArrayHasStringMember(LOG_LEVELS, maybeLogLevel);
  2933. var throwCLIParsingError = (flag, message) => {
  2934. throw new Error(`when parsing CLI flag "${flag}": ${message}`);
  2935. };
  2936. var throwNumberParsingError = (flag, value) => {
  2937. throwCLIParsingError(flag, `expected a number but received "${value}"`);
  2938. };
  2939. var desugarAlias = (maybeAlias) => {
  2940. const possiblyDesugared = CLI_FLAG_ALIASES[maybeAlias];
  2941. if (typeof possiblyDesugared === "string") {
  2942. return possiblyDesugared;
  2943. }
  2944. return maybeAlias;
  2945. };
  2946. var desugarRawAlias = (rawAlias) => "--" + desugarAlias(normalizeFlagName(rawAlias));
  2947. // src/cli/find-config.ts
  2948. var findConfig = async (opts) => {
  2949. const sys = opts.sys;
  2950. const cwd = sys.getCurrentDirectory();
  2951. const rootDir = normalizePath(cwd);
  2952. let configPath = opts.configPath;
  2953. if (isString(configPath)) {
  2954. if (!sys.platformPath.isAbsolute(configPath)) {
  2955. configPath = normalizePath(sys.platformPath.join(cwd, configPath));
  2956. } else {
  2957. configPath = normalizePath(configPath);
  2958. }
  2959. } else {
  2960. configPath = rootDir;
  2961. }
  2962. const results = {
  2963. configPath,
  2964. rootDir: normalizePath(cwd)
  2965. };
  2966. const stat = await sys.stat(configPath);
  2967. if (stat.error) {
  2968. const diagnostics = [];
  2969. const diagnostic = buildError(diagnostics);
  2970. diagnostic.absFilePath = configPath;
  2971. diagnostic.header = `Invalid config path`;
  2972. diagnostic.messageText = `Config path "${configPath}" not found`;
  2973. return result_exports.err(diagnostics);
  2974. }
  2975. if (stat.isFile) {
  2976. results.configPath = configPath;
  2977. results.rootDir = sys.platformPath.dirname(configPath);
  2978. } else if (stat.isDirectory) {
  2979. for (const configName of ["stencil.config.ts", "stencil.config.js"]) {
  2980. const testConfigFilePath = sys.platformPath.join(configPath, configName);
  2981. const stat2 = await sys.stat(testConfigFilePath);
  2982. if (stat2.isFile) {
  2983. results.configPath = testConfigFilePath;
  2984. results.rootDir = sys.platformPath.dirname(testConfigFilePath);
  2985. break;
  2986. }
  2987. }
  2988. }
  2989. return result_exports.ok(results);
  2990. };
  2991. // src/cli/load-compiler.ts
  2992. var loadCoreCompiler = async (sys) => {
  2993. return await sys.dynamicImport(sys.getCompilerExecutingPath());
  2994. };
  2995. // src/cli/logs.ts
  2996. var startupLog = (logger, task) => {
  2997. if (task === "info" || task === "serve" || task === "version") {
  2998. return;
  2999. }
  3000. logger.info(logger.cyan(`@stencil/core`));
  3001. };
  3002. var startupLogVersion = (logger, task, coreCompiler) => {
  3003. if (task === "info" || task === "serve" || task === "version") {
  3004. return;
  3005. }
  3006. const isDevBuild = coreCompiler.version.includes("-dev.");
  3007. let startupMsg;
  3008. if (isDevBuild) {
  3009. startupMsg = logger.yellow(`[LOCAL DEV] v${coreCompiler.version}`);
  3010. } else {
  3011. startupMsg = logger.cyan(`v${coreCompiler.version}`);
  3012. }
  3013. startupMsg += logger.emoji(" " + coreCompiler.vermoji);
  3014. logger.info(startupMsg);
  3015. };
  3016. var loadedCompilerLog = (sys, logger, flags, coreCompiler) => {
  3017. const sysDetails = sys.details;
  3018. const runtimeInfo = `${sys.name} ${sys.version}`;
  3019. const platformInfo = sysDetails ? `${sysDetails.platform}, ${sysDetails.cpuModel}` : `Unknown Platform, Unknown CPU Model`;
  3020. const statsInfo = sysDetails ? `cpus: ${sys.hardwareConcurrency}, freemem: ${Math.round(
  3021. sysDetails.freemem() / 1e6
  3022. )}MB, totalmem: ${Math.round(sysDetails.totalmem / 1e6)}MB` : "Unknown CPU Core Count, Unknown Memory";
  3023. if (logger.getLevel() === "debug") {
  3024. logger.debug(runtimeInfo);
  3025. logger.debug(platformInfo);
  3026. logger.debug(statsInfo);
  3027. logger.debug(`compiler: ${sys.getCompilerExecutingPath()}`);
  3028. logger.debug(`build: ${coreCompiler.buildId}`);
  3029. } else if (flags.ci) {
  3030. logger.info(runtimeInfo);
  3031. logger.info(platformInfo);
  3032. logger.info(statsInfo);
  3033. }
  3034. };
  3035. var startupCompilerLog = (coreCompiler, config) => {
  3036. if (config.suppressLogs === true) {
  3037. return;
  3038. }
  3039. const { logger } = config;
  3040. const isDebug = logger.getLevel() === "debug";
  3041. const isPrerelease = coreCompiler.version.includes("-");
  3042. const isDevBuild = coreCompiler.version.includes("-dev.");
  3043. if (isPrerelease && !isDevBuild) {
  3044. logger.warn(
  3045. logger.yellow(
  3046. `This is a prerelease build, undocumented changes might happen at any time. Technical support is not available for prereleases, but any assistance testing is appreciated.`
  3047. )
  3048. );
  3049. }
  3050. if (config.devMode && !isDebug) {
  3051. if (config.buildEs5) {
  3052. logger.warn(
  3053. `Generating ES5 during development is a very task expensive, initial and incremental builds will be much slower. Drop the '--es5' flag and use a modern browser for development.`
  3054. );
  3055. }
  3056. if (!config.enableCache) {
  3057. logger.warn(`Disabling cache during development will slow down incremental builds.`);
  3058. }
  3059. }
  3060. };
  3061. // src/cli/check-version.ts
  3062. var startCheckVersion = async (config, currentVersion) => {
  3063. if (config.devMode && !config.flags.ci && !currentVersion.includes("-dev.") && isFunction(config.sys.checkVersion)) {
  3064. return config.sys.checkVersion(config.logger, currentVersion);
  3065. }
  3066. return null;
  3067. };
  3068. var printCheckVersionResults = async (versionChecker) => {
  3069. if (versionChecker) {
  3070. const checkVersionResults = await versionChecker;
  3071. if (isFunction(checkVersionResults)) {
  3072. checkVersionResults();
  3073. }
  3074. }
  3075. };
  3076. // src/cli/task-prerender.ts
  3077. var taskPrerender = async (coreCompiler, config) => {
  3078. startupCompilerLog(coreCompiler, config);
  3079. const hydrateAppFilePath = config.flags.unknownArgs[0];
  3080. if (typeof hydrateAppFilePath !== "string") {
  3081. config.logger.error(`Missing hydrate app script path`);
  3082. return config.sys.exit(1);
  3083. }
  3084. const srcIndexHtmlPath = config.srcIndexHtml;
  3085. const diagnostics = await runPrerenderTask(coreCompiler, config, hydrateAppFilePath, void 0, srcIndexHtmlPath);
  3086. config.logger.printDiagnostics(diagnostics);
  3087. if (diagnostics.some((d) => d.level === "error")) {
  3088. return config.sys.exit(1);
  3089. }
  3090. };
  3091. var runPrerenderTask = async (coreCompiler, config, hydrateAppFilePath, componentGraph, srcIndexHtmlPath) => {
  3092. const diagnostics = [];
  3093. try {
  3094. const prerenderer = await coreCompiler.createPrerenderer(config);
  3095. const results = await prerenderer.start({
  3096. hydrateAppFilePath,
  3097. componentGraph,
  3098. srcIndexHtmlPath
  3099. });
  3100. diagnostics.push(...results.diagnostics);
  3101. } catch (e) {
  3102. catchError(diagnostics, e);
  3103. }
  3104. return diagnostics;
  3105. };
  3106. // src/cli/task-watch.ts
  3107. var taskWatch = async (coreCompiler, config) => {
  3108. let devServer = null;
  3109. let exitCode = 0;
  3110. try {
  3111. startupCompilerLog(coreCompiler, config);
  3112. const versionChecker = startCheckVersion(config, coreCompiler.version);
  3113. const compiler = await coreCompiler.createCompiler(config);
  3114. const watcher = await compiler.createWatcher();
  3115. if (!config.sys.getDevServerExecutingPath || !config.sys.dynamicImport || !config.sys.onProcessInterrupt) {
  3116. throw new Error(
  3117. `Environment doesn't provide required functions: getDevServerExecutingPath, dynamicImport, onProcessInterrupt`
  3118. );
  3119. }
  3120. if (config.flags.serve) {
  3121. const devServerPath = config.sys.getDevServerExecutingPath();
  3122. const { start } = await config.sys.dynamicImport(devServerPath);
  3123. devServer = await start(config.devServer, config.logger, watcher);
  3124. }
  3125. config.sys.onProcessInterrupt(() => {
  3126. config.logger.debug(`close watch`);
  3127. compiler && compiler.destroy();
  3128. });
  3129. const rmVersionCheckerLog = watcher.on("buildFinish", async () => {
  3130. rmVersionCheckerLog();
  3131. printCheckVersionResults(versionChecker);
  3132. });
  3133. if (devServer) {
  3134. const rmDevServerLog = watcher.on("buildFinish", () => {
  3135. var _a;
  3136. rmDevServerLog();
  3137. const url = (_a = devServer == null ? void 0 : devServer.browserUrl) != null ? _a : "UNKNOWN URL";
  3138. config.logger.info(`${config.logger.cyan(url)}
  3139. `);
  3140. });
  3141. }
  3142. const closeResults = await watcher.start();
  3143. if (closeResults.exitCode > 0) {
  3144. exitCode = closeResults.exitCode;
  3145. }
  3146. } catch (e) {
  3147. exitCode = 1;
  3148. config.logger.error(e);
  3149. }
  3150. if (devServer) {
  3151. await devServer.close();
  3152. }
  3153. if (exitCode > 0) {
  3154. return config.sys.exit(exitCode);
  3155. }
  3156. };
  3157. // src/cli/telemetry/helpers.ts
  3158. var tryFn = async (fn, ...args) => {
  3159. try {
  3160. return await fn(...args);
  3161. } catch {
  3162. }
  3163. return null;
  3164. };
  3165. var isInteractive = (sys, flags, object) => {
  3166. const terminalInfo = object || Object.freeze({
  3167. tty: sys.isTTY() ? true : false,
  3168. ci: ["CI", "BUILD_ID", "BUILD_NUMBER", "BITBUCKET_COMMIT", "CODEBUILD_BUILD_ARN"].filter(
  3169. (v) => {
  3170. var _a;
  3171. return !!((_a = sys.getEnvironmentVar) == null ? void 0 : _a.call(sys, v));
  3172. }
  3173. ).length > 0 || !!flags.ci
  3174. });
  3175. return terminalInfo.tty && !terminalInfo.ci;
  3176. };
  3177. var UUID_REGEX = new RegExp(/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i);
  3178. function uuidv4() {
  3179. return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
  3180. const r = Math.random() * 16 | 0;
  3181. const v = c == "x" ? r : r & 3 | 8;
  3182. return v.toString(16);
  3183. });
  3184. }
  3185. async function readJson(sys, path) {
  3186. const file = await sys.readFile(path);
  3187. return !!file && JSON.parse(file);
  3188. }
  3189. function hasDebug(flags) {
  3190. return !!flags.debug;
  3191. }
  3192. function hasVerbose(flags) {
  3193. return !!flags.verbose && hasDebug(flags);
  3194. }
  3195. // src/cli/ionic-config.ts
  3196. var isTest = () => process.env.JEST_WORKER_ID !== void 0;
  3197. var defaultConfig = (sys) => sys.resolvePath(`${sys.homeDir()}/.ionic/${isTest() ? "tmp-config.json" : "config.json"}`);
  3198. var defaultConfigDirectory = (sys) => sys.resolvePath(`${sys.homeDir()}/.ionic`);
  3199. async function readConfig(sys) {
  3200. let config = await readJson(sys, defaultConfig(sys));
  3201. if (!config) {
  3202. config = {
  3203. "tokens.telemetry": uuidv4(),
  3204. "telemetry.stencil": true
  3205. };
  3206. await writeConfig(sys, config);
  3207. } else if (!config["tokens.telemetry"] || !UUID_REGEX.test(config["tokens.telemetry"])) {
  3208. const newUuid = uuidv4();
  3209. await writeConfig(sys, { ...config, "tokens.telemetry": newUuid });
  3210. config["tokens.telemetry"] = newUuid;
  3211. }
  3212. return config;
  3213. }
  3214. async function writeConfig(sys, config) {
  3215. let result = false;
  3216. try {
  3217. await sys.createDir(defaultConfigDirectory(sys), { recursive: true });
  3218. await sys.writeFile(defaultConfig(sys), JSON.stringify(config, null, 2));
  3219. result = true;
  3220. } catch (error) {
  3221. console.error(`Stencil Telemetry: couldn't write configuration file to ${defaultConfig(sys)} - ${error}.`);
  3222. }
  3223. return result;
  3224. }
  3225. async function updateConfig(sys, newOptions) {
  3226. const config = await readConfig(sys);
  3227. return await writeConfig(sys, Object.assign(config, newOptions));
  3228. }
  3229. // src/cli/telemetry/shouldTrack.ts
  3230. async function shouldTrack(config, sys, ci) {
  3231. return !ci && isInteractive(sys, config.flags) && await checkTelemetry(sys);
  3232. }
  3233. // src/cli/telemetry/telemetry.ts
  3234. async function telemetryBuildFinishedAction(sys, config, coreCompiler, result) {
  3235. const tracking = await shouldTrack(config, sys, !!config.flags.ci);
  3236. if (!tracking) {
  3237. return;
  3238. }
  3239. const component_count = result.componentGraph ? Object.keys(result.componentGraph).length : void 0;
  3240. const data = await prepareData(coreCompiler, config, sys, result.duration, component_count);
  3241. await sendMetric(sys, config, "stencil_cli_command", data);
  3242. config.logger.debug(`${config.logger.blue("Telemetry")}: ${config.logger.gray(JSON.stringify(data))}`);
  3243. }
  3244. async function telemetryAction(sys, config, coreCompiler, action) {
  3245. const tracking = await shouldTrack(config, sys, !!config.flags.ci);
  3246. let duration = void 0;
  3247. let error;
  3248. if (action) {
  3249. const start = /* @__PURE__ */ new Date();
  3250. try {
  3251. await action();
  3252. } catch (e) {
  3253. error = e;
  3254. }
  3255. const end = /* @__PURE__ */ new Date();
  3256. duration = end.getTime() - start.getTime();
  3257. }
  3258. if (!tracking || config.flags.task == "build" && !config.flags.args.includes("--watch")) {
  3259. return;
  3260. }
  3261. const data = await prepareData(coreCompiler, config, sys, duration);
  3262. await sendMetric(sys, config, "stencil_cli_command", data);
  3263. config.logger.debug(`${config.logger.blue("Telemetry")}: ${config.logger.gray(JSON.stringify(data))}`);
  3264. if (error) {
  3265. throw error;
  3266. }
  3267. }
  3268. function hasAppTarget(config) {
  3269. return config.outputTargets.some(
  3270. (target) => target.type === WWW && (!!target.serviceWorker || !!target.baseUrl && target.baseUrl !== "/")
  3271. );
  3272. }
  3273. function isUsingYarn(sys) {
  3274. var _a, _b;
  3275. return ((_b = (_a = sys.getEnvironmentVar) == null ? void 0 : _a.call(sys, "npm_execpath")) == null ? void 0 : _b.includes("yarn")) || false;
  3276. }
  3277. function getActiveTargets(config) {
  3278. const result = config.outputTargets.map((t) => t.type);
  3279. return Array.from(new Set(result));
  3280. }
  3281. var prepareData = async (coreCompiler, config, sys, duration_ms, component_count = void 0) => {
  3282. var _a, _b, _c;
  3283. const { typescript, rollup } = coreCompiler.versions || { typescript: "unknown", rollup: "unknown" };
  3284. const { packages, packagesNoVersions } = await getInstalledPackages(sys, config);
  3285. const targets = getActiveTargets(config);
  3286. const yarn = isUsingYarn(sys);
  3287. const stencil = coreCompiler.version || "unknown";
  3288. const system = `${sys.name} ${sys.version}`;
  3289. const os_name = (_a = sys.details) == null ? void 0 : _a.platform;
  3290. const os_version = (_b = sys.details) == null ? void 0 : _b.release;
  3291. const cpu_model = (_c = sys.details) == null ? void 0 : _c.cpuModel;
  3292. const build = coreCompiler.buildId || "unknown";
  3293. const has_app_pwa_config = hasAppTarget(config);
  3294. const anonymizedConfig = anonymizeConfigForTelemetry(config);
  3295. return {
  3296. arguments: config.flags.args,
  3297. build,
  3298. component_count,
  3299. config: anonymizedConfig,
  3300. cpu_model,
  3301. duration_ms,
  3302. has_app_pwa_config,
  3303. os_name,
  3304. os_version,
  3305. packages,
  3306. packages_no_versions: packagesNoVersions,
  3307. rollup,
  3308. stencil,
  3309. system,
  3310. system_major: getMajorVersion(system),
  3311. targets,
  3312. task: config.flags.task,
  3313. typescript,
  3314. yarn
  3315. };
  3316. };
  3317. var OUTPUT_TARGET_KEYS_TO_KEEP = ["type"];
  3318. var CONFIG_PROPS_TO_ANONYMIZE = [
  3319. "rootDir",
  3320. "fsNamespace",
  3321. "packageJsonFilePath",
  3322. "namespace",
  3323. "srcDir",
  3324. "srcIndexHtml",
  3325. "buildLogFilePath",
  3326. "cacheDir",
  3327. "configPath",
  3328. "tsconfig"
  3329. ];
  3330. var CONFIG_PROPS_TO_DELETE = [
  3331. "commonjs",
  3332. "devServer",
  3333. "env",
  3334. "logger",
  3335. "rollupConfig",
  3336. "sys",
  3337. "testing",
  3338. "tsCompilerOptions"
  3339. ];
  3340. var anonymizeConfigForTelemetry = (config) => {
  3341. const anonymizedConfig = { ...config };
  3342. for (const prop of CONFIG_PROPS_TO_ANONYMIZE) {
  3343. if (anonymizedConfig[prop] !== void 0) {
  3344. anonymizedConfig[prop] = "omitted";
  3345. }
  3346. }
  3347. anonymizedConfig.outputTargets = config.outputTargets.map((target) => {
  3348. const anonymizedOT = JSON.parse(
  3349. JSON.stringify(target, (key, value) => {
  3350. if (!(typeof value === "string")) {
  3351. return value;
  3352. }
  3353. if (OUTPUT_TARGET_KEYS_TO_KEEP.includes(key)) {
  3354. return value;
  3355. }
  3356. return "omitted";
  3357. })
  3358. );
  3359. if (isOutputTargetHydrate(target) && target.external) {
  3360. anonymizedOT["external"] = target.external.concat();
  3361. }
  3362. return anonymizedOT;
  3363. });
  3364. for (const prop of CONFIG_PROPS_TO_DELETE) {
  3365. delete anonymizedConfig[prop];
  3366. }
  3367. return anonymizedConfig;
  3368. };
  3369. async function getInstalledPackages(sys, config) {
  3370. let packages = [];
  3371. let packagesNoVersions = [];
  3372. const yarn = isUsingYarn(sys);
  3373. try {
  3374. const appRootDir = sys.getCurrentDirectory();
  3375. const packageJson = await tryFn(
  3376. readJson,
  3377. sys,
  3378. sys.resolvePath(appRootDir + "/package.json")
  3379. );
  3380. if (!packageJson) {
  3381. return { packages, packagesNoVersions };
  3382. }
  3383. const rawPackages = Object.entries({
  3384. ...packageJson.devDependencies,
  3385. ...packageJson.dependencies
  3386. });
  3387. const ionicPackages = rawPackages.filter(
  3388. ([k]) => k.startsWith("@stencil/") || k.startsWith("@ionic/") || k.startsWith("@capacitor/")
  3389. );
  3390. try {
  3391. packages = yarn ? await yarnPackages(sys, ionicPackages) : await npmPackages(sys, ionicPackages);
  3392. } catch (e) {
  3393. packages = ionicPackages.map(([k, v]) => `${k}@${v.replace("^", "")}`);
  3394. }
  3395. packagesNoVersions = ionicPackages.map(([k]) => `${k}`);
  3396. return { packages, packagesNoVersions };
  3397. } catch (err2) {
  3398. hasDebug(config.flags) && console.error(err2);
  3399. return { packages, packagesNoVersions };
  3400. }
  3401. }
  3402. async function npmPackages(sys, ionicPackages) {
  3403. const appRootDir = sys.getCurrentDirectory();
  3404. const packageLockJson = await tryFn(readJson, sys, sys.resolvePath(appRootDir + "/package-lock.json"));
  3405. return ionicPackages.map(([k, v]) => {
  3406. var _a, _b, _c, _d;
  3407. let version = (_d = (_c = (_a = packageLockJson == null ? void 0 : packageLockJson.dependencies[k]) == null ? void 0 : _a.version) != null ? _c : (_b = packageLockJson == null ? void 0 : packageLockJson.devDependencies[k]) == null ? void 0 : _b.version) != null ? _d : v;
  3408. version = version.includes("file:") ? sanitizeDeclaredVersion(v) : version;
  3409. return `${k}@${version}`;
  3410. });
  3411. }
  3412. async function yarnPackages(sys, ionicPackages) {
  3413. var _a;
  3414. const appRootDir = sys.getCurrentDirectory();
  3415. const yarnLock = sys.readFileSync(sys.resolvePath(appRootDir + "/yarn.lock"));
  3416. const yarnLockYml = (_a = sys.parseYarnLockFile) == null ? void 0 : _a.call(sys, yarnLock);
  3417. return ionicPackages.map(([k, v]) => {
  3418. var _a2;
  3419. const identifiedVersion = `${k}@${v}`;
  3420. let version = (_a2 = yarnLockYml == null ? void 0 : yarnLockYml.object[identifiedVersion]) == null ? void 0 : _a2.version;
  3421. version = version && version.includes("undefined") ? sanitizeDeclaredVersion(identifiedVersion) : version;
  3422. return `${k}@${version}`;
  3423. });
  3424. }
  3425. function sanitizeDeclaredVersion(version) {
  3426. return version.replace(/[*^~]/g, "");
  3427. }
  3428. async function sendMetric(sys, config, name, value) {
  3429. const session_id = await getTelemetryToken(sys);
  3430. const message = {
  3431. name,
  3432. timestamp: (/* @__PURE__ */ new Date()).toISOString(),
  3433. source: "stencil_cli",
  3434. value,
  3435. session_id
  3436. };
  3437. await sendTelemetry(sys, config, message);
  3438. }
  3439. async function getTelemetryToken(sys) {
  3440. const config = await readConfig(sys);
  3441. if (config["tokens.telemetry"] === void 0) {
  3442. config["tokens.telemetry"] = uuidv4();
  3443. await writeConfig(sys, config);
  3444. }
  3445. return config["tokens.telemetry"];
  3446. }
  3447. async function sendTelemetry(sys, config, data) {
  3448. try {
  3449. const now = (/* @__PURE__ */ new Date()).toISOString();
  3450. const body = {
  3451. metrics: [data],
  3452. sent_at: now
  3453. };
  3454. if (!sys.fetch) {
  3455. throw new Error("No fetch implementation available");
  3456. }
  3457. const response = await sys.fetch("https://api.ionicjs.com/events/metrics", {
  3458. method: "POST",
  3459. headers: {
  3460. "Content-Type": "application/json"
  3461. },
  3462. body: JSON.stringify(body)
  3463. });
  3464. hasVerbose(config.flags) && console.debug("\nSent %O metric to events service (status: %O)", data.name, response.status, "\n");
  3465. if (response.status !== 204) {
  3466. hasVerbose(config.flags) && console.debug("\nBad response from events service. Request body: %O", response.body.toString(), "\n");
  3467. }
  3468. } catch (e) {
  3469. hasVerbose(config.flags) && console.debug("Telemetry request failed:", e);
  3470. }
  3471. }
  3472. async function checkTelemetry(sys) {
  3473. const config = await readConfig(sys);
  3474. if (config["telemetry.stencil"] === void 0) {
  3475. config["telemetry.stencil"] = true;
  3476. await writeConfig(sys, config);
  3477. }
  3478. return config["telemetry.stencil"];
  3479. }
  3480. async function enableTelemetry(sys) {
  3481. return await updateConfig(sys, { "telemetry.stencil": true });
  3482. }
  3483. async function disableTelemetry(sys) {
  3484. return await updateConfig(sys, { "telemetry.stencil": false });
  3485. }
  3486. function getMajorVersion(version) {
  3487. const parts = version.split(".");
  3488. return parts[0];
  3489. }
  3490. // src/cli/task-build.ts
  3491. var taskBuild = async (coreCompiler, config) => {
  3492. if (config.flags.watch) {
  3493. await taskWatch(coreCompiler, config);
  3494. return;
  3495. }
  3496. let exitCode = 0;
  3497. try {
  3498. startupCompilerLog(coreCompiler, config);
  3499. const versionChecker = startCheckVersion(config, coreCompiler.version);
  3500. const compiler = await coreCompiler.createCompiler(config);
  3501. const results = await compiler.build();
  3502. await telemetryBuildFinishedAction(config.sys, config, coreCompiler, results);
  3503. await compiler.destroy();
  3504. if (results.hasError) {
  3505. exitCode = 1;
  3506. } else if (config.flags.prerender) {
  3507. const prerenderDiagnostics = await runPrerenderTask(
  3508. coreCompiler,
  3509. config,
  3510. results.hydrateAppFilePath,
  3511. results.componentGraph,
  3512. void 0
  3513. );
  3514. config.logger.printDiagnostics(prerenderDiagnostics);
  3515. if (prerenderDiagnostics.some((d) => d.level === "error")) {
  3516. exitCode = 1;
  3517. }
  3518. }
  3519. await printCheckVersionResults(versionChecker);
  3520. } catch (e) {
  3521. exitCode = 1;
  3522. config.logger.error(e);
  3523. }
  3524. if (exitCode > 0) {
  3525. return config.sys.exit(exitCode);
  3526. }
  3527. };
  3528. // src/cli/task-docs.ts
  3529. var taskDocs = async (coreCompiler, config) => {
  3530. config.devServer = {};
  3531. config.outputTargets = config.outputTargets.filter(isOutputTargetDocs);
  3532. config.devMode = true;
  3533. startupCompilerLog(coreCompiler, config);
  3534. const compiler = await coreCompiler.createCompiler(config);
  3535. await compiler.build();
  3536. await compiler.destroy();
  3537. };
  3538. // src/cli/task-generate.ts
  3539. var import_path2 = require("path");
  3540. var taskGenerate = async (config) => {
  3541. if (!config.configPath) {
  3542. config.logger.error("Please run this command in your root directory (i. e. the one containing stencil.config.ts).");
  3543. return config.sys.exit(1);
  3544. }
  3545. const absoluteSrcDir = config.srcDir;
  3546. if (!absoluteSrcDir) {
  3547. config.logger.error(`Stencil's srcDir was not specified.`);
  3548. return config.sys.exit(1);
  3549. }
  3550. const { prompt } = await Promise.resolve().then(() => __toESM(require_lib()));
  3551. const input = config.flags.unknownArgs.find((arg) => !arg.startsWith("-")) || (await prompt({ name: "tagName", type: "text", message: "Component tag name (dash-case):" })).tagName;
  3552. if (void 0 === input) {
  3553. return;
  3554. }
  3555. const { dir, base: componentName } = (0, import_path2.parse)(input);
  3556. const tagError = validateComponentTag(componentName);
  3557. if (tagError) {
  3558. config.logger.error(tagError);
  3559. return config.sys.exit(1);
  3560. }
  3561. let cssExtension = "css";
  3562. if (!!config.plugins.find((plugin) => plugin.name === "sass")) {
  3563. cssExtension = await chooseSassExtension();
  3564. } else if (!!config.plugins.find((plugin) => plugin.name === "less")) {
  3565. cssExtension = "less";
  3566. }
  3567. const filesToGenerateExt = await chooseFilesToGenerate(cssExtension);
  3568. if (!filesToGenerateExt) {
  3569. return;
  3570. }
  3571. const extensionsToGenerate = ["tsx", ...filesToGenerateExt];
  3572. const testFolder = extensionsToGenerate.some(isTest2) ? "test" : "";
  3573. const outDir = (0, import_path2.join)(absoluteSrcDir, "components", dir, componentName);
  3574. await config.sys.createDir(normalizePath((0, import_path2.join)(outDir, testFolder)), { recursive: true });
  3575. const filesToGenerate = extensionsToGenerate.map((extension) => ({
  3576. extension,
  3577. path: getFilepathForFile(outDir, componentName, extension)
  3578. }));
  3579. await checkForOverwrite(filesToGenerate, config);
  3580. const writtenFiles = await Promise.all(
  3581. filesToGenerate.map(
  3582. (file) => getBoilerplateAndWriteFile(
  3583. config,
  3584. componentName,
  3585. extensionsToGenerate.includes("css") || extensionsToGenerate.includes("sass") || extensionsToGenerate.includes("scss") || extensionsToGenerate.includes("less"),
  3586. file,
  3587. cssExtension
  3588. )
  3589. )
  3590. ).catch((error) => config.logger.error(error));
  3591. if (!writtenFiles) {
  3592. return config.sys.exit(1);
  3593. }
  3594. console.log();
  3595. console.log(`${config.logger.gray("$")} stencil generate ${input}`);
  3596. console.log();
  3597. console.log(config.logger.bold("The following files have been generated:"));
  3598. const absoluteRootDir = config.rootDir;
  3599. writtenFiles.map((file) => console.log(` - ${(0, import_path2.relative)(absoluteRootDir, file)}`));
  3600. };
  3601. var chooseFilesToGenerate = async (cssExtension) => {
  3602. const { prompt } = await Promise.resolve().then(() => __toESM(require_lib()));
  3603. return (await prompt({
  3604. name: "filesToGenerate",
  3605. type: "multiselect",
  3606. message: "Which additional files do you want to generate?",
  3607. choices: [
  3608. { value: cssExtension, title: `Stylesheet (.${cssExtension})`, selected: true },
  3609. { value: "spec.tsx", title: "Spec Test (.spec.tsx)", selected: true },
  3610. { value: "e2e.ts", title: "E2E Test (.e2e.ts)", selected: true }
  3611. ]
  3612. })).filesToGenerate;
  3613. };
  3614. var chooseSassExtension = async () => {
  3615. const { prompt } = await Promise.resolve().then(() => __toESM(require_lib()));
  3616. return (await prompt({
  3617. name: "sassFormat",
  3618. type: "select",
  3619. message: "Which Sass format would you like to use? (More info: https://sass-lang.com/documentation/syntax/#the-indented-syntax)",
  3620. choices: [
  3621. { value: "sass", title: `*.sass Format`, selected: true },
  3622. { value: "scss", title: "*.scss Format" }
  3623. ]
  3624. })).sassFormat;
  3625. };
  3626. var getFilepathForFile = (filePath, componentName, extension) => isTest2(extension) ? normalizePath((0, import_path2.join)(filePath, "test", `${componentName}.${extension}`)) : normalizePath((0, import_path2.join)(filePath, `${componentName}.${extension}`));
  3627. var getBoilerplateAndWriteFile = async (config, componentName, withCss, file, styleExtension) => {
  3628. const boilerplate = getBoilerplateByExtension(componentName, file.extension, withCss, styleExtension);
  3629. await config.sys.writeFile(normalizePath(file.path), boilerplate);
  3630. return file.path;
  3631. };
  3632. var checkForOverwrite = async (files, config) => {
  3633. const alreadyPresent = [];
  3634. await Promise.all(
  3635. files.map(async ({ path }) => {
  3636. if (await config.sys.readFile(path) !== void 0) {
  3637. alreadyPresent.push(path);
  3638. }
  3639. })
  3640. );
  3641. if (alreadyPresent.length > 0) {
  3642. config.logger.error(
  3643. "Generating code would overwrite the following files:",
  3644. ...alreadyPresent.map((path) => " " + normalizePath(path))
  3645. );
  3646. await config.sys.exit(1);
  3647. }
  3648. };
  3649. var isTest2 = (extension) => {
  3650. return extension === "e2e.ts" || extension === "spec.tsx";
  3651. };
  3652. var getBoilerplateByExtension = (tagName, extension, withCss, styleExtension) => {
  3653. switch (extension) {
  3654. case "tsx":
  3655. return getComponentBoilerplate(tagName, withCss, styleExtension);
  3656. case "css":
  3657. case "less":
  3658. case "sass":
  3659. case "scss":
  3660. return getStyleUrlBoilerplate(styleExtension);
  3661. case "spec.tsx":
  3662. return getSpecTestBoilerplate(tagName);
  3663. case "e2e.ts":
  3664. return getE2eTestBoilerplate(tagName);
  3665. default:
  3666. throw new Error(`Unkown extension "${extension}".`);
  3667. }
  3668. };
  3669. var getComponentBoilerplate = (tagName, hasStyle, styleExtension) => {
  3670. const decorator = [`{`];
  3671. decorator.push(` tag: '${tagName}',`);
  3672. if (hasStyle) {
  3673. decorator.push(` styleUrl: '${tagName}.${styleExtension}',`);
  3674. }
  3675. decorator.push(` shadow: true,`);
  3676. decorator.push(`}`);
  3677. return `import { Component, Host, h } from '@stencil/core';
  3678. @Component(${decorator.join("\n")})
  3679. export class ${toPascalCase(tagName)} {
  3680. render() {
  3681. return (
  3682. <Host>
  3683. <slot></slot>
  3684. </Host>
  3685. );
  3686. }
  3687. }
  3688. `;
  3689. };
  3690. var getStyleUrlBoilerplate = (ext) => ext === "sass" ? `:host
  3691. display: block
  3692. ` : `:host {
  3693. display: block;
  3694. }
  3695. `;
  3696. var getSpecTestBoilerplate = (tagName) => `import { newSpecPage } from '@stencil/core/testing';
  3697. import { ${toPascalCase(tagName)} } from '../${tagName}';
  3698. describe('${tagName}', () => {
  3699. it('renders', async () => {
  3700. const page = await newSpecPage({
  3701. components: [${toPascalCase(tagName)}],
  3702. html: \`<${tagName}></${tagName}>\`,
  3703. });
  3704. expect(page.root).toEqualHtml(\`
  3705. <${tagName}>
  3706. <mock:shadow-root>
  3707. <slot></slot>
  3708. </mock:shadow-root>
  3709. </${tagName}>
  3710. \`);
  3711. });
  3712. });
  3713. `;
  3714. var getE2eTestBoilerplate = (tagName) => `import { newE2EPage } from '@stencil/core/testing';
  3715. describe('${tagName}', () => {
  3716. it('renders', async () => {
  3717. const page = await newE2EPage();
  3718. await page.setContent('<${tagName}></${tagName}>');
  3719. const element = await page.find('${tagName}');
  3720. expect(element).toHaveClass('hydrated');
  3721. });
  3722. });
  3723. `;
  3724. var toPascalCase = (str) => str.split("-").reduce((res, part) => res + part[0].toUpperCase() + part.slice(1), "");
  3725. // src/cli/task-telemetry.ts
  3726. var taskTelemetry = async (flags, sys, logger) => {
  3727. var _a;
  3728. const prompt = logger.dim(((_a = sys.details) == null ? void 0 : _a.platform) === "windows" ? ">" : "$");
  3729. const isEnabling = flags.args.includes("on");
  3730. const isDisabling = flags.args.includes("off");
  3731. const INFORMATION = `Opt in or out of telemetry. Information about the data we collect is available on our website: ${logger.bold(
  3732. "https://stenciljs.com/telemetry"
  3733. )}`;
  3734. const THANK_YOU = `Thank you for helping to make Stencil better! \u{1F496}`;
  3735. const ENABLED_MESSAGE = `${logger.green("Enabled")}. ${THANK_YOU}
  3736. `;
  3737. const DISABLED_MESSAGE = `${logger.red("Disabled")}
  3738. `;
  3739. const hasTelemetry = await checkTelemetry(sys);
  3740. if (isEnabling) {
  3741. const result = await enableTelemetry(sys);
  3742. result ? console.log(`
  3743. ${logger.bold("Telemetry is now ") + ENABLED_MESSAGE}`) : console.log(`Something went wrong when enabling Telemetry.`);
  3744. return;
  3745. }
  3746. if (isDisabling) {
  3747. const result = await disableTelemetry(sys);
  3748. result ? console.log(`
  3749. ${logger.bold("Telemetry is now ") + DISABLED_MESSAGE}`) : console.log(`Something went wrong when disabling Telemetry.`);
  3750. return;
  3751. }
  3752. console.log(` ${logger.bold("Telemetry:")} ${logger.dim(INFORMATION)}`);
  3753. console.log(`
  3754. ${logger.bold("Status")}: ${hasTelemetry ? ENABLED_MESSAGE : DISABLED_MESSAGE}`);
  3755. console.log(` ${prompt} ${logger.green("stencil telemetry [off|on]")}
  3756. ${logger.cyan("off")} ${logger.dim(".............")} Disable sharing anonymous usage data
  3757. ${logger.cyan("on")} ${logger.dim("..............")} Enable sharing anonymous usage data
  3758. `);
  3759. };
  3760. // src/cli/task-help.ts
  3761. var taskHelp = async (flags, logger, sys) => {
  3762. var _a;
  3763. const prompt = logger.dim(((_a = sys.details) == null ? void 0 : _a.platform) === "windows" ? ">" : "$");
  3764. console.log(`
  3765. ${logger.bold("Build:")} ${logger.dim("Build components for development or production.")}
  3766. ${prompt} ${logger.green("stencil build [--dev] [--watch] [--prerender] [--debug]")}
  3767. ${logger.cyan("--dev")} ${logger.dim(".............")} Development build
  3768. ${logger.cyan("--watch")} ${logger.dim("...........")} Rebuild when files update
  3769. ${logger.cyan("--serve")} ${logger.dim("...........")} Start the dev-server
  3770. ${logger.cyan("--prerender")} ${logger.dim(".......")} Prerender the application
  3771. ${logger.cyan("--docs")} ${logger.dim("............")} Generate component readme.md docs
  3772. ${logger.cyan("--config")} ${logger.dim("..........")} Set stencil config file
  3773. ${logger.cyan("--stats")} ${logger.dim("...........")} Write stencil-stats.json file
  3774. ${logger.cyan("--log")} ${logger.dim(".............")} Write stencil-build.log file
  3775. ${logger.cyan("--debug")} ${logger.dim("...........")} Set the log level to debug
  3776. ${logger.bold("Test:")} ${logger.dim("Run unit and end-to-end tests.")}
  3777. ${prompt} ${logger.green("stencil test [--spec] [--e2e]")}
  3778. ${logger.cyan("--spec")} ${logger.dim("............")} Run unit tests with Jest
  3779. ${logger.cyan("--e2e")} ${logger.dim(".............")} Run e2e tests with Puppeteer
  3780. ${logger.bold("Generate:")} ${logger.dim("Bootstrap components.")}
  3781. ${prompt} ${logger.green("stencil generate")} or ${logger.green("stencil g")}
  3782. `);
  3783. await taskTelemetry(flags, sys, logger);
  3784. console.log(`
  3785. ${logger.bold("Examples:")}
  3786. ${prompt} ${logger.green("stencil build --dev --watch --serve")}
  3787. ${prompt} ${logger.green("stencil build --prerender")}
  3788. ${prompt} ${logger.green("stencil test --spec --e2e")}
  3789. ${prompt} ${logger.green("stencil telemetry on")}
  3790. ${prompt} ${logger.green("stencil generate")}
  3791. ${prompt} ${logger.green("stencil g my-component")}
  3792. `);
  3793. };
  3794. // src/cli/task-info.ts
  3795. var taskInfo = (coreCompiler, sys, logger) => {
  3796. const details = sys.details;
  3797. const versions = coreCompiler.versions;
  3798. console.log(``);
  3799. console.log(`${logger.cyan(" System:")} ${sys.name} ${sys.version}`);
  3800. if (details) {
  3801. console.log(`${logger.cyan(" Platform:")} ${details.platform} (${details.release})`);
  3802. console.log(
  3803. `${logger.cyan(" CPU Model:")} ${details.cpuModel} (${sys.hardwareConcurrency} cpu${sys.hardwareConcurrency !== 1 ? "s" : ""})`
  3804. );
  3805. }
  3806. console.log(`${logger.cyan(" Compiler:")} ${sys.getCompilerExecutingPath()}`);
  3807. console.log(`${logger.cyan(" Build:")} ${coreCompiler.buildId}`);
  3808. console.log(`${logger.cyan(" Stencil:")} ${coreCompiler.version}${logger.emoji(" " + coreCompiler.vermoji)}`);
  3809. console.log(`${logger.cyan(" TypeScript:")} ${versions.typescript}`);
  3810. console.log(`${logger.cyan(" Rollup:")} ${versions.rollup}`);
  3811. console.log(`${logger.cyan(" Parse5:")} ${versions.parse5}`);
  3812. console.log(`${logger.cyan(" jQuery:")} ${versions.jquery}`);
  3813. console.log(`${logger.cyan(" Terser:")} ${versions.terser}`);
  3814. console.log(``);
  3815. };
  3816. // src/cli/task-serve.ts
  3817. var taskServe = async (config) => {
  3818. config.suppressLogs = true;
  3819. config.flags.serve = true;
  3820. config.devServer.openBrowser = !!config.flags.open;
  3821. config.devServer.reloadStrategy = null;
  3822. config.devServer.initialLoadUrl = "/";
  3823. config.devServer.websocket = false;
  3824. config.maxConcurrentWorkers = 1;
  3825. config.devServer.root = isString(config.flags.root) ? config.flags.root : config.sys.getCurrentDirectory();
  3826. if (!config.sys.getDevServerExecutingPath || !config.sys.dynamicImport || !config.sys.onProcessInterrupt) {
  3827. throw new Error(
  3828. `Environment doesn't provide required functions: getDevServerExecutingPath, dynamicImport, onProcessInterrupt`
  3829. );
  3830. }
  3831. const devServerPath = config.sys.getDevServerExecutingPath();
  3832. const { start } = await config.sys.dynamicImport(devServerPath);
  3833. const devServer = await start(config.devServer, config.logger);
  3834. console.log(`${config.logger.cyan(" Root:")} ${devServer.root}`);
  3835. console.log(`${config.logger.cyan(" Address:")} ${devServer.address}`);
  3836. console.log(`${config.logger.cyan(" Port:")} ${devServer.port}`);
  3837. console.log(`${config.logger.cyan(" Server:")} ${devServer.browserUrl}`);
  3838. console.log(``);
  3839. config.sys.onProcessInterrupt(() => {
  3840. if (devServer) {
  3841. config.logger.debug(`dev server close: ${devServer.browserUrl}`);
  3842. devServer.close();
  3843. }
  3844. });
  3845. };
  3846. // src/cli/task-test.ts
  3847. var taskTest = async (config) => {
  3848. var _a;
  3849. config.buildDocs = false;
  3850. const testingRunOpts = {
  3851. e2e: !!config.flags.e2e,
  3852. screenshot: !!config.flags.screenshot,
  3853. spec: !!config.flags.spec,
  3854. updateScreenshot: !!config.flags.updateScreenshot
  3855. };
  3856. const ensureModuleIds = ["@types/jest", "jest", "jest-cli"];
  3857. if (testingRunOpts.e2e) {
  3858. const puppeteer = config.testing.browserExecutablePath ? "puppeteer-core" : "puppeteer";
  3859. ensureModuleIds.push(puppeteer);
  3860. if (testingRunOpts.screenshot) {
  3861. config.logger.warn(
  3862. config.logger.yellow(
  3863. `EXPERIMENTAL: screenshot visual diff testing is currently under heavy development and has not reached a stable status. However, any assistance testing would be appreciated.`
  3864. )
  3865. );
  3866. }
  3867. }
  3868. const diagnostics = await ((_a = config.sys.lazyRequire) == null ? void 0 : _a.ensure(config.rootDir, ensureModuleIds));
  3869. if (diagnostics && diagnostics.length > 0) {
  3870. config.logger.printDiagnostics(diagnostics);
  3871. return config.sys.exit(1);
  3872. }
  3873. try {
  3874. const { createTesting } = await import("../testing/index.js");
  3875. const testing = await createTesting(config);
  3876. const passed = await testing.run(testingRunOpts);
  3877. await testing.destroy();
  3878. if (!passed) {
  3879. return config.sys.exit(1);
  3880. }
  3881. } catch (e) {
  3882. config.logger.error(e);
  3883. return config.sys.exit(1);
  3884. }
  3885. };
  3886. // src/cli/run.ts
  3887. var run = async (init) => {
  3888. const { args, logger, sys } = init;
  3889. try {
  3890. const flags = parseFlags(args);
  3891. const task = flags.task;
  3892. if (flags.debug || flags.verbose) {
  3893. logger.setLevel("debug");
  3894. }
  3895. if (flags.ci) {
  3896. logger.enableColors(false);
  3897. }
  3898. if (isFunction(sys.applyGlobalPatch)) {
  3899. sys.applyGlobalPatch(sys.getCurrentDirectory());
  3900. }
  3901. if (task && task === "version" || flags.version) {
  3902. const coreCompiler2 = await loadCoreCompiler(sys);
  3903. console.log(coreCompiler2.version);
  3904. return;
  3905. }
  3906. if (!task || task === "help" || flags.help) {
  3907. await taskHelp(createConfigFlags({ task: "help", args }), logger, sys);
  3908. return;
  3909. }
  3910. startupLog(logger, task);
  3911. const findConfigResults = await findConfig({ sys, configPath: flags.config });
  3912. if (findConfigResults.isErr) {
  3913. logger.printDiagnostics(findConfigResults.value);
  3914. return sys.exit(1);
  3915. }
  3916. const coreCompiler = await loadCoreCompiler(sys);
  3917. startupLogVersion(logger, task, coreCompiler);
  3918. loadedCompilerLog(sys, logger, flags, coreCompiler);
  3919. if (task === "info") {
  3920. taskInfo(coreCompiler, sys, logger);
  3921. return;
  3922. }
  3923. const foundConfig = result_exports.unwrap(findConfigResults);
  3924. const validated = await coreCompiler.loadConfig({
  3925. config: {
  3926. flags
  3927. },
  3928. configPath: foundConfig.configPath,
  3929. logger,
  3930. sys
  3931. });
  3932. if (validated.diagnostics.length > 0) {
  3933. logger.printDiagnostics(validated.diagnostics);
  3934. if (hasError(validated.diagnostics)) {
  3935. return sys.exit(1);
  3936. }
  3937. }
  3938. if (isFunction(sys.applyGlobalPatch)) {
  3939. sys.applyGlobalPatch(validated.config.rootDir);
  3940. }
  3941. await telemetryAction(sys, validated.config, coreCompiler, async () => {
  3942. await runTask(coreCompiler, validated.config, task, sys);
  3943. });
  3944. } catch (e) {
  3945. if (!shouldIgnoreError(e)) {
  3946. const details = `${logger.getLevel() === "debug" && e instanceof Error ? e.stack : ""}`;
  3947. logger.error(`uncaught cli error: ${e}${details}`);
  3948. return sys.exit(1);
  3949. }
  3950. }
  3951. };
  3952. var runTask = async (coreCompiler, config, task, sys) => {
  3953. var _a;
  3954. const flags = createConfigFlags((_a = config.flags) != null ? _a : { task });
  3955. config.flags = flags;
  3956. if (!config.sys) {
  3957. config.sys = sys;
  3958. }
  3959. const strictConfig = coreCompiler.validateConfig(config, {}).config;
  3960. switch (task) {
  3961. case "build":
  3962. await taskBuild(coreCompiler, strictConfig);
  3963. break;
  3964. case "docs":
  3965. await taskDocs(coreCompiler, strictConfig);
  3966. break;
  3967. case "generate":
  3968. case "g":
  3969. await taskGenerate(strictConfig);
  3970. break;
  3971. case "help":
  3972. await taskHelp(strictConfig.flags, strictConfig.logger, sys);
  3973. break;
  3974. case "prerender":
  3975. await taskPrerender(coreCompiler, strictConfig);
  3976. break;
  3977. case "serve":
  3978. await taskServe(strictConfig);
  3979. break;
  3980. case "telemetry":
  3981. await taskTelemetry(strictConfig.flags, sys, strictConfig.logger);
  3982. break;
  3983. case "test":
  3984. await taskTest(strictConfig);
  3985. break;
  3986. case "version":
  3987. console.log(coreCompiler.version);
  3988. break;
  3989. default:
  3990. strictConfig.logger.error(
  3991. `${strictConfig.logger.emoji("\u274C ")}Invalid stencil command, please see the options below:`
  3992. );
  3993. await taskHelp(strictConfig.flags, strictConfig.logger, sys);
  3994. return config.sys.exit(1);
  3995. }
  3996. };
  3997. // Annotate the CommonJS export names for ESM import in node:
  3998. 0 && (module.exports = {
  3999. BOOLEAN_CLI_FLAGS,
  4000. parseFlags,
  4001. run,
  4002. runTask
  4003. });