AmberCli.js 167 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645
  1. define("amber_cli/AmberCli", ["amber/boot", "amber_core/Kernel-Objects"], function($boot){
  2. var $core=$boot.api,nil=$boot.nil,$recv=$boot.asReceiver,$globals=$boot.globals;
  3. $core.addPackage('AmberCli');
  4. $core.packages["AmberCli"].innerEval = function (expr) { return eval(expr); };
  5. $core.packages["AmberCli"].transport = {"type":"amd","amdNamespace":"amber_cli"};
  6. $core.addClass('AmberCli', $globals.Object, [], 'AmberCli');
  7. //>>excludeStart("ide", pragmas.excludeIdeData);
  8. $globals.AmberCli.comment="I am the Amber CLI (CommandLine Interface) tool which runs on Node.js.\x0a\x0aMy responsibility is to start different Amber programs like the FileServer or the Repl.\x0aWhich program to start is determined by the first commandline parameters passed to the AmberCli executable.\x0aUse `help` to get a list of all available options.\x0aAny further commandline parameters are passed to the specific program.\x0a\x0a## Commands\x0a\x0aNew commands can be added by creating a class side method in the `commands` protocol which takes one parameter.\x0aThis parameter is an array of all commandline options + values passed on to the program.\x0aAny `camelCaseCommand` is transformed into a commandline parameter of the form `camel-case-command` and vice versa.";
  9. //>>excludeEnd("ide");
  10. $core.addMethod(
  11. $core.method({
  12. selector: "commandLineSwitches",
  13. protocol: 'commandline',
  14. fn: function (){
  15. var self=this;
  16. var switches;
  17. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  18. return $core.withContext(function($ctx1) {
  19. //>>excludeEnd("ctx");
  20. var $1;
  21. switches=$recv($recv(self._class())._methodsInProtocol_("commands"))._collect_((function(each){
  22. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  23. return $core.withContext(function($ctx2) {
  24. //>>excludeEnd("ctx");
  25. return $recv(each)._selector();
  26. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  27. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)});
  28. //>>excludeEnd("ctx");
  29. }));
  30. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  31. $ctx1.sendIdx["collect:"]=1;
  32. //>>excludeEnd("ctx");
  33. switches=$recv(switches)._select_((function(each){
  34. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  35. return $core.withContext(function($ctx2) {
  36. //>>excludeEnd("ctx");
  37. return $recv(each)._match_("^[^:]*:$");
  38. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  39. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,2)});
  40. //>>excludeEnd("ctx");
  41. }));
  42. switches=$recv(switches)._collect_((function(each){
  43. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  44. return $core.withContext(function($ctx2) {
  45. //>>excludeEnd("ctx");
  46. return $recv($recv($recv(each)._allButLast())._replace_with_("([A-Z])","-$1"))._asLowercase();
  47. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  48. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,3)});
  49. //>>excludeEnd("ctx");
  50. }));
  51. $1=switches;
  52. return $1;
  53. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  54. }, function($ctx1) {$ctx1.fill(self,"commandLineSwitches",{switches:switches},$globals.AmberCli.klass)});
  55. //>>excludeEnd("ctx");
  56. },
  57. //>>excludeStart("ide", pragmas.excludeIdeData);
  58. args: [],
  59. source: "commandLineSwitches\x0a\x09\x22Collect all methodnames from the 'commands' protocol of the class\x0a\x09 and select the ones with only one parameter.\x0a\x09 Then remove the ':' at the end of the name.\x0a\x09 Additionally all uppercase letters are made lowercase and preceded by a '-'.\x0a\x09 Example: fallbackPage: becomes --fallback-page.\x0a\x09 Return the Array containing the commandline switches.\x22\x0a\x09| switches |\x0a\x09switches := ((self class methodsInProtocol: 'commands') collect: [ :each | each selector]).\x0a\x09switches := switches select: [ :each | each match: '^[^:]*:$'].\x0a\x09switches :=switches collect: [ :each |\x0a\x09\x09(each allButLast replace: '([A-Z])' with: '-$1') asLowercase].\x0a\x09^ switches",
  60. referencedClasses: [],
  61. //>>excludeEnd("ide");
  62. messageSends: ["collect:", "methodsInProtocol:", "class", "selector", "select:", "match:", "asLowercase", "replace:with:", "allButLast"]
  63. }),
  64. $globals.AmberCli.klass);
  65. $core.addMethod(
  66. $core.method({
  67. selector: "config:",
  68. protocol: 'commands',
  69. fn: function (args){
  70. var self=this;
  71. function $Configurator(){return $globals.Configurator||(typeof Configurator=="undefined"?nil:Configurator)}
  72. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  73. return $core.withContext(function($ctx1) {
  74. //>>excludeEnd("ctx");
  75. $recv($recv($Configurator())._new())._start();
  76. return self;
  77. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  78. }, function($ctx1) {$ctx1.fill(self,"config:",{args:args},$globals.AmberCli.klass)});
  79. //>>excludeEnd("ctx");
  80. },
  81. //>>excludeStart("ide", pragmas.excludeIdeData);
  82. args: ["args"],
  83. source: "config: args\x0a\x09Configurator new start",
  84. referencedClasses: ["Configurator"],
  85. //>>excludeEnd("ide");
  86. messageSends: ["start", "new"]
  87. }),
  88. $globals.AmberCli.klass);
  89. $core.addMethod(
  90. $core.method({
  91. selector: "handleArguments:",
  92. protocol: 'commandline',
  93. fn: function (args){
  94. var self=this;
  95. var selector;
  96. function $Array(){return $globals.Array||(typeof Array=="undefined"?nil:Array)}
  97. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  98. return $core.withContext(function($ctx1) {
  99. //>>excludeEnd("ctx");
  100. var $1;
  101. $1=$recv(args)._first();
  102. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  103. $ctx1.sendIdx["first"]=1;
  104. //>>excludeEnd("ctx");
  105. selector=self._selectorForCommandLineSwitch_($1);
  106. $recv(args)._remove_($recv(args)._first());
  107. self._perform_withArguments_(selector,$recv($Array())._with_(args));
  108. return self;
  109. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  110. }, function($ctx1) {$ctx1.fill(self,"handleArguments:",{args:args,selector:selector},$globals.AmberCli.klass)});
  111. //>>excludeEnd("ctx");
  112. },
  113. //>>excludeStart("ide", pragmas.excludeIdeData);
  114. args: ["args"],
  115. source: "handleArguments: args\x0a\x09| selector |\x0a\x0a\x09selector := self selectorForCommandLineSwitch: (args first).\x0a\x09args remove: args first.\x0a\x09self perform: selector withArguments: (Array with: args)",
  116. referencedClasses: ["Array"],
  117. //>>excludeEnd("ide");
  118. messageSends: ["selectorForCommandLineSwitch:", "first", "remove:", "perform:withArguments:", "with:"]
  119. }),
  120. $globals.AmberCli.klass);
  121. $core.addMethod(
  122. $core.method({
  123. selector: "help:",
  124. protocol: 'commands',
  125. fn: function (args){
  126. var self=this;
  127. function $Transcript(){return $globals.Transcript||(typeof Transcript=="undefined"?nil:Transcript)}
  128. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  129. return $core.withContext(function($ctx1) {
  130. //>>excludeEnd("ctx");
  131. $recv($Transcript())._show_("Available commands");
  132. $recv(self._commandLineSwitches())._do_((function(each){
  133. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  134. return $core.withContext(function($ctx2) {
  135. //>>excludeEnd("ctx");
  136. return $recv(console)._log_(each);
  137. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  138. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)});
  139. //>>excludeEnd("ctx");
  140. }));
  141. return self;
  142. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  143. }, function($ctx1) {$ctx1.fill(self,"help:",{args:args},$globals.AmberCli.klass)});
  144. //>>excludeEnd("ctx");
  145. },
  146. //>>excludeStart("ide", pragmas.excludeIdeData);
  147. args: ["args"],
  148. source: "help: args\x0a\x09Transcript show: 'Available commands'.\x0a\x09self commandLineSwitches do: [ :each | console log: each ]",
  149. referencedClasses: ["Transcript"],
  150. //>>excludeEnd("ide");
  151. messageSends: ["show:", "do:", "commandLineSwitches", "log:"]
  152. }),
  153. $globals.AmberCli.klass);
  154. $core.addMethod(
  155. $core.method({
  156. selector: "init:",
  157. protocol: 'commands',
  158. fn: function (args){
  159. var self=this;
  160. function $Initer(){return $globals.Initer||(typeof Initer=="undefined"?nil:Initer)}
  161. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  162. return $core.withContext(function($ctx1) {
  163. //>>excludeEnd("ctx");
  164. $recv($recv($Initer())._new())._start();
  165. return self;
  166. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  167. }, function($ctx1) {$ctx1.fill(self,"init:",{args:args},$globals.AmberCli.klass)});
  168. //>>excludeEnd("ctx");
  169. },
  170. //>>excludeStart("ide", pragmas.excludeIdeData);
  171. args: ["args"],
  172. source: "init: args\x0a\x09Initer new start",
  173. referencedClasses: ["Initer"],
  174. //>>excludeEnd("ide");
  175. messageSends: ["start", "new"]
  176. }),
  177. $globals.AmberCli.klass);
  178. $core.addMethod(
  179. $core.method({
  180. selector: "main",
  181. protocol: 'startup',
  182. fn: function (){
  183. var self=this;
  184. var args,nodeMinorVersion;
  185. function $Transcript(){return $globals.Transcript||(typeof Transcript=="undefined"?nil:Transcript)}
  186. function $Smalltalk(){return $globals.Smalltalk||(typeof Smalltalk=="undefined"?nil:Smalltalk)}
  187. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  188. return $core.withContext(function($ctx1) {
  189. //>>excludeEnd("ctx");
  190. var $5,$4,$3,$2,$1,$8,$7,$6,$9,$10,$11;
  191. $5=$recv($Smalltalk())._version();
  192. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  193. $ctx1.sendIdx["version"]=1;
  194. //>>excludeEnd("ctx");
  195. $4="Welcome to Amber version ".__comma($5);
  196. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  197. $ctx1.sendIdx[","]=4;
  198. //>>excludeEnd("ctx");
  199. $3=$recv($4).__comma(" (NodeJS ");
  200. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  201. $ctx1.sendIdx[","]=3;
  202. //>>excludeEnd("ctx");
  203. $2=$recv($3).__comma($recv($recv(process)._versions())._node());
  204. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  205. $ctx1.sendIdx[","]=2;
  206. //>>excludeEnd("ctx");
  207. $1=$recv($2).__comma(").");
  208. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  209. $ctx1.sendIdx[","]=1;
  210. //>>excludeEnd("ctx");
  211. $recv($Transcript())._show_($1);
  212. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  213. $ctx1.sendIdx["show:"]=1;
  214. //>>excludeEnd("ctx");
  215. $8=$recv(process)._version();
  216. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  217. $ctx1.sendIdx["version"]=2;
  218. //>>excludeEnd("ctx");
  219. $7=$recv($8)._tokenize_(".");
  220. $6=$recv($7)._second();
  221. nodeMinorVersion=$recv($6)._asNumber();
  222. $9=$recv(nodeMinorVersion).__lt((8));
  223. if($core.assert($9)){
  224. $recv($Transcript())._show_("You are currently using Node.js ".__comma($recv(process)._version()));
  225. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  226. $ctx1.sendIdx["show:"]=2;
  227. //>>excludeEnd("ctx");
  228. $recv($Transcript())._show_("Required is at least Node.js v0.8.x or greater.");
  229. return (-1);
  230. };
  231. args=$recv(process)._argv();
  232. $recv(args)._removeFrom_to_((1),(2));
  233. $10=$recv(args)._isEmpty();
  234. if($core.assert($10)){
  235. self._help_(nil);
  236. } else {
  237. $11=self._handleArguments_(args);
  238. return $11;
  239. };
  240. return self;
  241. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  242. }, function($ctx1) {$ctx1.fill(self,"main",{args:args,nodeMinorVersion:nodeMinorVersion},$globals.AmberCli.klass)});
  243. //>>excludeEnd("ctx");
  244. },
  245. //>>excludeStart("ide", pragmas.excludeIdeData);
  246. args: [],
  247. source: "main\x0a\x09\x22Main entry point for Amber applications.\x0a\x09Parses commandline arguments and starts the according subprogram.\x22\x0a\x09| args nodeMinorVersion |\x0a\x09\x0a\x09Transcript show: 'Welcome to Amber version ', Smalltalk version, ' (NodeJS ', process versions node, ').'.\x0a\x0a\x09nodeMinorVersion := ((process version) tokenize: '.') second asNumber.\x0a\x09nodeMinorVersion < 8 ifTrue: [\x0a\x09\x09Transcript show: 'You are currently using Node.js ', (process version).\x0a\x09\x09Transcript show: 'Required is at least Node.js v0.8.x or greater.'.\x0a\x09\x09^ -1.\x0a\x09].\x0a\x0a\x09args := process argv.\x0a\x09\x22Remove the first args which contain the path to the node executable and the script file.\x22\x0a\x09args removeFrom: 1 to: 2.\x0a\x09\x0a\x09(args isEmpty)\x0a\x09\x09ifTrue: [self help: nil]\x0a\x09\x09ifFalse: [^self handleArguments: args]",
  248. referencedClasses: ["Transcript", "Smalltalk"],
  249. //>>excludeEnd("ide");
  250. messageSends: ["show:", ",", "version", "node", "versions", "asNumber", "second", "tokenize:", "ifTrue:", "<", "argv", "removeFrom:to:", "ifTrue:ifFalse:", "isEmpty", "help:", "handleArguments:"]
  251. }),
  252. $globals.AmberCli.klass);
  253. $core.addMethod(
  254. $core.method({
  255. selector: "repl:",
  256. protocol: 'commands',
  257. fn: function (args){
  258. var self=this;
  259. function $Repl(){return $globals.Repl||(typeof Repl=="undefined"?nil:Repl)}
  260. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  261. return $core.withContext(function($ctx1) {
  262. //>>excludeEnd("ctx");
  263. var $1;
  264. $1=$recv($recv($Repl())._new())._createInterface();
  265. return $1;
  266. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  267. }, function($ctx1) {$ctx1.fill(self,"repl:",{args:args},$globals.AmberCli.klass)});
  268. //>>excludeEnd("ctx");
  269. },
  270. //>>excludeStart("ide", pragmas.excludeIdeData);
  271. args: ["args"],
  272. source: "repl: args\x0a\x09^ Repl new createInterface",
  273. referencedClasses: ["Repl"],
  274. //>>excludeEnd("ide");
  275. messageSends: ["createInterface", "new"]
  276. }),
  277. $globals.AmberCli.klass);
  278. $core.addMethod(
  279. $core.method({
  280. selector: "selectorForCommandLineSwitch:",
  281. protocol: 'commandline',
  282. fn: function (aSwitch){
  283. var self=this;
  284. var command,selector;
  285. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  286. return $core.withContext(function($ctx1) {
  287. //>>excludeEnd("ctx");
  288. var $1,$2;
  289. $1=$recv(self._commandLineSwitches())._includes_(aSwitch);
  290. if($core.assert($1)){
  291. selector=$recv($recv(aSwitch)._replace_with_("-[a-z]",(function(each){
  292. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  293. return $core.withContext(function($ctx2) {
  294. //>>excludeEnd("ctx");
  295. return $recv($recv(each)._second())._asUppercase();
  296. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  297. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,2)});
  298. //>>excludeEnd("ctx");
  299. }))).__comma(":");
  300. selector;
  301. } else {
  302. selector="help:";
  303. selector;
  304. };
  305. $2=selector;
  306. return $2;
  307. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  308. }, function($ctx1) {$ctx1.fill(self,"selectorForCommandLineSwitch:",{aSwitch:aSwitch,command:command,selector:selector},$globals.AmberCli.klass)});
  309. //>>excludeEnd("ctx");
  310. },
  311. //>>excludeStart("ide", pragmas.excludeIdeData);
  312. args: ["aSwitch"],
  313. source: "selectorForCommandLineSwitch: aSwitch\x0a\x09\x22Add ':' at the end and replace all occurences of a lowercase letter preceded by a '-' with the Uppercase letter.\x0a\x09 Example: fallback-page becomes fallbackPage:.\x0a\x09 If no correct selector is found return 'help:'\x22\x0a\x09 | command selector |\x0a\x0a\x09 (self commandLineSwitches includes: aSwitch)\x0a\x09 ifTrue: [ selector := (aSwitch replace: '-[a-z]' with: [ :each | each second asUppercase ]), ':']\x0a\x09 ifFalse: [ selector := 'help:' ].\x0a\x09^ selector",
  314. referencedClasses: [],
  315. //>>excludeEnd("ide");
  316. messageSends: ["ifTrue:ifFalse:", "includes:", "commandLineSwitches", ",", "replace:with:", "asUppercase", "second"]
  317. }),
  318. $globals.AmberCli.klass);
  319. $core.addMethod(
  320. $core.method({
  321. selector: "serve:",
  322. protocol: 'commands',
  323. fn: function (args){
  324. var self=this;
  325. function $FileServer(){return $globals.FileServer||(typeof FileServer=="undefined"?nil:FileServer)}
  326. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  327. return $core.withContext(function($ctx1) {
  328. //>>excludeEnd("ctx");
  329. var $1;
  330. $1=$recv($recv($FileServer())._createServerWithArguments_(args))._start();
  331. return $1;
  332. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  333. }, function($ctx1) {$ctx1.fill(self,"serve:",{args:args},$globals.AmberCli.klass)});
  334. //>>excludeEnd("ctx");
  335. },
  336. //>>excludeStart("ide", pragmas.excludeIdeData);
  337. args: ["args"],
  338. source: "serve: args\x0a\x09^ (FileServer createServerWithArguments: args) start",
  339. referencedClasses: ["FileServer"],
  340. //>>excludeEnd("ide");
  341. messageSends: ["start", "createServerWithArguments:"]
  342. }),
  343. $globals.AmberCli.klass);
  344. $core.addMethod(
  345. $core.method({
  346. selector: "version:",
  347. protocol: 'commands',
  348. fn: function (arguments_){
  349. var self=this;
  350. return self;
  351. },
  352. //>>excludeStart("ide", pragmas.excludeIdeData);
  353. args: ["arguments"],
  354. source: "version: arguments",
  355. referencedClasses: [],
  356. //>>excludeEnd("ide");
  357. messageSends: []
  358. }),
  359. $globals.AmberCli.klass);
  360. $core.addClass('BaseFileManipulator', $globals.Object, ['path', 'fs'], 'AmberCli');
  361. $core.addMethod(
  362. $core.method({
  363. selector: "dirname",
  364. protocol: 'private',
  365. fn: function (){
  366. var self=this;
  367. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  368. return $core.withContext(function($ctx1) {
  369. //>>excludeEnd("ctx");
  370. return __dirname;
  371. return self;
  372. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  373. }, function($ctx1) {$ctx1.fill(self,"dirname",{},$globals.BaseFileManipulator)});
  374. //>>excludeEnd("ctx");
  375. },
  376. //>>excludeStart("ide", pragmas.excludeIdeData);
  377. args: [],
  378. source: "dirname\x0a\x09<return __dirname>",
  379. referencedClasses: [],
  380. //>>excludeEnd("ide");
  381. messageSends: []
  382. }),
  383. $globals.BaseFileManipulator);
  384. $core.addMethod(
  385. $core.method({
  386. selector: "initialize",
  387. protocol: 'initialization',
  388. fn: function (){
  389. var self=this;
  390. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  391. return $core.withContext(function($ctx1) {
  392. //>>excludeEnd("ctx");
  393. (
  394. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  395. $ctx1.supercall = true,
  396. //>>excludeEnd("ctx");
  397. $globals.BaseFileManipulator.superclass.fn.prototype._initialize.apply($recv(self), []));
  398. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  399. $ctx1.supercall = false;
  400. //>>excludeEnd("ctx");;
  401. self["@path"]=$recv(require)._value_("path");
  402. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  403. $ctx1.sendIdx["value:"]=1;
  404. //>>excludeEnd("ctx");
  405. self["@fs"]=$recv(require)._value_("fs");
  406. return self;
  407. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  408. }, function($ctx1) {$ctx1.fill(self,"initialize",{},$globals.BaseFileManipulator)});
  409. //>>excludeEnd("ctx");
  410. },
  411. //>>excludeStart("ide", pragmas.excludeIdeData);
  412. args: [],
  413. source: "initialize\x0a\x09super initialize.\x0a\x09path := require value: 'path'.\x0a\x09fs := require value: 'fs'",
  414. referencedClasses: [],
  415. //>>excludeEnd("ide");
  416. messageSends: ["initialize", "value:"]
  417. }),
  418. $globals.BaseFileManipulator);
  419. $core.addMethod(
  420. $core.method({
  421. selector: "rootDirname",
  422. protocol: 'private',
  423. fn: function (){
  424. var self=this;
  425. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  426. return $core.withContext(function($ctx1) {
  427. //>>excludeEnd("ctx");
  428. var $1;
  429. $1=$recv(self["@path"])._join_with_(self._dirname(),"..");
  430. return $1;
  431. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  432. }, function($ctx1) {$ctx1.fill(self,"rootDirname",{},$globals.BaseFileManipulator)});
  433. //>>excludeEnd("ctx");
  434. },
  435. //>>excludeStart("ide", pragmas.excludeIdeData);
  436. args: [],
  437. source: "rootDirname\x0a\x09^ path join: self dirname with: '..'",
  438. referencedClasses: [],
  439. //>>excludeEnd("ide");
  440. messageSends: ["join:with:", "dirname"]
  441. }),
  442. $globals.BaseFileManipulator);
  443. $core.addClass('Configurator', $globals.BaseFileManipulator, [], 'AmberCli');
  444. $core.addMethod(
  445. $core.method({
  446. selector: "initialize",
  447. protocol: 'initialization',
  448. fn: function (){
  449. var self=this;
  450. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  451. return $core.withContext(function($ctx1) {
  452. //>>excludeEnd("ctx");
  453. (
  454. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  455. $ctx1.supercall = true,
  456. //>>excludeEnd("ctx");
  457. $globals.Configurator.superclass.fn.prototype._initialize.apply($recv(self), []));
  458. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  459. $ctx1.supercall = false;
  460. //>>excludeEnd("ctx");;
  461. return self;
  462. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  463. }, function($ctx1) {$ctx1.fill(self,"initialize",{},$globals.Configurator)});
  464. //>>excludeEnd("ctx");
  465. },
  466. //>>excludeStart("ide", pragmas.excludeIdeData);
  467. args: [],
  468. source: "initialize\x0a\x09super initialize",
  469. referencedClasses: [],
  470. //>>excludeEnd("ide");
  471. messageSends: ["initialize"]
  472. }),
  473. $globals.Configurator);
  474. $core.addMethod(
  475. $core.method({
  476. selector: "start",
  477. protocol: 'action',
  478. fn: function (){
  479. var self=this;
  480. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  481. return $core.withContext(function($ctx1) {
  482. //>>excludeEnd("ctx");
  483. var $receiver;
  484. self._writeConfigThenDo_((function(err){
  485. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  486. return $core.withContext(function($ctx2) {
  487. //>>excludeEnd("ctx");
  488. if(($receiver = err) == null || $receiver.isNil){
  489. return $recv(process)._exit();
  490. } else {
  491. return $recv(process)._exit_((111));
  492. };
  493. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  494. }, function($ctx2) {$ctx2.fillBlock({err:err},$ctx1,1)});
  495. //>>excludeEnd("ctx");
  496. }));
  497. return self;
  498. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  499. }, function($ctx1) {$ctx1.fill(self,"start",{},$globals.Configurator)});
  500. //>>excludeEnd("ctx");
  501. },
  502. //>>excludeStart("ide", pragmas.excludeIdeData);
  503. args: [],
  504. source: "start\x0a\x09self writeConfigThenDo: [ :err | err\x0a\x09\x09ifNotNil: [ process exit: 111 ]\x0a\x09\x09ifNil: [ process exit ]]",
  505. referencedClasses: [],
  506. //>>excludeEnd("ide");
  507. messageSends: ["writeConfigThenDo:", "ifNotNil:ifNil:", "exit:", "exit"]
  508. }),
  509. $globals.Configurator);
  510. $core.addMethod(
  511. $core.method({
  512. selector: "writeConfigThenDo:",
  513. protocol: 'action',
  514. fn: function (aBlock){
  515. var self=this;
  516. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  517. return $core.withContext(function($ctx1) {
  518. //>>excludeEnd("ctx");
  519. $recv($recv(require)._value_("amber-dev/lib/config"))._writeConfig_toFile_thenDo_($recv(process)._cwd(),"config.js",aBlock);
  520. return self;
  521. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  522. }, function($ctx1) {$ctx1.fill(self,"writeConfigThenDo:",{aBlock:aBlock},$globals.Configurator)});
  523. //>>excludeEnd("ctx");
  524. },
  525. //>>excludeStart("ide", pragmas.excludeIdeData);
  526. args: ["aBlock"],
  527. source: "writeConfigThenDo: aBlock\x0a\x09(require value: 'amber-dev/lib/config')\x0a\x09\x09writeConfig: process cwd\x0a\x09\x09toFile: 'config.js'\x0a\x09\x09thenDo: aBlock",
  528. referencedClasses: [],
  529. //>>excludeEnd("ide");
  530. messageSends: ["writeConfig:toFile:thenDo:", "value:", "cwd"]
  531. }),
  532. $globals.Configurator);
  533. $core.addClass('FileServer', $globals.BaseFileManipulator, ['http', 'url', 'host', 'port', 'basePath', 'util', 'username', 'password', 'fallbackPage'], 'AmberCli');
  534. //>>excludeStart("ide", pragmas.excludeIdeData);
  535. $globals.FileServer.comment="I am the Amber Smalltalk FileServer.\x0aMy runtime requirement is a functional Node.js executable.\x0a\x0aTo start a FileServer instance on port `4000` use the following code:\x0a\x0a FileServer new start\x0a\x0aA parameterized instance can be created with the following code:\x0a\x0a FileServer createServerWithArguments: options\x0a\x0aHere, `options` is an array of commandline style strings each followed by a value e.g. `#('--port', '6000', '--host', '0.0.0.0')`.\x0aA list of all available parameters can be printed to the commandline by passing `--help` as parameter.\x0aSee the `Options` section for further details on how options are mapped to instance methods.\x0a\x0aAfter startup FileServer checks if the directory layout required by Amber is present and logs a warning on absence.\x0a\x0a\x0a## Options\x0a\x0aEach option is of the form `--some-option-string` which is transformed into a selector of the format `someOptionString:`.\x0aThe trailing `--` gets removed, each `-[a-z]` gets transformed into the according uppercase letter, and a `:` is appended to create a selector which takes a single argument.\x0aAfterwards, the selector gets executed on the `FileServer` instance with the value following in the options array as parameter.\x0a\x0a## Adding new commandline parameters\x0a\x0aAdding new commandline parameters to `FileServer` is as easy as adding a new single parameter method to the `accessing` protocol.";
  536. //>>excludeEnd("ide");
  537. $core.addMethod(
  538. $core.method({
  539. selector: "base64Decode:",
  540. protocol: 'private',
  541. fn: function (aString){
  542. var self=this;
  543. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  544. return $core.withContext(function($ctx1) {
  545. //>>excludeEnd("ctx");
  546. return (new Buffer(aString, 'base64').toString());
  547. return self;
  548. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  549. }, function($ctx1) {$ctx1.fill(self,"base64Decode:",{aString:aString},$globals.FileServer)});
  550. //>>excludeEnd("ctx");
  551. },
  552. //>>excludeStart("ide", pragmas.excludeIdeData);
  553. args: ["aString"],
  554. source: "base64Decode: aString\x0a\x09<return (new Buffer(aString, 'base64').toString())>",
  555. referencedClasses: [],
  556. //>>excludeEnd("ide");
  557. messageSends: []
  558. }),
  559. $globals.FileServer);
  560. $core.addMethod(
  561. $core.method({
  562. selector: "basePath",
  563. protocol: 'accessing',
  564. fn: function (){
  565. var self=this;
  566. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  567. return $core.withContext(function($ctx1) {
  568. //>>excludeEnd("ctx");
  569. var $2,$1,$receiver;
  570. $2=self["@basePath"];
  571. if(($receiver = $2) == null || $receiver.isNil){
  572. $1=$recv(self._class())._defaultBasePath();
  573. } else {
  574. $1=$2;
  575. };
  576. return $1;
  577. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  578. }, function($ctx1) {$ctx1.fill(self,"basePath",{},$globals.FileServer)});
  579. //>>excludeEnd("ctx");
  580. },
  581. //>>excludeStart("ide", pragmas.excludeIdeData);
  582. args: [],
  583. source: "basePath\x0a\x09^ basePath ifNil: [self class defaultBasePath]",
  584. referencedClasses: [],
  585. //>>excludeEnd("ide");
  586. messageSends: ["ifNil:", "defaultBasePath", "class"]
  587. }),
  588. $globals.FileServer);
  589. $core.addMethod(
  590. $core.method({
  591. selector: "basePath:",
  592. protocol: 'accessing',
  593. fn: function (aString){
  594. var self=this;
  595. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  596. return $core.withContext(function($ctx1) {
  597. //>>excludeEnd("ctx");
  598. self["@basePath"]=aString;
  599. self._validateBasePath();
  600. return self;
  601. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  602. }, function($ctx1) {$ctx1.fill(self,"basePath:",{aString:aString},$globals.FileServer)});
  603. //>>excludeEnd("ctx");
  604. },
  605. //>>excludeStart("ide", pragmas.excludeIdeData);
  606. args: ["aString"],
  607. source: "basePath: aString\x0a\x09basePath := aString.\x0a\x09self validateBasePath.",
  608. referencedClasses: [],
  609. //>>excludeEnd("ide");
  610. messageSends: ["validateBasePath"]
  611. }),
  612. $globals.FileServer);
  613. $core.addMethod(
  614. $core.method({
  615. selector: "checkDirectoryLayout",
  616. protocol: 'initialization',
  617. fn: function (){
  618. var self=this;
  619. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  620. return $core.withContext(function($ctx1) {
  621. //>>excludeEnd("ctx");
  622. var $1;
  623. $1=$recv(self["@fs"])._existsSync_(self._withBasePath_("index.html"));
  624. if(!$core.assert($1)){
  625. $recv(console)._warn_("Warning: project directory does not contain index.html.");
  626. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  627. $ctx1.sendIdx["warn:"]=1;
  628. //>>excludeEnd("ctx");
  629. $recv(console)._warn_(" You can specify the directory containing index.html with --base-path.");
  630. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  631. $ctx1.sendIdx["warn:"]=2;
  632. //>>excludeEnd("ctx");
  633. $recv(console)._warn_(" You can also specify a page to be served by default,");
  634. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  635. $ctx1.sendIdx["warn:"]=3;
  636. //>>excludeEnd("ctx");
  637. $recv(console)._warn_(" for all paths that do not map to a file, with --fallback-page.");
  638. };
  639. return self;
  640. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  641. }, function($ctx1) {$ctx1.fill(self,"checkDirectoryLayout",{},$globals.FileServer)});
  642. //>>excludeEnd("ctx");
  643. },
  644. //>>excludeStart("ide", pragmas.excludeIdeData);
  645. args: [],
  646. source: "checkDirectoryLayout\x0a\x09(fs existsSync:\x09(self withBasePath: 'index.html')) ifFalse: [\x0a\x09\x09console warn: 'Warning: project directory does not contain index.html.'.\x0a\x09\x09console warn: ' You can specify the directory containing index.html with --base-path.'.\x0a\x09\x09console warn: ' You can also specify a page to be served by default,'.\x0a\x09\x09console warn: ' for all paths that do not map to a file, with --fallback-page.'].",
  647. referencedClasses: [],
  648. //>>excludeEnd("ide");
  649. messageSends: ["ifFalse:", "existsSync:", "withBasePath:", "warn:"]
  650. }),
  651. $globals.FileServer);
  652. $core.addMethod(
  653. $core.method({
  654. selector: "fallbackPage",
  655. protocol: 'accessing',
  656. fn: function (){
  657. var self=this;
  658. var $1;
  659. $1=self["@fallbackPage"];
  660. return $1;
  661. },
  662. //>>excludeStart("ide", pragmas.excludeIdeData);
  663. args: [],
  664. source: "fallbackPage\x0a\x09^ fallbackPage",
  665. referencedClasses: [],
  666. //>>excludeEnd("ide");
  667. messageSends: []
  668. }),
  669. $globals.FileServer);
  670. $core.addMethod(
  671. $core.method({
  672. selector: "fallbackPage:",
  673. protocol: 'accessing',
  674. fn: function (aString){
  675. var self=this;
  676. self["@fallbackPage"]=aString;
  677. return self;
  678. },
  679. //>>excludeStart("ide", pragmas.excludeIdeData);
  680. args: ["aString"],
  681. source: "fallbackPage: aString\x0a\x09fallbackPage := aString",
  682. referencedClasses: [],
  683. //>>excludeEnd("ide");
  684. messageSends: []
  685. }),
  686. $globals.FileServer);
  687. $core.addMethod(
  688. $core.method({
  689. selector: "handleGETRequest:respondTo:",
  690. protocol: 'request handling',
  691. fn: function (aRequest,aResponse){
  692. var self=this;
  693. var uri,filename;
  694. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  695. return $core.withContext(function($ctx1) {
  696. //>>excludeEnd("ctx");
  697. var $1;
  698. uri=$recv(self["@url"])._parse_($recv(aRequest)._url());
  699. filename=$recv(self["@path"])._join_with_(self._basePath(),$recv(uri)._pathname());
  700. $recv(self["@fs"])._exists_do_(filename,(function(aBoolean){
  701. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  702. return $core.withContext(function($ctx2) {
  703. //>>excludeEnd("ctx");
  704. if($core.assert(aBoolean)){
  705. $1=$recv($recv(self["@fs"])._statSync_(filename))._isDirectory();
  706. if($core.assert($1)){
  707. return self._respondDirectoryNamed_from_to_(filename,uri,aResponse);
  708. } else {
  709. return self._respondFileNamed_to_(filename,aResponse);
  710. };
  711. } else {
  712. return self._respondNotFoundTo_(aResponse);
  713. };
  714. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  715. }, function($ctx2) {$ctx2.fillBlock({aBoolean:aBoolean},$ctx1,1)});
  716. //>>excludeEnd("ctx");
  717. }));
  718. return self;
  719. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  720. }, function($ctx1) {$ctx1.fill(self,"handleGETRequest:respondTo:",{aRequest:aRequest,aResponse:aResponse,uri:uri,filename:filename},$globals.FileServer)});
  721. //>>excludeEnd("ctx");
  722. },
  723. //>>excludeStart("ide", pragmas.excludeIdeData);
  724. args: ["aRequest", "aResponse"],
  725. source: "handleGETRequest: aRequest respondTo: aResponse\x0a\x09| uri filename |\x0a\x09uri := url parse: aRequest url.\x0a\x09filename := path join: self basePath with: uri pathname.\x0a\x09fs exists: filename do: [:aBoolean |\x0a\x09\x09aBoolean\x0a\x09\x09\x09ifFalse: [self respondNotFoundTo: aResponse]\x0a\x09\x09\x09ifTrue: [(fs statSync: filename) isDirectory\x0a\x09\x09\x09\x09ifTrue: [self respondDirectoryNamed: filename from: uri to: aResponse]\x0a\x09\x09\x09\x09ifFalse: [self respondFileNamed: filename to: aResponse]]]",
  726. referencedClasses: [],
  727. //>>excludeEnd("ide");
  728. messageSends: ["parse:", "url", "join:with:", "basePath", "pathname", "exists:do:", "ifFalse:ifTrue:", "respondNotFoundTo:", "ifTrue:ifFalse:", "isDirectory", "statSync:", "respondDirectoryNamed:from:to:", "respondFileNamed:to:"]
  729. }),
  730. $globals.FileServer);
  731. $core.addMethod(
  732. $core.method({
  733. selector: "handleOPTIONSRequest:respondTo:",
  734. protocol: 'request handling',
  735. fn: function (aRequest,aResponse){
  736. var self=this;
  737. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  738. return $core.withContext(function($ctx1) {
  739. //>>excludeEnd("ctx");
  740. $recv(aResponse)._writeHead_options_((200),$globals.HashedCollection._newFromPairs_(["Access-Control-Allow-Origin","*","Access-Control-Allow-Methods","GET, PUT, POST, DELETE, OPTIONS","Access-Control-Allow-Headers","Content-Type, Accept","Content-Length",(0),"Access-Control-Max-Age",(10)]));
  741. $recv(aResponse)._end();
  742. return self;
  743. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  744. }, function($ctx1) {$ctx1.fill(self,"handleOPTIONSRequest:respondTo:",{aRequest:aRequest,aResponse:aResponse},$globals.FileServer)});
  745. //>>excludeEnd("ctx");
  746. },
  747. //>>excludeStart("ide", pragmas.excludeIdeData);
  748. args: ["aRequest", "aResponse"],
  749. source: "handleOPTIONSRequest: aRequest respondTo: aResponse\x0a\x09aResponse writeHead: 200 options: #{'Access-Control-Allow-Origin' -> '*'.\x0a\x09\x09\x09\x09\x09'Access-Control-Allow-Methods' -> 'GET, PUT, POST, DELETE, OPTIONS'.\x0a\x09\x09\x09\x09\x09'Access-Control-Allow-Headers' -> 'Content-Type, Accept'.\x0a\x09\x09\x09\x09\x09'Content-Length' -> 0.\x0a\x09\x09\x09\x09\x09'Access-Control-Max-Age' -> 10}.\x0a\x09aResponse end",
  750. referencedClasses: [],
  751. //>>excludeEnd("ide");
  752. messageSends: ["writeHead:options:", "end"]
  753. }),
  754. $globals.FileServer);
  755. $core.addMethod(
  756. $core.method({
  757. selector: "handlePUTRequest:respondTo:",
  758. protocol: 'request handling',
  759. fn: function (aRequest,aResponse){
  760. var self=this;
  761. var file,stream;
  762. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  763. return $core.withContext(function($ctx1) {
  764. //>>excludeEnd("ctx");
  765. var $1,$2,$3,$4;
  766. $1=self._isAuthenticated_(aRequest);
  767. if(!$core.assert($1)){
  768. self._respondAuthenticationRequiredTo_(aResponse);
  769. return nil;
  770. };
  771. file=".".__comma($recv(aRequest)._url());
  772. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  773. $ctx1.sendIdx[","]=1;
  774. //>>excludeEnd("ctx");
  775. stream=$recv(self["@fs"])._createWriteStream_(file);
  776. $recv(stream)._on_do_("error",(function(error){
  777. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  778. return $core.withContext(function($ctx2) {
  779. //>>excludeEnd("ctx");
  780. $2=console;
  781. $3="Error creating WriteStream for file ".__comma(file);
  782. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  783. $ctx2.sendIdx[","]=2;
  784. //>>excludeEnd("ctx");
  785. $recv($2)._warn_($3);
  786. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  787. $ctx2.sendIdx["warn:"]=1;
  788. //>>excludeEnd("ctx");
  789. $recv(console)._warn_(" Did you forget to create the necessary directory in your project (often /src)?");
  790. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  791. $ctx2.sendIdx["warn:"]=2;
  792. //>>excludeEnd("ctx");
  793. $recv(console)._warn_(" The exact error is: ".__comma(error));
  794. return self._respondNotCreatedTo_(aResponse);
  795. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  796. }, function($ctx2) {$ctx2.fillBlock({error:error},$ctx1,2)});
  797. //>>excludeEnd("ctx");
  798. }));
  799. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  800. $ctx1.sendIdx["on:do:"]=1;
  801. //>>excludeEnd("ctx");
  802. $recv(stream)._on_do_("close",(function(){
  803. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  804. return $core.withContext(function($ctx2) {
  805. //>>excludeEnd("ctx");
  806. return self._respondCreatedTo_(aResponse);
  807. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  808. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,3)});
  809. //>>excludeEnd("ctx");
  810. }));
  811. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  812. $ctx1.sendIdx["on:do:"]=2;
  813. //>>excludeEnd("ctx");
  814. $recv(aRequest)._setEncoding_("utf8");
  815. $recv(aRequest)._on_do_("data",(function(data){
  816. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  817. return $core.withContext(function($ctx2) {
  818. //>>excludeEnd("ctx");
  819. return $recv(stream)._write_(data);
  820. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  821. }, function($ctx2) {$ctx2.fillBlock({data:data},$ctx1,4)});
  822. //>>excludeEnd("ctx");
  823. }));
  824. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  825. $ctx1.sendIdx["on:do:"]=3;
  826. //>>excludeEnd("ctx");
  827. $recv(aRequest)._on_do_("end",(function(){
  828. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  829. return $core.withContext(function($ctx2) {
  830. //>>excludeEnd("ctx");
  831. $4=$recv(stream)._writable();
  832. if($core.assert($4)){
  833. return $recv(stream)._end();
  834. };
  835. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  836. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,5)});
  837. //>>excludeEnd("ctx");
  838. }));
  839. return self;
  840. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  841. }, function($ctx1) {$ctx1.fill(self,"handlePUTRequest:respondTo:",{aRequest:aRequest,aResponse:aResponse,file:file,stream:stream},$globals.FileServer)});
  842. //>>excludeEnd("ctx");
  843. },
  844. //>>excludeStart("ide", pragmas.excludeIdeData);
  845. args: ["aRequest", "aResponse"],
  846. source: "handlePUTRequest: aRequest respondTo: aResponse\x0a\x09| file stream |\x0a\x09(self isAuthenticated: aRequest)\x0a\x09\x09ifFalse: [self respondAuthenticationRequiredTo: aResponse. ^ nil].\x0a\x0a\x09file := '.', aRequest url.\x0a\x09stream := fs createWriteStream: file.\x0a\x0a\x09stream on: 'error' do: [:error |\x0a\x09\x09console warn: 'Error creating WriteStream for file ', file.\x0a\x09\x09console warn: ' Did you forget to create the necessary directory in your project (often /src)?'.\x0a\x09\x09console warn: ' The exact error is: ', error.\x0a\x09\x09self respondNotCreatedTo: aResponse].\x0a\x0a\x09stream on: 'close' do: [\x0a\x09\x09self respondCreatedTo: aResponse].\x0a\x0a\x09aRequest setEncoding: 'utf8'.\x0a\x09aRequest on: 'data' do: [:data |\x0a\x09\x09stream write: data].\x0a\x0a\x09aRequest on: 'end' do: [\x0a\x09\x09stream writable ifTrue: [stream end]]",
  847. referencedClasses: [],
  848. //>>excludeEnd("ide");
  849. messageSends: ["ifFalse:", "isAuthenticated:", "respondAuthenticationRequiredTo:", ",", "url", "createWriteStream:", "on:do:", "warn:", "respondNotCreatedTo:", "respondCreatedTo:", "setEncoding:", "write:", "ifTrue:", "writable", "end"]
  850. }),
  851. $globals.FileServer);
  852. $core.addMethod(
  853. $core.method({
  854. selector: "handleRequest:respondTo:",
  855. protocol: 'request handling',
  856. fn: function (aRequest,aResponse){
  857. var self=this;
  858. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  859. return $core.withContext(function($ctx1) {
  860. //>>excludeEnd("ctx");
  861. var $2,$1,$4,$3,$5;
  862. $2=$recv(aRequest)._method();
  863. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  864. $ctx1.sendIdx["method"]=1;
  865. //>>excludeEnd("ctx");
  866. $1=$recv($2).__eq("PUT");
  867. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  868. $ctx1.sendIdx["="]=1;
  869. //>>excludeEnd("ctx");
  870. if($core.assert($1)){
  871. self._handlePUTRequest_respondTo_(aRequest,aResponse);
  872. };
  873. $4=$recv(aRequest)._method();
  874. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  875. $ctx1.sendIdx["method"]=2;
  876. //>>excludeEnd("ctx");
  877. $3=$recv($4).__eq("GET");
  878. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  879. $ctx1.sendIdx["="]=2;
  880. //>>excludeEnd("ctx");
  881. if($core.assert($3)){
  882. self._handleGETRequest_respondTo_(aRequest,aResponse);
  883. };
  884. $5=$recv($recv(aRequest)._method()).__eq("OPTIONS");
  885. if($core.assert($5)){
  886. self._handleOPTIONSRequest_respondTo_(aRequest,aResponse);
  887. };
  888. return self;
  889. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  890. }, function($ctx1) {$ctx1.fill(self,"handleRequest:respondTo:",{aRequest:aRequest,aResponse:aResponse},$globals.FileServer)});
  891. //>>excludeEnd("ctx");
  892. },
  893. //>>excludeStart("ide", pragmas.excludeIdeData);
  894. args: ["aRequest", "aResponse"],
  895. source: "handleRequest: aRequest respondTo: aResponse\x0a\x09aRequest method = 'PUT'\x0a\x09\x09ifTrue: [self handlePUTRequest: aRequest respondTo: aResponse].\x0a\x09aRequest method = 'GET'\x0a\x09\x09ifTrue:[self handleGETRequest: aRequest respondTo: aResponse].\x0a\x09aRequest method = 'OPTIONS'\x0a\x09\x09ifTrue:[self handleOPTIONSRequest: aRequest respondTo: aResponse]",
  896. referencedClasses: [],
  897. //>>excludeEnd("ide");
  898. messageSends: ["ifTrue:", "=", "method", "handlePUTRequest:respondTo:", "handleGETRequest:respondTo:", "handleOPTIONSRequest:respondTo:"]
  899. }),
  900. $globals.FileServer);
  901. $core.addMethod(
  902. $core.method({
  903. selector: "host",
  904. protocol: 'accessing',
  905. fn: function (){
  906. var self=this;
  907. var $1;
  908. $1=self["@host"];
  909. return $1;
  910. },
  911. //>>excludeStart("ide", pragmas.excludeIdeData);
  912. args: [],
  913. source: "host\x0a\x09^ host",
  914. referencedClasses: [],
  915. //>>excludeEnd("ide");
  916. messageSends: []
  917. }),
  918. $globals.FileServer);
  919. $core.addMethod(
  920. $core.method({
  921. selector: "host:",
  922. protocol: 'accessing',
  923. fn: function (hostname){
  924. var self=this;
  925. self["@host"]=hostname;
  926. return self;
  927. },
  928. //>>excludeStart("ide", pragmas.excludeIdeData);
  929. args: ["hostname"],
  930. source: "host: hostname\x0a\x09host := hostname",
  931. referencedClasses: [],
  932. //>>excludeEnd("ide");
  933. messageSends: []
  934. }),
  935. $globals.FileServer);
  936. $core.addMethod(
  937. $core.method({
  938. selector: "initialize",
  939. protocol: 'initialization',
  940. fn: function (){
  941. var self=this;
  942. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  943. return $core.withContext(function($ctx1) {
  944. //>>excludeEnd("ctx");
  945. var $1;
  946. (
  947. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  948. $ctx1.supercall = true,
  949. //>>excludeEnd("ctx");
  950. $globals.FileServer.superclass.fn.prototype._initialize.apply($recv(self), []));
  951. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  952. $ctx1.supercall = false;
  953. //>>excludeEnd("ctx");;
  954. self["@http"]=self._require_("http");
  955. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  956. $ctx1.sendIdx["require:"]=1;
  957. //>>excludeEnd("ctx");
  958. self["@util"]=self._require_("util");
  959. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  960. $ctx1.sendIdx["require:"]=2;
  961. //>>excludeEnd("ctx");
  962. self["@url"]=self._require_("url");
  963. $1=self._class();
  964. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  965. $ctx1.sendIdx["class"]=1;
  966. //>>excludeEnd("ctx");
  967. self["@host"]=$recv($1)._defaultHost();
  968. self["@port"]=$recv(self._class())._defaultPort();
  969. self["@username"]=nil;
  970. self["@password"]=nil;
  971. self["@fallbackPage"]=nil;
  972. return self;
  973. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  974. }, function($ctx1) {$ctx1.fill(self,"initialize",{},$globals.FileServer)});
  975. //>>excludeEnd("ctx");
  976. },
  977. //>>excludeStart("ide", pragmas.excludeIdeData);
  978. args: [],
  979. source: "initialize\x0a\x09super initialize.\x0a\x09http := self require: 'http'.\x0a\x09util := self require: 'util'.\x0a\x09url := self require: 'url'.\x0a\x09host := self class defaultHost.\x0a\x09port := self class defaultPort.\x0a\x09username := nil.\x0a\x09password := nil.\x0a\x09fallbackPage := nil.",
  980. referencedClasses: [],
  981. //>>excludeEnd("ide");
  982. messageSends: ["initialize", "require:", "defaultHost", "class", "defaultPort"]
  983. }),
  984. $globals.FileServer);
  985. $core.addMethod(
  986. $core.method({
  987. selector: "isAuthenticated:",
  988. protocol: 'private',
  989. fn: function (aRequest){
  990. var self=this;
  991. var header,token,auth,parts;
  992. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  993. return $core.withContext(function($ctx1) {
  994. //>>excludeEnd("ctx");
  995. var $2,$1,$3,$4,$5,$6,$9,$10,$8,$7,$receiver;
  996. $2=$recv(self["@username"])._isNil();
  997. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  998. $ctx1.sendIdx["isNil"]=1;
  999. //>>excludeEnd("ctx");
  1000. $1=$recv($2)._and_((function(){
  1001. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1002. return $core.withContext(function($ctx2) {
  1003. //>>excludeEnd("ctx");
  1004. return $recv(self["@password"])._isNil();
  1005. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1006. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)});
  1007. //>>excludeEnd("ctx");
  1008. }));
  1009. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1010. $ctx1.sendIdx["and:"]=1;
  1011. //>>excludeEnd("ctx");
  1012. if($core.assert($1)){
  1013. return true;
  1014. };
  1015. $3=$recv($recv(aRequest)._headers())._at_("authorization");
  1016. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1017. $ctx1.sendIdx["at:"]=1;
  1018. //>>excludeEnd("ctx");
  1019. if(($receiver = $3) == null || $receiver.isNil){
  1020. header="";
  1021. } else {
  1022. header=$3;
  1023. };
  1024. $4=$recv(header)._isEmpty();
  1025. if($core.assert($4)){
  1026. return false;
  1027. } else {
  1028. $5=$recv(header)._tokenize_(" ");
  1029. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1030. $ctx1.sendIdx["tokenize:"]=1;
  1031. //>>excludeEnd("ctx");
  1032. if(($receiver = $5) == null || $receiver.isNil){
  1033. token="";
  1034. } else {
  1035. token=$5;
  1036. };
  1037. token;
  1038. $6=$recv(token)._at_((2));
  1039. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1040. $ctx1.sendIdx["at:"]=2;
  1041. //>>excludeEnd("ctx");
  1042. auth=self._base64Decode_($6);
  1043. auth;
  1044. parts=$recv(auth)._tokenize_(":");
  1045. parts;
  1046. $9=self["@username"];
  1047. $10=$recv(parts)._at_((1));
  1048. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1049. $ctx1.sendIdx["at:"]=3;
  1050. //>>excludeEnd("ctx");
  1051. $8=$recv($9).__eq($10);
  1052. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1053. $ctx1.sendIdx["="]=1;
  1054. //>>excludeEnd("ctx");
  1055. $7=$recv($8)._and_((function(){
  1056. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1057. return $core.withContext(function($ctx2) {
  1058. //>>excludeEnd("ctx");
  1059. return $recv(self["@password"]).__eq($recv(parts)._at_((2)));
  1060. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1061. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,7)});
  1062. //>>excludeEnd("ctx");
  1063. }));
  1064. if($core.assert($7)){
  1065. return true;
  1066. } else {
  1067. return false;
  1068. };
  1069. };
  1070. return self;
  1071. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1072. }, function($ctx1) {$ctx1.fill(self,"isAuthenticated:",{aRequest:aRequest,header:header,token:token,auth:auth,parts:parts},$globals.FileServer)});
  1073. //>>excludeEnd("ctx");
  1074. },
  1075. //>>excludeStart("ide", pragmas.excludeIdeData);
  1076. args: ["aRequest"],
  1077. source: "isAuthenticated: aRequest\x0a\x09\x22Basic HTTP Auth: http://stackoverflow.com/a/5957629/293175\x0a\x09 and https://gist.github.com/1686663\x22\x0a\x09| header token auth parts|\x0a\x0a\x09(username isNil and: [password isNil]) ifTrue: [^ true].\x0a\x0a\x09\x22get authentication header\x22\x0a\x09header := (aRequest headers at: 'authorization') ifNil:[''].\x0a\x09(header isEmpty)\x0a\x09ifTrue: [^ false]\x0a\x09ifFalse: [\x0a\x09\x09\x22get authentication token\x22\x0a\x09\x09token := (header tokenize: ' ') ifNil:[''].\x0a\x09\x09\x22convert back from base64\x22\x0a\x09\x09auth := self base64Decode: (token at: 2).\x0a\x09\x09\x22split token at colon\x22\x0a\x09\x09parts := auth tokenize: ':'.\x0a\x0a\x09\x09((username = (parts at: 1)) and: [password = (parts at: 2)])\x0a\x09\x09\x09ifTrue: [^ true]\x0a\x09\x09\x09ifFalse: [^ false]\x0a\x09].",
  1078. referencedClasses: [],
  1079. //>>excludeEnd("ide");
  1080. messageSends: ["ifTrue:", "and:", "isNil", "ifNil:", "at:", "headers", "ifTrue:ifFalse:", "isEmpty", "tokenize:", "base64Decode:", "="]
  1081. }),
  1082. $globals.FileServer);
  1083. $core.addMethod(
  1084. $core.method({
  1085. selector: "password:",
  1086. protocol: 'accessing',
  1087. fn: function (aPassword){
  1088. var self=this;
  1089. self["@password"]=aPassword;
  1090. return self;
  1091. },
  1092. //>>excludeStart("ide", pragmas.excludeIdeData);
  1093. args: ["aPassword"],
  1094. source: "password: aPassword\x0a\x09password := aPassword.",
  1095. referencedClasses: [],
  1096. //>>excludeEnd("ide");
  1097. messageSends: []
  1098. }),
  1099. $globals.FileServer);
  1100. $core.addMethod(
  1101. $core.method({
  1102. selector: "port",
  1103. protocol: 'accessing',
  1104. fn: function (){
  1105. var self=this;
  1106. var $1;
  1107. $1=self["@port"];
  1108. return $1;
  1109. },
  1110. //>>excludeStart("ide", pragmas.excludeIdeData);
  1111. args: [],
  1112. source: "port\x0a\x09^ port",
  1113. referencedClasses: [],
  1114. //>>excludeEnd("ide");
  1115. messageSends: []
  1116. }),
  1117. $globals.FileServer);
  1118. $core.addMethod(
  1119. $core.method({
  1120. selector: "port:",
  1121. protocol: 'accessing',
  1122. fn: function (aNumber){
  1123. var self=this;
  1124. self["@port"]=aNumber;
  1125. return self;
  1126. },
  1127. //>>excludeStart("ide", pragmas.excludeIdeData);
  1128. args: ["aNumber"],
  1129. source: "port: aNumber\x0a\x09port := aNumber",
  1130. referencedClasses: [],
  1131. //>>excludeEnd("ide");
  1132. messageSends: []
  1133. }),
  1134. $globals.FileServer);
  1135. $core.addMethod(
  1136. $core.method({
  1137. selector: "require:",
  1138. protocol: 'private',
  1139. fn: function (aModuleString){
  1140. var self=this;
  1141. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1142. return $core.withContext(function($ctx1) {
  1143. //>>excludeEnd("ctx");
  1144. var $1;
  1145. $1=$recv(require)._value_(aModuleString);
  1146. return $1;
  1147. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1148. }, function($ctx1) {$ctx1.fill(self,"require:",{aModuleString:aModuleString},$globals.FileServer)});
  1149. //>>excludeEnd("ctx");
  1150. },
  1151. //>>excludeStart("ide", pragmas.excludeIdeData);
  1152. args: ["aModuleString"],
  1153. source: "require: aModuleString\x0a\x09\x22call to the require function\x22\x0a\x09^require value: aModuleString",
  1154. referencedClasses: [],
  1155. //>>excludeEnd("ide");
  1156. messageSends: ["value:"]
  1157. }),
  1158. $globals.FileServer);
  1159. $core.addMethod(
  1160. $core.method({
  1161. selector: "respondAuthenticationRequiredTo:",
  1162. protocol: 'request handling',
  1163. fn: function (aResponse){
  1164. var self=this;
  1165. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1166. return $core.withContext(function($ctx1) {
  1167. //>>excludeEnd("ctx");
  1168. var $1;
  1169. $recv(aResponse)._writeHead_options_((401),$globals.HashedCollection._newFromPairs_(["WWW-Authenticate","Basic realm=\x22Secured Developer Area\x22"]));
  1170. $recv(aResponse)._write_("<html><body>Authentication needed</body></html>");
  1171. $1=$recv(aResponse)._end();
  1172. return self;
  1173. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1174. }, function($ctx1) {$ctx1.fill(self,"respondAuthenticationRequiredTo:",{aResponse:aResponse},$globals.FileServer)});
  1175. //>>excludeEnd("ctx");
  1176. },
  1177. //>>excludeStart("ide", pragmas.excludeIdeData);
  1178. args: ["aResponse"],
  1179. source: "respondAuthenticationRequiredTo: aResponse\x0a\x09aResponse\x0a\x09\x09writeHead: 401 options: #{'WWW-Authenticate' -> 'Basic realm=\x22Secured Developer Area\x22'};\x0a\x09\x09write: '<html><body>Authentication needed</body></html>';\x0a\x09\x09end.",
  1180. referencedClasses: [],
  1181. //>>excludeEnd("ide");
  1182. messageSends: ["writeHead:options:", "write:", "end"]
  1183. }),
  1184. $globals.FileServer);
  1185. $core.addMethod(
  1186. $core.method({
  1187. selector: "respondCreatedTo:",
  1188. protocol: 'request handling',
  1189. fn: function (aResponse){
  1190. var self=this;
  1191. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1192. return $core.withContext(function($ctx1) {
  1193. //>>excludeEnd("ctx");
  1194. var $1;
  1195. $recv(aResponse)._writeHead_options_((201),$globals.HashedCollection._newFromPairs_(["Content-Type","text/plain","Access-Control-Allow-Origin","*"]));
  1196. $1=$recv(aResponse)._end();
  1197. return self;
  1198. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1199. }, function($ctx1) {$ctx1.fill(self,"respondCreatedTo:",{aResponse:aResponse},$globals.FileServer)});
  1200. //>>excludeEnd("ctx");
  1201. },
  1202. //>>excludeStart("ide", pragmas.excludeIdeData);
  1203. args: ["aResponse"],
  1204. source: "respondCreatedTo: aResponse\x0a\x09aResponse\x0a\x09\x09writeHead: 201 options: #{'Content-Type' -> 'text/plain'. 'Access-Control-Allow-Origin' -> '*'};\x0a\x09\x09end.",
  1205. referencedClasses: [],
  1206. //>>excludeEnd("ide");
  1207. messageSends: ["writeHead:options:", "end"]
  1208. }),
  1209. $globals.FileServer);
  1210. $core.addMethod(
  1211. $core.method({
  1212. selector: "respondDirectoryNamed:from:to:",
  1213. protocol: 'request handling',
  1214. fn: function (aDirname,aUrl,aResponse){
  1215. var self=this;
  1216. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1217. return $core.withContext(function($ctx1) {
  1218. //>>excludeEnd("ctx");
  1219. var $2,$1,$3,$5,$7,$6,$4,$receiver;
  1220. $2=$recv(aUrl)._pathname();
  1221. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1222. $ctx1.sendIdx["pathname"]=1;
  1223. //>>excludeEnd("ctx");
  1224. $1=$recv($2)._endsWith_("/");
  1225. if($core.assert($1)){
  1226. $3=$recv(aDirname).__comma("index.html");
  1227. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1228. $ctx1.sendIdx[","]=1;
  1229. //>>excludeEnd("ctx");
  1230. self._respondFileNamed_to_($3,aResponse);
  1231. } else {
  1232. $5=$recv($recv(aUrl)._pathname()).__comma("/");
  1233. $7=$recv(aUrl)._search();
  1234. if(($receiver = $7) == null || $receiver.isNil){
  1235. $6="";
  1236. } else {
  1237. $6=$7;
  1238. };
  1239. $4=$recv($5).__comma($6);
  1240. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1241. $ctx1.sendIdx[","]=2;
  1242. //>>excludeEnd("ctx");
  1243. self._respondRedirect_to_($4,aResponse);
  1244. };
  1245. return self;
  1246. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1247. }, function($ctx1) {$ctx1.fill(self,"respondDirectoryNamed:from:to:",{aDirname:aDirname,aUrl:aUrl,aResponse:aResponse},$globals.FileServer)});
  1248. //>>excludeEnd("ctx");
  1249. },
  1250. //>>excludeStart("ide", pragmas.excludeIdeData);
  1251. args: ["aDirname", "aUrl", "aResponse"],
  1252. source: "respondDirectoryNamed: aDirname from: aUrl to: aResponse\x0a\x09(aUrl pathname endsWith: '/')\x0a\x09\x09ifTrue: [self respondFileNamed: aDirname, 'index.html' to: aResponse]\x0a\x09\x09ifFalse: [self respondRedirect: aUrl pathname, '/', (aUrl search ifNil: ['']) to: aResponse]",
  1253. referencedClasses: [],
  1254. //>>excludeEnd("ide");
  1255. messageSends: ["ifTrue:ifFalse:", "endsWith:", "pathname", "respondFileNamed:to:", ",", "respondRedirect:to:", "ifNil:", "search"]
  1256. }),
  1257. $globals.FileServer);
  1258. $core.addMethod(
  1259. $core.method({
  1260. selector: "respondFileNamed:to:",
  1261. protocol: 'request handling',
  1262. fn: function (aFilename,aResponse){
  1263. var self=this;
  1264. var type,filename;
  1265. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1266. return $core.withContext(function($ctx1) {
  1267. //>>excludeEnd("ctx");
  1268. var $1,$2,$3,$4,$5;
  1269. filename=aFilename;
  1270. $recv(self["@fs"])._readFile_do_(filename,(function(ex,file){
  1271. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1272. return $core.withContext(function($ctx2) {
  1273. //>>excludeEnd("ctx");
  1274. $1=$recv(ex)._notNil();
  1275. if($core.assert($1)){
  1276. $2=console;
  1277. $3=$recv(filename).__comma(" does not exist");
  1278. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1279. $ctx2.sendIdx[","]=1;
  1280. //>>excludeEnd("ctx");
  1281. $recv($2)._log_($3);
  1282. return self._respondNotFoundTo_(aResponse);
  1283. } else {
  1284. type=$recv(self._class())._mimeTypeFor_(filename);
  1285. type;
  1286. $4=$recv(type).__eq("application/javascript");
  1287. if($core.assert($4)){
  1288. type=$recv(type).__comma(";charset=utf-8");
  1289. type;
  1290. };
  1291. $recv(aResponse)._writeHead_options_((200),$globals.HashedCollection._newFromPairs_(["Content-Type",type]));
  1292. $recv(aResponse)._write_encoding_(file,"binary");
  1293. $5=$recv(aResponse)._end();
  1294. return $5;
  1295. };
  1296. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1297. }, function($ctx2) {$ctx2.fillBlock({ex:ex,file:file},$ctx1,1)});
  1298. //>>excludeEnd("ctx");
  1299. }));
  1300. return self;
  1301. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1302. }, function($ctx1) {$ctx1.fill(self,"respondFileNamed:to:",{aFilename:aFilename,aResponse:aResponse,type:type,filename:filename},$globals.FileServer)});
  1303. //>>excludeEnd("ctx");
  1304. },
  1305. //>>excludeStart("ide", pragmas.excludeIdeData);
  1306. args: ["aFilename", "aResponse"],
  1307. source: "respondFileNamed: aFilename to: aResponse\x0a\x09| type filename |\x0a\x0a\x09filename := aFilename.\x0a\x0a\x09fs readFile: filename do: [:ex :file |\x0a\x09\x09ex notNil \x0a\x09\x09\x09ifTrue: [\x0a\x09\x09\x09\x09console log: filename, ' does not exist'.\x0a\x09\x09\x09\x09self respondNotFoundTo: aResponse]\x0a\x09\x09\x09ifFalse: [\x0a\x09\x09\x09\x09type := self class mimeTypeFor: filename.\x0a\x09\x09\x09\x09type = 'application/javascript'\x0a\x09\x09\x09\x09\x09ifTrue: [ type:=type,';charset=utf-8' ].\x0a\x09\x09\x09\x09aResponse \x0a\x09\x09\x09\x09\x09writeHead: 200 options: #{'Content-Type' -> type};\x0a\x09\x09\x09\x09\x09write: file encoding: 'binary';\x0a\x09\x09\x09\x09\x09end]]",
  1308. referencedClasses: [],
  1309. //>>excludeEnd("ide");
  1310. messageSends: ["readFile:do:", "ifTrue:ifFalse:", "notNil", "log:", ",", "respondNotFoundTo:", "mimeTypeFor:", "class", "ifTrue:", "=", "writeHead:options:", "write:encoding:", "end"]
  1311. }),
  1312. $globals.FileServer);
  1313. $core.addMethod(
  1314. $core.method({
  1315. selector: "respondInternalErrorTo:",
  1316. protocol: 'request handling',
  1317. fn: function (aResponse){
  1318. var self=this;
  1319. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1320. return $core.withContext(function($ctx1) {
  1321. //>>excludeEnd("ctx");
  1322. var $1;
  1323. $recv(aResponse)._writeHead_options_((500),$globals.HashedCollection._newFromPairs_(["Content-Type","text/plain"]));
  1324. $recv(aResponse)._write_("500 Internal server error");
  1325. $1=$recv(aResponse)._end();
  1326. return self;
  1327. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1328. }, function($ctx1) {$ctx1.fill(self,"respondInternalErrorTo:",{aResponse:aResponse},$globals.FileServer)});
  1329. //>>excludeEnd("ctx");
  1330. },
  1331. //>>excludeStart("ide", pragmas.excludeIdeData);
  1332. args: ["aResponse"],
  1333. source: "respondInternalErrorTo: aResponse\x0a\x09aResponse \x0a\x09\x09writeHead: 500 options: #{'Content-Type' -> 'text/plain'};\x0a\x09\x09write: '500 Internal server error';\x0a\x09\x09end",
  1334. referencedClasses: [],
  1335. //>>excludeEnd("ide");
  1336. messageSends: ["writeHead:options:", "write:", "end"]
  1337. }),
  1338. $globals.FileServer);
  1339. $core.addMethod(
  1340. $core.method({
  1341. selector: "respondNotCreatedTo:",
  1342. protocol: 'request handling',
  1343. fn: function (aResponse){
  1344. var self=this;
  1345. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1346. return $core.withContext(function($ctx1) {
  1347. //>>excludeEnd("ctx");
  1348. var $1;
  1349. $recv(aResponse)._writeHead_options_((400),$globals.HashedCollection._newFromPairs_(["Content-Type","text/plain"]));
  1350. $recv(aResponse)._write_("File could not be created. Did you forget to create the src directory on the server?");
  1351. $1=$recv(aResponse)._end();
  1352. return self;
  1353. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1354. }, function($ctx1) {$ctx1.fill(self,"respondNotCreatedTo:",{aResponse:aResponse},$globals.FileServer)});
  1355. //>>excludeEnd("ctx");
  1356. },
  1357. //>>excludeStart("ide", pragmas.excludeIdeData);
  1358. args: ["aResponse"],
  1359. source: "respondNotCreatedTo: aResponse\x0a\x09aResponse\x0a\x09\x09writeHead: 400 options: #{'Content-Type' -> 'text/plain'};\x0a\x09\x09write: 'File could not be created. Did you forget to create the src directory on the server?';\x0a\x09\x09end.",
  1360. referencedClasses: [],
  1361. //>>excludeEnd("ide");
  1362. messageSends: ["writeHead:options:", "write:", "end"]
  1363. }),
  1364. $globals.FileServer);
  1365. $core.addMethod(
  1366. $core.method({
  1367. selector: "respondNotFoundTo:",
  1368. protocol: 'request handling',
  1369. fn: function (aResponse){
  1370. var self=this;
  1371. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1372. return $core.withContext(function($ctx1) {
  1373. //>>excludeEnd("ctx");
  1374. var $2,$1,$3,$4;
  1375. $2=self._fallbackPage();
  1376. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1377. $ctx1.sendIdx["fallbackPage"]=1;
  1378. //>>excludeEnd("ctx");
  1379. $1=$recv($2)._isNil();
  1380. if(!$core.assert($1)){
  1381. $3=self._respondFileNamed_to_(self._fallbackPage(),aResponse);
  1382. return $3;
  1383. };
  1384. $recv(aResponse)._writeHead_options_((404),$globals.HashedCollection._newFromPairs_(["Content-Type","text/html"]));
  1385. $recv(aResponse)._write_("<html><body><p>404 Not found</p>");
  1386. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1387. $ctx1.sendIdx["write:"]=1;
  1388. //>>excludeEnd("ctx");
  1389. $recv(aResponse)._write_("<p>Did you forget to put an index.html file into the directory which is served by \x22bin/amber serve\x22? To solve this you can:<ul>");
  1390. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1391. $ctx1.sendIdx["write:"]=2;
  1392. //>>excludeEnd("ctx");
  1393. $recv(aResponse)._write_("<li>create an index.html in the served directory.</li>");
  1394. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1395. $ctx1.sendIdx["write:"]=3;
  1396. //>>excludeEnd("ctx");
  1397. $recv(aResponse)._write_("<li>can also specify the location of a page to be served whenever path does not resolve to a file with the \x22--fallback-page\x22 option.</li>");
  1398. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1399. $ctx1.sendIdx["write:"]=4;
  1400. //>>excludeEnd("ctx");
  1401. $recv(aResponse)._write_("<li>change the directory to be served with the \x22--base-path\x22 option.</li>");
  1402. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1403. $ctx1.sendIdx["write:"]=5;
  1404. //>>excludeEnd("ctx");
  1405. $recv(aResponse)._write_("</ul></p></body></html>");
  1406. $4=$recv(aResponse)._end();
  1407. return self;
  1408. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1409. }, function($ctx1) {$ctx1.fill(self,"respondNotFoundTo:",{aResponse:aResponse},$globals.FileServer)});
  1410. //>>excludeEnd("ctx");
  1411. },
  1412. //>>excludeStart("ide", pragmas.excludeIdeData);
  1413. args: ["aResponse"],
  1414. source: "respondNotFoundTo: aResponse\x0a\x09self fallbackPage isNil ifFalse: [^self respondFileNamed: self fallbackPage to: aResponse].\x0a\x09aResponse \x0a\x09\x09writeHead: 404 options: #{'Content-Type' -> 'text/html'};\x0a\x09\x09write: '<html><body><p>404 Not found</p>';\x0a\x09\x09write: '<p>Did you forget to put an index.html file into the directory which is served by \x22bin/amber serve\x22? To solve this you can:<ul>';\x0a\x09\x09write: '<li>create an index.html in the served directory.</li>';\x0a\x09\x09write: '<li>can also specify the location of a page to be served whenever path does not resolve to a file with the \x22--fallback-page\x22 option.</li>';\x0a\x09\x09write: '<li>change the directory to be served with the \x22--base-path\x22 option.</li>';\x0a\x09\x09write: '</ul></p></body></html>';\x0a\x09\x09end",
  1415. referencedClasses: [],
  1416. //>>excludeEnd("ide");
  1417. messageSends: ["ifFalse:", "isNil", "fallbackPage", "respondFileNamed:to:", "writeHead:options:", "write:", "end"]
  1418. }),
  1419. $globals.FileServer);
  1420. $core.addMethod(
  1421. $core.method({
  1422. selector: "respondOKTo:",
  1423. protocol: 'request handling',
  1424. fn: function (aResponse){
  1425. var self=this;
  1426. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1427. return $core.withContext(function($ctx1) {
  1428. //>>excludeEnd("ctx");
  1429. var $1;
  1430. $recv(aResponse)._writeHead_options_((200),$globals.HashedCollection._newFromPairs_(["Content-Type","text/plain","Access-Control-Allow-Origin","*"]));
  1431. $1=$recv(aResponse)._end();
  1432. return self;
  1433. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1434. }, function($ctx1) {$ctx1.fill(self,"respondOKTo:",{aResponse:aResponse},$globals.FileServer)});
  1435. //>>excludeEnd("ctx");
  1436. },
  1437. //>>excludeStart("ide", pragmas.excludeIdeData);
  1438. args: ["aResponse"],
  1439. source: "respondOKTo: aResponse\x0a\x09aResponse\x0a\x09\x09writeHead: 200 options: #{'Content-Type' -> 'text/plain'. 'Access-Control-Allow-Origin' -> '*'};\x0a\x09\x09end.",
  1440. referencedClasses: [],
  1441. //>>excludeEnd("ide");
  1442. messageSends: ["writeHead:options:", "end"]
  1443. }),
  1444. $globals.FileServer);
  1445. $core.addMethod(
  1446. $core.method({
  1447. selector: "respondRedirect:to:",
  1448. protocol: 'request handling',
  1449. fn: function (aString,aResponse){
  1450. var self=this;
  1451. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1452. return $core.withContext(function($ctx1) {
  1453. //>>excludeEnd("ctx");
  1454. var $1;
  1455. $recv(aResponse)._writeHead_options_((303),$globals.HashedCollection._newFromPairs_(["Location",aString]));
  1456. $1=$recv(aResponse)._end();
  1457. return self;
  1458. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1459. }, function($ctx1) {$ctx1.fill(self,"respondRedirect:to:",{aString:aString,aResponse:aResponse},$globals.FileServer)});
  1460. //>>excludeEnd("ctx");
  1461. },
  1462. //>>excludeStart("ide", pragmas.excludeIdeData);
  1463. args: ["aString", "aResponse"],
  1464. source: "respondRedirect: aString to: aResponse\x0a\x09aResponse\x0a\x09\x09writeHead: 303 options: #{'Location' -> aString};\x0a\x09\x09end.",
  1465. referencedClasses: [],
  1466. //>>excludeEnd("ide");
  1467. messageSends: ["writeHead:options:", "end"]
  1468. }),
  1469. $globals.FileServer);
  1470. $core.addMethod(
  1471. $core.method({
  1472. selector: "start",
  1473. protocol: 'starting',
  1474. fn: function (){
  1475. var self=this;
  1476. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1477. return $core.withContext(function($ctx1) {
  1478. //>>excludeEnd("ctx");
  1479. var $1,$2,$3,$4,$8,$7,$6,$10,$9,$5,$11;
  1480. self._checkDirectoryLayout();
  1481. $1=$recv(self["@http"])._createServer_((function(request,response){
  1482. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1483. return $core.withContext(function($ctx2) {
  1484. //>>excludeEnd("ctx");
  1485. return self._handleRequest_respondTo_(request,response);
  1486. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1487. }, function($ctx2) {$ctx2.fillBlock({request:request,response:response},$ctx1,1)});
  1488. //>>excludeEnd("ctx");
  1489. }));
  1490. $recv($1)._on_do_("error",(function(error){
  1491. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1492. return $core.withContext(function($ctx2) {
  1493. //>>excludeEnd("ctx");
  1494. $2=console;
  1495. $3="Error starting server: ".__comma(error);
  1496. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1497. $ctx2.sendIdx[","]=1;
  1498. //>>excludeEnd("ctx");
  1499. return $recv($2)._log_($3);
  1500. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1501. $ctx2.sendIdx["log:"]=1;
  1502. //>>excludeEnd("ctx");
  1503. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1504. }, function($ctx2) {$ctx2.fillBlock({error:error},$ctx1,2)});
  1505. //>>excludeEnd("ctx");
  1506. }));
  1507. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1508. $ctx1.sendIdx["on:do:"]=1;
  1509. //>>excludeEnd("ctx");
  1510. $recv($1)._on_do_("listening",(function(){
  1511. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1512. return $core.withContext(function($ctx2) {
  1513. //>>excludeEnd("ctx");
  1514. $4=console;
  1515. $8=self._host();
  1516. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1517. $ctx2.sendIdx["host"]=1;
  1518. //>>excludeEnd("ctx");
  1519. $7="Starting file server on http://".__comma($8);
  1520. $6=$recv($7).__comma(":");
  1521. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1522. $ctx2.sendIdx[","]=3;
  1523. //>>excludeEnd("ctx");
  1524. $10=self._port();
  1525. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1526. $ctx2.sendIdx["port"]=1;
  1527. //>>excludeEnd("ctx");
  1528. $9=$recv($10)._asString();
  1529. $5=$recv($6).__comma($9);
  1530. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1531. $ctx2.sendIdx[","]=2;
  1532. //>>excludeEnd("ctx");
  1533. return $recv($4)._log_($5);
  1534. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1535. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,3)});
  1536. //>>excludeEnd("ctx");
  1537. }));
  1538. $11=$recv($1)._listen_host_(self._port(),self._host());
  1539. return self;
  1540. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1541. }, function($ctx1) {$ctx1.fill(self,"start",{},$globals.FileServer)});
  1542. //>>excludeEnd("ctx");
  1543. },
  1544. //>>excludeStart("ide", pragmas.excludeIdeData);
  1545. args: [],
  1546. source: "start\x0a\x09\x22Checks if required directory layout is present (issue warning if not).\x0a\x09 Afterwards start the server.\x22\x0a\x09self checkDirectoryLayout.\x0a\x09(http createServer: [:request :response |\x0a\x09 self handleRequest: request respondTo: response])\x0a\x09 on: 'error' do: [:error | console log: 'Error starting server: ', error];\x0a\x09 on: 'listening' do: [console log: 'Starting file server on http://', self host, ':', self port asString];\x0a\x09 listen: self port host: self host.",
  1547. referencedClasses: [],
  1548. //>>excludeEnd("ide");
  1549. messageSends: ["checkDirectoryLayout", "on:do:", "createServer:", "handleRequest:respondTo:", "log:", ",", "host", "asString", "port", "listen:host:"]
  1550. }),
  1551. $globals.FileServer);
  1552. $core.addMethod(
  1553. $core.method({
  1554. selector: "startOn:",
  1555. protocol: 'starting',
  1556. fn: function (aPort){
  1557. var self=this;
  1558. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1559. return $core.withContext(function($ctx1) {
  1560. //>>excludeEnd("ctx");
  1561. self._port_(aPort);
  1562. self._start();
  1563. return self;
  1564. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1565. }, function($ctx1) {$ctx1.fill(self,"startOn:",{aPort:aPort},$globals.FileServer)});
  1566. //>>excludeEnd("ctx");
  1567. },
  1568. //>>excludeStart("ide", pragmas.excludeIdeData);
  1569. args: ["aPort"],
  1570. source: "startOn: aPort\x0a\x09self port: aPort.\x0a\x09self start",
  1571. referencedClasses: [],
  1572. //>>excludeEnd("ide");
  1573. messageSends: ["port:", "start"]
  1574. }),
  1575. $globals.FileServer);
  1576. $core.addMethod(
  1577. $core.method({
  1578. selector: "username:",
  1579. protocol: 'accessing',
  1580. fn: function (aUsername){
  1581. var self=this;
  1582. self["@username"]=aUsername;
  1583. return self;
  1584. },
  1585. //>>excludeStart("ide", pragmas.excludeIdeData);
  1586. args: ["aUsername"],
  1587. source: "username: aUsername\x0a\x09username := aUsername.",
  1588. referencedClasses: [],
  1589. //>>excludeEnd("ide");
  1590. messageSends: []
  1591. }),
  1592. $globals.FileServer);
  1593. $core.addMethod(
  1594. $core.method({
  1595. selector: "validateBasePath",
  1596. protocol: 'private',
  1597. fn: function (){
  1598. var self=this;
  1599. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1600. return $core.withContext(function($ctx1) {
  1601. //>>excludeEnd("ctx");
  1602. var $1,$2,$3,$4,$7,$6,$5,$8,$9,$receiver;
  1603. $1=self["@fs"];
  1604. $2=self._basePath();
  1605. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1606. $ctx1.sendIdx["basePath"]=1;
  1607. //>>excludeEnd("ctx");
  1608. $recv($1)._stat_then_($2,(function(err,stat){
  1609. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1610. return $core.withContext(function($ctx2) {
  1611. //>>excludeEnd("ctx");
  1612. if(($receiver = err) == null || $receiver.isNil){
  1613. $3=$recv(stat)._isDirectory();
  1614. if(!$core.assert($3)){
  1615. $4=console;
  1616. $7=self._basePath();
  1617. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1618. $ctx2.sendIdx["basePath"]=2;
  1619. //>>excludeEnd("ctx");
  1620. $6="Warning: --base-path parameter ".__comma($7);
  1621. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1622. $ctx2.sendIdx[","]=2;
  1623. //>>excludeEnd("ctx");
  1624. $5=$recv($6).__comma(" is not a directory.");
  1625. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1626. $ctx2.sendIdx[","]=1;
  1627. //>>excludeEnd("ctx");
  1628. return $recv($4)._warn_($5);
  1629. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1630. $ctx2.sendIdx["warn:"]=1;
  1631. //>>excludeEnd("ctx");
  1632. };
  1633. } else {
  1634. $8=console;
  1635. $9=$recv("Warning: path at --base-path parameter ".__comma(self._basePath())).__comma(" does not exist.");
  1636. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1637. $ctx2.sendIdx[","]=3;
  1638. //>>excludeEnd("ctx");
  1639. return $recv($8)._warn_($9);
  1640. };
  1641. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1642. }, function($ctx2) {$ctx2.fillBlock({err:err,stat:stat},$ctx1,1)});
  1643. //>>excludeEnd("ctx");
  1644. }));
  1645. return self;
  1646. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1647. }, function($ctx1) {$ctx1.fill(self,"validateBasePath",{},$globals.FileServer)});
  1648. //>>excludeEnd("ctx");
  1649. },
  1650. //>>excludeStart("ide", pragmas.excludeIdeData);
  1651. args: [],
  1652. source: "validateBasePath\x0a\x09\x22The basePath must be an existing directory. \x22\x0a\x09fs stat: self basePath then: [ :err :stat | err\x0a\x09\x09ifNil: [ stat isDirectory ifFalse: [ console warn: 'Warning: --base-path parameter ' , self basePath , ' is not a directory.' ]]\x0a\x09\x09ifNotNil: [ console warn: 'Warning: path at --base-path parameter ' , self basePath , ' does not exist.' ]].",
  1653. referencedClasses: [],
  1654. //>>excludeEnd("ide");
  1655. messageSends: ["stat:then:", "basePath", "ifNil:ifNotNil:", "ifFalse:", "isDirectory", "warn:", ","]
  1656. }),
  1657. $globals.FileServer);
  1658. $core.addMethod(
  1659. $core.method({
  1660. selector: "withBasePath:",
  1661. protocol: 'private',
  1662. fn: function (aBaseRelativePath){
  1663. var self=this;
  1664. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1665. return $core.withContext(function($ctx1) {
  1666. //>>excludeEnd("ctx");
  1667. var $1;
  1668. $1=$recv(self["@path"])._join_with_(self._basePath(),aBaseRelativePath);
  1669. return $1;
  1670. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1671. }, function($ctx1) {$ctx1.fill(self,"withBasePath:",{aBaseRelativePath:aBaseRelativePath},$globals.FileServer)});
  1672. //>>excludeEnd("ctx");
  1673. },
  1674. //>>excludeStart("ide", pragmas.excludeIdeData);
  1675. args: ["aBaseRelativePath"],
  1676. source: "withBasePath: aBaseRelativePath\x0a\x09\x22return a file path which is relative to the basePath.\x22\x0a\x09^ path join: self basePath with: aBaseRelativePath",
  1677. referencedClasses: [],
  1678. //>>excludeEnd("ide");
  1679. messageSends: ["join:with:", "basePath"]
  1680. }),
  1681. $globals.FileServer);
  1682. $core.addMethod(
  1683. $core.method({
  1684. selector: "writeData:toFileNamed:",
  1685. protocol: 'private',
  1686. fn: function (data,aFilename){
  1687. var self=this;
  1688. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1689. return $core.withContext(function($ctx1) {
  1690. //>>excludeEnd("ctx");
  1691. $recv(console)._log_(aFilename);
  1692. return self;
  1693. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1694. }, function($ctx1) {$ctx1.fill(self,"writeData:toFileNamed:",{data:data,aFilename:aFilename},$globals.FileServer)});
  1695. //>>excludeEnd("ctx");
  1696. },
  1697. //>>excludeStart("ide", pragmas.excludeIdeData);
  1698. args: ["data", "aFilename"],
  1699. source: "writeData: data toFileNamed: aFilename\x0a\x09console log: aFilename",
  1700. referencedClasses: [],
  1701. //>>excludeEnd("ide");
  1702. messageSends: ["log:"]
  1703. }),
  1704. $globals.FileServer);
  1705. $globals.FileServer.klass.iVarNames = ['mimeTypes'];
  1706. $core.addMethod(
  1707. $core.method({
  1708. selector: "commandLineSwitches",
  1709. protocol: 'accessing',
  1710. fn: function (){
  1711. var self=this;
  1712. var switches;
  1713. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1714. return $core.withContext(function($ctx1) {
  1715. //>>excludeEnd("ctx");
  1716. var $1;
  1717. switches=$recv(self._methodsInProtocol_("accessing"))._collect_((function(each){
  1718. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1719. return $core.withContext(function($ctx2) {
  1720. //>>excludeEnd("ctx");
  1721. return $recv(each)._selector();
  1722. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1723. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)});
  1724. //>>excludeEnd("ctx");
  1725. }));
  1726. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1727. $ctx1.sendIdx["collect:"]=1;
  1728. //>>excludeEnd("ctx");
  1729. switches=$recv(switches)._select_((function(each){
  1730. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1731. return $core.withContext(function($ctx2) {
  1732. //>>excludeEnd("ctx");
  1733. return $recv(each)._match_("^[^:]*:$");
  1734. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1735. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,2)});
  1736. //>>excludeEnd("ctx");
  1737. }));
  1738. switches=$recv(switches)._collect_((function(each){
  1739. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1740. return $core.withContext(function($ctx2) {
  1741. //>>excludeEnd("ctx");
  1742. return $recv($recv($recv($recv(each)._allButLast())._replace_with_("([A-Z])","-$1"))._asLowercase())._replace_with_("^([a-z])","--$1");
  1743. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1744. $ctx2.sendIdx["replace:with:"]=1;
  1745. //>>excludeEnd("ctx");
  1746. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1747. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,3)});
  1748. //>>excludeEnd("ctx");
  1749. }));
  1750. $1=switches;
  1751. return $1;
  1752. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1753. }, function($ctx1) {$ctx1.fill(self,"commandLineSwitches",{switches:switches},$globals.FileServer.klass)});
  1754. //>>excludeEnd("ctx");
  1755. },
  1756. //>>excludeStart("ide", pragmas.excludeIdeData);
  1757. args: [],
  1758. source: "commandLineSwitches\x0a\x09\x22Collect all methodnames from the 'accessing' protocol\x0a\x09 and select the ones with only one parameter.\x0a\x09 Then remove the ':' at the end of the name\x0a\x09 and add a '--' at the beginning.\x0a\x09 Additionally all uppercase letters are made lowercase and preceded by a '-'.\x0a\x09 Example: fallbackPage: becomes --fallback-page.\x0a\x09 Return the Array containing the commandline switches.\x22\x0a\x09| switches |\x0a\x09switches := ((self methodsInProtocol: 'accessing') collect: [ :each | each selector]).\x0a\x09switches := switches select: [ :each | each match: '^[^:]*:$'].\x0a\x09switches :=switches collect: [ :each |\x0a\x09\x09(each allButLast replace: '([A-Z])' with: '-$1') asLowercase replace: '^([a-z])' with: '--$1' ].\x0a\x09^ switches",
  1759. referencedClasses: [],
  1760. //>>excludeEnd("ide");
  1761. messageSends: ["collect:", "methodsInProtocol:", "selector", "select:", "match:", "replace:with:", "asLowercase", "allButLast"]
  1762. }),
  1763. $globals.FileServer.klass);
  1764. $core.addMethod(
  1765. $core.method({
  1766. selector: "createServerWithArguments:",
  1767. protocol: 'initialization',
  1768. fn: function (options){
  1769. var self=this;
  1770. var server,popFront,front,optionName,optionValue,switches;
  1771. function $Array(){return $globals.Array||(typeof Array=="undefined"?nil:Array)}
  1772. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1773. return $core.withContext(function($ctx1) {
  1774. //>>excludeEnd("ctx");
  1775. var $1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11;
  1776. var $early={};
  1777. try {
  1778. switches=self._commandLineSwitches();
  1779. server=self._new();
  1780. $recv(options)._ifEmpty_((function(){
  1781. $1=server;
  1782. throw $early=[$1];
  1783. }));
  1784. $2=$recv($recv(options)._size())._even();
  1785. if(!$core.assert($2)){
  1786. $recv(console)._log_("Using default parameters.");
  1787. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1788. $ctx1.sendIdx["log:"]=1;
  1789. //>>excludeEnd("ctx");
  1790. $3=console;
  1791. $4="Wrong commandline options or not enough arguments for: ".__comma(options);
  1792. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1793. $ctx1.sendIdx[","]=1;
  1794. //>>excludeEnd("ctx");
  1795. $recv($3)._log_($4);
  1796. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1797. $ctx1.sendIdx["log:"]=2;
  1798. //>>excludeEnd("ctx");
  1799. $5=console;
  1800. $6="Use any of the following ones: ".__comma(switches);
  1801. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1802. $ctx1.sendIdx[","]=2;
  1803. //>>excludeEnd("ctx");
  1804. $recv($5)._log_($6);
  1805. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1806. $ctx1.sendIdx["log:"]=3;
  1807. //>>excludeEnd("ctx");
  1808. $7=server;
  1809. return $7;
  1810. };
  1811. popFront=(function(args){
  1812. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1813. return $core.withContext(function($ctx2) {
  1814. //>>excludeEnd("ctx");
  1815. front=$recv(args)._first();
  1816. front;
  1817. $recv(args)._remove_(front);
  1818. return front;
  1819. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1820. }, function($ctx2) {$ctx2.fillBlock({args:args},$ctx1,3)});
  1821. //>>excludeEnd("ctx");
  1822. });
  1823. $recv((function(){
  1824. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1825. return $core.withContext(function($ctx2) {
  1826. //>>excludeEnd("ctx");
  1827. return $recv(options)._notEmpty();
  1828. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1829. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,4)});
  1830. //>>excludeEnd("ctx");
  1831. }))._whileTrue_((function(){
  1832. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1833. return $core.withContext(function($ctx2) {
  1834. //>>excludeEnd("ctx");
  1835. optionName=$recv(popFront)._value_(options);
  1836. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1837. $ctx2.sendIdx["value:"]=1;
  1838. //>>excludeEnd("ctx");
  1839. optionName;
  1840. optionValue=$recv(popFront)._value_(options);
  1841. optionValue;
  1842. $8=$recv(switches)._includes_(optionName);
  1843. if($core.assert($8)){
  1844. optionName=self._selectorForCommandLineSwitch_(optionName);
  1845. optionName;
  1846. return $recv(server)._perform_withArguments_(optionName,$recv($Array())._with_(optionValue));
  1847. } else {
  1848. $9=console;
  1849. $10=$recv(optionName).__comma(" is not a valid commandline option");
  1850. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1851. $ctx2.sendIdx[","]=3;
  1852. //>>excludeEnd("ctx");
  1853. $recv($9)._log_($10);
  1854. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1855. $ctx2.sendIdx["log:"]=4;
  1856. //>>excludeEnd("ctx");
  1857. return $recv(console)._log_("Use any of the following ones: ".__comma(switches));
  1858. };
  1859. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1860. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,5)});
  1861. //>>excludeEnd("ctx");
  1862. }));
  1863. $11=server;
  1864. return $11;
  1865. }
  1866. catch(e) {if(e===$early)return e[0]; throw e}
  1867. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1868. }, function($ctx1) {$ctx1.fill(self,"createServerWithArguments:",{options:options,server:server,popFront:popFront,front:front,optionName:optionName,optionValue:optionValue,switches:switches},$globals.FileServer.klass)});
  1869. //>>excludeEnd("ctx");
  1870. },
  1871. //>>excludeStart("ide", pragmas.excludeIdeData);
  1872. args: ["options"],
  1873. source: "createServerWithArguments: options\x0a\x09\x22If options are empty return a default FileServer instance.\x0a\x09 If options are given loop through them and set the passed in values\x0a\x09 on the FileServer instance.\x0a\x09 \x0a\x09 Commanline options map directly to methods in the 'accessing' protocol\x0a\x09 taking one parameter.\x0a\x09 Adding a method to this protocol makes it directly settable through\x0a\x09 command line options.\x0a\x09 \x22\x0a\x09| server popFront front optionName optionValue switches |\x0a\x0a\x09switches := self commandLineSwitches.\x0a\x0a\x09server := self new.\x0a\x0a\x09options ifEmpty: [^server].\x0a\x0a\x09(options size even) ifFalse: [\x0a\x09\x09console log: 'Using default parameters.'.\x0a\x09\x09console log: 'Wrong commandline options or not enough arguments for: ' , options.\x0a\x09\x09console log: 'Use any of the following ones: ', switches.\x0a\x09\x09^server].\x0a\x0a\x09popFront := [:args |\x0a\x09\x09front := args first.\x0a\x09\x09args remove: front.\x0a\x09\x09front].\x0a\x0a\x09[options notEmpty] whileTrue: [\x0a\x09\x09optionName := popFront value: options.\x0a\x09\x09optionValue := popFront value: options.\x0a\x0a\x09\x09(switches includes: optionName) ifTrue: [\x0a\x09\x09\x09optionName := self selectorForCommandLineSwitch: optionName.\x0a\x09\x09\x09server perform: optionName withArguments: (Array with: optionValue)]\x0a\x09\x09\x09ifFalse: [\x0a\x09\x09\x09\x09console log: optionName, ' is not a valid commandline option'.\x0a\x09\x09\x09\x09console log: 'Use any of the following ones: ', switches ]].\x0a\x09^ server.",
  1874. referencedClasses: ["Array"],
  1875. //>>excludeEnd("ide");
  1876. messageSends: ["commandLineSwitches", "new", "ifEmpty:", "ifFalse:", "even", "size", "log:", ",", "first", "remove:", "whileTrue:", "notEmpty", "value:", "ifTrue:ifFalse:", "includes:", "selectorForCommandLineSwitch:", "perform:withArguments:", "with:"]
  1877. }),
  1878. $globals.FileServer.klass);
  1879. $core.addMethod(
  1880. $core.method({
  1881. selector: "defaultBasePath",
  1882. protocol: 'accessing',
  1883. fn: function (){
  1884. var self=this;
  1885. return "./";
  1886. },
  1887. //>>excludeStart("ide", pragmas.excludeIdeData);
  1888. args: [],
  1889. source: "defaultBasePath\x0a\x09^ './'",
  1890. referencedClasses: [],
  1891. //>>excludeEnd("ide");
  1892. messageSends: []
  1893. }),
  1894. $globals.FileServer.klass);
  1895. $core.addMethod(
  1896. $core.method({
  1897. selector: "defaultHost",
  1898. protocol: 'accessing',
  1899. fn: function (){
  1900. var self=this;
  1901. return "127.0.0.1";
  1902. },
  1903. //>>excludeStart("ide", pragmas.excludeIdeData);
  1904. args: [],
  1905. source: "defaultHost\x0a\x09^ '127.0.0.1'",
  1906. referencedClasses: [],
  1907. //>>excludeEnd("ide");
  1908. messageSends: []
  1909. }),
  1910. $globals.FileServer.klass);
  1911. $core.addMethod(
  1912. $core.method({
  1913. selector: "defaultMimeTypes",
  1914. protocol: 'accessing',
  1915. fn: function (){
  1916. var self=this;
  1917. var $1;
  1918. $1=$globals.HashedCollection._newFromPairs_(["%","application/x-trash","323","text/h323","abw","application/x-abiword","ai","application/postscript","aif","audio/x-aiff","aifc","audio/x-aiff","aiff","audio/x-aiff","alc","chemical/x-alchemy","art","image/x-jg","asc","text/plain","asf","video/x-ms-asf","asn","chemical/x-ncbi-asn1-spec","aso","chemical/x-ncbi-asn1-binary","asx","video/x-ms-asf","au","audio/basic","avi","video/x-msvideo","b","chemical/x-molconn-Z","bak","application/x-trash","bat","application/x-msdos-program","bcpio","application/x-bcpio","bib","text/x-bibtex","bin","application/octet-stream","bmp","image/x-ms-bmp","book","application/x-maker","bsd","chemical/x-crossfire","c","text/x-csrc","c++","text/x-c++src","c3d","chemical/x-chem3d","cac","chemical/x-cache","cache","chemical/x-cache","cascii","chemical/x-cactvs-binary","cat","application/vnd.ms-pki.seccat","cbin","chemical/x-cactvs-binary","cc","text/x-c++src","cdf","application/x-cdf","cdr","image/x-coreldraw","cdt","image/x-coreldrawtemplate","cdx","chemical/x-cdx","cdy","application/vnd.cinderella","cef","chemical/x-cxf","cer","chemical/x-cerius","chm","chemical/x-chemdraw","chrt","application/x-kchart","cif","chemical/x-cif","class","application/java-vm","cls","text/x-tex","cmdf","chemical/x-cmdf","cml","chemical/x-cml","cod","application/vnd.rim.cod","com","application/x-msdos-program","cpa","chemical/x-compass","cpio","application/x-cpio","cpp","text/x-c++src","cpt","image/x-corelphotopaint","crl","application/x-pkcs7-crl","crt","application/x-x509-ca-cert","csf","chemical/x-cache-csf","csh","text/x-csh","csm","chemical/x-csml","csml","chemical/x-csml","css","text/css","csv","text/comma-separated-values","ctab","chemical/x-cactvs-binary","ctx","chemical/x-ctx","cu","application/cu-seeme","cub","chemical/x-gaussian-cube","cxf","chemical/x-cxf","cxx","text/x-c++src","dat","chemical/x-mopac-input","dcr","application/x-director","deb","application/x-debian-package","dif","video/dv","diff","text/plain","dir","application/x-director","djv","image/vnd.djvu","djvu","image/vnd.djvu","dl","video/dl","dll","application/x-msdos-program","dmg","application/x-apple-diskimage","dms","application/x-dms","doc","application/msword","dot","application/msword","dv","video/dv","dvi","application/x-dvi","dx","chemical/x-jcamp-dx","dxr","application/x-director","emb","chemical/x-embl-dl-nucleotide","embl","chemical/x-embl-dl-nucleotide","ent","chemical/x-pdb","eps","application/postscript","etx","text/x-setext","exe","application/x-msdos-program","ez","application/andrew-inset","fb","application/x-maker","fbdoc","application/x-maker","fch","chemical/x-gaussian-checkpoint","fchk","chemical/x-gaussian-checkpoint","fig","application/x-xfig","flac","application/x-flac","fli","video/fli","fm","application/x-maker","frame","application/x-maker","frm","application/x-maker","gal","chemical/x-gaussian-log","gam","chemical/x-gamess-input","gamin","chemical/x-gamess-input","gau","chemical/x-gaussian-input","gcd","text/x-pcs-gcd","gcf","application/x-graphing-calculator","gcg","chemical/x-gcg8-sequence","gen","chemical/x-genbank","gf","application/x-tex-gf","gif","image/gif","gjc","chemical/x-gaussian-input","gjf","chemical/x-gaussian-input","gl","video/gl","gnumeric","application/x-gnumeric","gpt","chemical/x-mopac-graph","gsf","application/x-font","gsm","audio/x-gsm","gtar","application/x-gtar","h","text/x-chdr","h++","text/x-c++hdr","hdf","application/x-hdf","hh","text/x-c++hdr","hin","chemical/x-hin","hpp","text/x-c++hdr","hqx","application/mac-binhex40","hs","text/x-haskell","hta","application/hta","htc","text/x-component","htm","text/html","html","text/html","hxx","text/x-c++hdr","ica","application/x-ica","ice","x-conference/x-cooltalk","ico","image/x-icon","ics","text/calendar","icz","text/calendar","ief","image/ief","iges","model/iges","igs","model/iges","iii","application/x-iphone","inp","chemical/x-gamess-input","ins","application/x-internet-signup","iso","application/x-iso9660-image","isp","application/x-internet-signup","ist","chemical/x-isostar","istr","chemical/x-isostar","jad","text/vnd.sun.j2me.app-descriptor","jar","application/java-archive","java","text/x-java","jdx","chemical/x-jcamp-dx","jmz","application/x-jmol","jng","image/x-jng","jnlp","application/x-java-jnlp-file","jpe","image/jpeg","jpeg","image/jpeg","jpg","image/jpeg","js","application/javascript","kar","audio/midi","key","application/pgp-keys","kil","application/x-killustrator","kin","chemical/x-kinemage","kpr","application/x-kpresenter","kpt","application/x-kpresenter","ksp","application/x-kspread","kwd","application/x-kword","kwt","application/x-kword","latex","application/x-latex","lha","application/x-lha","lhs","text/x-literate-haskell","lsf","video/x-la-asf","lsx","video/x-la-asf","ltx","text/x-tex","lzh","application/x-lzh","lzx","application/x-lzx","m3u","audio/x-mpegurl","m4a","audio/mpeg","maker","application/x-maker","man","application/x-troff-man","mcif","chemical/x-mmcif","mcm","chemical/x-macmolecule","mdb","application/msaccess","me","application/x-troff-me","mesh","model/mesh","mid","audio/midi","midi","audio/midi","mif","application/x-mif","mm","application/x-freemind","mmd","chemical/x-macromodel-input","mmf","application/vnd.smaf","mml","text/mathml","mmod","chemical/x-macromodel-input","mng","video/x-mng","moc","text/x-moc","mol","chemical/x-mdl-molfile","mol2","chemical/x-mol2","moo","chemical/x-mopac-out","mop","chemical/x-mopac-input","mopcrt","chemical/x-mopac-input","mov","video/quicktime","movie","video/x-sgi-movie","mp2","audio/mpeg","mp3","audio/mpeg","mp4","video/mp4","mpc","chemical/x-mopac-input","mpe","video/mpeg","mpeg","video/mpeg","mpega","audio/mpeg","mpg","video/mpeg","mpga","audio/mpeg","ms","application/x-troff-ms","msh","model/mesh","msi","application/x-msi","mvb","chemical/x-mopac-vib","mxu","video/vnd.mpegurl","nb","application/mathematica","nc","application/x-netcdf","nwc","application/x-nwc","o","application/x-object","oda","application/oda","odb","application/vnd.oasis.opendocument.database","odc","application/vnd.oasis.opendocument.chart","odf","application/vnd.oasis.opendocument.formula","odg","application/vnd.oasis.opendocument.graphics","odi","application/vnd.oasis.opendocument.image","odm","application/vnd.oasis.opendocument.text-master","odp","application/vnd.oasis.opendocument.presentation","ods","application/vnd.oasis.opendocument.spreadsheet","odt","application/vnd.oasis.opendocument.text","ogg","application/ogg","old","application/x-trash","oth","application/vnd.oasis.opendocument.text-web","oza","application/x-oz-application","p","text/x-pascal","p7r","application/x-pkcs7-certreqresp","pac","application/x-ns-proxy-autoconfig","pas","text/x-pascal","pat","image/x-coreldrawpattern","pbm","image/x-portable-bitmap","pcf","application/x-font","pcf.Z","application/x-font","pcx","image/pcx","pdb","chemical/x-pdb","pdf","application/pdf","pfa","application/x-font","pfb","application/x-font","pgm","image/x-portable-graymap","pgn","application/x-chess-pgn","pgp","application/pgp-signature","pk","application/x-tex-pk","pl","text/x-perl","pls","audio/x-scpls","pm","text/x-perl","png","image/png","pnm","image/x-portable-anymap","pot","text/plain","ppm","image/x-portable-pixmap","pps","application/vnd.ms-powerpoint","ppt","application/vnd.ms-powerpoint","prf","application/pics-rules","prt","chemical/x-ncbi-asn1-ascii","ps","application/postscript","psd","image/x-photoshop","psp","text/x-psp","py","text/x-python","pyc","application/x-python-code","pyo","application/x-python-code","qt","video/quicktime","qtl","application/x-quicktimeplayer","ra","audio/x-realaudio","ram","audio/x-pn-realaudio","rar","application/rar","ras","image/x-cmu-raster","rd","chemical/x-mdl-rdfile","rdf","application/rdf+xml","rgb","image/x-rgb","rm","audio/x-pn-realaudio","roff","application/x-troff","ros","chemical/x-rosdal","rpm","application/x-redhat-package-manager","rss","application/rss+xml","rtf","text/rtf","rtx","text/richtext","rxn","chemical/x-mdl-rxnfile","sct","text/scriptlet","sd","chemical/x-mdl-sdfile","sd2","audio/x-sd2","sda","application/vnd.stardivision.draw","sdc","application/vnd.stardivision.calc","sdd","application/vnd.stardivision.impress","sdf","chemical/x-mdl-sdfile","sdp","application/vnd.stardivision.impress","sdw","application/vnd.stardivision.writer","ser","application/java-serialized-object","sgf","application/x-go-sgf","sgl","application/vnd.stardivision.writer-global","sh","text/x-sh","shar","application/x-shar","shtml","text/html","sid","audio/prs.sid","sik","application/x-trash","silo","model/mesh","sis","application/vnd.symbian.install","sit","application/x-stuffit","skd","application/x-koan","skm","application/x-koan","skp","application/x-koan","skt","application/x-koan","smf","application/vnd.stardivision.math","smi","application/smil","smil","application/smil","snd","audio/basic","spc","chemical/x-galactic-spc","spl","application/x-futuresplash","src","application/x-wais-source","stc","application/vnd.sun.xml.calc.template","std","application/vnd.sun.xml.draw.template","sti","application/vnd.sun.xml.impress.template","stl","application/vnd.ms-pki.stl","stw","application/vnd.sun.xml.writer.template","sty","text/x-tex","sv4cpio","application/x-sv4cpio","sv4crc","application/x-sv4crc","svg","image/svg+xml","svgz","image/svg+xml","sw","chemical/x-swissprot","swf","application/x-shockwave-flash","swfl","application/x-shockwave-flash","sxc","application/vnd.sun.xml.calc","sxd","application/vnd.sun.xml.draw","sxg","application/vnd.sun.xml.writer.global","sxi","application/vnd.sun.xml.impress","sxm","application/vnd.sun.xml.math","sxw","application/vnd.sun.xml.writer","t","application/x-troff","tar","application/x-tar","taz","application/x-gtar","tcl","text/x-tcl","tex","text/x-tex","texi","application/x-texinfo","texinfo","application/x-texinfo","text","text/plain","tgf","chemical/x-mdl-tgf","tgz","application/x-gtar","tif","image/tiff","tiff","image/tiff","tk","text/x-tcl","tm","text/texmacs","torrent","application/x-bittorrent","tr","application/x-troff","ts","text/texmacs","tsp","application/dsptype","tsv","text/tab-separated-values","txt","text/plain","udeb","application/x-debian-package","uls","text/iuls","ustar","application/x-ustar","val","chemical/x-ncbi-asn1-binary","vcd","application/x-cdlink","vcf","text/x-vcard","vcs","text/x-vcalendar","vmd","chemical/x-vmd","vms","chemical/x-vamas-iso14976","vor","application/vnd.stardivision.writer","vrm","x-world/x-vrml","vrml","x-world/x-vrml","vsd","application/vnd.visio","wad","application/x-doom","wav","audio/x-wav","wax","audio/x-ms-wax","wbmp","image/vnd.wap.wbmp","wbxml","application/vnd.wap.wbxml","wk","application/x-123","wm","video/x-ms-wm","wma","audio/x-ms-wma","wmd","application/x-ms-wmd","wml","text/vnd.wap.wml","wmlc","application/vnd.wap.wmlc","wmls","text/vnd.wap.wmlscript","wmlsc","application/vnd.wap.wmlscriptc","wmv","video/x-ms-wmv","wmx","video/x-ms-wmx","wmz","application/x-ms-wmz","wp5","application/wordperfect5.1","wpd","application/wordperfect","wrl","x-world/x-vrml","wsc","text/scriptlet","wvx","video/x-ms-wvx","wz","application/x-wingz","xbm","image/x-xbitmap","xcf","application/x-xcf","xht","application/xhtml+xml","xhtml","application/xhtml+xml","xlb","application/vnd.ms-excel","xls","application/vnd.ms-excel","xlt","application/vnd.ms-excel","xml","application/xml","xpi","application/x-xpinstall","xpm","image/x-xpixmap","xsl","application/xml","xtel","chemical/x-xtel","xul","application/vnd.mozilla.xul+xml","xwd","image/x-xwindowdump","xyz","chemical/x-xyz","zip","application/zip","zmt","chemical/x-mopac-input","~","application/x-trash"]);
  1919. return $1;
  1920. },
  1921. //>>excludeStart("ide", pragmas.excludeIdeData);
  1922. args: [],
  1923. source: "defaultMimeTypes\x0a\x09^ #{\x0a\x09\x09'%' -> 'application/x-trash'.\x0a\x09\x09'323' -> 'text/h323'.\x0a\x09\x09'abw' -> 'application/x-abiword'.\x0a\x09\x09'ai' -> 'application/postscript'.\x0a\x09\x09'aif' -> 'audio/x-aiff'.\x0a\x09\x09'aifc' -> 'audio/x-aiff'.\x0a\x09\x09'aiff' -> 'audio/x-aiff'.\x0a\x09\x09'alc' -> 'chemical/x-alchemy'.\x0a\x09\x09'art' -> 'image/x-jg'.\x0a\x09\x09'asc' -> 'text/plain'.\x0a\x09\x09'asf' -> 'video/x-ms-asf'.\x0a\x09\x09'asn' -> 'chemical/x-ncbi-asn1-spec'.\x0a\x09\x09'aso' -> 'chemical/x-ncbi-asn1-binary'.\x0a\x09\x09'asx' -> 'video/x-ms-asf'.\x0a\x09\x09'au' -> 'audio/basic'.\x0a\x09\x09'avi' -> 'video/x-msvideo'.\x0a\x09\x09'b' -> 'chemical/x-molconn-Z'.\x0a\x09\x09'bak' -> 'application/x-trash'.\x0a\x09\x09'bat' -> 'application/x-msdos-program'.\x0a\x09\x09'bcpio' -> 'application/x-bcpio'.\x0a\x09\x09'bib' -> 'text/x-bibtex'.\x0a\x09\x09'bin' -> 'application/octet-stream'.\x0a\x09\x09'bmp' -> 'image/x-ms-bmp'.\x0a\x09\x09'book' -> 'application/x-maker'.\x0a\x09\x09'bsd' -> 'chemical/x-crossfire'.\x0a\x09\x09'c' -> 'text/x-csrc'.\x0a\x09\x09'c++' -> 'text/x-c++src'.\x0a\x09\x09'c3d' -> 'chemical/x-chem3d'.\x0a\x09\x09'cac' -> 'chemical/x-cache'.\x0a\x09\x09'cache' -> 'chemical/x-cache'.\x0a\x09\x09'cascii' -> 'chemical/x-cactvs-binary'.\x0a\x09\x09'cat' -> 'application/vnd.ms-pki.seccat'.\x0a\x09\x09'cbin' -> 'chemical/x-cactvs-binary'.\x0a\x09\x09'cc' -> 'text/x-c++src'.\x0a\x09\x09'cdf' -> 'application/x-cdf'.\x0a\x09\x09'cdr' -> 'image/x-coreldraw'.\x0a\x09\x09'cdt' -> 'image/x-coreldrawtemplate'.\x0a\x09\x09'cdx' -> 'chemical/x-cdx'.\x0a\x09\x09'cdy' -> 'application/vnd.cinderella'.\x0a\x09\x09'cef' -> 'chemical/x-cxf'.\x0a\x09\x09'cer' -> 'chemical/x-cerius'.\x0a\x09\x09'chm' -> 'chemical/x-chemdraw'.\x0a\x09\x09'chrt' -> 'application/x-kchart'.\x0a\x09\x09'cif' -> 'chemical/x-cif'.\x0a\x09\x09'class' -> 'application/java-vm'.\x0a\x09\x09'cls' -> 'text/x-tex'.\x0a\x09\x09'cmdf' -> 'chemical/x-cmdf'.\x0a\x09\x09'cml' -> 'chemical/x-cml'.\x0a\x09\x09'cod' -> 'application/vnd.rim.cod'.\x0a\x09\x09'com' -> 'application/x-msdos-program'.\x0a\x09\x09'cpa' -> 'chemical/x-compass'.\x0a\x09\x09'cpio' -> 'application/x-cpio'.\x0a\x09\x09'cpp' -> 'text/x-c++src'.\x0a\x09\x09'cpt' -> 'image/x-corelphotopaint'.\x0a\x09\x09'crl' -> 'application/x-pkcs7-crl'.\x0a\x09\x09'crt' -> 'application/x-x509-ca-cert'.\x0a\x09\x09'csf' -> 'chemical/x-cache-csf'.\x0a\x09\x09'csh' -> 'text/x-csh'.\x0a\x09\x09'csm' -> 'chemical/x-csml'.\x0a\x09\x09'csml' -> 'chemical/x-csml'.\x0a\x09\x09'css' -> 'text/css'.\x0a\x09\x09'csv' -> 'text/comma-separated-values'.\x0a\x09\x09'ctab' -> 'chemical/x-cactvs-binary'.\x0a\x09\x09'ctx' -> 'chemical/x-ctx'.\x0a\x09\x09'cu' -> 'application/cu-seeme'.\x0a\x09\x09'cub' -> 'chemical/x-gaussian-cube'.\x0a\x09\x09'cxf' -> 'chemical/x-cxf'.\x0a\x09\x09'cxx' -> 'text/x-c++src'.\x0a\x09\x09'dat' -> 'chemical/x-mopac-input'.\x0a\x09\x09'dcr' -> 'application/x-director'.\x0a\x09\x09'deb' -> 'application/x-debian-package'.\x0a\x09\x09'dif' -> 'video/dv'.\x0a\x09\x09'diff' -> 'text/plain'.\x0a\x09\x09'dir' -> 'application/x-director'.\x0a\x09\x09'djv' -> 'image/vnd.djvu'.\x0a\x09\x09'djvu' -> 'image/vnd.djvu'.\x0a\x09\x09'dl' -> 'video/dl'.\x0a\x09\x09'dll' -> 'application/x-msdos-program'.\x0a\x09\x09'dmg' -> 'application/x-apple-diskimage'.\x0a\x09\x09'dms' -> 'application/x-dms'.\x0a\x09\x09'doc' -> 'application/msword'.\x0a\x09\x09'dot' -> 'application/msword'.\x0a\x09\x09'dv' -> 'video/dv'.\x0a\x09\x09'dvi' -> 'application/x-dvi'.\x0a\x09\x09'dx' -> 'chemical/x-jcamp-dx'.\x0a\x09\x09'dxr' -> 'application/x-director'.\x0a\x09\x09'emb' -> 'chemical/x-embl-dl-nucleotide'.\x0a\x09\x09'embl' -> 'chemical/x-embl-dl-nucleotide'.\x0a\x09\x09'ent' -> 'chemical/x-pdb'.\x0a\x09\x09'eps' -> 'application/postscript'.\x0a\x09\x09'etx' -> 'text/x-setext'.\x0a\x09\x09'exe' -> 'application/x-msdos-program'.\x0a\x09\x09'ez' -> 'application/andrew-inset'.\x0a\x09\x09'fb' -> 'application/x-maker'.\x0a\x09\x09'fbdoc' -> 'application/x-maker'.\x0a\x09\x09'fch' -> 'chemical/x-gaussian-checkpoint'.\x0a\x09\x09'fchk' -> 'chemical/x-gaussian-checkpoint'.\x0a\x09\x09'fig' -> 'application/x-xfig'.\x0a\x09\x09'flac' -> 'application/x-flac'.\x0a\x09\x09'fli' -> 'video/fli'.\x0a\x09\x09'fm' -> 'application/x-maker'.\x0a\x09\x09'frame' -> 'application/x-maker'.\x0a\x09\x09'frm' -> 'application/x-maker'.\x0a\x09\x09'gal' -> 'chemical/x-gaussian-log'.\x0a\x09\x09'gam' -> 'chemical/x-gamess-input'.\x0a\x09\x09'gamin' -> 'chemical/x-gamess-input'.\x0a\x09\x09'gau' -> 'chemical/x-gaussian-input'.\x0a\x09\x09'gcd' -> 'text/x-pcs-gcd'.\x0a\x09\x09'gcf' -> 'application/x-graphing-calculator'.\x0a\x09\x09'gcg' -> 'chemical/x-gcg8-sequence'.\x0a\x09\x09'gen' -> 'chemical/x-genbank'.\x0a\x09\x09'gf' -> 'application/x-tex-gf'.\x0a\x09\x09'gif' -> 'image/gif'.\x0a\x09\x09'gjc' -> 'chemical/x-gaussian-input'.\x0a\x09\x09'gjf' -> 'chemical/x-gaussian-input'.\x0a\x09\x09'gl' -> 'video/gl'.\x0a\x09\x09'gnumeric' -> 'application/x-gnumeric'.\x0a\x09\x09'gpt' -> 'chemical/x-mopac-graph'.\x0a\x09\x09'gsf' -> 'application/x-font'.\x0a\x09\x09'gsm' -> 'audio/x-gsm'.\x0a\x09\x09'gtar' -> 'application/x-gtar'.\x0a\x09\x09'h' -> 'text/x-chdr'.\x0a\x09\x09'h++' -> 'text/x-c++hdr'.\x0a\x09\x09'hdf' -> 'application/x-hdf'.\x0a\x09\x09'hh' -> 'text/x-c++hdr'.\x0a\x09\x09'hin' -> 'chemical/x-hin'.\x0a\x09\x09'hpp' -> 'text/x-c++hdr'.\x0a\x09\x09'hqx' -> 'application/mac-binhex40'.\x0a\x09\x09'hs' -> 'text/x-haskell'.\x0a\x09\x09'hta' -> 'application/hta'.\x0a\x09\x09'htc' -> 'text/x-component'.\x0a\x09\x09'htm' -> 'text/html'.\x0a\x09\x09'html' -> 'text/html'.\x0a\x09\x09'hxx' -> 'text/x-c++hdr'.\x0a\x09\x09'ica' -> 'application/x-ica'.\x0a\x09\x09'ice' -> 'x-conference/x-cooltalk'.\x0a\x09\x09'ico' -> 'image/x-icon'.\x0a\x09\x09'ics' -> 'text/calendar'.\x0a\x09\x09'icz' -> 'text/calendar'.\x0a\x09\x09'ief' -> 'image/ief'.\x0a\x09\x09'iges' -> 'model/iges'.\x0a\x09\x09'igs' -> 'model/iges'.\x0a\x09\x09'iii' -> 'application/x-iphone'.\x0a\x09\x09'inp' -> 'chemical/x-gamess-input'.\x0a\x09\x09'ins' -> 'application/x-internet-signup'.\x0a\x09\x09'iso' -> 'application/x-iso9660-image'.\x0a\x09\x09'isp' -> 'application/x-internet-signup'.\x0a\x09\x09'ist' -> 'chemical/x-isostar'.\x0a\x09\x09'istr' -> 'chemical/x-isostar'.\x0a\x09\x09'jad' -> 'text/vnd.sun.j2me.app-descriptor'.\x0a\x09\x09'jar' -> 'application/java-archive'.\x0a\x09\x09'java' -> 'text/x-java'.\x0a\x09\x09'jdx' -> 'chemical/x-jcamp-dx'.\x0a\x09\x09'jmz' -> 'application/x-jmol'.\x0a\x09\x09'jng' -> 'image/x-jng'.\x0a\x09\x09'jnlp' -> 'application/x-java-jnlp-file'.\x0a\x09\x09'jpe' -> 'image/jpeg'.\x0a\x09\x09'jpeg' -> 'image/jpeg'.\x0a\x09\x09'jpg' -> 'image/jpeg'.\x0a\x09\x09'js' -> 'application/javascript'.\x0a\x09\x09'kar' -> 'audio/midi'.\x0a\x09\x09'key' -> 'application/pgp-keys'.\x0a\x09\x09'kil' -> 'application/x-killustrator'.\x0a\x09\x09'kin' -> 'chemical/x-kinemage'.\x0a\x09\x09'kpr' -> 'application/x-kpresenter'.\x0a\x09\x09'kpt' -> 'application/x-kpresenter'.\x0a\x09\x09'ksp' -> 'application/x-kspread'.\x0a\x09\x09'kwd' -> 'application/x-kword'.\x0a\x09\x09'kwt' -> 'application/x-kword'.\x0a\x09\x09'latex' -> 'application/x-latex'.\x0a\x09\x09'lha' -> 'application/x-lha'.\x0a\x09\x09'lhs' -> 'text/x-literate-haskell'.\x0a\x09\x09'lsf' -> 'video/x-la-asf'.\x0a\x09\x09'lsx' -> 'video/x-la-asf'.\x0a\x09\x09'ltx' -> 'text/x-tex'.\x0a\x09\x09'lzh' -> 'application/x-lzh'.\x0a\x09\x09'lzx' -> 'application/x-lzx'.\x0a\x09\x09'm3u' -> 'audio/x-mpegurl'.\x0a\x09\x09'm4a' -> 'audio/mpeg'.\x0a\x09\x09'maker' -> 'application/x-maker'.\x0a\x09\x09'man' -> 'application/x-troff-man'.\x0a\x09\x09'mcif' -> 'chemical/x-mmcif'.\x0a\x09\x09'mcm' -> 'chemical/x-macmolecule'.\x0a\x09\x09'mdb' -> 'application/msaccess'.\x0a\x09\x09'me' -> 'application/x-troff-me'.\x0a\x09\x09'mesh' -> 'model/mesh'.\x0a\x09\x09'mid' -> 'audio/midi'.\x0a\x09\x09'midi' -> 'audio/midi'.\x0a\x09\x09'mif' -> 'application/x-mif'.\x0a\x09\x09'mm' -> 'application/x-freemind'.\x0a\x09\x09'mmd' -> 'chemical/x-macromodel-input'.\x0a\x09\x09'mmf' -> 'application/vnd.smaf'.\x0a\x09\x09'mml' -> 'text/mathml'.\x0a\x09\x09'mmod' -> 'chemical/x-macromodel-input'.\x0a\x09\x09'mng' -> 'video/x-mng'.\x0a\x09\x09'moc' -> 'text/x-moc'.\x0a\x09\x09'mol' -> 'chemical/x-mdl-molfile'.\x0a\x09\x09'mol2' -> 'chemical/x-mol2'.\x0a\x09\x09'moo' -> 'chemical/x-mopac-out'.\x0a\x09\x09'mop' -> 'chemical/x-mopac-input'.\x0a\x09\x09'mopcrt' -> 'chemical/x-mopac-input'.\x0a\x09\x09'mov' -> 'video/quicktime'.\x0a\x09\x09'movie' -> 'video/x-sgi-movie'.\x0a\x09\x09'mp2' -> 'audio/mpeg'.\x0a\x09\x09'mp3' -> 'audio/mpeg'.\x0a\x09\x09'mp4' -> 'video/mp4'.\x0a\x09\x09'mpc' -> 'chemical/x-mopac-input'.\x0a\x09\x09'mpe' -> 'video/mpeg'.\x0a\x09\x09'mpeg' -> 'video/mpeg'.\x0a\x09\x09'mpega' -> 'audio/mpeg'.\x0a\x09\x09'mpg' -> 'video/mpeg'.\x0a\x09\x09'mpga' -> 'audio/mpeg'.\x0a\x09\x09'ms' -> 'application/x-troff-ms'.\x0a\x09\x09'msh' -> 'model/mesh'.\x0a\x09\x09'msi' -> 'application/x-msi'.\x0a\x09\x09'mvb' -> 'chemical/x-mopac-vib'.\x0a\x09\x09'mxu' -> 'video/vnd.mpegurl'.\x0a\x09\x09'nb' -> 'application/mathematica'.\x0a\x09\x09'nc' -> 'application/x-netcdf'.\x0a\x09\x09'nwc' -> 'application/x-nwc'.\x0a\x09\x09'o' -> 'application/x-object'.\x0a\x09\x09'oda' -> 'application/oda'.\x0a\x09\x09'odb' -> 'application/vnd.oasis.opendocument.database'.\x0a\x09\x09'odc' -> 'application/vnd.oasis.opendocument.chart'.\x0a\x09\x09'odf' -> 'application/vnd.oasis.opendocument.formula'.\x0a\x09\x09'odg' -> 'application/vnd.oasis.opendocument.graphics'.\x0a\x09\x09'odi' -> 'application/vnd.oasis.opendocument.image'.\x0a\x09\x09'odm' -> 'application/vnd.oasis.opendocument.text-master'.\x0a\x09\x09'odp' -> 'application/vnd.oasis.opendocument.presentation'.\x0a\x09\x09'ods' -> 'application/vnd.oasis.opendocument.spreadsheet'.\x0a\x09\x09'odt' -> 'application/vnd.oasis.opendocument.text'.\x0a\x09\x09'ogg' -> 'application/ogg'.\x0a\x09\x09'old' -> 'application/x-trash'.\x0a\x09\x09'oth' -> 'application/vnd.oasis.opendocument.text-web'.\x0a\x09\x09'oza' -> 'application/x-oz-application'.\x0a\x09\x09'p' -> 'text/x-pascal'.\x0a\x09\x09'p7r' -> 'application/x-pkcs7-certreqresp'.\x0a\x09\x09'pac' -> 'application/x-ns-proxy-autoconfig'.\x0a\x09\x09'pas' -> 'text/x-pascal'.\x0a\x09\x09'pat' -> 'image/x-coreldrawpattern'.\x0a\x09\x09'pbm' -> 'image/x-portable-bitmap'.\x0a\x09\x09'pcf' -> 'application/x-font'.\x0a\x09\x09'pcf.Z' -> 'application/x-font'.\x0a\x09\x09'pcx' -> 'image/pcx'.\x0a\x09\x09'pdb' -> 'chemical/x-pdb'.\x0a\x09\x09'pdf' -> 'application/pdf'.\x0a\x09\x09'pfa' -> 'application/x-font'.\x0a\x09\x09'pfb' -> 'application/x-font'.\x0a\x09\x09'pgm' -> 'image/x-portable-graymap'.\x0a\x09\x09'pgn' -> 'application/x-chess-pgn'.\x0a\x09\x09'pgp' -> 'application/pgp-signature'.\x0a\x09\x09'pk' -> 'application/x-tex-pk'.\x0a\x09\x09'pl' -> 'text/x-perl'.\x0a\x09\x09'pls' -> 'audio/x-scpls'.\x0a\x09\x09'pm' -> 'text/x-perl'.\x0a\x09\x09'png' -> 'image/png'.\x0a\x09\x09'pnm' -> 'image/x-portable-anymap'.\x0a\x09\x09'pot' -> 'text/plain'.\x0a\x09\x09'ppm' -> 'image/x-portable-pixmap'.\x0a\x09\x09'pps' -> 'application/vnd.ms-powerpoint'.\x0a\x09\x09'ppt' -> 'application/vnd.ms-powerpoint'.\x0a\x09\x09'prf' -> 'application/pics-rules'.\x0a\x09\x09'prt' -> 'chemical/x-ncbi-asn1-ascii'.\x0a\x09\x09'ps' -> 'application/postscript'.\x0a\x09\x09'psd' -> 'image/x-photoshop'.\x0a\x09\x09'psp' -> 'text/x-psp'.\x0a\x09\x09'py' -> 'text/x-python'.\x0a\x09\x09'pyc' -> 'application/x-python-code'.\x0a\x09\x09'pyo' -> 'application/x-python-code'.\x0a\x09\x09'qt' -> 'video/quicktime'.\x0a\x09\x09'qtl' -> 'application/x-quicktimeplayer'.\x0a\x09\x09'ra' -> 'audio/x-realaudio'.\x0a\x09\x09'ram' -> 'audio/x-pn-realaudio'.\x0a\x09\x09'rar' -> 'application/rar'.\x0a\x09\x09'ras' -> 'image/x-cmu-raster'.\x0a\x09\x09'rd' -> 'chemical/x-mdl-rdfile'.\x0a\x09\x09'rdf' -> 'application/rdf+xml'.\x0a\x09\x09'rgb' -> 'image/x-rgb'.\x0a\x09\x09'rm' -> 'audio/x-pn-realaudio'.\x0a\x09\x09'roff' -> 'application/x-troff'.\x0a\x09\x09'ros' -> 'chemical/x-rosdal'.\x0a\x09\x09'rpm' -> 'application/x-redhat-package-manager'.\x0a\x09\x09'rss' -> 'application/rss+xml'.\x0a\x09\x09'rtf' -> 'text/rtf'.\x0a\x09\x09'rtx' -> 'text/richtext'.\x0a\x09\x09'rxn' -> 'chemical/x-mdl-rxnfile'.\x0a\x09\x09'sct' -> 'text/scriptlet'.\x0a\x09\x09'sd' -> 'chemical/x-mdl-sdfile'.\x0a\x09\x09'sd2' -> 'audio/x-sd2'.\x0a\x09\x09'sda' -> 'application/vnd.stardivision.draw'.\x0a\x09\x09'sdc' -> 'application/vnd.stardivision.calc'.\x0a\x09\x09'sdd' -> 'application/vnd.stardivision.impress'.\x0a\x09\x09'sdf' -> 'chemical/x-mdl-sdfile'.\x0a\x09\x09'sdp' -> 'application/vnd.stardivision.impress'.\x0a\x09\x09'sdw' -> 'application/vnd.stardivision.writer'.\x0a\x09\x09'ser' -> 'application/java-serialized-object'.\x0a\x09\x09'sgf' -> 'application/x-go-sgf'.\x0a\x09\x09'sgl' -> 'application/vnd.stardivision.writer-global'.\x0a\x09\x09'sh' -> 'text/x-sh'.\x0a\x09\x09'shar' -> 'application/x-shar'.\x0a\x09\x09'shtml' -> 'text/html'.\x0a\x09\x09'sid' -> 'audio/prs.sid'.\x0a\x09\x09'sik' -> 'application/x-trash'.\x0a\x09\x09'silo' -> 'model/mesh'.\x0a\x09\x09'sis' -> 'application/vnd.symbian.install'.\x0a\x09\x09'sit' -> 'application/x-stuffit'.\x0a\x09\x09'skd' -> 'application/x-koan'.\x0a\x09\x09'skm' -> 'application/x-koan'.\x0a\x09\x09'skp' -> 'application/x-koan'.\x0a\x09\x09'skt' -> 'application/x-koan'.\x0a\x09\x09'smf' -> 'application/vnd.stardivision.math'.\x0a\x09\x09'smi' -> 'application/smil'.\x0a\x09\x09'smil' -> 'application/smil'.\x0a\x09\x09'snd' -> 'audio/basic'.\x0a\x09\x09'spc' -> 'chemical/x-galactic-spc'.\x0a\x09\x09'spl' -> 'application/x-futuresplash'.\x0a\x09\x09'src' -> 'application/x-wais-source'.\x0a\x09\x09'stc' -> 'application/vnd.sun.xml.calc.template'.\x0a\x09\x09'std' -> 'application/vnd.sun.xml.draw.template'.\x0a\x09\x09'sti' -> 'application/vnd.sun.xml.impress.template'.\x0a\x09\x09'stl' -> 'application/vnd.ms-pki.stl'.\x0a\x09\x09'stw' -> 'application/vnd.sun.xml.writer.template'.\x0a\x09\x09'sty' -> 'text/x-tex'.\x0a\x09\x09'sv4cpio' -> 'application/x-sv4cpio'.\x0a\x09\x09'sv4crc' -> 'application/x-sv4crc'.\x0a\x09\x09'svg' -> 'image/svg+xml'.\x0a\x09\x09'svgz' -> 'image/svg+xml'.\x0a\x09\x09'sw' -> 'chemical/x-swissprot'.\x0a\x09\x09'swf' -> 'application/x-shockwave-flash'.\x0a\x09\x09'swfl' -> 'application/x-shockwave-flash'.\x0a\x09\x09'sxc' -> 'application/vnd.sun.xml.calc'.\x0a\x09\x09'sxd' -> 'application/vnd.sun.xml.draw'.\x0a\x09\x09'sxg' -> 'application/vnd.sun.xml.writer.global'.\x0a\x09\x09'sxi' -> 'application/vnd.sun.xml.impress'.\x0a\x09\x09'sxm' -> 'application/vnd.sun.xml.math'.\x0a\x09\x09'sxw' -> 'application/vnd.sun.xml.writer'.\x0a\x09\x09't' -> 'application/x-troff'.\x0a\x09\x09'tar' -> 'application/x-tar'.\x0a\x09\x09'taz' -> 'application/x-gtar'.\x0a\x09\x09'tcl' -> 'text/x-tcl'.\x0a\x09\x09'tex' -> 'text/x-tex'.\x0a\x09\x09'texi' -> 'application/x-texinfo'.\x0a\x09\x09'texinfo' -> 'application/x-texinfo'.\x0a\x09\x09'text' -> 'text/plain'.\x0a\x09\x09'tgf' -> 'chemical/x-mdl-tgf'.\x0a\x09\x09'tgz' -> 'application/x-gtar'.\x0a\x09\x09'tif' -> 'image/tiff'.\x0a\x09\x09'tiff' -> 'image/tiff'.\x0a\x09\x09'tk' -> 'text/x-tcl'.\x0a\x09\x09'tm' -> 'text/texmacs'.\x0a\x09\x09'torrent' -> 'application/x-bittorrent'.\x0a\x09\x09'tr' -> 'application/x-troff'.\x0a\x09\x09'ts' -> 'text/texmacs'.\x0a\x09\x09'tsp' -> 'application/dsptype'.\x0a\x09\x09'tsv' -> 'text/tab-separated-values'.\x0a\x09\x09'txt' -> 'text/plain'.\x0a\x09\x09'udeb' -> 'application/x-debian-package'.\x0a\x09\x09'uls' -> 'text/iuls'.\x0a\x09\x09'ustar' -> 'application/x-ustar'.\x0a\x09\x09'val' -> 'chemical/x-ncbi-asn1-binary'.\x0a\x09\x09'vcd' -> 'application/x-cdlink'.\x0a\x09\x09'vcf' -> 'text/x-vcard'.\x0a\x09\x09'vcs' -> 'text/x-vcalendar'.\x0a\x09\x09'vmd' -> 'chemical/x-vmd'.\x0a\x09\x09'vms' -> 'chemical/x-vamas-iso14976'.\x0a\x09\x09'vor' -> 'application/vnd.stardivision.writer'.\x0a\x09\x09'vrm' -> 'x-world/x-vrml'.\x0a\x09\x09'vrml' -> 'x-world/x-vrml'.\x0a\x09\x09'vsd' -> 'application/vnd.visio'.\x0a\x09\x09'wad' -> 'application/x-doom'.\x0a\x09\x09'wav' -> 'audio/x-wav'.\x0a\x09\x09'wax' -> 'audio/x-ms-wax'.\x0a\x09\x09'wbmp' -> 'image/vnd.wap.wbmp'.\x0a\x09\x09'wbxml' -> 'application/vnd.wap.wbxml'.\x0a\x09\x09'wk' -> 'application/x-123'.\x0a\x09\x09'wm' -> 'video/x-ms-wm'.\x0a\x09\x09'wma' -> 'audio/x-ms-wma'.\x0a\x09\x09'wmd' -> 'application/x-ms-wmd'.\x0a\x09\x09'wml' -> 'text/vnd.wap.wml'.\x0a\x09\x09'wmlc' -> 'application/vnd.wap.wmlc'.\x0a\x09\x09'wmls' -> 'text/vnd.wap.wmlscript'.\x0a\x09\x09'wmlsc' -> 'application/vnd.wap.wmlscriptc'.\x0a\x09\x09'wmv' -> 'video/x-ms-wmv'.\x0a\x09\x09'wmx' -> 'video/x-ms-wmx'.\x0a\x09\x09'wmz' -> 'application/x-ms-wmz'.\x0a\x09\x09'wp5' -> 'application/wordperfect5.1'.\x0a\x09\x09'wpd' -> 'application/wordperfect'.\x0a\x09\x09'wrl' -> 'x-world/x-vrml'.\x0a\x09\x09'wsc' -> 'text/scriptlet'.\x0a\x09\x09'wvx' -> 'video/x-ms-wvx'.\x0a\x09\x09'wz' -> 'application/x-wingz'.\x0a\x09\x09'xbm' -> 'image/x-xbitmap'.\x0a\x09\x09'xcf' -> 'application/x-xcf'.\x0a\x09\x09'xht' -> 'application/xhtml+xml'.\x0a\x09\x09'xhtml' -> 'application/xhtml+xml'.\x0a\x09\x09'xlb' -> 'application/vnd.ms-excel'.\x0a\x09\x09'xls' -> 'application/vnd.ms-excel'.\x0a\x09\x09'xlt' -> 'application/vnd.ms-excel'.\x0a\x09\x09'xml' -> 'application/xml'.\x0a\x09\x09'xpi' -> 'application/x-xpinstall'.\x0a\x09\x09'xpm' -> 'image/x-xpixmap'.\x0a\x09\x09'xsl' -> 'application/xml'.\x0a\x09\x09'xtel' -> 'chemical/x-xtel'.\x0a\x09\x09'xul' -> 'application/vnd.mozilla.xul+xml'.\x0a\x09\x09'xwd' -> 'image/x-xwindowdump'.\x0a\x09\x09'xyz' -> 'chemical/x-xyz'.\x0a\x09\x09'zip' -> 'application/zip'.\x0a\x09\x09'zmt' -> 'chemical/x-mopac-input'.\x0a\x09\x09'~' -> 'application/x-trash'\x0a\x09}",
  1924. referencedClasses: [],
  1925. //>>excludeEnd("ide");
  1926. messageSends: []
  1927. }),
  1928. $globals.FileServer.klass);
  1929. $core.addMethod(
  1930. $core.method({
  1931. selector: "defaultPort",
  1932. protocol: 'accessing',
  1933. fn: function (){
  1934. var self=this;
  1935. return (4000);
  1936. },
  1937. //>>excludeStart("ide", pragmas.excludeIdeData);
  1938. args: [],
  1939. source: "defaultPort\x0a\x09^ 4000",
  1940. referencedClasses: [],
  1941. //>>excludeEnd("ide");
  1942. messageSends: []
  1943. }),
  1944. $globals.FileServer.klass);
  1945. $core.addMethod(
  1946. $core.method({
  1947. selector: "main",
  1948. protocol: 'initialization',
  1949. fn: function (){
  1950. var self=this;
  1951. var fileServer,args;
  1952. function $FileServer(){return $globals.FileServer||(typeof FileServer=="undefined"?nil:FileServer)}
  1953. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1954. return $core.withContext(function($ctx1) {
  1955. //>>excludeEnd("ctx");
  1956. var $1,$2;
  1957. var $early={};
  1958. try {
  1959. args=$recv(process)._argv();
  1960. $recv(args)._removeFrom_to_((1),(3));
  1961. $recv(args)._detect_ifNone_((function(each){
  1962. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1963. return $core.withContext(function($ctx2) {
  1964. //>>excludeEnd("ctx");
  1965. $1=$recv(each).__eq("--help");
  1966. if($core.assert($1)){
  1967. return $recv($FileServer())._printHelp();
  1968. };
  1969. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1970. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)});
  1971. //>>excludeEnd("ctx");
  1972. }),(function(){
  1973. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1974. return $core.withContext(function($ctx2) {
  1975. //>>excludeEnd("ctx");
  1976. fileServer=$recv($FileServer())._createServerWithArguments_(args);
  1977. fileServer;
  1978. $2=$recv(fileServer)._start();
  1979. throw $early=[$2];
  1980. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1981. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,3)});
  1982. //>>excludeEnd("ctx");
  1983. }));
  1984. return self;
  1985. }
  1986. catch(e) {if(e===$early)return e[0]; throw e}
  1987. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1988. }, function($ctx1) {$ctx1.fill(self,"main",{fileServer:fileServer,args:args},$globals.FileServer.klass)});
  1989. //>>excludeEnd("ctx");
  1990. },
  1991. //>>excludeStart("ide", pragmas.excludeIdeData);
  1992. args: [],
  1993. source: "main\x0a\x09\x22Main entry point for Amber applications.\x0a\x09 Creates and starts a FileServer instance.\x22\x0a\x09| fileServer args |\x0a\x09args := process argv.\x0a\x09\x22Remove the first args which contain the path to the node executable and the script file.\x22\x0a\x09args removeFrom: 1 to: 3.\x0a\x0a\x09args detect: [ :each |\x0a\x09\x09(each = '--help') ifTrue: [FileServer printHelp]]\x0a\x09ifNone: [\x0a\x09\x09fileServer := FileServer createServerWithArguments: args.\x0a\x09\x09^ fileServer start]",
  1994. referencedClasses: ["FileServer"],
  1995. //>>excludeEnd("ide");
  1996. messageSends: ["argv", "removeFrom:to:", "detect:ifNone:", "ifTrue:", "=", "printHelp", "createServerWithArguments:", "start"]
  1997. }),
  1998. $globals.FileServer.klass);
  1999. $core.addMethod(
  2000. $core.method({
  2001. selector: "mimeTypeFor:",
  2002. protocol: 'accessing',
  2003. fn: function (aString){
  2004. var self=this;
  2005. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2006. return $core.withContext(function($ctx1) {
  2007. //>>excludeEnd("ctx");
  2008. var $1;
  2009. $1=$recv(self._mimeTypes())._at_ifAbsent_($recv(aString)._replace_with_(".*[\x5c.]",""),(function(){
  2010. return "text/plain";
  2011. }));
  2012. return $1;
  2013. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2014. }, function($ctx1) {$ctx1.fill(self,"mimeTypeFor:",{aString:aString},$globals.FileServer.klass)});
  2015. //>>excludeEnd("ctx");
  2016. },
  2017. //>>excludeStart("ide", pragmas.excludeIdeData);
  2018. args: ["aString"],
  2019. source: "mimeTypeFor: aString\x0a\x09^ self mimeTypes at: (aString replace: '.*[\x5c.]' with: '') ifAbsent: ['text/plain']",
  2020. referencedClasses: [],
  2021. //>>excludeEnd("ide");
  2022. messageSends: ["at:ifAbsent:", "mimeTypes", "replace:with:"]
  2023. }),
  2024. $globals.FileServer.klass);
  2025. $core.addMethod(
  2026. $core.method({
  2027. selector: "mimeTypes",
  2028. protocol: 'accessing',
  2029. fn: function (){
  2030. var self=this;
  2031. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2032. return $core.withContext(function($ctx1) {
  2033. //>>excludeEnd("ctx");
  2034. var $2,$1,$receiver;
  2035. $2=self["@mimeTypes"];
  2036. if(($receiver = $2) == null || $receiver.isNil){
  2037. self["@mimeTypes"]=self._defaultMimeTypes();
  2038. $1=self["@mimeTypes"];
  2039. } else {
  2040. $1=$2;
  2041. };
  2042. return $1;
  2043. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2044. }, function($ctx1) {$ctx1.fill(self,"mimeTypes",{},$globals.FileServer.klass)});
  2045. //>>excludeEnd("ctx");
  2046. },
  2047. //>>excludeStart("ide", pragmas.excludeIdeData);
  2048. args: [],
  2049. source: "mimeTypes\x0a\x09^ mimeTypes ifNil: [mimeTypes := self defaultMimeTypes]",
  2050. referencedClasses: [],
  2051. //>>excludeEnd("ide");
  2052. messageSends: ["ifNil:", "defaultMimeTypes"]
  2053. }),
  2054. $globals.FileServer.klass);
  2055. $core.addMethod(
  2056. $core.method({
  2057. selector: "printHelp",
  2058. protocol: 'accessing',
  2059. fn: function (){
  2060. var self=this;
  2061. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2062. return $core.withContext(function($ctx1) {
  2063. //>>excludeEnd("ctx");
  2064. $recv(console)._log_("Available commandline options are:");
  2065. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2066. $ctx1.sendIdx["log:"]=1;
  2067. //>>excludeEnd("ctx");
  2068. $recv(console)._log_("--help");
  2069. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2070. $ctx1.sendIdx["log:"]=2;
  2071. //>>excludeEnd("ctx");
  2072. $recv(self._commandLineSwitches())._do_((function(each){
  2073. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2074. return $core.withContext(function($ctx2) {
  2075. //>>excludeEnd("ctx");
  2076. return $recv(console)._log_($recv(each).__comma(" <parameter>"));
  2077. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2078. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)});
  2079. //>>excludeEnd("ctx");
  2080. }));
  2081. return self;
  2082. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2083. }, function($ctx1) {$ctx1.fill(self,"printHelp",{},$globals.FileServer.klass)});
  2084. //>>excludeEnd("ctx");
  2085. },
  2086. //>>excludeStart("ide", pragmas.excludeIdeData);
  2087. args: [],
  2088. source: "printHelp\x0a\x09console log: 'Available commandline options are:'.\x0a\x09console log: '--help'.\x0a\x09self commandLineSwitches do: [ :each |\x0a\x09\x09console log: each, ' <parameter>']",
  2089. referencedClasses: [],
  2090. //>>excludeEnd("ide");
  2091. messageSends: ["log:", "do:", "commandLineSwitches", ","]
  2092. }),
  2093. $globals.FileServer.klass);
  2094. $core.addMethod(
  2095. $core.method({
  2096. selector: "selectorForCommandLineSwitch:",
  2097. protocol: 'accessing',
  2098. fn: function (aSwitch){
  2099. var self=this;
  2100. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2101. return $core.withContext(function($ctx1) {
  2102. //>>excludeEnd("ctx");
  2103. var $2,$1;
  2104. $2=$recv($recv(aSwitch)._replace_with_("^--",""))._replace_with_("-[a-z]",(function(each){
  2105. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2106. return $core.withContext(function($ctx2) {
  2107. //>>excludeEnd("ctx");
  2108. return $recv($recv(each)._second())._asUppercase();
  2109. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2110. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)});
  2111. //>>excludeEnd("ctx");
  2112. }));
  2113. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2114. $ctx1.sendIdx["replace:with:"]=1;
  2115. //>>excludeEnd("ctx");
  2116. $1=$recv($2).__comma(":");
  2117. return $1;
  2118. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2119. }, function($ctx1) {$ctx1.fill(self,"selectorForCommandLineSwitch:",{aSwitch:aSwitch},$globals.FileServer.klass)});
  2120. //>>excludeEnd("ctx");
  2121. },
  2122. //>>excludeStart("ide", pragmas.excludeIdeData);
  2123. args: ["aSwitch"],
  2124. source: "selectorForCommandLineSwitch: aSwitch\x0a\x09\x22Remove the trailing '--', add ':' at the end\x0a\x09 and replace all occurences of a lowercase letter preceded by a '-' with\x0a\x09 the Uppercase letter.\x0a\x09 Example: --fallback-page becomes fallbackPage:\x22\x0a\x09^ ((aSwitch replace: '^--' with: '')\x0a\x09\x09replace: '-[a-z]' with: [ :each | each second asUppercase ]), ':'",
  2125. referencedClasses: [],
  2126. //>>excludeEnd("ide");
  2127. messageSends: [",", "replace:with:", "asUppercase", "second"]
  2128. }),
  2129. $globals.FileServer.klass);
  2130. $core.addClass('Initer', $globals.BaseFileManipulator, ['childProcess', 'nmPath'], 'AmberCli');
  2131. $core.addMethod(
  2132. $core.method({
  2133. selector: "bowerInstallThenDo:",
  2134. protocol: 'action',
  2135. fn: function (aBlock){
  2136. var self=this;
  2137. var child;
  2138. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2139. return $core.withContext(function($ctx1) {
  2140. //>>excludeEnd("ctx");
  2141. var $1,$4,$3,$2;
  2142. child=$recv(self["@childProcess"])._fork_args_(self._npmScriptForModule_named_("bower","bower"),["install"]);
  2143. $1=child;
  2144. $recv($1)._on_do_("error",aBlock);
  2145. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2146. $ctx1.sendIdx["on:do:"]=1;
  2147. //>>excludeEnd("ctx");
  2148. $2=$recv($1)._on_do_("close",(function(code){
  2149. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2150. return $core.withContext(function($ctx2) {
  2151. //>>excludeEnd("ctx");
  2152. $4=$recv(code).__eq((0));
  2153. if($core.assert($4)){
  2154. $3=nil;
  2155. } else {
  2156. $3=code;
  2157. };
  2158. return $recv(aBlock)._value_($3);
  2159. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2160. }, function($ctx2) {$ctx2.fillBlock({code:code},$ctx1,1)});
  2161. //>>excludeEnd("ctx");
  2162. }));
  2163. return self;
  2164. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2165. }, function($ctx1) {$ctx1.fill(self,"bowerInstallThenDo:",{aBlock:aBlock,child:child},$globals.Initer)});
  2166. //>>excludeEnd("ctx");
  2167. },
  2168. //>>excludeStart("ide", pragmas.excludeIdeData);
  2169. args: ["aBlock"],
  2170. source: "bowerInstallThenDo: aBlock\x0a\x09| child |\x0a\x09child := childProcess\x0a\x09\x09fork: (self npmScriptForModule: 'bower' named: 'bower')\x0a\x09\x09args: #('install').\x0a\x09child\x0a\x09\x09on: 'error' do: aBlock;\x0a\x09\x09on: 'close' do: [ :code |\x0a\x09\x09\x09aBlock value: (code = 0 ifTrue: [ nil ] ifFalse: [ code ]) ]",
  2171. referencedClasses: [],
  2172. //>>excludeEnd("ide");
  2173. messageSends: ["fork:args:", "npmScriptForModule:named:", "on:do:", "value:", "ifTrue:ifFalse:", "="]
  2174. }),
  2175. $globals.Initer);
  2176. $core.addMethod(
  2177. $core.method({
  2178. selector: "finishMessage",
  2179. protocol: 'action',
  2180. fn: function (){
  2181. var self=this;
  2182. function $String(){return $globals.String||(typeof String=="undefined"?nil:String)}
  2183. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2184. return $core.withContext(function($ctx1) {
  2185. //>>excludeEnd("ctx");
  2186. $recv(console)._log_([" ", "The project should now be set up.", " ", " ", "To manage project from cli (run tests, recompile),", "the `grunt` command-line tool needs to be installed.", "If not present, it can be installed with:", " (sudo) npm install -g grunt-cli", " ", "To manage project dependencies,", "the `bower` command-line tool needs to be installed.", "If not present, it can be installed with:", " (sudo) npm install -g bower", " "]._join_($recv($String())._lf()));
  2187. $recv((function(){
  2188. }))._valueWithTimeout_((600));
  2189. return self;
  2190. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2191. }, function($ctx1) {$ctx1.fill(self,"finishMessage",{},$globals.Initer)});
  2192. //>>excludeEnd("ctx");
  2193. },
  2194. //>>excludeStart("ide", pragmas.excludeIdeData);
  2195. args: [],
  2196. source: "finishMessage\x0a\x09console log: (#(\x0a\x09\x09' '\x0a\x09\x09'The project should now be set up.'\x0a\x09\x09' '\x0a\x09\x09' '\x0a\x09\x09'To manage project from cli (run tests, recompile),'\x0a\x09\x09'the `grunt` command-line tool needs to be installed.'\x0a\x09\x09'If not present, it can be installed with:'\x0a\x09\x09' (sudo) npm install -g grunt-cli'\x0a\x09\x09' '\x0a\x09\x09'To manage project dependencies,'\x0a\x09\x09'the `bower` command-line tool needs to be installed.'\x0a\x09\x09'If not present, it can be installed with:'\x0a\x09\x09' (sudo) npm install -g bower'\x0a\x09\x09' '\x0a\x09) join: String lf).\x0a\x09[] valueWithTimeout: 600",
  2197. referencedClasses: ["String"],
  2198. //>>excludeEnd("ide");
  2199. messageSends: ["log:", "join:", "lf", "valueWithTimeout:"]
  2200. }),
  2201. $globals.Initer);
  2202. $core.addMethod(
  2203. $core.method({
  2204. selector: "gruntInitThenDo:",
  2205. protocol: 'action',
  2206. fn: function (aBlock){
  2207. var self=this;
  2208. var child,sanitizedTemplatePath;
  2209. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2210. return $core.withContext(function($ctx1) {
  2211. //>>excludeEnd("ctx");
  2212. var $1,$4,$3,$2;
  2213. sanitizedTemplatePath=$recv($recv($recv(self["@path"])._join_with_(self["@nmPath"],"grunt-init-amber"))._replace_with_("\x5c\x5c","\x5c\x5c"))._replace_with_(":","\x5c:");
  2214. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2215. $ctx1.sendIdx["replace:with:"]=1;
  2216. //>>excludeEnd("ctx");
  2217. child=$recv(self["@childProcess"])._fork_args_(self._npmScriptForModule_named_("grunt-init","grunt-init"),[sanitizedTemplatePath]);
  2218. $1=child;
  2219. $recv($1)._on_do_("error",aBlock);
  2220. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2221. $ctx1.sendIdx["on:do:"]=1;
  2222. //>>excludeEnd("ctx");
  2223. $2=$recv($1)._on_do_("close",(function(code){
  2224. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2225. return $core.withContext(function($ctx2) {
  2226. //>>excludeEnd("ctx");
  2227. $4=$recv(code).__eq((0));
  2228. if($core.assert($4)){
  2229. $3=nil;
  2230. } else {
  2231. $3=code;
  2232. };
  2233. return $recv(aBlock)._value_($3);
  2234. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2235. }, function($ctx2) {$ctx2.fillBlock({code:code},$ctx1,1)});
  2236. //>>excludeEnd("ctx");
  2237. }));
  2238. return self;
  2239. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2240. }, function($ctx1) {$ctx1.fill(self,"gruntInitThenDo:",{aBlock:aBlock,child:child,sanitizedTemplatePath:sanitizedTemplatePath},$globals.Initer)});
  2241. //>>excludeEnd("ctx");
  2242. },
  2243. //>>excludeStart("ide", pragmas.excludeIdeData);
  2244. args: ["aBlock"],
  2245. source: "gruntInitThenDo: aBlock\x0a\x09| child sanitizedTemplatePath |\x0a\x09sanitizedTemplatePath := ((path join: nmPath with: 'grunt-init-amber')\x0a\x09\x09replace: '\x5c\x5c' with: '\x5c\x5c') replace: ':' with: '\x5c:'.\x0a\x09child := childProcess\x0a\x09\x09fork: (self npmScriptForModule: 'grunt-init' named: 'grunt-init')\x0a\x09\x09args: {sanitizedTemplatePath}.\x0a\x09child\x0a\x09\x09on: 'error' do: aBlock;\x0a\x09\x09on: 'close' do: [ :code |\x0a\x09\x09\x09aBlock value: (code = 0 ifTrue: [ nil ] ifFalse: [ code ]) ]",
  2246. referencedClasses: [],
  2247. //>>excludeEnd("ide");
  2248. messageSends: ["replace:with:", "join:with:", "fork:args:", "npmScriptForModule:named:", "on:do:", "value:", "ifTrue:ifFalse:", "="]
  2249. }),
  2250. $globals.Initer);
  2251. $core.addMethod(
  2252. $core.method({
  2253. selector: "gruntThenDo:",
  2254. protocol: 'action',
  2255. fn: function (aBlock){
  2256. var self=this;
  2257. var child;
  2258. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2259. return $core.withContext(function($ctx1) {
  2260. //>>excludeEnd("ctx");
  2261. var $1,$4,$3,$2;
  2262. child=$recv(self["@childProcess"])._fork_args_(self._npmScriptForModule_named_("grunt-cli","grunt"),["default", "devel"]);
  2263. $1=child;
  2264. $recv($1)._on_do_("error",aBlock);
  2265. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2266. $ctx1.sendIdx["on:do:"]=1;
  2267. //>>excludeEnd("ctx");
  2268. $2=$recv($1)._on_do_("close",(function(code){
  2269. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2270. return $core.withContext(function($ctx2) {
  2271. //>>excludeEnd("ctx");
  2272. $4=$recv(code).__eq((0));
  2273. if($core.assert($4)){
  2274. $3=nil;
  2275. } else {
  2276. $3=code;
  2277. };
  2278. return $recv(aBlock)._value_($3);
  2279. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2280. }, function($ctx2) {$ctx2.fillBlock({code:code},$ctx1,1)});
  2281. //>>excludeEnd("ctx");
  2282. }));
  2283. return self;
  2284. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2285. }, function($ctx1) {$ctx1.fill(self,"gruntThenDo:",{aBlock:aBlock,child:child},$globals.Initer)});
  2286. //>>excludeEnd("ctx");
  2287. },
  2288. //>>excludeStart("ide", pragmas.excludeIdeData);
  2289. args: ["aBlock"],
  2290. source: "gruntThenDo: aBlock\x0a\x09| child |\x0a\x09child := childProcess\x0a\x09\x09fork: (self npmScriptForModule: 'grunt-cli' named: 'grunt')\x0a\x09\x09args: #('default' 'devel').\x0a\x09child\x0a\x09\x09on: 'error' do: aBlock;\x0a\x09\x09on: 'close' do: [ :code |\x0a\x09\x09\x09aBlock value: (code = 0 ifTrue: [ nil ] ifFalse: [ code ]) ]",
  2291. referencedClasses: [],
  2292. //>>excludeEnd("ide");
  2293. messageSends: ["fork:args:", "npmScriptForModule:named:", "on:do:", "value:", "ifTrue:ifFalse:", "="]
  2294. }),
  2295. $globals.Initer);
  2296. $core.addMethod(
  2297. $core.method({
  2298. selector: "initialize",
  2299. protocol: 'initialization',
  2300. fn: function (){
  2301. var self=this;
  2302. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2303. return $core.withContext(function($ctx1) {
  2304. //>>excludeEnd("ctx");
  2305. (
  2306. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2307. $ctx1.supercall = true,
  2308. //>>excludeEnd("ctx");
  2309. $globals.Initer.superclass.fn.prototype._initialize.apply($recv(self), []));
  2310. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2311. $ctx1.supercall = false;
  2312. //>>excludeEnd("ctx");;
  2313. self["@childProcess"]=$recv(require)._value_("child_process");
  2314. self["@nmPath"]=$recv(self["@path"])._join_with_(self._rootDirname(),"node_modules");
  2315. return self;
  2316. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2317. }, function($ctx1) {$ctx1.fill(self,"initialize",{},$globals.Initer)});
  2318. //>>excludeEnd("ctx");
  2319. },
  2320. //>>excludeStart("ide", pragmas.excludeIdeData);
  2321. args: [],
  2322. source: "initialize\x0a\x09super initialize.\x0a\x09childProcess := require value: 'child_process'.\x0a\x09nmPath := path join: self rootDirname with: 'node_modules'",
  2323. referencedClasses: [],
  2324. //>>excludeEnd("ide");
  2325. messageSends: ["initialize", "value:", "join:with:", "rootDirname"]
  2326. }),
  2327. $globals.Initer);
  2328. $core.addMethod(
  2329. $core.method({
  2330. selector: "npmInstallThenDo:",
  2331. protocol: 'action',
  2332. fn: function (aBlock){
  2333. var self=this;
  2334. var child;
  2335. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2336. return $core.withContext(function($ctx1) {
  2337. //>>excludeEnd("ctx");
  2338. var $1;
  2339. child=$recv(self["@childProcess"])._exec_thenDo_("npm install",aBlock);
  2340. $1=$recv(child)._stdout();
  2341. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2342. $ctx1.sendIdx["stdout"]=1;
  2343. //>>excludeEnd("ctx");
  2344. $recv($1)._pipe_options_($recv(process)._stdout(),$globals.HashedCollection._newFromPairs_(["end",false]));
  2345. return self;
  2346. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2347. }, function($ctx1) {$ctx1.fill(self,"npmInstallThenDo:",{aBlock:aBlock,child:child},$globals.Initer)});
  2348. //>>excludeEnd("ctx");
  2349. },
  2350. //>>excludeStart("ide", pragmas.excludeIdeData);
  2351. args: ["aBlock"],
  2352. source: "npmInstallThenDo: aBlock\x0a\x09| child |\x0a\x09child := childProcess\x0a\x09\x09exec: 'npm install'\x0a\x09\x09thenDo: aBlock.\x0a\x09child stdout pipe: process stdout options: #{ 'end' -> false }",
  2353. referencedClasses: [],
  2354. //>>excludeEnd("ide");
  2355. messageSends: ["exec:thenDo:", "pipe:options:", "stdout"]
  2356. }),
  2357. $globals.Initer);
  2358. $core.addMethod(
  2359. $core.method({
  2360. selector: "npmScriptForModule:named:",
  2361. protocol: 'npm',
  2362. fn: function (aString,anotherString){
  2363. var self=this;
  2364. var modulePath,packageJson,binSection,scriptPath;
  2365. function $JSObjectProxy(){return $globals.JSObjectProxy||(typeof JSObjectProxy=="undefined"?nil:JSObjectProxy)}
  2366. function $Smalltalk(){return $globals.Smalltalk||(typeof Smalltalk=="undefined"?nil:Smalltalk)}
  2367. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2368. return $core.withContext(function($ctx1) {
  2369. //>>excludeEnd("ctx");
  2370. var $1,$3,$4,$2,$5,$6;
  2371. $1=self["@path"];
  2372. $3=$recv($JSObjectProxy())._on_(require);
  2373. $4=$recv(aString).__comma("/package.json");
  2374. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2375. $ctx1.sendIdx[","]=1;
  2376. //>>excludeEnd("ctx");
  2377. $2=$recv($3)._resolve_($4);
  2378. modulePath=$recv($1)._dirname_($2);
  2379. packageJson=$recv($Smalltalk())._readJSObject_($recv(require)._value_($recv(aString).__comma("/package.json")));
  2380. binSection=$recv(packageJson)._at_("bin");
  2381. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2382. $ctx1.sendIdx["at:"]=1;
  2383. //>>excludeEnd("ctx");
  2384. $5=$recv(binSection)._isString();
  2385. if($core.assert($5)){
  2386. scriptPath=binSection;
  2387. } else {
  2388. scriptPath=$recv(binSection)._at_(anotherString);
  2389. };
  2390. $6=$recv(self["@path"])._join_with_(modulePath,scriptPath);
  2391. return $6;
  2392. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2393. }, function($ctx1) {$ctx1.fill(self,"npmScriptForModule:named:",{aString:aString,anotherString:anotherString,modulePath:modulePath,packageJson:packageJson,binSection:binSection,scriptPath:scriptPath},$globals.Initer)});
  2394. //>>excludeEnd("ctx");
  2395. },
  2396. //>>excludeStart("ide", pragmas.excludeIdeData);
  2397. args: ["aString", "anotherString"],
  2398. source: "npmScriptForModule: aString named: anotherString\x0a\x09| modulePath packageJson binSection scriptPath |\x0a\x09modulePath := path dirname: (\x0a\x09\x09(JSObjectProxy on: require)\x0a\x09\x09\x09resolve: aString, '/package.json').\x0a\x09packageJson := Smalltalk readJSObject: (\x0a\x09\x09require value: aString, '/package.json').\x0a\x09binSection := packageJson at: 'bin'.\x0a\x09scriptPath := binSection isString\x0a\x09\x09ifTrue: [ binSection ]\x0a\x09\x09ifFalse: [ binSection at: anotherString ].\x0a\x09^ path join: modulePath with: scriptPath",
  2399. referencedClasses: ["JSObjectProxy", "Smalltalk"],
  2400. //>>excludeEnd("ide");
  2401. messageSends: ["dirname:", "resolve:", "on:", ",", "readJSObject:", "value:", "at:", "ifTrue:ifFalse:", "isString", "join:with:"]
  2402. }),
  2403. $globals.Initer);
  2404. $core.addMethod(
  2405. $core.method({
  2406. selector: "start",
  2407. protocol: 'action',
  2408. fn: function (){
  2409. var self=this;
  2410. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2411. return $core.withContext(function($ctx1) {
  2412. //>>excludeEnd("ctx");
  2413. var $1,$2,$3,$4,$5,$6,$7,$8,$receiver;
  2414. self._gruntInitThenDo_((function(error){
  2415. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2416. return $core.withContext(function($ctx2) {
  2417. //>>excludeEnd("ctx");
  2418. if(($receiver = error) == null || $receiver.isNil){
  2419. return self._bowerInstallThenDo_((function(error2){
  2420. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2421. return $core.withContext(function($ctx3) {
  2422. //>>excludeEnd("ctx");
  2423. if(($receiver = error2) == null || $receiver.isNil){
  2424. return self._npmInstallThenDo_((function(error3){
  2425. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2426. return $core.withContext(function($ctx4) {
  2427. //>>excludeEnd("ctx");
  2428. if(($receiver = error3) == null || $receiver.isNil){
  2429. return self._gruntThenDo_((function(error4){
  2430. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2431. return $core.withContext(function($ctx5) {
  2432. //>>excludeEnd("ctx");
  2433. if(($receiver = error4) == null || $receiver.isNil){
  2434. self._finishMessage();
  2435. return $recv(process)._exit();
  2436. } else {
  2437. $7=console;
  2438. $recv($7)._log_("grunt exec error:");
  2439. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2440. $ctx5.sendIdx["log:"]=7;
  2441. //>>excludeEnd("ctx");
  2442. $8=$recv($7)._log_(error4);
  2443. $8;
  2444. return $recv(process)._exit_((104));
  2445. };
  2446. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2447. }, function($ctx5) {$ctx5.fillBlock({error4:error4},$ctx4,10)});
  2448. //>>excludeEnd("ctx");
  2449. }));
  2450. } else {
  2451. $5=console;
  2452. $recv($5)._log_("npm install exec error:");
  2453. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2454. $ctx4.sendIdx["log:"]=5;
  2455. //>>excludeEnd("ctx");
  2456. $6=$recv($5)._log_(error3);
  2457. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2458. $ctx4.sendIdx["log:"]=6;
  2459. //>>excludeEnd("ctx");
  2460. $6;
  2461. return $recv(process)._exit_((103));
  2462. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2463. $ctx4.sendIdx["exit:"]=3;
  2464. //>>excludeEnd("ctx");
  2465. };
  2466. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2467. }, function($ctx4) {$ctx4.fillBlock({error3:error3},$ctx3,7)});
  2468. //>>excludeEnd("ctx");
  2469. }));
  2470. } else {
  2471. $3=console;
  2472. $recv($3)._log_("bower install exec error:");
  2473. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2474. $ctx3.sendIdx["log:"]=3;
  2475. //>>excludeEnd("ctx");
  2476. $4=$recv($3)._log_(error2);
  2477. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2478. $ctx3.sendIdx["log:"]=4;
  2479. //>>excludeEnd("ctx");
  2480. $4;
  2481. return $recv(process)._exit_((102));
  2482. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2483. $ctx3.sendIdx["exit:"]=2;
  2484. //>>excludeEnd("ctx");
  2485. };
  2486. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2487. }, function($ctx3) {$ctx3.fillBlock({error2:error2},$ctx2,4)});
  2488. //>>excludeEnd("ctx");
  2489. }));
  2490. } else {
  2491. $1=console;
  2492. $recv($1)._log_("grunt-init exec error:");
  2493. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2494. $ctx2.sendIdx["log:"]=1;
  2495. //>>excludeEnd("ctx");
  2496. $2=$recv($1)._log_(error);
  2497. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2498. $ctx2.sendIdx["log:"]=2;
  2499. //>>excludeEnd("ctx");
  2500. $2;
  2501. return $recv(process)._exit_((101));
  2502. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2503. $ctx2.sendIdx["exit:"]=1;
  2504. //>>excludeEnd("ctx");
  2505. };
  2506. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2507. }, function($ctx2) {$ctx2.fillBlock({error:error},$ctx1,1)});
  2508. //>>excludeEnd("ctx");
  2509. }));
  2510. return self;
  2511. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2512. }, function($ctx1) {$ctx1.fill(self,"start",{},$globals.Initer)});
  2513. //>>excludeEnd("ctx");
  2514. },
  2515. //>>excludeStart("ide", pragmas.excludeIdeData);
  2516. args: [],
  2517. source: "start\x0a\x09self gruntInitThenDo: [ :error | error\x0a\x09ifNotNil: [\x0a\x09\x09console log: 'grunt-init exec error:'; log: error.\x0a\x09\x09process exit: 101 ]\x0a\x09ifNil: [\x0a\x0a\x09self bowerInstallThenDo: [ :error2 | error2\x0a\x09ifNotNil: [\x0a\x09\x09console log: 'bower install exec error:'; log: error2.\x0a\x09\x09process exit: 102 ]\x0a\x09ifNil: [\x0a\x0a\x09self npmInstallThenDo: [ :error3 | error3\x0a\x09ifNotNil: [\x0a\x09\x09console log: 'npm install exec error:'; log: error3.\x0a\x09\x09process exit: 103 ]\x0a\x09ifNil: [\x0a\x0a\x09self gruntThenDo: [ :error4 | error4\x0a\x09ifNotNil: [\x0a\x09\x09console log: 'grunt exec error:'; log: error4.\x0a\x09\x09process exit: 104 ]\x0a\x09ifNil: [\x0a\x0a\x09self finishMessage.\x0a\x09process exit ]]]]]]]]",
  2518. referencedClasses: [],
  2519. //>>excludeEnd("ide");
  2520. messageSends: ["gruntInitThenDo:", "ifNotNil:ifNil:", "log:", "exit:", "bowerInstallThenDo:", "npmInstallThenDo:", "gruntThenDo:", "finishMessage", "exit"]
  2521. }),
  2522. $globals.Initer);
  2523. $core.addClass('Repl', $globals.Object, ['readline', 'interface', 'util', 'session', 'resultCount', 'commands'], 'AmberCli');
  2524. //>>excludeStart("ide", pragmas.excludeIdeData);
  2525. $globals.Repl.comment="I am a class representing a REPL (Read Evaluate Print Loop) and provide a command line interface to Amber Smalltalk.\x0aOn the prompt you can type Amber statements which will be evaluated after pressing <Enter>.\x0aThe evaluation is comparable with executing a 'DoIt' in a workspace.\x0a\x0aMy runtime requirement is a functional Node.js executable with working Readline support.";
  2526. //>>excludeEnd("ide");
  2527. $core.addMethod(
  2528. $core.method({
  2529. selector: "addVariableNamed:to:",
  2530. protocol: 'private',
  2531. fn: function (aString,anObject){
  2532. var self=this;
  2533. var newClass,newObject;
  2534. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2535. return $core.withContext(function($ctx1) {
  2536. //>>excludeEnd("ctx");
  2537. var $1;
  2538. newClass=self._subclass_withVariable_($recv(anObject)._class(),aString);
  2539. self._encapsulateVariable_withValue_in_(aString,anObject,newClass);
  2540. newObject=$recv(newClass)._new();
  2541. self._setPreviousVariablesFor_from_(newObject,anObject);
  2542. $1=newObject;
  2543. return $1;
  2544. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2545. }, function($ctx1) {$ctx1.fill(self,"addVariableNamed:to:",{aString:aString,anObject:anObject,newClass:newClass,newObject:newObject},$globals.Repl)});
  2546. //>>excludeEnd("ctx");
  2547. },
  2548. //>>excludeStart("ide", pragmas.excludeIdeData);
  2549. args: ["aString", "anObject"],
  2550. source: "addVariableNamed: aString to: anObject\x0a\x09| newClass newObject |\x0a\x09newClass := self subclass: anObject class withVariable: aString.\x0a\x09self encapsulateVariable: aString withValue: anObject in: newClass.\x0a\x09newObject := newClass new.\x0a\x09self setPreviousVariablesFor: newObject from: anObject.\x0a\x09^ newObject",
  2551. referencedClasses: [],
  2552. //>>excludeEnd("ide");
  2553. messageSends: ["subclass:withVariable:", "class", "encapsulateVariable:withValue:in:", "new", "setPreviousVariablesFor:from:"]
  2554. }),
  2555. $globals.Repl);
  2556. $core.addMethod(
  2557. $core.method({
  2558. selector: "assignNewVariable:do:",
  2559. protocol: 'private',
  2560. fn: function (buffer,aBlock){
  2561. var self=this;
  2562. function $Error(){return $globals.Error||(typeof Error=="undefined"?nil:Error)}
  2563. function $ConsoleErrorHandler(){return $globals.ConsoleErrorHandler||(typeof ConsoleErrorHandler=="undefined"?nil:ConsoleErrorHandler)}
  2564. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2565. return $core.withContext(function($ctx1) {
  2566. //>>excludeEnd("ctx");
  2567. var $3,$4,$2,$1,$receiver;
  2568. $1=self._parseAssignment_do_(buffer,(function(name,expr){
  2569. var varName,value;
  2570. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2571. return $core.withContext(function($ctx2) {
  2572. //>>excludeEnd("ctx");
  2573. if(($receiver = name) == null || $receiver.isNil){
  2574. varName=self._nextResultName();
  2575. } else {
  2576. varName=name;
  2577. };
  2578. varName;
  2579. self["@session"]=self._addVariableNamed_to_(varName,self["@session"]);
  2580. self["@session"];
  2581. $recv((function(){
  2582. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2583. return $core.withContext(function($ctx3) {
  2584. //>>excludeEnd("ctx");
  2585. $3=$recv(varName).__comma(" := ");
  2586. if(($receiver = expr) == null || $receiver.isNil){
  2587. $4=buffer;
  2588. } else {
  2589. $4=expr;
  2590. };
  2591. $2=$recv($3).__comma($4);
  2592. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2593. $ctx3.sendIdx[","]=1;
  2594. //>>excludeEnd("ctx");
  2595. value=self._eval_on_($2,self["@session"]);
  2596. return value;
  2597. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2598. }, function($ctx3) {$ctx3.fillBlock({},$ctx2,3)});
  2599. //>>excludeEnd("ctx");
  2600. }))._on_do_($Error(),(function(e){
  2601. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2602. return $core.withContext(function($ctx3) {
  2603. //>>excludeEnd("ctx");
  2604. $recv($recv($ConsoleErrorHandler())._new())._logError_(e);
  2605. value=nil;
  2606. return value;
  2607. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2608. }, function($ctx3) {$ctx3.fillBlock({e:e},$ctx2,5)});
  2609. //>>excludeEnd("ctx");
  2610. }));
  2611. return $recv(aBlock)._value_value_(varName,value);
  2612. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2613. }, function($ctx2) {$ctx2.fillBlock({name:name,expr:expr,varName:varName,value:value},$ctx1,1)});
  2614. //>>excludeEnd("ctx");
  2615. }));
  2616. return $1;
  2617. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2618. }, function($ctx1) {$ctx1.fill(self,"assignNewVariable:do:",{buffer:buffer,aBlock:aBlock},$globals.Repl)});
  2619. //>>excludeEnd("ctx");
  2620. },
  2621. //>>excludeStart("ide", pragmas.excludeIdeData);
  2622. args: ["buffer", "aBlock"],
  2623. source: "assignNewVariable: buffer do: aBlock\x0a\x09\x22Assigns a new variable and calls the given block with the variable's name and value\x0a\x09 if buffer contains an assignment expression. If it doesn't the block is called with nil for\x0a\x09 both arguments.\x22\x0a\x09^ self parseAssignment: buffer do: [ :name :expr || varName value |\x0a\x09\x09varName := name ifNil: [self nextResultName].\x0a\x09\x09session := self addVariableNamed: varName to: session.\x0a\x09\x09[ value := self eval: varName, ' := ', (expr ifNil: [buffer]) on: session ]\x0a\x09\x09\x09on: Error\x0a\x09\x09\x09do: [ :e | ConsoleErrorHandler new logError: e. value := nil].\x0a\x09\x09aBlock value: varName value: value]",
  2624. referencedClasses: ["Error", "ConsoleErrorHandler"],
  2625. //>>excludeEnd("ide");
  2626. messageSends: ["parseAssignment:do:", "ifNil:", "nextResultName", "addVariableNamed:to:", "on:do:", "eval:on:", ",", "logError:", "new", "value:value:"]
  2627. }),
  2628. $globals.Repl);
  2629. $core.addMethod(
  2630. $core.method({
  2631. selector: "clearScreen",
  2632. protocol: 'actions',
  2633. fn: function (){
  2634. var self=this;
  2635. var esc,cls;
  2636. function $String(){return $globals.String||(typeof String=="undefined"?nil:String)}
  2637. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2638. return $core.withContext(function($ctx1) {
  2639. //>>excludeEnd("ctx");
  2640. var $1;
  2641. esc=$recv($String())._fromCharCode_((27));
  2642. $1=$recv($recv(esc).__comma("[2J")).__comma(esc);
  2643. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2644. $ctx1.sendIdx[","]=2;
  2645. //>>excludeEnd("ctx");
  2646. cls=$recv($1).__comma("[0;0f");
  2647. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2648. $ctx1.sendIdx[","]=1;
  2649. //>>excludeEnd("ctx");
  2650. $recv($recv(process)._stdout())._write_(cls);
  2651. $recv(self["@interface"])._prompt();
  2652. return self;
  2653. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2654. }, function($ctx1) {$ctx1.fill(self,"clearScreen",{esc:esc,cls:cls},$globals.Repl)});
  2655. //>>excludeEnd("ctx");
  2656. },
  2657. //>>excludeStart("ide", pragmas.excludeIdeData);
  2658. args: [],
  2659. source: "clearScreen\x0a\x09| esc cls |\x0a\x09esc := String fromCharCode: 27.\x0a\x09cls := esc, '[2J', esc, '[0;0f'.\x0a\x09process stdout write: cls.\x0a\x09interface prompt",
  2660. referencedClasses: ["String"],
  2661. //>>excludeEnd("ide");
  2662. messageSends: ["fromCharCode:", ",", "write:", "stdout", "prompt"]
  2663. }),
  2664. $globals.Repl);
  2665. $core.addMethod(
  2666. $core.method({
  2667. selector: "close",
  2668. protocol: 'actions',
  2669. fn: function (){
  2670. var self=this;
  2671. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2672. return $core.withContext(function($ctx1) {
  2673. //>>excludeEnd("ctx");
  2674. $recv($recv(process)._stdin())._destroy();
  2675. return self;
  2676. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2677. }, function($ctx1) {$ctx1.fill(self,"close",{},$globals.Repl)});
  2678. //>>excludeEnd("ctx");
  2679. },
  2680. //>>excludeStart("ide", pragmas.excludeIdeData);
  2681. args: [],
  2682. source: "close\x0a\x09process stdin destroy",
  2683. referencedClasses: [],
  2684. //>>excludeEnd("ide");
  2685. messageSends: ["destroy", "stdin"]
  2686. }),
  2687. $globals.Repl);
  2688. $core.addMethod(
  2689. $core.method({
  2690. selector: "commands",
  2691. protocol: 'accessing',
  2692. fn: function (){
  2693. var self=this;
  2694. var $1;
  2695. $1=self["@commands"];
  2696. return $1;
  2697. },
  2698. //>>excludeStart("ide", pragmas.excludeIdeData);
  2699. args: [],
  2700. source: "commands\x0a\x09^ commands",
  2701. referencedClasses: [],
  2702. //>>excludeEnd("ide");
  2703. messageSends: []
  2704. }),
  2705. $globals.Repl);
  2706. $core.addMethod(
  2707. $core.method({
  2708. selector: "createInterface",
  2709. protocol: 'actions',
  2710. fn: function (){
  2711. var self=this;
  2712. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2713. return $core.withContext(function($ctx1) {
  2714. //>>excludeEnd("ctx");
  2715. var $1;
  2716. self["@interface"]=$recv(self["@readline"])._createInterface_stdout_($recv(process)._stdin(),$recv(process)._stdout());
  2717. $recv(self["@interface"])._on_do_("line",(function(buffer){
  2718. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2719. return $core.withContext(function($ctx2) {
  2720. //>>excludeEnd("ctx");
  2721. return self._processLine_(buffer);
  2722. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2723. }, function($ctx2) {$ctx2.fillBlock({buffer:buffer},$ctx1,1)});
  2724. //>>excludeEnd("ctx");
  2725. }));
  2726. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2727. $ctx1.sendIdx["on:do:"]=1;
  2728. //>>excludeEnd("ctx");
  2729. $recv(self["@interface"])._on_do_("close",(function(){
  2730. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2731. return $core.withContext(function($ctx2) {
  2732. //>>excludeEnd("ctx");
  2733. return self._close();
  2734. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2735. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,2)});
  2736. //>>excludeEnd("ctx");
  2737. }));
  2738. self._printWelcome();
  2739. self._setupHotkeys();
  2740. $1=self._setPrompt();
  2741. $recv(self["@interface"])._prompt();
  2742. return self;
  2743. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2744. }, function($ctx1) {$ctx1.fill(self,"createInterface",{},$globals.Repl)});
  2745. //>>excludeEnd("ctx");
  2746. },
  2747. //>>excludeStart("ide", pragmas.excludeIdeData);
  2748. args: [],
  2749. source: "createInterface\x0a\x09interface := readline createInterface: process stdin stdout: process stdout.\x0a\x09interface on: 'line' do: [:buffer | self processLine: buffer].\x0a\x09interface on: 'close' do: [self close].\x0a\x09self printWelcome; setupHotkeys; setPrompt.\x0a\x09interface prompt",
  2750. referencedClasses: [],
  2751. //>>excludeEnd("ide");
  2752. messageSends: ["createInterface:stdout:", "stdin", "stdout", "on:do:", "processLine:", "close", "printWelcome", "setupHotkeys", "setPrompt", "prompt"]
  2753. }),
  2754. $globals.Repl);
  2755. $core.addMethod(
  2756. $core.method({
  2757. selector: "encapsulateVariable:withValue:in:",
  2758. protocol: 'private',
  2759. fn: function (aString,anObject,aClass){
  2760. var self=this;
  2761. var compiler;
  2762. function $Compiler(){return $globals.Compiler||(typeof Compiler=="undefined"?nil:Compiler)}
  2763. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2764. return $core.withContext(function($ctx1) {
  2765. //>>excludeEnd("ctx");
  2766. var $1,$4,$3,$2,$5,$6;
  2767. compiler=$recv($Compiler())._new();
  2768. $1=compiler;
  2769. $4=$recv(aString).__comma(": anObject ^ ");
  2770. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2771. $ctx1.sendIdx[","]=3;
  2772. //>>excludeEnd("ctx");
  2773. $3=$recv($4).__comma(aString);
  2774. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2775. $ctx1.sendIdx[","]=2;
  2776. //>>excludeEnd("ctx");
  2777. $2=$recv($3).__comma(" := anObject");
  2778. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2779. $ctx1.sendIdx[","]=1;
  2780. //>>excludeEnd("ctx");
  2781. $recv($1)._install_forClass_protocol_($2,aClass,"session");
  2782. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2783. $ctx1.sendIdx["install:forClass:protocol:"]=1;
  2784. //>>excludeEnd("ctx");
  2785. $5=compiler;
  2786. $6=$recv($recv(aString).__comma(" ^ ")).__comma(aString);
  2787. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2788. $ctx1.sendIdx[","]=4;
  2789. //>>excludeEnd("ctx");
  2790. $recv($5)._install_forClass_protocol_($6,aClass,"session");
  2791. return self;
  2792. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2793. }, function($ctx1) {$ctx1.fill(self,"encapsulateVariable:withValue:in:",{aString:aString,anObject:anObject,aClass:aClass,compiler:compiler},$globals.Repl)});
  2794. //>>excludeEnd("ctx");
  2795. },
  2796. //>>excludeStart("ide", pragmas.excludeIdeData);
  2797. args: ["aString", "anObject", "aClass"],
  2798. source: "encapsulateVariable: aString withValue: anObject in: aClass\x0a\x09\x22Add getter and setter for given variable to session.\x22\x0a\x09| compiler |\x0a\x09compiler := Compiler new.\x0a\x09compiler install: aString, ': anObject ^ ', aString, ' := anObject' forClass: aClass protocol: 'session'.\x0a\x09compiler install: aString, ' ^ ', aString forClass: aClass protocol: 'session'.",
  2799. referencedClasses: ["Compiler"],
  2800. //>>excludeEnd("ide");
  2801. messageSends: ["new", "install:forClass:protocol:", ","]
  2802. }),
  2803. $globals.Repl);
  2804. $core.addMethod(
  2805. $core.method({
  2806. selector: "eval:",
  2807. protocol: 'actions',
  2808. fn: function (buffer){
  2809. var self=this;
  2810. function $DoIt(){return $globals.DoIt||(typeof DoIt=="undefined"?nil:DoIt)}
  2811. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2812. return $core.withContext(function($ctx1) {
  2813. //>>excludeEnd("ctx");
  2814. var $1;
  2815. $1=self._eval_on_(buffer,$recv($DoIt())._new());
  2816. return $1;
  2817. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2818. }, function($ctx1) {$ctx1.fill(self,"eval:",{buffer:buffer},$globals.Repl)});
  2819. //>>excludeEnd("ctx");
  2820. },
  2821. //>>excludeStart("ide", pragmas.excludeIdeData);
  2822. args: ["buffer"],
  2823. source: "eval: buffer\x0a\x09^ self eval: buffer on: DoIt new.",
  2824. referencedClasses: ["DoIt"],
  2825. //>>excludeEnd("ide");
  2826. messageSends: ["eval:on:", "new"]
  2827. }),
  2828. $globals.Repl);
  2829. $core.addMethod(
  2830. $core.method({
  2831. selector: "eval:on:",
  2832. protocol: 'actions',
  2833. fn: function (buffer,anObject){
  2834. var self=this;
  2835. var result;
  2836. function $Compiler(){return $globals.Compiler||(typeof Compiler=="undefined"?nil:Compiler)}
  2837. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2838. return $core.withContext(function($ctx1) {
  2839. //>>excludeEnd("ctx");
  2840. var $1,$2,$3;
  2841. $1=$recv(buffer)._isEmpty();
  2842. if(!$core.assert($1)){
  2843. $recv((function(){
  2844. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2845. return $core.withContext(function($ctx2) {
  2846. //>>excludeEnd("ctx");
  2847. result=$recv($recv($Compiler())._new())._evaluateExpression_on_(buffer,anObject);
  2848. return result;
  2849. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2850. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,2)});
  2851. //>>excludeEnd("ctx");
  2852. }))._tryCatch_((function(e){
  2853. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2854. return $core.withContext(function($ctx2) {
  2855. //>>excludeEnd("ctx");
  2856. $2=$recv(e)._isSmalltalkError();
  2857. if($core.assert($2)){
  2858. return $recv(e)._resignal();
  2859. } else {
  2860. return $recv($recv(process)._stdout())._write_($recv(e)._jsStack());
  2861. };
  2862. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2863. }, function($ctx2) {$ctx2.fillBlock({e:e},$ctx1,3)});
  2864. //>>excludeEnd("ctx");
  2865. }));
  2866. };
  2867. $3=result;
  2868. return $3;
  2869. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2870. }, function($ctx1) {$ctx1.fill(self,"eval:on:",{buffer:buffer,anObject:anObject,result:result},$globals.Repl)});
  2871. //>>excludeEnd("ctx");
  2872. },
  2873. //>>excludeStart("ide", pragmas.excludeIdeData);
  2874. args: ["buffer", "anObject"],
  2875. source: "eval: buffer on: anObject\x0a\x09| result |\x0a\x09buffer isEmpty ifFalse: [\x0a\x09\x09[result := Compiler new evaluateExpression: buffer on: anObject]\x0a\x09\x09\x09tryCatch: [:e |\x0a\x09\x09\x09\x09e isSmalltalkError\x0a\x09\x09\x09\x09 ifTrue: [ e resignal ]\x0a\x09\x09\x09 \x09 ifFalse: [ process stdout write: e jsStack ]]].\x0a\x09^ result",
  2876. referencedClasses: ["Compiler"],
  2877. //>>excludeEnd("ide");
  2878. messageSends: ["ifFalse:", "isEmpty", "tryCatch:", "evaluateExpression:on:", "new", "ifTrue:ifFalse:", "isSmalltalkError", "resignal", "write:", "stdout", "jsStack"]
  2879. }),
  2880. $globals.Repl);
  2881. $core.addMethod(
  2882. $core.method({
  2883. selector: "executeCommand:",
  2884. protocol: 'private',
  2885. fn: function (aString){
  2886. var self=this;
  2887. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2888. return $core.withContext(function($ctx1) {
  2889. //>>excludeEnd("ctx");
  2890. var $1;
  2891. var $early={};
  2892. try {
  2893. $recv(self._commands())._keysAndValuesDo_((function(names,cmd){
  2894. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2895. return $core.withContext(function($ctx2) {
  2896. //>>excludeEnd("ctx");
  2897. $1=$recv(names)._includes_(aString);
  2898. if($core.assert($1)){
  2899. $recv(cmd)._value();
  2900. throw $early=[true];
  2901. };
  2902. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2903. }, function($ctx2) {$ctx2.fillBlock({names:names,cmd:cmd},$ctx1,1)});
  2904. //>>excludeEnd("ctx");
  2905. }));
  2906. return false;
  2907. }
  2908. catch(e) {if(e===$early)return e[0]; throw e}
  2909. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2910. }, function($ctx1) {$ctx1.fill(self,"executeCommand:",{aString:aString},$globals.Repl)});
  2911. //>>excludeEnd("ctx");
  2912. },
  2913. //>>excludeStart("ide", pragmas.excludeIdeData);
  2914. args: ["aString"],
  2915. source: "executeCommand: aString\x0a\x09\x22Tries to process the given string as a command. Returns true if it was a command, false if not.\x22\x0a\x09self commands keysAndValuesDo: [:names :cmd |\x0a\x09\x09(names includes: aString) ifTrue: [\x0a\x09\x09\x09cmd value.\x0a\x09\x09\x09^ true]].\x0a\x09^ false",
  2916. referencedClasses: [],
  2917. //>>excludeEnd("ide");
  2918. messageSends: ["keysAndValuesDo:", "commands", "ifTrue:", "includes:", "value"]
  2919. }),
  2920. $globals.Repl);
  2921. $core.addMethod(
  2922. $core.method({
  2923. selector: "initialize",
  2924. protocol: 'initialization',
  2925. fn: function (){
  2926. var self=this;
  2927. function $DoIt(){return $globals.DoIt||(typeof DoIt=="undefined"?nil:DoIt)}
  2928. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2929. return $core.withContext(function($ctx1) {
  2930. //>>excludeEnd("ctx");
  2931. (
  2932. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2933. $ctx1.supercall = true,
  2934. //>>excludeEnd("ctx");
  2935. $globals.Repl.superclass.fn.prototype._initialize.apply($recv(self), []));
  2936. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2937. $ctx1.supercall = false;
  2938. //>>excludeEnd("ctx");;
  2939. self["@session"]=$recv($DoIt())._new();
  2940. self["@readline"]=$recv(require)._value_("readline");
  2941. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2942. $ctx1.sendIdx["value:"]=1;
  2943. //>>excludeEnd("ctx");
  2944. self["@util"]=$recv(require)._value_("util");
  2945. self._setupCommands();
  2946. return self;
  2947. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2948. }, function($ctx1) {$ctx1.fill(self,"initialize",{},$globals.Repl)});
  2949. //>>excludeEnd("ctx");
  2950. },
  2951. //>>excludeStart("ide", pragmas.excludeIdeData);
  2952. args: [],
  2953. source: "initialize\x0a\x09super initialize.\x0a\x09session := DoIt new.\x0a\x09readline := require value: 'readline'.\x0a\x09util := require value: 'util'.\x0a\x09self setupCommands",
  2954. referencedClasses: ["DoIt"],
  2955. //>>excludeEnd("ide");
  2956. messageSends: ["initialize", "new", "value:", "setupCommands"]
  2957. }),
  2958. $globals.Repl);
  2959. $core.addMethod(
  2960. $core.method({
  2961. selector: "instanceVariableNamesFor:",
  2962. protocol: 'private',
  2963. fn: function (aClass){
  2964. var self=this;
  2965. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2966. return $core.withContext(function($ctx1) {
  2967. //>>excludeEnd("ctx");
  2968. var $2,$3,$1,$receiver;
  2969. $2=$recv(aClass)._superclass();
  2970. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2971. $ctx1.sendIdx["superclass"]=1;
  2972. //>>excludeEnd("ctx");
  2973. if(($receiver = $2) == null || $receiver.isNil){
  2974. $1=$recv(aClass)._instanceVariableNames();
  2975. } else {
  2976. $3=$recv(aClass)._instanceVariableNames();
  2977. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2978. $ctx1.sendIdx["instanceVariableNames"]=1;
  2979. //>>excludeEnd("ctx");
  2980. $1=$recv($3)._copyWithAll_(self._instanceVariableNamesFor_($recv(aClass)._superclass()));
  2981. };
  2982. return $1;
  2983. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2984. }, function($ctx1) {$ctx1.fill(self,"instanceVariableNamesFor:",{aClass:aClass},$globals.Repl)});
  2985. //>>excludeEnd("ctx");
  2986. },
  2987. //>>excludeStart("ide", pragmas.excludeIdeData);
  2988. args: ["aClass"],
  2989. source: "instanceVariableNamesFor: aClass\x0a\x09\x22Yields all instance variable names for the given class, including inherited ones.\x22\x0a\x09^ aClass superclass\x0a\x09\x09ifNotNil: [\x0a\x09\x09\x09aClass instanceVariableNames copyWithAll: (self instanceVariableNamesFor: aClass superclass)]\x0a\x09\x09ifNil: [\x0a\x09\x09\x09aClass instanceVariableNames]",
  2990. referencedClasses: [],
  2991. //>>excludeEnd("ide");
  2992. messageSends: ["ifNotNil:ifNil:", "superclass", "copyWithAll:", "instanceVariableNames", "instanceVariableNamesFor:"]
  2993. }),
  2994. $globals.Repl);
  2995. $core.addMethod(
  2996. $core.method({
  2997. selector: "isIdentifier:",
  2998. protocol: 'private',
  2999. fn: function (aString){
  3000. var self=this;
  3001. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  3002. return $core.withContext(function($ctx1) {
  3003. //>>excludeEnd("ctx");
  3004. var $1;
  3005. $1=$recv(aString)._match_("^[a-z_]\x5cw*$"._asRegexp());
  3006. return $1;
  3007. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  3008. }, function($ctx1) {$ctx1.fill(self,"isIdentifier:",{aString:aString},$globals.Repl)});
  3009. //>>excludeEnd("ctx");
  3010. },
  3011. //>>excludeStart("ide", pragmas.excludeIdeData);
  3012. args: ["aString"],
  3013. source: "isIdentifier: aString\x0a\x09^ aString match: '^[a-z_]\x5cw*$' asRegexp",
  3014. referencedClasses: [],
  3015. //>>excludeEnd("ide");
  3016. messageSends: ["match:", "asRegexp"]
  3017. }),
  3018. $globals.Repl);
  3019. $core.addMethod(
  3020. $core.method({
  3021. selector: "isVariableDefined:",
  3022. protocol: 'private',
  3023. fn: function (aString){
  3024. var self=this;
  3025. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  3026. return $core.withContext(function($ctx1) {
  3027. //>>excludeEnd("ctx");
  3028. var $1;
  3029. $1=$recv(self._instanceVariableNamesFor_($recv(self["@session"])._class()))._includes_(aString);
  3030. return $1;
  3031. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  3032. }, function($ctx1) {$ctx1.fill(self,"isVariableDefined:",{aString:aString},$globals.Repl)});
  3033. //>>excludeEnd("ctx");
  3034. },
  3035. //>>excludeStart("ide", pragmas.excludeIdeData);
  3036. args: ["aString"],
  3037. source: "isVariableDefined: aString\x0a\x09^ (self instanceVariableNamesFor: session class) includes: aString",
  3038. referencedClasses: [],
  3039. //>>excludeEnd("ide");
  3040. messageSends: ["includes:", "instanceVariableNamesFor:", "class"]
  3041. }),
  3042. $globals.Repl);
  3043. $core.addMethod(
  3044. $core.method({
  3045. selector: "nextResultName",
  3046. protocol: 'private',
  3047. fn: function (){
  3048. var self=this;
  3049. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  3050. return $core.withContext(function($ctx1) {
  3051. //>>excludeEnd("ctx");
  3052. var $1,$2,$receiver;
  3053. $1=self["@resultCount"];
  3054. if(($receiver = $1) == null || $receiver.isNil){
  3055. self["@resultCount"]=(1);
  3056. } else {
  3057. self["@resultCount"]=$recv(self["@resultCount"]).__plus((1));
  3058. };
  3059. $2="res".__comma($recv(self["@resultCount"])._asString());
  3060. return $2;
  3061. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  3062. }, function($ctx1) {$ctx1.fill(self,"nextResultName",{},$globals.Repl)});
  3063. //>>excludeEnd("ctx");
  3064. },
  3065. //>>excludeStart("ide", pragmas.excludeIdeData);
  3066. args: [],
  3067. source: "nextResultName\x0a\x09resultCount := resultCount\x0a \x09ifNotNil: [resultCount + 1]\x0a \x09ifNil: [1].\x0a ^ 'res', resultCount asString",
  3068. referencedClasses: [],
  3069. //>>excludeEnd("ide");
  3070. messageSends: ["ifNotNil:ifNil:", "+", ",", "asString"]
  3071. }),
  3072. $globals.Repl);
  3073. $core.addMethod(
  3074. $core.method({
  3075. selector: "onKeyPress:",
  3076. protocol: 'private',
  3077. fn: function (key){
  3078. var self=this;
  3079. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  3080. return $core.withContext(function($ctx1) {
  3081. //>>excludeEnd("ctx");
  3082. var $1;
  3083. $1=$recv($recv(key)._ctrl())._and_((function(){
  3084. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  3085. return $core.withContext(function($ctx2) {
  3086. //>>excludeEnd("ctx");
  3087. return $recv($recv(key)._name()).__eq("l");
  3088. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  3089. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)});
  3090. //>>excludeEnd("ctx");
  3091. }));
  3092. if($core.assert($1)){
  3093. self._clearScreen();
  3094. };
  3095. return self;
  3096. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  3097. }, function($ctx1) {$ctx1.fill(self,"onKeyPress:",{key:key},$globals.Repl)});
  3098. //>>excludeEnd("ctx");
  3099. },
  3100. //>>excludeStart("ide", pragmas.excludeIdeData);
  3101. args: ["key"],
  3102. source: "onKeyPress: key\x0a\x09(key ctrl and: [key name = 'l'])\x0a\x09\x09ifTrue: [self clearScreen]",
  3103. referencedClasses: [],
  3104. //>>excludeEnd("ide");
  3105. messageSends: ["ifTrue:", "and:", "ctrl", "=", "name", "clearScreen"]
  3106. }),
  3107. $globals.Repl);
  3108. $core.addMethod(
  3109. $core.method({
  3110. selector: "parseAssignment:do:",
  3111. protocol: 'private',
  3112. fn: function (aString,aBlock){
  3113. var self=this;
  3114. var assignment;
  3115. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  3116. return $core.withContext(function($ctx1) {
  3117. //>>excludeEnd("ctx");
  3118. var $3,$2,$1;
  3119. assignment=$recv($recv(aString)._tokenize_(":="))._collect_((function(s){
  3120. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  3121. return $core.withContext(function($ctx2) {
  3122. //>>excludeEnd("ctx");
  3123. return $recv(s)._trimBoth();
  3124. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  3125. }, function($ctx2) {$ctx2.fillBlock({s:s},$ctx1,1)});
  3126. //>>excludeEnd("ctx");
  3127. }));
  3128. $2=$recv($recv($recv(assignment)._size()).__eq((2)))._and_((function(){
  3129. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  3130. return $core.withContext(function($ctx2) {
  3131. //>>excludeEnd("ctx");
  3132. $3=$recv(assignment)._first();
  3133. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  3134. $ctx2.sendIdx["first"]=1;
  3135. //>>excludeEnd("ctx");
  3136. return self._isIdentifier_($3);
  3137. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  3138. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,2)});
  3139. //>>excludeEnd("ctx");
  3140. }));
  3141. if($core.assert($2)){
  3142. $1=$recv(aBlock)._value_value_($recv(assignment)._first(),$recv(assignment)._last());
  3143. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  3144. $ctx1.sendIdx["value:value:"]=1;
  3145. //>>excludeEnd("ctx");
  3146. } else {
  3147. $1=$recv(aBlock)._value_value_(nil,nil);
  3148. };
  3149. return $1;
  3150. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  3151. }, function($ctx1) {$ctx1.fill(self,"parseAssignment:do:",{aString:aString,aBlock:aBlock,assignment:assignment},$globals.Repl)});
  3152. //>>excludeEnd("ctx");
  3153. },
  3154. //>>excludeStart("ide", pragmas.excludeIdeData);
  3155. args: ["aString", "aBlock"],
  3156. source: "parseAssignment: aString do: aBlock\x0a\x09\x22Assigns a new variable if the given string is an assignment expression. Calls the given block with name and value.\x0a\x09 If the string is not one no variable will be assigned and the block will be called with nil for both arguments.\x22\x0a\x09| assignment |\x0a\x09assignment := (aString tokenize: ':=') collect: [:s | s trimBoth].\x0a\x09^ (assignment size = 2 and: [self isIdentifier: assignment first])\x0a\x09\x09ifTrue: [ aBlock value: assignment first value: assignment last ]\x0a\x09\x09ifFalse: [ aBlock value: nil value: nil ]",
  3157. referencedClasses: [],
  3158. //>>excludeEnd("ide");
  3159. messageSends: ["collect:", "tokenize:", "trimBoth", "ifTrue:ifFalse:", "and:", "=", "size", "isIdentifier:", "first", "value:value:", "last"]
  3160. }),
  3161. $globals.Repl);
  3162. $core.addMethod(
  3163. $core.method({
  3164. selector: "presentResultNamed:withValue:",
  3165. protocol: 'private',
  3166. fn: function (varName,value){
  3167. var self=this;
  3168. function $Transcript(){return $globals.Transcript||(typeof Transcript=="undefined"?nil:Transcript)}
  3169. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  3170. return $core.withContext(function($ctx1) {
  3171. //>>excludeEnd("ctx");
  3172. var $3,$2,$1,$4;
  3173. $3=$recv($recv(varName).__comma(": ")).__comma($recv($recv(value)._class())._name());
  3174. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  3175. $ctx1.sendIdx[","]=3;
  3176. //>>excludeEnd("ctx");
  3177. $2=$recv($3).__comma(" = ");
  3178. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  3179. $ctx1.sendIdx[","]=2;
  3180. //>>excludeEnd("ctx");
  3181. $1=$recv($2).__comma($recv(value)._asString());
  3182. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  3183. $ctx1.sendIdx[","]=1;
  3184. //>>excludeEnd("ctx");
  3185. $recv($Transcript())._show_($1);
  3186. $4=$recv($Transcript())._cr();
  3187. $recv(self["@interface"])._prompt();
  3188. return self;
  3189. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  3190. }, function($ctx1) {$ctx1.fill(self,"presentResultNamed:withValue:",{varName:varName,value:value},$globals.Repl)});
  3191. //>>excludeEnd("ctx");
  3192. },
  3193. //>>excludeStart("ide", pragmas.excludeIdeData);
  3194. args: ["varName", "value"],
  3195. source: "presentResultNamed: varName withValue: value\x0a\x09Transcript show: varName, ': ', value class name, ' = ', value asString; cr.\x0a\x09interface prompt",
  3196. referencedClasses: ["Transcript"],
  3197. //>>excludeEnd("ide");
  3198. messageSends: ["show:", ",", "name", "class", "asString", "cr", "prompt"]
  3199. }),
  3200. $globals.Repl);
  3201. $core.addMethod(
  3202. $core.method({
  3203. selector: "printWelcome",
  3204. protocol: 'actions',
  3205. fn: function (){
  3206. var self=this;
  3207. function $Transcript(){return $globals.Transcript||(typeof Transcript=="undefined"?nil:Transcript)}
  3208. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  3209. return $core.withContext(function($ctx1) {
  3210. //>>excludeEnd("ctx");
  3211. var $1;
  3212. $recv($Transcript())._show_("Type :q to exit.");
  3213. $1=$recv($Transcript())._cr();
  3214. return self;
  3215. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  3216. }, function($ctx1) {$ctx1.fill(self,"printWelcome",{},$globals.Repl)});
  3217. //>>excludeEnd("ctx");
  3218. },
  3219. //>>excludeStart("ide", pragmas.excludeIdeData);
  3220. args: [],
  3221. source: "printWelcome\x0a\x09Transcript show: 'Type :q to exit.'; cr.",
  3222. referencedClasses: ["Transcript"],
  3223. //>>excludeEnd("ide");
  3224. messageSends: ["show:", "cr"]
  3225. }),
  3226. $globals.Repl);
  3227. $core.addMethod(
  3228. $core.method({
  3229. selector: "processLine:",
  3230. protocol: 'private',
  3231. fn: function (buffer){
  3232. var self=this;
  3233. var show;
  3234. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  3235. return $core.withContext(function($ctx1) {
  3236. //>>excludeEnd("ctx");
  3237. var $1,$2;
  3238. show=(function(varName,value){
  3239. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  3240. return $core.withContext(function($ctx2) {
  3241. //>>excludeEnd("ctx");
  3242. return self._presentResultNamed_withValue_(varName,value);
  3243. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  3244. }, function($ctx2) {$ctx2.fillBlock({varName:varName,value:value},$ctx1,1)});
  3245. //>>excludeEnd("ctx");
  3246. });
  3247. $1=self._executeCommand_(buffer);
  3248. if(!$core.assert($1)){
  3249. $2=self._isVariableDefined_(buffer);
  3250. if($core.assert($2)){
  3251. $recv(show)._value_value_(buffer,$recv(self["@session"])._perform_(buffer));
  3252. } else {
  3253. self._assignNewVariable_do_(buffer,show);
  3254. };
  3255. };
  3256. return self;
  3257. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  3258. }, function($ctx1) {$ctx1.fill(self,"processLine:",{buffer:buffer,show:show},$globals.Repl)});
  3259. //>>excludeEnd("ctx");
  3260. },
  3261. //>>excludeStart("ide", pragmas.excludeIdeData);
  3262. args: ["buffer"],
  3263. source: "processLine: buffer\x0a\x09\x22Processes lines entered through the readline interface.\x22\x0a\x09| show |\x0a\x09show := [:varName :value | self presentResultNamed: varName withValue: value].\x0a\x09(self executeCommand: buffer) ifFalse: [\x0a\x09\x09(self isVariableDefined: buffer)\x0a\x09\x09\x09ifTrue: [show value: buffer value: (session perform: buffer)]\x0a\x09\x09\x09ifFalse: [self assignNewVariable: buffer do: show]]",
  3264. referencedClasses: [],
  3265. //>>excludeEnd("ide");
  3266. messageSends: ["presentResultNamed:withValue:", "ifFalse:", "executeCommand:", "ifTrue:ifFalse:", "isVariableDefined:", "value:value:", "perform:", "assignNewVariable:do:"]
  3267. }),
  3268. $globals.Repl);
  3269. $core.addMethod(
  3270. $core.method({
  3271. selector: "prompt",
  3272. protocol: 'accessing',
  3273. fn: function (){
  3274. var self=this;
  3275. return "amber >> ";
  3276. },
  3277. //>>excludeStart("ide", pragmas.excludeIdeData);
  3278. args: [],
  3279. source: "prompt\x0a\x09^ 'amber >> '",
  3280. referencedClasses: [],
  3281. //>>excludeEnd("ide");
  3282. messageSends: []
  3283. }),
  3284. $globals.Repl);
  3285. $core.addMethod(
  3286. $core.method({
  3287. selector: "setPreviousVariablesFor:from:",
  3288. protocol: 'private',
  3289. fn: function (newObject,oldObject){
  3290. var self=this;
  3291. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  3292. return $core.withContext(function($ctx1) {
  3293. //>>excludeEnd("ctx");
  3294. $recv(self._instanceVariableNamesFor_($recv(oldObject)._class()))._do_((function(each){
  3295. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  3296. return $core.withContext(function($ctx2) {
  3297. //>>excludeEnd("ctx");
  3298. return $recv(newObject)._perform_withArguments_($recv(each).__comma(":"),[$recv(oldObject)._perform_(each)]);
  3299. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  3300. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)});
  3301. //>>excludeEnd("ctx");
  3302. }));
  3303. return self;
  3304. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  3305. }, function($ctx1) {$ctx1.fill(self,"setPreviousVariablesFor:from:",{newObject:newObject,oldObject:oldObject},$globals.Repl)});
  3306. //>>excludeEnd("ctx");
  3307. },
  3308. //>>excludeStart("ide", pragmas.excludeIdeData);
  3309. args: ["newObject", "oldObject"],
  3310. source: "setPreviousVariablesFor: newObject from: oldObject\x0a\x09(self instanceVariableNamesFor: oldObject class) do: [:each |\x0a\x09\x09newObject perform: each, ':' withArguments: {oldObject perform: each}].",
  3311. referencedClasses: [],
  3312. //>>excludeEnd("ide");
  3313. messageSends: ["do:", "instanceVariableNamesFor:", "class", "perform:withArguments:", ",", "perform:"]
  3314. }),
  3315. $globals.Repl);
  3316. $core.addMethod(
  3317. $core.method({
  3318. selector: "setPrompt",
  3319. protocol: 'actions',
  3320. fn: function (){
  3321. var self=this;
  3322. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  3323. return $core.withContext(function($ctx1) {
  3324. //>>excludeEnd("ctx");
  3325. $recv(self["@interface"])._setPrompt_(self._prompt());
  3326. return self;
  3327. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  3328. }, function($ctx1) {$ctx1.fill(self,"setPrompt",{},$globals.Repl)});
  3329. //>>excludeEnd("ctx");
  3330. },
  3331. //>>excludeStart("ide", pragmas.excludeIdeData);
  3332. args: [],
  3333. source: "setPrompt\x0a\x09interface setPrompt: self prompt",
  3334. referencedClasses: [],
  3335. //>>excludeEnd("ide");
  3336. messageSends: ["setPrompt:", "prompt"]
  3337. }),
  3338. $globals.Repl);
  3339. $core.addMethod(
  3340. $core.method({
  3341. selector: "setupCommands",
  3342. protocol: 'initialization',
  3343. fn: function (){
  3344. var self=this;
  3345. function $Dictionary(){return $globals.Dictionary||(typeof Dictionary=="undefined"?nil:Dictionary)}
  3346. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  3347. return $core.withContext(function($ctx1) {
  3348. //>>excludeEnd("ctx");
  3349. var $2,$1;
  3350. $2=$recv([":q"]).__minus_gt((function(){
  3351. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  3352. return $core.withContext(function($ctx2) {
  3353. //>>excludeEnd("ctx");
  3354. return $recv(process)._exit();
  3355. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  3356. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)});
  3357. //>>excludeEnd("ctx");
  3358. }));
  3359. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  3360. $ctx1.sendIdx["->"]=1;
  3361. //>>excludeEnd("ctx");
  3362. $1=[$2,$recv([""]).__minus_gt((function(){
  3363. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  3364. return $core.withContext(function($ctx2) {
  3365. //>>excludeEnd("ctx");
  3366. return $recv(self["@interface"])._prompt();
  3367. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  3368. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,2)});
  3369. //>>excludeEnd("ctx");
  3370. }))];
  3371. self["@commands"]=$recv($Dictionary())._from_($1);
  3372. return self;
  3373. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  3374. }, function($ctx1) {$ctx1.fill(self,"setupCommands",{},$globals.Repl)});
  3375. //>>excludeEnd("ctx");
  3376. },
  3377. //>>excludeStart("ide", pragmas.excludeIdeData);
  3378. args: [],
  3379. source: "setupCommands\x0a\x09commands := Dictionary from: {\x0a\x09\x09{':q'} -> [process exit].\x0a\x09\x09{''} -> [interface prompt]}",
  3380. referencedClasses: ["Dictionary"],
  3381. //>>excludeEnd("ide");
  3382. messageSends: ["from:", "->", "exit", "prompt"]
  3383. }),
  3384. $globals.Repl);
  3385. $core.addMethod(
  3386. $core.method({
  3387. selector: "setupHotkeys",
  3388. protocol: 'initialization',
  3389. fn: function (){
  3390. var self=this;
  3391. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  3392. return $core.withContext(function($ctx1) {
  3393. //>>excludeEnd("ctx");
  3394. var $receiver;
  3395. $recv($recv(process)._stdin())._on_do_("keypress",(function(s,key){
  3396. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  3397. return $core.withContext(function($ctx2) {
  3398. //>>excludeEnd("ctx");
  3399. if(($receiver = key) == null || $receiver.isNil){
  3400. return key;
  3401. } else {
  3402. return self._onKeyPress_(key);
  3403. };
  3404. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  3405. }, function($ctx2) {$ctx2.fillBlock({s:s,key:key},$ctx1,1)});
  3406. //>>excludeEnd("ctx");
  3407. }));
  3408. return self;
  3409. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  3410. }, function($ctx1) {$ctx1.fill(self,"setupHotkeys",{},$globals.Repl)});
  3411. //>>excludeEnd("ctx");
  3412. },
  3413. //>>excludeStart("ide", pragmas.excludeIdeData);
  3414. args: [],
  3415. source: "setupHotkeys\x0a\x09process stdin on: 'keypress' do: [:s :key | key ifNotNil: [self onKeyPress: key]].",
  3416. referencedClasses: [],
  3417. //>>excludeEnd("ide");
  3418. messageSends: ["on:do:", "stdin", "ifNotNil:", "onKeyPress:"]
  3419. }),
  3420. $globals.Repl);
  3421. $core.addMethod(
  3422. $core.method({
  3423. selector: "subclass:withVariable:",
  3424. protocol: 'private',
  3425. fn: function (aClass,varName){
  3426. var self=this;
  3427. function $ClassBuilder(){return $globals.ClassBuilder||(typeof ClassBuilder=="undefined"?nil:ClassBuilder)}
  3428. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  3429. return $core.withContext(function($ctx1) {
  3430. //>>excludeEnd("ctx");
  3431. var $1;
  3432. $1=$recv($recv($ClassBuilder())._new())._addSubclassOf_named_instanceVariableNames_package_(aClass,$recv(self._subclassNameFor_(aClass))._asSymbol(),[varName],"Compiler-Core");
  3433. return $1;
  3434. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  3435. }, function($ctx1) {$ctx1.fill(self,"subclass:withVariable:",{aClass:aClass,varName:varName},$globals.Repl)});
  3436. //>>excludeEnd("ctx");
  3437. },
  3438. //>>excludeStart("ide", pragmas.excludeIdeData);
  3439. args: ["aClass", "varName"],
  3440. source: "subclass: aClass withVariable: varName\x0a\x09\x22Create subclass with new variable.\x22\x0a\x09^ ClassBuilder new\x0a\x09\x09addSubclassOf: aClass\x0a\x09\x09named: (self subclassNameFor: aClass) asSymbol\x0a\x09\x09instanceVariableNames: {varName}\x0a\x09\x09package: 'Compiler-Core'",
  3441. referencedClasses: ["ClassBuilder"],
  3442. //>>excludeEnd("ide");
  3443. messageSends: ["addSubclassOf:named:instanceVariableNames:package:", "new", "asSymbol", "subclassNameFor:"]
  3444. }),
  3445. $globals.Repl);
  3446. $core.addMethod(
  3447. $core.method({
  3448. selector: "subclassNameFor:",
  3449. protocol: 'private',
  3450. fn: function (aClass){
  3451. var self=this;
  3452. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  3453. return $core.withContext(function($ctx1) {
  3454. //>>excludeEnd("ctx");
  3455. var $3,$2,$7,$6,$5,$4,$8,$1,$receiver;
  3456. $3=$recv(aClass)._name();
  3457. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  3458. $ctx1.sendIdx["name"]=1;
  3459. //>>excludeEnd("ctx");
  3460. $2=$recv($3)._matchesOf_("\x5cd+$");
  3461. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  3462. $ctx1.sendIdx["matchesOf:"]=1;
  3463. //>>excludeEnd("ctx");
  3464. if(($receiver = $2) == null || $receiver.isNil){
  3465. $1=$recv($recv(aClass)._name()).__comma("2");
  3466. } else {
  3467. var counter;
  3468. $7=$recv(aClass)._name();
  3469. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  3470. $ctx1.sendIdx["name"]=2;
  3471. //>>excludeEnd("ctx");
  3472. $6=$recv($7)._matchesOf_("\x5cd+$");
  3473. $5=$recv($6)._first();
  3474. $4=$recv($5)._asNumber();
  3475. counter=$recv($4).__plus((1));
  3476. counter;
  3477. $8=$recv(aClass)._name();
  3478. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  3479. $ctx1.sendIdx["name"]=3;
  3480. //>>excludeEnd("ctx");
  3481. $1=$recv($8)._replaceRegexp_with_("\x5cd+$"._asRegexp(),$recv(counter)._asString());
  3482. };
  3483. return $1;
  3484. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  3485. }, function($ctx1) {$ctx1.fill(self,"subclassNameFor:",{aClass:aClass},$globals.Repl)});
  3486. //>>excludeEnd("ctx");
  3487. },
  3488. //>>excludeStart("ide", pragmas.excludeIdeData);
  3489. args: ["aClass"],
  3490. source: "subclassNameFor: aClass\x0a\x09^ (aClass name matchesOf: '\x5cd+$')\x0a\x09\x09ifNotNil: [ | counter |\x0a\x09\x09\x09counter := (aClass name matchesOf: '\x5cd+$') first asNumber + 1.\x0a\x09\x09\x09aClass name replaceRegexp: '\x5cd+$' asRegexp with: counter asString]\x0a\x09\x09ifNil: [\x0a\x09\x09\x09aClass name, '2'].",
  3491. referencedClasses: [],
  3492. //>>excludeEnd("ide");
  3493. messageSends: ["ifNotNil:ifNil:", "matchesOf:", "name", "+", "asNumber", "first", "replaceRegexp:with:", "asRegexp", "asString", ","]
  3494. }),
  3495. $globals.Repl);
  3496. $core.addMethod(
  3497. $core.method({
  3498. selector: "main",
  3499. protocol: 'initialization',
  3500. fn: function (){
  3501. var self=this;
  3502. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  3503. return $core.withContext(function($ctx1) {
  3504. //>>excludeEnd("ctx");
  3505. $recv(self._new())._createInterface();
  3506. return self;
  3507. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  3508. }, function($ctx1) {$ctx1.fill(self,"main",{},$globals.Repl.klass)});
  3509. //>>excludeEnd("ctx");
  3510. },
  3511. //>>excludeStart("ide", pragmas.excludeIdeData);
  3512. args: [],
  3513. source: "main\x0a\x09self new createInterface",
  3514. referencedClasses: [],
  3515. //>>excludeEnd("ide");
  3516. messageSends: ["createInterface", "new"]
  3517. }),
  3518. $globals.Repl.klass);
  3519. });