AmberCli.js 162 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414
  1. define(["amber/boot", "require", "amber/core/Kernel-Objects"], function($boot,requirejs){"use strict";
  2. var $core=$boot.api,nil=$boot.nilAsValue,$nil=$boot.nilAsReceiver,$recv=$boot.asReceiver,$globals=$boot.globals;
  3. var $pkg = $core.addPackage("AmberCli");
  4. $pkg.innerEval = function (expr) { return eval(expr); };
  5. $pkg.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. //>>excludeStart("ide", pragmas.excludeIdeData);
  15. args: [],
  16. 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",
  17. referencedClasses: [],
  18. //>>excludeEnd("ide");
  19. pragmas: [],
  20. messageSends: ["collect:", "methodsInProtocol:", "class", "selector", "select:", "match:", "asLowercase", "replace:with:", "allButLast"]
  21. }, function ($methodClass){ return function (){
  22. var self=this,$self=this;
  23. var switches;
  24. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  25. return $core.withContext(function($ctx1) {
  26. //>>excludeEnd("ctx");
  27. switches=[$recv($recv($self._class())._methodsInProtocol_("commands"))._collect_((function(each){
  28. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  29. return $core.withContext(function($ctx2) {
  30. //>>excludeEnd("ctx");
  31. return $recv(each)._selector();
  32. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  33. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)});
  34. //>>excludeEnd("ctx");
  35. }))
  36. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  37. ,$ctx1.sendIdx["collect:"]=1
  38. //>>excludeEnd("ctx");
  39. ][0];
  40. switches=$recv(switches)._select_((function(each){
  41. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  42. return $core.withContext(function($ctx2) {
  43. //>>excludeEnd("ctx");
  44. return $recv(each)._match_("^[^:]*:$");
  45. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  46. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,2)});
  47. //>>excludeEnd("ctx");
  48. }));
  49. switches=$recv(switches)._collect_((function(each){
  50. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  51. return $core.withContext(function($ctx2) {
  52. //>>excludeEnd("ctx");
  53. return $recv($recv($recv(each)._allButLast())._replace_with_("([A-Z])","-$1"))._asLowercase();
  54. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  55. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,3)});
  56. //>>excludeEnd("ctx");
  57. }));
  58. return switches;
  59. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  60. }, function($ctx1) {$ctx1.fill(self,"commandLineSwitches",{switches:switches})});
  61. //>>excludeEnd("ctx");
  62. }; }),
  63. $globals.AmberCli.a$cls);
  64. $core.addMethod(
  65. $core.method({
  66. selector: "config:",
  67. protocol: "commands",
  68. //>>excludeStart("ide", pragmas.excludeIdeData);
  69. args: ["args"],
  70. source: "config: args\x0a\x09Configurator new start",
  71. referencedClasses: ["Configurator"],
  72. //>>excludeEnd("ide");
  73. pragmas: [],
  74. messageSends: ["start", "new"]
  75. }, function ($methodClass){ return function (args){
  76. var self=this,$self=this;
  77. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  78. return $core.withContext(function($ctx1) {
  79. //>>excludeEnd("ctx");
  80. $recv($recv($globals.Configurator)._new())._start();
  81. return self;
  82. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  83. }, function($ctx1) {$ctx1.fill(self,"config:",{args:args})});
  84. //>>excludeEnd("ctx");
  85. }; }),
  86. $globals.AmberCli.a$cls);
  87. $core.addMethod(
  88. $core.method({
  89. selector: "handleArguments:",
  90. protocol: "commandline",
  91. //>>excludeStart("ide", pragmas.excludeIdeData);
  92. args: ["args"],
  93. source: "handleArguments: args\x0a\x09| selector |\x0a\x0a\x09selector := self selectorForCommandLineSwitch: (args first).\x0a\x09args remove: args first.\x0a\x09self perform: selector withArguments: { args }",
  94. referencedClasses: [],
  95. //>>excludeEnd("ide");
  96. pragmas: [],
  97. messageSends: ["selectorForCommandLineSwitch:", "first", "remove:", "perform:withArguments:"]
  98. }, function ($methodClass){ return function (args){
  99. var self=this,$self=this;
  100. var selector;
  101. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  102. return $core.withContext(function($ctx1) {
  103. //>>excludeEnd("ctx");
  104. selector=$self._selectorForCommandLineSwitch_([$recv(args)._first()
  105. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  106. ,$ctx1.sendIdx["first"]=1
  107. //>>excludeEnd("ctx");
  108. ][0]);
  109. $recv(args)._remove_($recv(args)._first());
  110. $self._perform_withArguments_(selector,[args]);
  111. return self;
  112. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  113. }, function($ctx1) {$ctx1.fill(self,"handleArguments:",{args:args,selector:selector})});
  114. //>>excludeEnd("ctx");
  115. }; }),
  116. $globals.AmberCli.a$cls);
  117. $core.addMethod(
  118. $core.method({
  119. selector: "help:",
  120. protocol: "commands",
  121. //>>excludeStart("ide", pragmas.excludeIdeData);
  122. args: ["args"],
  123. source: "help: args\x0a\x09Transcript show: 'Available commands'.\x0a\x09self commandLineSwitches do: [ :each | console log: each ]",
  124. referencedClasses: ["Transcript"],
  125. //>>excludeEnd("ide");
  126. pragmas: [],
  127. messageSends: ["show:", "do:", "commandLineSwitches", "log:"]
  128. }, function ($methodClass){ return function (args){
  129. var self=this,$self=this;
  130. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  131. return $core.withContext(function($ctx1) {
  132. //>>excludeEnd("ctx");
  133. $recv($globals.Transcript)._show_("Available commands");
  134. $recv($self._commandLineSwitches())._do_((function(each){
  135. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  136. return $core.withContext(function($ctx2) {
  137. //>>excludeEnd("ctx");
  138. return $recv(console)._log_(each);
  139. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  140. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)});
  141. //>>excludeEnd("ctx");
  142. }));
  143. return self;
  144. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  145. }, function($ctx1) {$ctx1.fill(self,"help:",{args:args})});
  146. //>>excludeEnd("ctx");
  147. }; }),
  148. $globals.AmberCli.a$cls);
  149. $core.addMethod(
  150. $core.method({
  151. selector: "init:",
  152. protocol: "commands",
  153. //>>excludeStart("ide", pragmas.excludeIdeData);
  154. args: ["args"],
  155. source: "init: args\x0a\x09Initer new start",
  156. referencedClasses: ["Initer"],
  157. //>>excludeEnd("ide");
  158. pragmas: [],
  159. messageSends: ["start", "new"]
  160. }, function ($methodClass){ return function (args){
  161. var self=this,$self=this;
  162. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  163. return $core.withContext(function($ctx1) {
  164. //>>excludeEnd("ctx");
  165. $recv($recv($globals.Initer)._new())._start();
  166. return self;
  167. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  168. }, function($ctx1) {$ctx1.fill(self,"init:",{args:args})});
  169. //>>excludeEnd("ctx");
  170. }; }),
  171. $globals.AmberCli.a$cls);
  172. $core.addMethod(
  173. $core.method({
  174. selector: "main",
  175. protocol: "startup",
  176. //>>excludeStart("ide", pragmas.excludeIdeData);
  177. args: [],
  178. source: "main\x0a\x09\x22Main entry point for Amber applications.\x0a\x09Parses commandline arguments and starts the according subprogram.\x22\x0a\x09| args packageJSON |\x0a\x09\x0a\x09packageJSON := require value: '../package.json'.\x0a\x09Transcript show: 'Welcome to Amber CLI version ', packageJSON version, ' (Amber ', Smalltalk version, ', NodeJS ', process versions node, ').'.\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\x09args\x0a\x09\x09ifEmpty: [self help: nil]\x0a\x09\x09ifNotEmpty: [^self handleArguments: args]",
  179. referencedClasses: ["Transcript", "Smalltalk"],
  180. //>>excludeEnd("ide");
  181. pragmas: [],
  182. messageSends: ["value:", "show:", ",", "version", "node", "versions", "argv", "removeFrom:to:", "ifEmpty:ifNotEmpty:", "help:", "handleArguments:"]
  183. }, function ($methodClass){ return function (){
  184. var self=this,$self=this;
  185. var args,packageJSON;
  186. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  187. return $core.withContext(function($ctx1) {
  188. //>>excludeEnd("ctx");
  189. var $early={};
  190. try {
  191. packageJSON=$recv(require)._value_("../package.json");
  192. $recv($globals.Transcript)._show_([$recv([$recv([$recv([$recv([$recv("Welcome to Amber CLI version ".__comma([$recv(packageJSON)._version()
  193. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  194. ,$ctx1.sendIdx["version"]=1
  195. //>>excludeEnd("ctx");
  196. ][0])).__comma(" (Amber ")
  197. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  198. ,$ctx1.sendIdx[","]=5
  199. //>>excludeEnd("ctx");
  200. ][0]).__comma($recv($globals.Smalltalk)._version())
  201. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  202. ,$ctx1.sendIdx[","]=4
  203. //>>excludeEnd("ctx");
  204. ][0]).__comma(", NodeJS ")
  205. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  206. ,$ctx1.sendIdx[","]=3
  207. //>>excludeEnd("ctx");
  208. ][0]).__comma($recv($recv(process)._versions())._node())
  209. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  210. ,$ctx1.sendIdx[","]=2
  211. //>>excludeEnd("ctx");
  212. ][0]).__comma(").")
  213. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  214. ,$ctx1.sendIdx[","]=1
  215. //>>excludeEnd("ctx");
  216. ][0]);
  217. args=$recv(process)._argv();
  218. $recv(args)._removeFrom_to_((1),(2));
  219. $recv(args)._ifEmpty_ifNotEmpty_((function(){
  220. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  221. return $core.withContext(function($ctx2) {
  222. //>>excludeEnd("ctx");
  223. return $self._help_(nil);
  224. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  225. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)});
  226. //>>excludeEnd("ctx");
  227. }),(function(){
  228. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  229. return $core.withContext(function($ctx2) {
  230. //>>excludeEnd("ctx");
  231. throw $early=[$self._handleArguments_(args)];
  232. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  233. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,2)});
  234. //>>excludeEnd("ctx");
  235. }));
  236. return self;
  237. }
  238. catch(e) {if(e===$early)return e[0]; throw e}
  239. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  240. }, function($ctx1) {$ctx1.fill(self,"main",{args:args,packageJSON:packageJSON})});
  241. //>>excludeEnd("ctx");
  242. }; }),
  243. $globals.AmberCli.a$cls);
  244. $core.addMethod(
  245. $core.method({
  246. selector: "repl:",
  247. protocol: "commands",
  248. //>>excludeStart("ide", pragmas.excludeIdeData);
  249. args: ["args"],
  250. source: "repl: args\x0a\x09^ Repl new createInterface",
  251. referencedClasses: ["Repl"],
  252. //>>excludeEnd("ide");
  253. pragmas: [],
  254. messageSends: ["createInterface", "new"]
  255. }, function ($methodClass){ return function (args){
  256. var self=this,$self=this;
  257. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  258. return $core.withContext(function($ctx1) {
  259. //>>excludeEnd("ctx");
  260. return $recv($recv($globals.Repl)._new())._createInterface();
  261. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  262. }, function($ctx1) {$ctx1.fill(self,"repl:",{args:args})});
  263. //>>excludeEnd("ctx");
  264. }; }),
  265. $globals.AmberCli.a$cls);
  266. $core.addMethod(
  267. $core.method({
  268. selector: "selectorForCommandLineSwitch:",
  269. protocol: "commandline",
  270. //>>excludeStart("ide", pragmas.excludeIdeData);
  271. args: ["aSwitch"],
  272. 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",
  273. referencedClasses: [],
  274. //>>excludeEnd("ide");
  275. pragmas: [],
  276. messageSends: ["ifTrue:ifFalse:", "includes:", "commandLineSwitches", ",", "replace:with:", "asUppercase", "second"]
  277. }, function ($methodClass){ return function (aSwitch){
  278. var self=this,$self=this;
  279. var command,selector;
  280. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  281. return $core.withContext(function($ctx1) {
  282. //>>excludeEnd("ctx");
  283. if($core.assert($recv($self._commandLineSwitches())._includes_(aSwitch))){
  284. selector=$recv($recv(aSwitch)._replace_with_("-[a-z]",(function(each){
  285. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  286. return $core.withContext(function($ctx2) {
  287. //>>excludeEnd("ctx");
  288. return $recv($recv(each)._second())._asUppercase();
  289. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  290. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,2)});
  291. //>>excludeEnd("ctx");
  292. }))).__comma(":");
  293. selector;
  294. } else {
  295. selector="help:";
  296. selector;
  297. }
  298. return selector;
  299. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  300. }, function($ctx1) {$ctx1.fill(self,"selectorForCommandLineSwitch:",{aSwitch:aSwitch,command:command,selector:selector})});
  301. //>>excludeEnd("ctx");
  302. }; }),
  303. $globals.AmberCli.a$cls);
  304. $core.addMethod(
  305. $core.method({
  306. selector: "serve:",
  307. protocol: "commands",
  308. //>>excludeStart("ide", pragmas.excludeIdeData);
  309. args: ["args"],
  310. source: "serve: args\x0a\x09^ (FileServer createServerWithArguments: args) start",
  311. referencedClasses: ["FileServer"],
  312. //>>excludeEnd("ide");
  313. pragmas: [],
  314. messageSends: ["start", "createServerWithArguments:"]
  315. }, function ($methodClass){ return function (args){
  316. var self=this,$self=this;
  317. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  318. return $core.withContext(function($ctx1) {
  319. //>>excludeEnd("ctx");
  320. return $recv($recv($globals.FileServer)._createServerWithArguments_(args))._start();
  321. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  322. }, function($ctx1) {$ctx1.fill(self,"serve:",{args:args})});
  323. //>>excludeEnd("ctx");
  324. }; }),
  325. $globals.AmberCli.a$cls);
  326. $core.addMethod(
  327. $core.method({
  328. selector: "version:",
  329. protocol: "commands",
  330. //>>excludeStart("ide", pragmas.excludeIdeData);
  331. args: ["arguments"],
  332. source: "version: arguments",
  333. referencedClasses: [],
  334. //>>excludeEnd("ide");
  335. pragmas: [],
  336. messageSends: []
  337. }, function ($methodClass){ return function (arguments_){
  338. var self=this,$self=this;
  339. return self;
  340. }; }),
  341. $globals.AmberCli.a$cls);
  342. $core.addClass("BaseFileManipulator", $globals.Object, ["path", "fs"], "AmberCli");
  343. $core.addMethod(
  344. $core.method({
  345. selector: "dirname",
  346. protocol: "private",
  347. //>>excludeStart("ide", pragmas.excludeIdeData);
  348. args: [],
  349. source: "dirname\x0a\x09<inlineJS: 'return __dirname'>",
  350. referencedClasses: [],
  351. //>>excludeEnd("ide");
  352. pragmas: [["inlineJS:", ["return __dirname"]]],
  353. messageSends: []
  354. }, function ($methodClass){ return function (){
  355. var self=this,$self=this;
  356. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  357. return $core.withContext(function($ctx1) {
  358. //>>excludeEnd("ctx");
  359. return __dirname;
  360. return self;
  361. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  362. }, function($ctx1) {$ctx1.fill(self,"dirname",{})});
  363. //>>excludeEnd("ctx");
  364. }; }),
  365. $globals.BaseFileManipulator);
  366. $core.addMethod(
  367. $core.method({
  368. selector: "initialize",
  369. protocol: "initialization",
  370. //>>excludeStart("ide", pragmas.excludeIdeData);
  371. args: [],
  372. source: "initialize\x0a\x09super initialize.\x0a\x09path := require value: 'path'.\x0a\x09fs := require value: 'fs'",
  373. referencedClasses: [],
  374. //>>excludeEnd("ide");
  375. pragmas: [],
  376. messageSends: ["initialize", "value:"]
  377. }, function ($methodClass){ return function (){
  378. var self=this,$self=this;
  379. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  380. return $core.withContext(function($ctx1) {
  381. //>>excludeEnd("ctx");
  382. [(
  383. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  384. $ctx1.supercall = true,
  385. //>>excludeEnd("ctx");
  386. ($methodClass.superclass||$boot.nilAsClass).fn.prototype._initialize.call($self))
  387. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  388. ,$ctx1.supercall = false
  389. //>>excludeEnd("ctx");
  390. ][0];
  391. $self.path=[$recv(require)._value_("path")
  392. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  393. ,$ctx1.sendIdx["value:"]=1
  394. //>>excludeEnd("ctx");
  395. ][0];
  396. $self.fs=$recv(require)._value_("fs");
  397. return self;
  398. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  399. }, function($ctx1) {$ctx1.fill(self,"initialize",{})});
  400. //>>excludeEnd("ctx");
  401. }; }),
  402. $globals.BaseFileManipulator);
  403. $core.addMethod(
  404. $core.method({
  405. selector: "rootDirname",
  406. protocol: "private",
  407. //>>excludeStart("ide", pragmas.excludeIdeData);
  408. args: [],
  409. source: "rootDirname\x0a\x09^ path join: self dirname with: '..'",
  410. referencedClasses: [],
  411. //>>excludeEnd("ide");
  412. pragmas: [],
  413. messageSends: ["join:with:", "dirname"]
  414. }, function ($methodClass){ return function (){
  415. var self=this,$self=this;
  416. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  417. return $core.withContext(function($ctx1) {
  418. //>>excludeEnd("ctx");
  419. return $recv($self.path)._join_with_($self._dirname(),"..");
  420. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  421. }, function($ctx1) {$ctx1.fill(self,"rootDirname",{})});
  422. //>>excludeEnd("ctx");
  423. }; }),
  424. $globals.BaseFileManipulator);
  425. $core.addClass("Configurator", $globals.BaseFileManipulator, [], "AmberCli");
  426. $core.addMethod(
  427. $core.method({
  428. selector: "initialize",
  429. protocol: "initialization",
  430. //>>excludeStart("ide", pragmas.excludeIdeData);
  431. args: [],
  432. source: "initialize\x0a\x09super initialize",
  433. referencedClasses: [],
  434. //>>excludeEnd("ide");
  435. pragmas: [],
  436. messageSends: ["initialize"]
  437. }, function ($methodClass){ return function (){
  438. var self=this,$self=this;
  439. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  440. return $core.withContext(function($ctx1) {
  441. //>>excludeEnd("ctx");
  442. [(
  443. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  444. $ctx1.supercall = true,
  445. //>>excludeEnd("ctx");
  446. ($methodClass.superclass||$boot.nilAsClass).fn.prototype._initialize.call($self))
  447. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  448. ,$ctx1.supercall = false
  449. //>>excludeEnd("ctx");
  450. ][0];
  451. return self;
  452. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  453. }, function($ctx1) {$ctx1.fill(self,"initialize",{})});
  454. //>>excludeEnd("ctx");
  455. }; }),
  456. $globals.Configurator);
  457. $core.addMethod(
  458. $core.method({
  459. selector: "start",
  460. protocol: "action",
  461. //>>excludeStart("ide", pragmas.excludeIdeData);
  462. args: [],
  463. source: "start\x0a\x09self writeConfigThenDo: [ :err | err\x0a\x09\x09ifNotNil: [ process exit: 111 ]\x0a\x09\x09ifNil: [ process exit ]]",
  464. referencedClasses: [],
  465. //>>excludeEnd("ide");
  466. pragmas: [],
  467. messageSends: ["writeConfigThenDo:", "ifNotNil:ifNil:", "exit:", "exit"]
  468. }, function ($methodClass){ return function (){
  469. var self=this,$self=this;
  470. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  471. return $core.withContext(function($ctx1) {
  472. //>>excludeEnd("ctx");
  473. $self._writeConfigThenDo_((function(err){
  474. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  475. return $core.withContext(function($ctx2) {
  476. //>>excludeEnd("ctx");
  477. if(err == null || err.a$nil){
  478. return $recv(process)._exit();
  479. } else {
  480. return $recv(process)._exit_((111));
  481. }
  482. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  483. }, function($ctx2) {$ctx2.fillBlock({err:err},$ctx1,1)});
  484. //>>excludeEnd("ctx");
  485. }));
  486. return self;
  487. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  488. }, function($ctx1) {$ctx1.fill(self,"start",{})});
  489. //>>excludeEnd("ctx");
  490. }; }),
  491. $globals.Configurator);
  492. $core.addMethod(
  493. $core.method({
  494. selector: "writeConfigThenDo:",
  495. protocol: "action",
  496. //>>excludeStart("ide", pragmas.excludeIdeData);
  497. args: ["aBlock"],
  498. source: "writeConfigThenDo: aBlock\x0a\x09(require value: '@ambers/sdk') configBuilder\x0a\x09\x09writeConfig: process cwd\x0a\x09\x09toFile: 'config.js'\x0a\x09\x09thenDo: aBlock",
  499. referencedClasses: [],
  500. //>>excludeEnd("ide");
  501. pragmas: [],
  502. messageSends: ["writeConfig:toFile:thenDo:", "configBuilder", "value:", "cwd"]
  503. }, function ($methodClass){ return function (aBlock){
  504. var self=this,$self=this;
  505. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  506. return $core.withContext(function($ctx1) {
  507. //>>excludeEnd("ctx");
  508. $recv($recv($recv(require)._value_("@ambers/sdk"))._configBuilder())._writeConfig_toFile_thenDo_($recv(process)._cwd(),"config.js",aBlock);
  509. return self;
  510. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  511. }, function($ctx1) {$ctx1.fill(self,"writeConfigThenDo:",{aBlock:aBlock})});
  512. //>>excludeEnd("ctx");
  513. }; }),
  514. $globals.Configurator);
  515. $core.addClass("FileServer", $globals.BaseFileManipulator, ["http", "url", "host", "port", "basePath", "util", "username", "password", "fallbackPage"], "AmberCli");
  516. //>>excludeStart("ide", pragmas.excludeIdeData);
  517. $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.";
  518. //>>excludeEnd("ide");
  519. $core.addMethod(
  520. $core.method({
  521. selector: "base64Decode:",
  522. protocol: "private",
  523. //>>excludeStart("ide", pragmas.excludeIdeData);
  524. args: ["aString"],
  525. source: "base64Decode: aString\x0a\x09<inlineJS: 'return (new Buffer(aString, \x22base64\x22).toString())'>",
  526. referencedClasses: [],
  527. //>>excludeEnd("ide");
  528. pragmas: [["inlineJS:", ["return (new Buffer(aString, \x22base64\x22).toString())"]]],
  529. messageSends: []
  530. }, function ($methodClass){ return function (aString){
  531. var self=this,$self=this;
  532. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  533. return $core.withContext(function($ctx1) {
  534. //>>excludeEnd("ctx");
  535. return (new Buffer(aString, "base64").toString());
  536. return self;
  537. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  538. }, function($ctx1) {$ctx1.fill(self,"base64Decode:",{aString:aString})});
  539. //>>excludeEnd("ctx");
  540. }; }),
  541. $globals.FileServer);
  542. $core.addMethod(
  543. $core.method({
  544. selector: "basePath",
  545. protocol: "accessing",
  546. //>>excludeStart("ide", pragmas.excludeIdeData);
  547. args: [],
  548. source: "basePath\x0a\x09^ basePath ifNil: [self class defaultBasePath]",
  549. referencedClasses: [],
  550. //>>excludeEnd("ide");
  551. pragmas: [],
  552. messageSends: ["ifNil:", "defaultBasePath", "class"]
  553. }, function ($methodClass){ return function (){
  554. var self=this,$self=this;
  555. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  556. return $core.withContext(function($ctx1) {
  557. //>>excludeEnd("ctx");
  558. var $1;
  559. $1=$self.basePath;
  560. if($1 == null || $1.a$nil){
  561. return $recv($self._class())._defaultBasePath();
  562. } else {
  563. return $1;
  564. }
  565. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  566. }, function($ctx1) {$ctx1.fill(self,"basePath",{})});
  567. //>>excludeEnd("ctx");
  568. }; }),
  569. $globals.FileServer);
  570. $core.addMethod(
  571. $core.method({
  572. selector: "basePath:",
  573. protocol: "accessing",
  574. //>>excludeStart("ide", pragmas.excludeIdeData);
  575. args: ["aString"],
  576. source: "basePath: aString\x0a\x09basePath := aString.\x0a\x09self validateBasePath.",
  577. referencedClasses: [],
  578. //>>excludeEnd("ide");
  579. pragmas: [],
  580. messageSends: ["validateBasePath"]
  581. }, function ($methodClass){ return function (aString){
  582. var self=this,$self=this;
  583. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  584. return $core.withContext(function($ctx1) {
  585. //>>excludeEnd("ctx");
  586. $self.basePath=aString;
  587. $self._validateBasePath();
  588. return self;
  589. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  590. }, function($ctx1) {$ctx1.fill(self,"basePath:",{aString:aString})});
  591. //>>excludeEnd("ctx");
  592. }; }),
  593. $globals.FileServer);
  594. $core.addMethod(
  595. $core.method({
  596. selector: "checkDirectoryLayout",
  597. protocol: "initialization",
  598. //>>excludeStart("ide", pragmas.excludeIdeData);
  599. args: [],
  600. 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.'].",
  601. referencedClasses: [],
  602. //>>excludeEnd("ide");
  603. pragmas: [],
  604. messageSends: ["ifFalse:", "existsSync:", "withBasePath:", "warn:"]
  605. }, function ($methodClass){ return function (){
  606. var self=this,$self=this;
  607. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  608. return $core.withContext(function($ctx1) {
  609. //>>excludeEnd("ctx");
  610. if(!$core.assert($recv($self.fs)._existsSync_($self._withBasePath_("index.html")))){
  611. [$recv(console)._warn_("Warning: project directory does not contain index.html.")
  612. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  613. ,$ctx1.sendIdx["warn:"]=1
  614. //>>excludeEnd("ctx");
  615. ][0];
  616. [$recv(console)._warn_(" You can specify the directory containing index.html with --base-path.")
  617. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  618. ,$ctx1.sendIdx["warn:"]=2
  619. //>>excludeEnd("ctx");
  620. ][0];
  621. [$recv(console)._warn_(" You can also specify a page to be served by default,")
  622. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  623. ,$ctx1.sendIdx["warn:"]=3
  624. //>>excludeEnd("ctx");
  625. ][0];
  626. $recv(console)._warn_(" for all paths that do not map to a file, with --fallback-page.");
  627. }
  628. return self;
  629. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  630. }, function($ctx1) {$ctx1.fill(self,"checkDirectoryLayout",{})});
  631. //>>excludeEnd("ctx");
  632. }; }),
  633. $globals.FileServer);
  634. $core.addMethod(
  635. $core.method({
  636. selector: "fallbackPage",
  637. protocol: "accessing",
  638. //>>excludeStart("ide", pragmas.excludeIdeData);
  639. args: [],
  640. source: "fallbackPage\x0a\x09^ fallbackPage",
  641. referencedClasses: [],
  642. //>>excludeEnd("ide");
  643. pragmas: [],
  644. messageSends: []
  645. }, function ($methodClass){ return function (){
  646. var self=this,$self=this;
  647. return $self.fallbackPage;
  648. }; }),
  649. $globals.FileServer);
  650. $core.addMethod(
  651. $core.method({
  652. selector: "fallbackPage:",
  653. protocol: "accessing",
  654. //>>excludeStart("ide", pragmas.excludeIdeData);
  655. args: ["aString"],
  656. source: "fallbackPage: aString\x0a\x09fallbackPage := aString",
  657. referencedClasses: [],
  658. //>>excludeEnd("ide");
  659. pragmas: [],
  660. messageSends: []
  661. }, function ($methodClass){ return function (aString){
  662. var self=this,$self=this;
  663. $self.fallbackPage=aString;
  664. return self;
  665. }; }),
  666. $globals.FileServer);
  667. $core.addMethod(
  668. $core.method({
  669. selector: "handleGETRequest:respondTo:",
  670. protocol: "request handling",
  671. //>>excludeStart("ide", pragmas.excludeIdeData);
  672. args: ["aRequest", "aResponse"],
  673. 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]]]",
  674. referencedClasses: [],
  675. //>>excludeEnd("ide");
  676. pragmas: [],
  677. messageSends: ["parse:", "url", "join:with:", "basePath", "pathname", "exists:do:", "ifFalse:ifTrue:", "respondNotFoundTo:", "ifTrue:ifFalse:", "isDirectory", "statSync:", "respondDirectoryNamed:from:to:", "respondFileNamed:to:"]
  678. }, function ($methodClass){ return function (aRequest,aResponse){
  679. var self=this,$self=this;
  680. var uri,filename;
  681. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  682. return $core.withContext(function($ctx1) {
  683. //>>excludeEnd("ctx");
  684. uri=$recv($self.url)._parse_($recv(aRequest)._url());
  685. filename=$recv($self.path)._join_with_($self._basePath(),$recv(uri)._pathname());
  686. $recv($self.fs)._exists_do_(filename,(function(aBoolean){
  687. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  688. return $core.withContext(function($ctx2) {
  689. //>>excludeEnd("ctx");
  690. if($core.assert(aBoolean)){
  691. if($core.assert($recv($recv($self.fs)._statSync_(filename))._isDirectory())){
  692. return $self._respondDirectoryNamed_from_to_(filename,uri,aResponse);
  693. } else {
  694. return $self._respondFileNamed_to_(filename,aResponse);
  695. }
  696. } else {
  697. return $self._respondNotFoundTo_(aResponse);
  698. }
  699. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  700. }, function($ctx2) {$ctx2.fillBlock({aBoolean:aBoolean},$ctx1,1)});
  701. //>>excludeEnd("ctx");
  702. }));
  703. return self;
  704. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  705. }, function($ctx1) {$ctx1.fill(self,"handleGETRequest:respondTo:",{aRequest:aRequest,aResponse:aResponse,uri:uri,filename:filename})});
  706. //>>excludeEnd("ctx");
  707. }; }),
  708. $globals.FileServer);
  709. $core.addMethod(
  710. $core.method({
  711. selector: "handleOPTIONSRequest:respondTo:",
  712. protocol: "request handling",
  713. //>>excludeStart("ide", pragmas.excludeIdeData);
  714. args: ["aRequest", "aResponse"],
  715. 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",
  716. referencedClasses: [],
  717. //>>excludeEnd("ide");
  718. pragmas: [],
  719. messageSends: ["writeHead:options:", "end"]
  720. }, function ($methodClass){ return function (aRequest,aResponse){
  721. var self=this,$self=this;
  722. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  723. return $core.withContext(function($ctx1) {
  724. //>>excludeEnd("ctx");
  725. $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)]));
  726. $recv(aResponse)._end();
  727. return self;
  728. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  729. }, function($ctx1) {$ctx1.fill(self,"handleOPTIONSRequest:respondTo:",{aRequest:aRequest,aResponse:aResponse})});
  730. //>>excludeEnd("ctx");
  731. }; }),
  732. $globals.FileServer);
  733. $core.addMethod(
  734. $core.method({
  735. selector: "handlePUTRequest:respondTo:",
  736. protocol: "request handling",
  737. //>>excludeStart("ide", pragmas.excludeIdeData);
  738. args: ["aRequest", "aResponse"],
  739. 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]]",
  740. referencedClasses: [],
  741. //>>excludeEnd("ide");
  742. pragmas: [],
  743. messageSends: ["ifFalse:", "isAuthenticated:", "respondAuthenticationRequiredTo:", ",", "url", "createWriteStream:", "on:do:", "warn:", "respondNotCreatedTo:", "respondCreatedTo:", "setEncoding:", "write:", "ifTrue:", "writable", "end"]
  744. }, function ($methodClass){ return function (aRequest,aResponse){
  745. var self=this,$self=this;
  746. var file,stream;
  747. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  748. return $core.withContext(function($ctx1) {
  749. //>>excludeEnd("ctx");
  750. if(!$core.assert($self._isAuthenticated_(aRequest))){
  751. $self._respondAuthenticationRequiredTo_(aResponse);
  752. return nil;
  753. }
  754. file=[".".__comma($recv(aRequest)._url())
  755. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  756. ,$ctx1.sendIdx[","]=1
  757. //>>excludeEnd("ctx");
  758. ][0];
  759. stream=$recv($self.fs)._createWriteStream_(file);
  760. [$recv(stream)._on_do_("error",(function(error){
  761. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  762. return $core.withContext(function($ctx2) {
  763. //>>excludeEnd("ctx");
  764. [$recv(console)._warn_(["Error creating WriteStream for file ".__comma(file)
  765. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  766. ,$ctx2.sendIdx[","]=2
  767. //>>excludeEnd("ctx");
  768. ][0])
  769. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  770. ,$ctx2.sendIdx["warn:"]=1
  771. //>>excludeEnd("ctx");
  772. ][0];
  773. [$recv(console)._warn_(" Did you forget to create the necessary directory in your project (often /src)?")
  774. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  775. ,$ctx2.sendIdx["warn:"]=2
  776. //>>excludeEnd("ctx");
  777. ][0];
  778. $recv(console)._warn_(" The exact error is: ".__comma(error));
  779. return $self._respondNotCreatedTo_(aResponse);
  780. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  781. }, function($ctx2) {$ctx2.fillBlock({error:error},$ctx1,2)});
  782. //>>excludeEnd("ctx");
  783. }))
  784. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  785. ,$ctx1.sendIdx["on:do:"]=1
  786. //>>excludeEnd("ctx");
  787. ][0];
  788. [$recv(stream)._on_do_("close",(function(){
  789. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  790. return $core.withContext(function($ctx2) {
  791. //>>excludeEnd("ctx");
  792. return $self._respondCreatedTo_(aResponse);
  793. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  794. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,3)});
  795. //>>excludeEnd("ctx");
  796. }))
  797. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  798. ,$ctx1.sendIdx["on:do:"]=2
  799. //>>excludeEnd("ctx");
  800. ][0];
  801. $recv(aRequest)._setEncoding_("utf8");
  802. [$recv(aRequest)._on_do_("data",(function(data){
  803. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  804. return $core.withContext(function($ctx2) {
  805. //>>excludeEnd("ctx");
  806. return $recv(stream)._write_(data);
  807. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  808. }, function($ctx2) {$ctx2.fillBlock({data:data},$ctx1,4)});
  809. //>>excludeEnd("ctx");
  810. }))
  811. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  812. ,$ctx1.sendIdx["on:do:"]=3
  813. //>>excludeEnd("ctx");
  814. ][0];
  815. $recv(aRequest)._on_do_("end",(function(){
  816. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  817. return $core.withContext(function($ctx2) {
  818. //>>excludeEnd("ctx");
  819. if($core.assert($recv(stream)._writable())){
  820. return $recv(stream)._end();
  821. }
  822. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  823. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,5)});
  824. //>>excludeEnd("ctx");
  825. }));
  826. return self;
  827. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  828. }, function($ctx1) {$ctx1.fill(self,"handlePUTRequest:respondTo:",{aRequest:aRequest,aResponse:aResponse,file:file,stream:stream})});
  829. //>>excludeEnd("ctx");
  830. }; }),
  831. $globals.FileServer);
  832. $core.addMethod(
  833. $core.method({
  834. selector: "handleRequest:respondTo:",
  835. protocol: "request handling",
  836. //>>excludeStart("ide", pragmas.excludeIdeData);
  837. args: ["aRequest", "aResponse"],
  838. 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]",
  839. referencedClasses: [],
  840. //>>excludeEnd("ide");
  841. pragmas: [],
  842. messageSends: ["ifTrue:", "=", "method", "handlePUTRequest:respondTo:", "handleGETRequest:respondTo:", "handleOPTIONSRequest:respondTo:"]
  843. }, function ($methodClass){ return function (aRequest,aResponse){
  844. var self=this,$self=this;
  845. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  846. return $core.withContext(function($ctx1) {
  847. //>>excludeEnd("ctx");
  848. if($core.assert([$recv([$recv(aRequest)._method()
  849. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  850. ,$ctx1.sendIdx["method"]=1
  851. //>>excludeEnd("ctx");
  852. ][0]).__eq("PUT")
  853. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  854. ,$ctx1.sendIdx["="]=1
  855. //>>excludeEnd("ctx");
  856. ][0])){
  857. $self._handlePUTRequest_respondTo_(aRequest,aResponse);
  858. }
  859. if($core.assert([$recv([$recv(aRequest)._method()
  860. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  861. ,$ctx1.sendIdx["method"]=2
  862. //>>excludeEnd("ctx");
  863. ][0]).__eq("GET")
  864. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  865. ,$ctx1.sendIdx["="]=2
  866. //>>excludeEnd("ctx");
  867. ][0])){
  868. $self._handleGETRequest_respondTo_(aRequest,aResponse);
  869. }
  870. if($core.assert($recv($recv(aRequest)._method()).__eq("OPTIONS"))){
  871. $self._handleOPTIONSRequest_respondTo_(aRequest,aResponse);
  872. }
  873. return self;
  874. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  875. }, function($ctx1) {$ctx1.fill(self,"handleRequest:respondTo:",{aRequest:aRequest,aResponse:aResponse})});
  876. //>>excludeEnd("ctx");
  877. }; }),
  878. $globals.FileServer);
  879. $core.addMethod(
  880. $core.method({
  881. selector: "host",
  882. protocol: "accessing",
  883. //>>excludeStart("ide", pragmas.excludeIdeData);
  884. args: [],
  885. source: "host\x0a\x09^ host",
  886. referencedClasses: [],
  887. //>>excludeEnd("ide");
  888. pragmas: [],
  889. messageSends: []
  890. }, function ($methodClass){ return function (){
  891. var self=this,$self=this;
  892. return $self.host;
  893. }; }),
  894. $globals.FileServer);
  895. $core.addMethod(
  896. $core.method({
  897. selector: "host:",
  898. protocol: "accessing",
  899. //>>excludeStart("ide", pragmas.excludeIdeData);
  900. args: ["hostname"],
  901. source: "host: hostname\x0a\x09host := hostname",
  902. referencedClasses: [],
  903. //>>excludeEnd("ide");
  904. pragmas: [],
  905. messageSends: []
  906. }, function ($methodClass){ return function (hostname){
  907. var self=this,$self=this;
  908. $self.host=hostname;
  909. return self;
  910. }; }),
  911. $globals.FileServer);
  912. $core.addMethod(
  913. $core.method({
  914. selector: "initialize",
  915. protocol: "initialization",
  916. //>>excludeStart("ide", pragmas.excludeIdeData);
  917. args: [],
  918. 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.",
  919. referencedClasses: [],
  920. //>>excludeEnd("ide");
  921. pragmas: [],
  922. messageSends: ["initialize", "require:", "defaultHost", "class", "defaultPort"]
  923. }, function ($methodClass){ return function (){
  924. var self=this,$self=this;
  925. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  926. return $core.withContext(function($ctx1) {
  927. //>>excludeEnd("ctx");
  928. [(
  929. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  930. $ctx1.supercall = true,
  931. //>>excludeEnd("ctx");
  932. ($methodClass.superclass||$boot.nilAsClass).fn.prototype._initialize.call($self))
  933. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  934. ,$ctx1.supercall = false
  935. //>>excludeEnd("ctx");
  936. ][0];
  937. $self.http=[$self._require_("http")
  938. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  939. ,$ctx1.sendIdx["require:"]=1
  940. //>>excludeEnd("ctx");
  941. ][0];
  942. $self.util=[$self._require_("util")
  943. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  944. ,$ctx1.sendIdx["require:"]=2
  945. //>>excludeEnd("ctx");
  946. ][0];
  947. $self.url=$self._require_("url");
  948. $self.host=$recv([$self._class()
  949. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  950. ,$ctx1.sendIdx["class"]=1
  951. //>>excludeEnd("ctx");
  952. ][0])._defaultHost();
  953. $self.port=$recv($self._class())._defaultPort();
  954. $self.username=nil;
  955. $self.password=nil;
  956. $self.fallbackPage=nil;
  957. return self;
  958. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  959. }, function($ctx1) {$ctx1.fill(self,"initialize",{})});
  960. //>>excludeEnd("ctx");
  961. }; }),
  962. $globals.FileServer);
  963. $core.addMethod(
  964. $core.method({
  965. selector: "isAuthenticated:",
  966. protocol: "private",
  967. //>>excludeStart("ide", pragmas.excludeIdeData);
  968. args: ["aRequest"],
  969. 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\x09header\x0a\x09ifEmpty: [^ false]\x0a\x09ifNotEmpty: [\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].",
  970. referencedClasses: [],
  971. //>>excludeEnd("ide");
  972. pragmas: [],
  973. messageSends: ["ifTrue:", "and:", "isNil", "ifNil:", "at:", "headers", "ifEmpty:ifNotEmpty:", "tokenize:", "base64Decode:", "ifTrue:ifFalse:", "="]
  974. }, function ($methodClass){ return function (aRequest){
  975. var self=this,$self=this;
  976. var header,token,auth,parts;
  977. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  978. return $core.withContext(function($ctx1) {
  979. //>>excludeEnd("ctx");
  980. var $1,$2;
  981. var $early={};
  982. try {
  983. if($core.assert([$recv([$recv($self.username)._isNil()
  984. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  985. ,$ctx1.sendIdx["isNil"]=1
  986. //>>excludeEnd("ctx");
  987. ][0])._and_((function(){
  988. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  989. return $core.withContext(function($ctx2) {
  990. //>>excludeEnd("ctx");
  991. return $recv($self.password)._isNil();
  992. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  993. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)});
  994. //>>excludeEnd("ctx");
  995. }))
  996. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  997. ,$ctx1.sendIdx["and:"]=1
  998. //>>excludeEnd("ctx");
  999. ][0])){
  1000. return true;
  1001. }
  1002. $1=[$recv($recv(aRequest)._headers())._at_("authorization")
  1003. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1004. ,$ctx1.sendIdx["at:"]=1
  1005. //>>excludeEnd("ctx");
  1006. ][0];
  1007. if($1 == null || $1.a$nil){
  1008. header="";
  1009. } else {
  1010. header=$1;
  1011. }
  1012. $recv(header)._ifEmpty_ifNotEmpty_((function(){
  1013. throw $early=[false];
  1014. }),(function(){
  1015. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1016. return $core.withContext(function($ctx2) {
  1017. //>>excludeEnd("ctx");
  1018. $2=[$recv(header)._tokenize_(" ")
  1019. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1020. ,$ctx2.sendIdx["tokenize:"]=1
  1021. //>>excludeEnd("ctx");
  1022. ][0];
  1023. if($2 == null || $2.a$nil){
  1024. token="";
  1025. } else {
  1026. token=$2;
  1027. }
  1028. auth=$self._base64Decode_([$recv(token)._at_((2))
  1029. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1030. ,$ctx2.sendIdx["at:"]=2
  1031. //>>excludeEnd("ctx");
  1032. ][0]);
  1033. parts=$recv(auth)._tokenize_(":");
  1034. if($core.assert($recv([$recv($self.username).__eq([$recv(parts)._at_((1))
  1035. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1036. ,$ctx2.sendIdx["at:"]=3
  1037. //>>excludeEnd("ctx");
  1038. ][0])
  1039. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1040. ,$ctx2.sendIdx["="]=1
  1041. //>>excludeEnd("ctx");
  1042. ][0])._and_((function(){
  1043. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1044. return $core.withContext(function($ctx3) {
  1045. //>>excludeEnd("ctx");
  1046. return $recv($self.password).__eq($recv(parts)._at_((2)));
  1047. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1048. }, function($ctx3) {$ctx3.fillBlock({},$ctx2,7)});
  1049. //>>excludeEnd("ctx");
  1050. })))){
  1051. throw $early=[true];
  1052. } else {
  1053. throw $early=[false];
  1054. }
  1055. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1056. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,5)});
  1057. //>>excludeEnd("ctx");
  1058. }));
  1059. return self;
  1060. }
  1061. catch(e) {if(e===$early)return e[0]; throw e}
  1062. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1063. }, function($ctx1) {$ctx1.fill(self,"isAuthenticated:",{aRequest:aRequest,header:header,token:token,auth:auth,parts:parts})});
  1064. //>>excludeEnd("ctx");
  1065. }; }),
  1066. $globals.FileServer);
  1067. $core.addMethod(
  1068. $core.method({
  1069. selector: "password:",
  1070. protocol: "accessing",
  1071. //>>excludeStart("ide", pragmas.excludeIdeData);
  1072. args: ["aPassword"],
  1073. source: "password: aPassword\x0a\x09password := aPassword.",
  1074. referencedClasses: [],
  1075. //>>excludeEnd("ide");
  1076. pragmas: [],
  1077. messageSends: []
  1078. }, function ($methodClass){ return function (aPassword){
  1079. var self=this,$self=this;
  1080. $self.password=aPassword;
  1081. return self;
  1082. }; }),
  1083. $globals.FileServer);
  1084. $core.addMethod(
  1085. $core.method({
  1086. selector: "port",
  1087. protocol: "accessing",
  1088. //>>excludeStart("ide", pragmas.excludeIdeData);
  1089. args: [],
  1090. source: "port\x0a\x09^ port",
  1091. referencedClasses: [],
  1092. //>>excludeEnd("ide");
  1093. pragmas: [],
  1094. messageSends: []
  1095. }, function ($methodClass){ return function (){
  1096. var self=this,$self=this;
  1097. return $self.port;
  1098. }; }),
  1099. $globals.FileServer);
  1100. $core.addMethod(
  1101. $core.method({
  1102. selector: "port:",
  1103. protocol: "accessing",
  1104. //>>excludeStart("ide", pragmas.excludeIdeData);
  1105. args: ["aNumber"],
  1106. source: "port: aNumber\x0a\x09port := aNumber",
  1107. referencedClasses: [],
  1108. //>>excludeEnd("ide");
  1109. pragmas: [],
  1110. messageSends: []
  1111. }, function ($methodClass){ return function (aNumber){
  1112. var self=this,$self=this;
  1113. $self.port=aNumber;
  1114. return self;
  1115. }; }),
  1116. $globals.FileServer);
  1117. $core.addMethod(
  1118. $core.method({
  1119. selector: "require:",
  1120. protocol: "private",
  1121. //>>excludeStart("ide", pragmas.excludeIdeData);
  1122. args: ["aModuleString"],
  1123. source: "require: aModuleString\x0a\x09\x22call to the require function\x22\x0a\x09^require value: aModuleString",
  1124. referencedClasses: [],
  1125. //>>excludeEnd("ide");
  1126. pragmas: [],
  1127. messageSends: ["value:"]
  1128. }, function ($methodClass){ return function (aModuleString){
  1129. var self=this,$self=this;
  1130. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1131. return $core.withContext(function($ctx1) {
  1132. //>>excludeEnd("ctx");
  1133. return $recv(require)._value_(aModuleString);
  1134. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1135. }, function($ctx1) {$ctx1.fill(self,"require:",{aModuleString:aModuleString})});
  1136. //>>excludeEnd("ctx");
  1137. }; }),
  1138. $globals.FileServer);
  1139. $core.addMethod(
  1140. $core.method({
  1141. selector: "respondAuthenticationRequiredTo:",
  1142. protocol: "request handling",
  1143. //>>excludeStart("ide", pragmas.excludeIdeData);
  1144. args: ["aResponse"],
  1145. 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.",
  1146. referencedClasses: [],
  1147. //>>excludeEnd("ide");
  1148. pragmas: [],
  1149. messageSends: ["writeHead:options:", "write:", "end"]
  1150. }, function ($methodClass){ return function (aResponse){
  1151. var self=this,$self=this;
  1152. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1153. return $core.withContext(function($ctx1) {
  1154. //>>excludeEnd("ctx");
  1155. $recv(aResponse)._writeHead_options_((401),$globals.HashedCollection._newFromPairs_(["WWW-Authenticate","Basic realm=\x22Secured Developer Area\x22"]));
  1156. $recv(aResponse)._write_("<html><body>Authentication needed</body></html>");
  1157. $recv(aResponse)._end();
  1158. return self;
  1159. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1160. }, function($ctx1) {$ctx1.fill(self,"respondAuthenticationRequiredTo:",{aResponse:aResponse})});
  1161. //>>excludeEnd("ctx");
  1162. }; }),
  1163. $globals.FileServer);
  1164. $core.addMethod(
  1165. $core.method({
  1166. selector: "respondCreatedTo:",
  1167. protocol: "request handling",
  1168. //>>excludeStart("ide", pragmas.excludeIdeData);
  1169. args: ["aResponse"],
  1170. source: "respondCreatedTo: aResponse\x0a\x09aResponse\x0a\x09\x09writeHead: 201 options: #{'Content-Type' -> 'text/plain'. 'Access-Control-Allow-Origin' -> '*'};\x0a\x09\x09end.",
  1171. referencedClasses: [],
  1172. //>>excludeEnd("ide");
  1173. pragmas: [],
  1174. messageSends: ["writeHead:options:", "end"]
  1175. }, function ($methodClass){ return function (aResponse){
  1176. var self=this,$self=this;
  1177. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1178. return $core.withContext(function($ctx1) {
  1179. //>>excludeEnd("ctx");
  1180. $recv(aResponse)._writeHead_options_((201),$globals.HashedCollection._newFromPairs_(["Content-Type","text/plain","Access-Control-Allow-Origin","*"]));
  1181. $recv(aResponse)._end();
  1182. return self;
  1183. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1184. }, function($ctx1) {$ctx1.fill(self,"respondCreatedTo:",{aResponse:aResponse})});
  1185. //>>excludeEnd("ctx");
  1186. }; }),
  1187. $globals.FileServer);
  1188. $core.addMethod(
  1189. $core.method({
  1190. selector: "respondDirectoryNamed:from:to:",
  1191. protocol: "request handling",
  1192. //>>excludeStart("ide", pragmas.excludeIdeData);
  1193. args: ["aDirname", "aUrl", "aResponse"],
  1194. 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]",
  1195. referencedClasses: [],
  1196. //>>excludeEnd("ide");
  1197. pragmas: [],
  1198. messageSends: ["ifTrue:ifFalse:", "endsWith:", "pathname", "respondFileNamed:to:", ",", "respondRedirect:to:", "ifNil:", "search"]
  1199. }, function ($methodClass){ return function (aDirname,aUrl,aResponse){
  1200. var self=this,$self=this;
  1201. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1202. return $core.withContext(function($ctx1) {
  1203. //>>excludeEnd("ctx");
  1204. var $1,$2,$3;
  1205. if($core.assert($recv([$recv(aUrl)._pathname()
  1206. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1207. ,$ctx1.sendIdx["pathname"]=1
  1208. //>>excludeEnd("ctx");
  1209. ][0])._endsWith_("/"))){
  1210. $self._respondFileNamed_to_([$recv(aDirname).__comma("index.html")
  1211. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1212. ,$ctx1.sendIdx[","]=1
  1213. //>>excludeEnd("ctx");
  1214. ][0],aResponse);
  1215. } else {
  1216. $1=$recv($recv(aUrl)._pathname()).__comma("/");
  1217. $2=$recv(aUrl)._search();
  1218. if($2 == null || $2.a$nil){
  1219. $3="";
  1220. } else {
  1221. $3=$2;
  1222. }
  1223. $self._respondRedirect_to_([$recv($1).__comma($3)
  1224. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1225. ,$ctx1.sendIdx[","]=2
  1226. //>>excludeEnd("ctx");
  1227. ][0],aResponse);
  1228. }
  1229. return self;
  1230. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1231. }, function($ctx1) {$ctx1.fill(self,"respondDirectoryNamed:from:to:",{aDirname:aDirname,aUrl:aUrl,aResponse:aResponse})});
  1232. //>>excludeEnd("ctx");
  1233. }; }),
  1234. $globals.FileServer);
  1235. $core.addMethod(
  1236. $core.method({
  1237. selector: "respondFileNamed:to:",
  1238. protocol: "request handling",
  1239. //>>excludeStart("ide", pragmas.excludeIdeData);
  1240. args: ["aFilename", "aResponse"],
  1241. 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]]",
  1242. referencedClasses: [],
  1243. //>>excludeEnd("ide");
  1244. pragmas: [],
  1245. messageSends: ["readFile:do:", "ifTrue:ifFalse:", "notNil", "log:", ",", "respondNotFoundTo:", "mimeTypeFor:", "class", "ifTrue:", "=", "writeHead:options:", "write:encoding:", "end"]
  1246. }, function ($methodClass){ return function (aFilename,aResponse){
  1247. var self=this,$self=this;
  1248. var type,filename;
  1249. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1250. return $core.withContext(function($ctx1) {
  1251. //>>excludeEnd("ctx");
  1252. filename=aFilename;
  1253. $recv($self.fs)._readFile_do_(filename,(function(ex,file){
  1254. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1255. return $core.withContext(function($ctx2) {
  1256. //>>excludeEnd("ctx");
  1257. if($core.assert($recv(ex)._notNil())){
  1258. $recv(console)._log_([$recv(filename).__comma(" does not exist")
  1259. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1260. ,$ctx2.sendIdx[","]=1
  1261. //>>excludeEnd("ctx");
  1262. ][0]);
  1263. return $self._respondNotFoundTo_(aResponse);
  1264. } else {
  1265. type=$recv($self._class())._mimeTypeFor_(filename);
  1266. if($core.assert($recv(type).__eq("application/javascript"))){
  1267. type=$recv(type).__comma(";charset=utf-8");
  1268. type;
  1269. }
  1270. $recv(aResponse)._writeHead_options_((200),$globals.HashedCollection._newFromPairs_(["Content-Type",type]));
  1271. $recv(aResponse)._write_encoding_(file,"binary");
  1272. return $recv(aResponse)._end();
  1273. }
  1274. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1275. }, function($ctx2) {$ctx2.fillBlock({ex:ex,file:file},$ctx1,1)});
  1276. //>>excludeEnd("ctx");
  1277. }));
  1278. return self;
  1279. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1280. }, function($ctx1) {$ctx1.fill(self,"respondFileNamed:to:",{aFilename:aFilename,aResponse:aResponse,type:type,filename:filename})});
  1281. //>>excludeEnd("ctx");
  1282. }; }),
  1283. $globals.FileServer);
  1284. $core.addMethod(
  1285. $core.method({
  1286. selector: "respondInternalErrorTo:",
  1287. protocol: "request handling",
  1288. //>>excludeStart("ide", pragmas.excludeIdeData);
  1289. args: ["aResponse"],
  1290. source: "respondInternalErrorTo: aResponse\x0a\x09aResponse \x0a\x09\x09writeHead: 500 options: #{'Content-Type' -> 'text/plain'};\x0a\x09\x09write: '500 Internal server error';\x0a\x09\x09end",
  1291. referencedClasses: [],
  1292. //>>excludeEnd("ide");
  1293. pragmas: [],
  1294. messageSends: ["writeHead:options:", "write:", "end"]
  1295. }, function ($methodClass){ return function (aResponse){
  1296. var self=this,$self=this;
  1297. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1298. return $core.withContext(function($ctx1) {
  1299. //>>excludeEnd("ctx");
  1300. $recv(aResponse)._writeHead_options_((500),$globals.HashedCollection._newFromPairs_(["Content-Type","text/plain"]));
  1301. $recv(aResponse)._write_("500 Internal server error");
  1302. $recv(aResponse)._end();
  1303. return self;
  1304. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1305. }, function($ctx1) {$ctx1.fill(self,"respondInternalErrorTo:",{aResponse:aResponse})});
  1306. //>>excludeEnd("ctx");
  1307. }; }),
  1308. $globals.FileServer);
  1309. $core.addMethod(
  1310. $core.method({
  1311. selector: "respondNotCreatedTo:",
  1312. protocol: "request handling",
  1313. //>>excludeStart("ide", pragmas.excludeIdeData);
  1314. args: ["aResponse"],
  1315. 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.",
  1316. referencedClasses: [],
  1317. //>>excludeEnd("ide");
  1318. pragmas: [],
  1319. messageSends: ["writeHead:options:", "write:", "end"]
  1320. }, function ($methodClass){ return function (aResponse){
  1321. var self=this,$self=this;
  1322. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1323. return $core.withContext(function($ctx1) {
  1324. //>>excludeEnd("ctx");
  1325. $recv(aResponse)._writeHead_options_((400),$globals.HashedCollection._newFromPairs_(["Content-Type","text/plain"]));
  1326. $recv(aResponse)._write_("File could not be created. Did you forget to create the src directory on the server?");
  1327. $recv(aResponse)._end();
  1328. return self;
  1329. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1330. }, function($ctx1) {$ctx1.fill(self,"respondNotCreatedTo:",{aResponse:aResponse})});
  1331. //>>excludeEnd("ctx");
  1332. }; }),
  1333. $globals.FileServer);
  1334. $core.addMethod(
  1335. $core.method({
  1336. selector: "respondNotFoundTo:",
  1337. protocol: "request handling",
  1338. //>>excludeStart("ide", pragmas.excludeIdeData);
  1339. args: ["aResponse"],
  1340. 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",
  1341. referencedClasses: [],
  1342. //>>excludeEnd("ide");
  1343. pragmas: [],
  1344. messageSends: ["ifFalse:", "isNil", "fallbackPage", "respondFileNamed:to:", "writeHead:options:", "write:", "end"]
  1345. }, function ($methodClass){ return function (aResponse){
  1346. var self=this,$self=this;
  1347. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1348. return $core.withContext(function($ctx1) {
  1349. //>>excludeEnd("ctx");
  1350. if(!$core.assert($recv([$self._fallbackPage()
  1351. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1352. ,$ctx1.sendIdx["fallbackPage"]=1
  1353. //>>excludeEnd("ctx");
  1354. ][0])._isNil())){
  1355. return $self._respondFileNamed_to_($self._fallbackPage(),aResponse);
  1356. }
  1357. $recv(aResponse)._writeHead_options_((404),$globals.HashedCollection._newFromPairs_(["Content-Type","text/html"]));
  1358. [$recv(aResponse)._write_("<html><body><p>404 Not found</p>")
  1359. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1360. ,$ctx1.sendIdx["write:"]=1
  1361. //>>excludeEnd("ctx");
  1362. ][0];
  1363. [$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>")
  1364. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1365. ,$ctx1.sendIdx["write:"]=2
  1366. //>>excludeEnd("ctx");
  1367. ][0];
  1368. [$recv(aResponse)._write_("<li>create an index.html in the served directory.</li>")
  1369. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1370. ,$ctx1.sendIdx["write:"]=3
  1371. //>>excludeEnd("ctx");
  1372. ][0];
  1373. [$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>")
  1374. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1375. ,$ctx1.sendIdx["write:"]=4
  1376. //>>excludeEnd("ctx");
  1377. ][0];
  1378. [$recv(aResponse)._write_("<li>change the directory to be served with the \x22--base-path\x22 option.</li>")
  1379. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1380. ,$ctx1.sendIdx["write:"]=5
  1381. //>>excludeEnd("ctx");
  1382. ][0];
  1383. $recv(aResponse)._write_("</ul></p></body></html>");
  1384. $recv(aResponse)._end();
  1385. return self;
  1386. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1387. }, function($ctx1) {$ctx1.fill(self,"respondNotFoundTo:",{aResponse:aResponse})});
  1388. //>>excludeEnd("ctx");
  1389. }; }),
  1390. $globals.FileServer);
  1391. $core.addMethod(
  1392. $core.method({
  1393. selector: "respondOKTo:",
  1394. protocol: "request handling",
  1395. //>>excludeStart("ide", pragmas.excludeIdeData);
  1396. args: ["aResponse"],
  1397. source: "respondOKTo: aResponse\x0a\x09aResponse\x0a\x09\x09writeHead: 200 options: #{'Content-Type' -> 'text/plain'. 'Access-Control-Allow-Origin' -> '*'};\x0a\x09\x09end.",
  1398. referencedClasses: [],
  1399. //>>excludeEnd("ide");
  1400. pragmas: [],
  1401. messageSends: ["writeHead:options:", "end"]
  1402. }, function ($methodClass){ return function (aResponse){
  1403. var self=this,$self=this;
  1404. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1405. return $core.withContext(function($ctx1) {
  1406. //>>excludeEnd("ctx");
  1407. $recv(aResponse)._writeHead_options_((200),$globals.HashedCollection._newFromPairs_(["Content-Type","text/plain","Access-Control-Allow-Origin","*"]));
  1408. $recv(aResponse)._end();
  1409. return self;
  1410. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1411. }, function($ctx1) {$ctx1.fill(self,"respondOKTo:",{aResponse:aResponse})});
  1412. //>>excludeEnd("ctx");
  1413. }; }),
  1414. $globals.FileServer);
  1415. $core.addMethod(
  1416. $core.method({
  1417. selector: "respondRedirect:to:",
  1418. protocol: "request handling",
  1419. //>>excludeStart("ide", pragmas.excludeIdeData);
  1420. args: ["aString", "aResponse"],
  1421. source: "respondRedirect: aString to: aResponse\x0a\x09aResponse\x0a\x09\x09writeHead: 303 options: #{'Location' -> aString};\x0a\x09\x09end.",
  1422. referencedClasses: [],
  1423. //>>excludeEnd("ide");
  1424. pragmas: [],
  1425. messageSends: ["writeHead:options:", "end"]
  1426. }, function ($methodClass){ return function (aString,aResponse){
  1427. var self=this,$self=this;
  1428. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1429. return $core.withContext(function($ctx1) {
  1430. //>>excludeEnd("ctx");
  1431. $recv(aResponse)._writeHead_options_((303),$globals.HashedCollection._newFromPairs_(["Location",aString]));
  1432. $recv(aResponse)._end();
  1433. return self;
  1434. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1435. }, function($ctx1) {$ctx1.fill(self,"respondRedirect:to:",{aString:aString,aResponse:aResponse})});
  1436. //>>excludeEnd("ctx");
  1437. }; }),
  1438. $globals.FileServer);
  1439. $core.addMethod(
  1440. $core.method({
  1441. selector: "start",
  1442. protocol: "starting",
  1443. //>>excludeStart("ide", pragmas.excludeIdeData);
  1444. args: [],
  1445. 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.",
  1446. referencedClasses: [],
  1447. //>>excludeEnd("ide");
  1448. pragmas: [],
  1449. messageSends: ["checkDirectoryLayout", "on:do:", "createServer:", "handleRequest:respondTo:", "log:", ",", "host", "asString", "port", "listen:host:"]
  1450. }, function ($methodClass){ return function (){
  1451. var self=this,$self=this;
  1452. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1453. return $core.withContext(function($ctx1) {
  1454. //>>excludeEnd("ctx");
  1455. var $1;
  1456. $self._checkDirectoryLayout();
  1457. $1=$recv($self.http)._createServer_((function(request,response){
  1458. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1459. return $core.withContext(function($ctx2) {
  1460. //>>excludeEnd("ctx");
  1461. return $self._handleRequest_respondTo_(request,response);
  1462. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1463. }, function($ctx2) {$ctx2.fillBlock({request:request,response:response},$ctx1,1)});
  1464. //>>excludeEnd("ctx");
  1465. }));
  1466. [$recv($1)._on_do_("error",(function(error){
  1467. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1468. return $core.withContext(function($ctx2) {
  1469. //>>excludeEnd("ctx");
  1470. return [$recv(console)._log_(["Error starting server: ".__comma(error)
  1471. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1472. ,$ctx2.sendIdx[","]=1
  1473. //>>excludeEnd("ctx");
  1474. ][0])
  1475. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1476. ,$ctx2.sendIdx["log:"]=1
  1477. //>>excludeEnd("ctx");
  1478. ][0];
  1479. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1480. }, function($ctx2) {$ctx2.fillBlock({error:error},$ctx1,2)});
  1481. //>>excludeEnd("ctx");
  1482. }))
  1483. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1484. ,$ctx1.sendIdx["on:do:"]=1
  1485. //>>excludeEnd("ctx");
  1486. ][0];
  1487. $recv($1)._on_do_("listening",(function(){
  1488. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1489. return $core.withContext(function($ctx2) {
  1490. //>>excludeEnd("ctx");
  1491. return $recv(console)._log_([$recv([$recv("Starting file server on http://".__comma([$self._host()
  1492. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1493. ,$ctx2.sendIdx["host"]=1
  1494. //>>excludeEnd("ctx");
  1495. ][0])).__comma(":")
  1496. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1497. ,$ctx2.sendIdx[","]=3
  1498. //>>excludeEnd("ctx");
  1499. ][0]).__comma($recv([$self._port()
  1500. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1501. ,$ctx2.sendIdx["port"]=1
  1502. //>>excludeEnd("ctx");
  1503. ][0])._asString())
  1504. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1505. ,$ctx2.sendIdx[","]=2
  1506. //>>excludeEnd("ctx");
  1507. ][0]);
  1508. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1509. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,3)});
  1510. //>>excludeEnd("ctx");
  1511. }));
  1512. $recv($1)._listen_host_($self._port(),$self._host());
  1513. return self;
  1514. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1515. }, function($ctx1) {$ctx1.fill(self,"start",{})});
  1516. //>>excludeEnd("ctx");
  1517. }; }),
  1518. $globals.FileServer);
  1519. $core.addMethod(
  1520. $core.method({
  1521. selector: "startOn:",
  1522. protocol: "starting",
  1523. //>>excludeStart("ide", pragmas.excludeIdeData);
  1524. args: ["aPort"],
  1525. source: "startOn: aPort\x0a\x09self port: aPort.\x0a\x09self start",
  1526. referencedClasses: [],
  1527. //>>excludeEnd("ide");
  1528. pragmas: [],
  1529. messageSends: ["port:", "start"]
  1530. }, function ($methodClass){ return function (aPort){
  1531. var self=this,$self=this;
  1532. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1533. return $core.withContext(function($ctx1) {
  1534. //>>excludeEnd("ctx");
  1535. $self._port_(aPort);
  1536. $self._start();
  1537. return self;
  1538. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1539. }, function($ctx1) {$ctx1.fill(self,"startOn:",{aPort:aPort})});
  1540. //>>excludeEnd("ctx");
  1541. }; }),
  1542. $globals.FileServer);
  1543. $core.addMethod(
  1544. $core.method({
  1545. selector: "username:",
  1546. protocol: "accessing",
  1547. //>>excludeStart("ide", pragmas.excludeIdeData);
  1548. args: ["aUsername"],
  1549. source: "username: aUsername\x0a\x09username := aUsername.",
  1550. referencedClasses: [],
  1551. //>>excludeEnd("ide");
  1552. pragmas: [],
  1553. messageSends: []
  1554. }, function ($methodClass){ return function (aUsername){
  1555. var self=this,$self=this;
  1556. $self.username=aUsername;
  1557. return self;
  1558. }; }),
  1559. $globals.FileServer);
  1560. $core.addMethod(
  1561. $core.method({
  1562. selector: "validateBasePath",
  1563. protocol: "private",
  1564. //>>excludeStart("ide", pragmas.excludeIdeData);
  1565. args: [],
  1566. 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.' ]].",
  1567. referencedClasses: [],
  1568. //>>excludeEnd("ide");
  1569. pragmas: [],
  1570. messageSends: ["stat:then:", "basePath", "ifNil:ifNotNil:", "ifFalse:", "isDirectory", "warn:", ","]
  1571. }, function ($methodClass){ return function (){
  1572. var self=this,$self=this;
  1573. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1574. return $core.withContext(function($ctx1) {
  1575. //>>excludeEnd("ctx");
  1576. $recv($self.fs)._stat_then_([$self._basePath()
  1577. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1578. ,$ctx1.sendIdx["basePath"]=1
  1579. //>>excludeEnd("ctx");
  1580. ][0],(function(err,stat){
  1581. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1582. return $core.withContext(function($ctx2) {
  1583. //>>excludeEnd("ctx");
  1584. if(err == null || err.a$nil){
  1585. if(!$core.assert($recv(stat)._isDirectory())){
  1586. return [$recv(console)._warn_([$recv(["Warning: --base-path parameter ".__comma([$self._basePath()
  1587. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1588. ,$ctx2.sendIdx["basePath"]=2
  1589. //>>excludeEnd("ctx");
  1590. ][0])
  1591. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1592. ,$ctx2.sendIdx[","]=2
  1593. //>>excludeEnd("ctx");
  1594. ][0]).__comma(" is not a directory.")
  1595. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1596. ,$ctx2.sendIdx[","]=1
  1597. //>>excludeEnd("ctx");
  1598. ][0])
  1599. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1600. ,$ctx2.sendIdx["warn:"]=1
  1601. //>>excludeEnd("ctx");
  1602. ][0];
  1603. }
  1604. } else {
  1605. return $recv(console)._warn_([$recv("Warning: path at --base-path parameter ".__comma($self._basePath())).__comma(" does not exist.")
  1606. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1607. ,$ctx2.sendIdx[","]=3
  1608. //>>excludeEnd("ctx");
  1609. ][0]);
  1610. }
  1611. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1612. }, function($ctx2) {$ctx2.fillBlock({err:err,stat:stat},$ctx1,1)});
  1613. //>>excludeEnd("ctx");
  1614. }));
  1615. return self;
  1616. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1617. }, function($ctx1) {$ctx1.fill(self,"validateBasePath",{})});
  1618. //>>excludeEnd("ctx");
  1619. }; }),
  1620. $globals.FileServer);
  1621. $core.addMethod(
  1622. $core.method({
  1623. selector: "withBasePath:",
  1624. protocol: "private",
  1625. //>>excludeStart("ide", pragmas.excludeIdeData);
  1626. args: ["aBaseRelativePath"],
  1627. source: "withBasePath: aBaseRelativePath\x0a\x09\x22return a file path which is relative to the basePath.\x22\x0a\x09^ path join: self basePath with: aBaseRelativePath",
  1628. referencedClasses: [],
  1629. //>>excludeEnd("ide");
  1630. pragmas: [],
  1631. messageSends: ["join:with:", "basePath"]
  1632. }, function ($methodClass){ return function (aBaseRelativePath){
  1633. var self=this,$self=this;
  1634. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1635. return $core.withContext(function($ctx1) {
  1636. //>>excludeEnd("ctx");
  1637. return $recv($self.path)._join_with_($self._basePath(),aBaseRelativePath);
  1638. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1639. }, function($ctx1) {$ctx1.fill(self,"withBasePath:",{aBaseRelativePath:aBaseRelativePath})});
  1640. //>>excludeEnd("ctx");
  1641. }; }),
  1642. $globals.FileServer);
  1643. $core.addMethod(
  1644. $core.method({
  1645. selector: "writeData:toFileNamed:",
  1646. protocol: "private",
  1647. //>>excludeStart("ide", pragmas.excludeIdeData);
  1648. args: ["data", "aFilename"],
  1649. source: "writeData: data toFileNamed: aFilename\x0a\x09console log: aFilename",
  1650. referencedClasses: [],
  1651. //>>excludeEnd("ide");
  1652. pragmas: [],
  1653. messageSends: ["log:"]
  1654. }, function ($methodClass){ return function (data,aFilename){
  1655. var self=this,$self=this;
  1656. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1657. return $core.withContext(function($ctx1) {
  1658. //>>excludeEnd("ctx");
  1659. $recv(console)._log_(aFilename);
  1660. return self;
  1661. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1662. }, function($ctx1) {$ctx1.fill(self,"writeData:toFileNamed:",{data:data,aFilename:aFilename})});
  1663. //>>excludeEnd("ctx");
  1664. }; }),
  1665. $globals.FileServer);
  1666. $core.setSlots($globals.FileServer.a$cls, ["mimeTypes"]);
  1667. $core.addMethod(
  1668. $core.method({
  1669. selector: "commandLineSwitches",
  1670. protocol: "accessing",
  1671. //>>excludeStart("ide", pragmas.excludeIdeData);
  1672. args: [],
  1673. 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",
  1674. referencedClasses: [],
  1675. //>>excludeEnd("ide");
  1676. pragmas: [],
  1677. messageSends: ["collect:", "methodsInProtocol:", "selector", "select:", "match:", "replace:with:", "asLowercase", "allButLast"]
  1678. }, function ($methodClass){ return function (){
  1679. var self=this,$self=this;
  1680. var switches;
  1681. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1682. return $core.withContext(function($ctx1) {
  1683. //>>excludeEnd("ctx");
  1684. switches=[$recv($self._methodsInProtocol_("accessing"))._collect_((function(each){
  1685. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1686. return $core.withContext(function($ctx2) {
  1687. //>>excludeEnd("ctx");
  1688. return $recv(each)._selector();
  1689. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1690. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)});
  1691. //>>excludeEnd("ctx");
  1692. }))
  1693. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1694. ,$ctx1.sendIdx["collect:"]=1
  1695. //>>excludeEnd("ctx");
  1696. ][0];
  1697. switches=$recv(switches)._select_((function(each){
  1698. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1699. return $core.withContext(function($ctx2) {
  1700. //>>excludeEnd("ctx");
  1701. return $recv(each)._match_("^[^:]*:$");
  1702. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1703. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,2)});
  1704. //>>excludeEnd("ctx");
  1705. }));
  1706. switches=$recv(switches)._collect_((function(each){
  1707. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1708. return $core.withContext(function($ctx2) {
  1709. //>>excludeEnd("ctx");
  1710. return [$recv($recv($recv($recv(each)._allButLast())._replace_with_("([A-Z])","-$1"))._asLowercase())._replace_with_("^([a-z])","--$1")
  1711. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1712. ,$ctx2.sendIdx["replace:with:"]=1
  1713. //>>excludeEnd("ctx");
  1714. ][0];
  1715. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1716. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,3)});
  1717. //>>excludeEnd("ctx");
  1718. }));
  1719. return switches;
  1720. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1721. }, function($ctx1) {$ctx1.fill(self,"commandLineSwitches",{switches:switches})});
  1722. //>>excludeEnd("ctx");
  1723. }; }),
  1724. $globals.FileServer.a$cls);
  1725. $core.addMethod(
  1726. $core.method({
  1727. selector: "createServerWithArguments:",
  1728. protocol: "initialization",
  1729. //>>excludeStart("ide", pragmas.excludeIdeData);
  1730. args: ["options"],
  1731. 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: { 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.",
  1732. referencedClasses: [],
  1733. //>>excludeEnd("ide");
  1734. pragmas: [],
  1735. messageSends: ["commandLineSwitches", "new", "ifEmpty:", "ifFalse:", "even", "size", "log:", ",", "first", "remove:", "whileTrue:", "notEmpty", "value:", "ifTrue:ifFalse:", "includes:", "selectorForCommandLineSwitch:", "perform:withArguments:"]
  1736. }, function ($methodClass){ return function (options){
  1737. var self=this,$self=this;
  1738. var server,popFront,front,optionName,optionValue,switches;
  1739. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1740. return $core.withContext(function($ctx1) {
  1741. //>>excludeEnd("ctx");
  1742. var $early={};
  1743. try {
  1744. switches=$self._commandLineSwitches();
  1745. server=$self._new();
  1746. $recv(options)._ifEmpty_((function(){
  1747. throw $early=[server];
  1748. }));
  1749. if(!$core.assert($recv($recv(options)._size())._even())){
  1750. [$recv(console)._log_("Using default parameters.")
  1751. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1752. ,$ctx1.sendIdx["log:"]=1
  1753. //>>excludeEnd("ctx");
  1754. ][0];
  1755. [$recv(console)._log_(["Wrong commandline options or not enough arguments for: ".__comma(options)
  1756. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1757. ,$ctx1.sendIdx[","]=1
  1758. //>>excludeEnd("ctx");
  1759. ][0])
  1760. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1761. ,$ctx1.sendIdx["log:"]=2
  1762. //>>excludeEnd("ctx");
  1763. ][0];
  1764. [$recv(console)._log_(["Use any of the following ones: ".__comma(switches)
  1765. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1766. ,$ctx1.sendIdx[","]=2
  1767. //>>excludeEnd("ctx");
  1768. ][0])
  1769. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1770. ,$ctx1.sendIdx["log:"]=3
  1771. //>>excludeEnd("ctx");
  1772. ][0];
  1773. return server;
  1774. }
  1775. popFront=(function(args){
  1776. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1777. return $core.withContext(function($ctx2) {
  1778. //>>excludeEnd("ctx");
  1779. front=$recv(args)._first();
  1780. $recv(args)._remove_(front);
  1781. return front;
  1782. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1783. }, function($ctx2) {$ctx2.fillBlock({args:args},$ctx1,3)});
  1784. //>>excludeEnd("ctx");
  1785. });
  1786. $recv((function(){
  1787. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1788. return $core.withContext(function($ctx2) {
  1789. //>>excludeEnd("ctx");
  1790. return $recv(options)._notEmpty();
  1791. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1792. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,4)});
  1793. //>>excludeEnd("ctx");
  1794. }))._whileTrue_((function(){
  1795. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1796. return $core.withContext(function($ctx2) {
  1797. //>>excludeEnd("ctx");
  1798. optionName=[$recv(popFront)._value_(options)
  1799. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1800. ,$ctx2.sendIdx["value:"]=1
  1801. //>>excludeEnd("ctx");
  1802. ][0];
  1803. optionValue=$recv(popFront)._value_(options);
  1804. if($core.assert($recv(switches)._includes_(optionName))){
  1805. optionName=$self._selectorForCommandLineSwitch_(optionName);
  1806. return $recv(server)._perform_withArguments_(optionName,[optionValue]);
  1807. } else {
  1808. [$recv(console)._log_([$recv(optionName).__comma(" is not a valid commandline option")
  1809. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1810. ,$ctx2.sendIdx[","]=3
  1811. //>>excludeEnd("ctx");
  1812. ][0])
  1813. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1814. ,$ctx2.sendIdx["log:"]=4
  1815. //>>excludeEnd("ctx");
  1816. ][0];
  1817. return $recv(console)._log_("Use any of the following ones: ".__comma(switches));
  1818. }
  1819. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1820. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,5)});
  1821. //>>excludeEnd("ctx");
  1822. }));
  1823. return server;
  1824. }
  1825. catch(e) {if(e===$early)return e[0]; throw e}
  1826. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1827. }, function($ctx1) {$ctx1.fill(self,"createServerWithArguments:",{options:options,server:server,popFront:popFront,front:front,optionName:optionName,optionValue:optionValue,switches:switches})});
  1828. //>>excludeEnd("ctx");
  1829. }; }),
  1830. $globals.FileServer.a$cls);
  1831. $core.addMethod(
  1832. $core.method({
  1833. selector: "defaultBasePath",
  1834. protocol: "accessing",
  1835. //>>excludeStart("ide", pragmas.excludeIdeData);
  1836. args: [],
  1837. source: "defaultBasePath\x0a\x09^ './'",
  1838. referencedClasses: [],
  1839. //>>excludeEnd("ide");
  1840. pragmas: [],
  1841. messageSends: []
  1842. }, function ($methodClass){ return function (){
  1843. var self=this,$self=this;
  1844. return "./";
  1845. }; }),
  1846. $globals.FileServer.a$cls);
  1847. $core.addMethod(
  1848. $core.method({
  1849. selector: "defaultHost",
  1850. protocol: "accessing",
  1851. //>>excludeStart("ide", pragmas.excludeIdeData);
  1852. args: [],
  1853. source: "defaultHost\x0a\x09^ '127.0.0.1'",
  1854. referencedClasses: [],
  1855. //>>excludeEnd("ide");
  1856. pragmas: [],
  1857. messageSends: []
  1858. }, function ($methodClass){ return function (){
  1859. var self=this,$self=this;
  1860. return "127.0.0.1";
  1861. }; }),
  1862. $globals.FileServer.a$cls);
  1863. $core.addMethod(
  1864. $core.method({
  1865. selector: "defaultMimeTypes",
  1866. protocol: "accessing",
  1867. //>>excludeStart("ide", pragmas.excludeIdeData);
  1868. args: [],
  1869. 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}",
  1870. referencedClasses: [],
  1871. //>>excludeEnd("ide");
  1872. pragmas: [],
  1873. messageSends: []
  1874. }, function ($methodClass){ return function (){
  1875. var self=this,$self=this;
  1876. return $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"]);
  1877. }; }),
  1878. $globals.FileServer.a$cls);
  1879. $core.addMethod(
  1880. $core.method({
  1881. selector: "defaultPort",
  1882. protocol: "accessing",
  1883. //>>excludeStart("ide", pragmas.excludeIdeData);
  1884. args: [],
  1885. source: "defaultPort\x0a\x09^ 4000",
  1886. referencedClasses: [],
  1887. //>>excludeEnd("ide");
  1888. pragmas: [],
  1889. messageSends: []
  1890. }, function ($methodClass){ return function (){
  1891. var self=this,$self=this;
  1892. return (4000);
  1893. }; }),
  1894. $globals.FileServer.a$cls);
  1895. $core.addMethod(
  1896. $core.method({
  1897. selector: "main",
  1898. protocol: "initialization",
  1899. //>>excludeStart("ide", pragmas.excludeIdeData);
  1900. args: [],
  1901. 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]",
  1902. referencedClasses: ["FileServer"],
  1903. //>>excludeEnd("ide");
  1904. pragmas: [],
  1905. messageSends: ["argv", "removeFrom:to:", "detect:ifNone:", "ifTrue:", "=", "printHelp", "createServerWithArguments:", "start"]
  1906. }, function ($methodClass){ return function (){
  1907. var self=this,$self=this;
  1908. var fileServer,args;
  1909. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1910. return $core.withContext(function($ctx1) {
  1911. //>>excludeEnd("ctx");
  1912. var $early={};
  1913. try {
  1914. args=$recv(process)._argv();
  1915. $recv(args)._removeFrom_to_((1),(3));
  1916. $recv(args)._detect_ifNone_((function(each){
  1917. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1918. return $core.withContext(function($ctx2) {
  1919. //>>excludeEnd("ctx");
  1920. if($core.assert($recv(each).__eq("--help"))){
  1921. return $recv($globals.FileServer)._printHelp();
  1922. }
  1923. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1924. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)});
  1925. //>>excludeEnd("ctx");
  1926. }),(function(){
  1927. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1928. return $core.withContext(function($ctx2) {
  1929. //>>excludeEnd("ctx");
  1930. fileServer=$recv($globals.FileServer)._createServerWithArguments_(args);
  1931. throw $early=[$recv(fileServer)._start()];
  1932. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1933. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,3)});
  1934. //>>excludeEnd("ctx");
  1935. }));
  1936. return self;
  1937. }
  1938. catch(e) {if(e===$early)return e[0]; throw e}
  1939. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1940. }, function($ctx1) {$ctx1.fill(self,"main",{fileServer:fileServer,args:args})});
  1941. //>>excludeEnd("ctx");
  1942. }; }),
  1943. $globals.FileServer.a$cls);
  1944. $core.addMethod(
  1945. $core.method({
  1946. selector: "mimeTypeFor:",
  1947. protocol: "accessing",
  1948. //>>excludeStart("ide", pragmas.excludeIdeData);
  1949. args: ["aString"],
  1950. source: "mimeTypeFor: aString\x0a\x09^ self mimeTypes at: (aString replace: '.*[\x5c.]' with: '') ifAbsent: ['text/plain']",
  1951. referencedClasses: [],
  1952. //>>excludeEnd("ide");
  1953. pragmas: [],
  1954. messageSends: ["at:ifAbsent:", "mimeTypes", "replace:with:"]
  1955. }, function ($methodClass){ return function (aString){
  1956. var self=this,$self=this;
  1957. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1958. return $core.withContext(function($ctx1) {
  1959. //>>excludeEnd("ctx");
  1960. return $recv($self._mimeTypes())._at_ifAbsent_($recv(aString)._replace_with_(".*[\x5c.]",""),(function(){
  1961. return "text/plain";
  1962. }));
  1963. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1964. }, function($ctx1) {$ctx1.fill(self,"mimeTypeFor:",{aString:aString})});
  1965. //>>excludeEnd("ctx");
  1966. }; }),
  1967. $globals.FileServer.a$cls);
  1968. $core.addMethod(
  1969. $core.method({
  1970. selector: "mimeTypes",
  1971. protocol: "accessing",
  1972. //>>excludeStart("ide", pragmas.excludeIdeData);
  1973. args: [],
  1974. source: "mimeTypes\x0a\x09^ mimeTypes ifNil: [mimeTypes := self defaultMimeTypes]",
  1975. referencedClasses: [],
  1976. //>>excludeEnd("ide");
  1977. pragmas: [],
  1978. messageSends: ["ifNil:", "defaultMimeTypes"]
  1979. }, function ($methodClass){ return function (){
  1980. var self=this,$self=this;
  1981. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1982. return $core.withContext(function($ctx1) {
  1983. //>>excludeEnd("ctx");
  1984. var $1;
  1985. $1=$self.mimeTypes;
  1986. if($1 == null || $1.a$nil){
  1987. $self.mimeTypes=$self._defaultMimeTypes();
  1988. return $self.mimeTypes;
  1989. } else {
  1990. return $1;
  1991. }
  1992. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1993. }, function($ctx1) {$ctx1.fill(self,"mimeTypes",{})});
  1994. //>>excludeEnd("ctx");
  1995. }; }),
  1996. $globals.FileServer.a$cls);
  1997. $core.addMethod(
  1998. $core.method({
  1999. selector: "printHelp",
  2000. protocol: "accessing",
  2001. //>>excludeStart("ide", pragmas.excludeIdeData);
  2002. args: [],
  2003. source: "printHelp\x0a\x09console log: 'Available commandline options are:'.\x0a\x09console log: '--help'.\x0a\x09self commandLineSwitches do: [ :each |\x0a\x09\x09console log: each, ' <parameter>']",
  2004. referencedClasses: [],
  2005. //>>excludeEnd("ide");
  2006. pragmas: [],
  2007. messageSends: ["log:", "do:", "commandLineSwitches", ","]
  2008. }, function ($methodClass){ return function (){
  2009. var self=this,$self=this;
  2010. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2011. return $core.withContext(function($ctx1) {
  2012. //>>excludeEnd("ctx");
  2013. [$recv(console)._log_("Available commandline options are:")
  2014. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2015. ,$ctx1.sendIdx["log:"]=1
  2016. //>>excludeEnd("ctx");
  2017. ][0];
  2018. [$recv(console)._log_("--help")
  2019. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2020. ,$ctx1.sendIdx["log:"]=2
  2021. //>>excludeEnd("ctx");
  2022. ][0];
  2023. $recv($self._commandLineSwitches())._do_((function(each){
  2024. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2025. return $core.withContext(function($ctx2) {
  2026. //>>excludeEnd("ctx");
  2027. return $recv(console)._log_($recv(each).__comma(" <parameter>"));
  2028. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2029. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)});
  2030. //>>excludeEnd("ctx");
  2031. }));
  2032. return self;
  2033. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2034. }, function($ctx1) {$ctx1.fill(self,"printHelp",{})});
  2035. //>>excludeEnd("ctx");
  2036. }; }),
  2037. $globals.FileServer.a$cls);
  2038. $core.addMethod(
  2039. $core.method({
  2040. selector: "selectorForCommandLineSwitch:",
  2041. protocol: "accessing",
  2042. //>>excludeStart("ide", pragmas.excludeIdeData);
  2043. args: ["aSwitch"],
  2044. 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 ]), ':'",
  2045. referencedClasses: [],
  2046. //>>excludeEnd("ide");
  2047. pragmas: [],
  2048. messageSends: [",", "replace:with:", "asUppercase", "second"]
  2049. }, function ($methodClass){ return function (aSwitch){
  2050. var self=this,$self=this;
  2051. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2052. return $core.withContext(function($ctx1) {
  2053. //>>excludeEnd("ctx");
  2054. return $recv([$recv($recv(aSwitch)._replace_with_("^--",""))._replace_with_("-[a-z]",(function(each){
  2055. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2056. return $core.withContext(function($ctx2) {
  2057. //>>excludeEnd("ctx");
  2058. return $recv($recv(each)._second())._asUppercase();
  2059. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2060. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)});
  2061. //>>excludeEnd("ctx");
  2062. }))
  2063. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2064. ,$ctx1.sendIdx["replace:with:"]=1
  2065. //>>excludeEnd("ctx");
  2066. ][0]).__comma(":");
  2067. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2068. }, function($ctx1) {$ctx1.fill(self,"selectorForCommandLineSwitch:",{aSwitch:aSwitch})});
  2069. //>>excludeEnd("ctx");
  2070. }; }),
  2071. $globals.FileServer.a$cls);
  2072. $core.addClass("Initer", $globals.BaseFileManipulator, ["childProcess", "nmPath"], "AmberCli");
  2073. $core.addMethod(
  2074. $core.method({
  2075. selector: "finishMessage",
  2076. protocol: "action",
  2077. //>>excludeStart("ide", pragmas.excludeIdeData);
  2078. args: [],
  2079. 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) join: String lf).\x0a\x09[] valueWithTimeout: 600",
  2080. referencedClasses: ["String"],
  2081. //>>excludeEnd("ide");
  2082. pragmas: [],
  2083. messageSends: ["log:", "join:", "lf", "valueWithTimeout:"]
  2084. }, function ($methodClass){ return function (){
  2085. var self=this,$self=this;
  2086. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2087. return $core.withContext(function($ctx1) {
  2088. //>>excludeEnd("ctx");
  2089. $recv(console)._log_([" ", "The project should now be set up.", " ", " "]._join_($recv($globals.String)._lf()));
  2090. $recv((function(){
  2091. }))._valueWithTimeout_((600));
  2092. return self;
  2093. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2094. }, function($ctx1) {$ctx1.fill(self,"finishMessage",{})});
  2095. //>>excludeEnd("ctx");
  2096. }; }),
  2097. $globals.Initer);
  2098. $core.addMethod(
  2099. $core.method({
  2100. selector: "gruntInitThenDo:",
  2101. protocol: "action",
  2102. //>>excludeStart("ide", pragmas.excludeIdeData);
  2103. args: ["aBlock"],
  2104. source: "gruntInitThenDo: aBlock\x0a\x09| child sanitizedTemplatePath |\x0a\x09sanitizedTemplatePath := ((path join: nmPath with: '@ambers/grunt-init-amber-project')\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 ]) ]",
  2105. referencedClasses: [],
  2106. //>>excludeEnd("ide");
  2107. pragmas: [],
  2108. messageSends: ["replace:with:", "join:with:", "fork:args:", "npmScriptForModule:named:", "on:do:", "value:", "ifTrue:ifFalse:", "="]
  2109. }, function ($methodClass){ return function (aBlock){
  2110. var self=this,$self=this;
  2111. var child,sanitizedTemplatePath;
  2112. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2113. return $core.withContext(function($ctx1) {
  2114. //>>excludeEnd("ctx");
  2115. var $1,$2;
  2116. sanitizedTemplatePath=[$recv($recv($recv($self.path)._join_with_($self.nmPath,"@ambers/grunt-init-amber-project"))._replace_with_("\x5c\x5c","\x5c\x5c"))._replace_with_(":","\x5c:")
  2117. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2118. ,$ctx1.sendIdx["replace:with:"]=1
  2119. //>>excludeEnd("ctx");
  2120. ][0];
  2121. child=$recv($self.childProcess)._fork_args_($self._npmScriptForModule_named_("grunt-init","grunt-init"),[sanitizedTemplatePath]);
  2122. $1=child;
  2123. [$recv($1)._on_do_("error",aBlock)
  2124. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2125. ,$ctx1.sendIdx["on:do:"]=1
  2126. //>>excludeEnd("ctx");
  2127. ][0];
  2128. $recv($1)._on_do_("close",(function(code){
  2129. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2130. return $core.withContext(function($ctx2) {
  2131. //>>excludeEnd("ctx");
  2132. if($core.assert($recv(code).__eq((0)))){
  2133. $2=nil;
  2134. } else {
  2135. $2=code;
  2136. }
  2137. return $recv(aBlock)._value_($2);
  2138. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2139. }, function($ctx2) {$ctx2.fillBlock({code:code},$ctx1,1)});
  2140. //>>excludeEnd("ctx");
  2141. }));
  2142. return self;
  2143. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2144. }, function($ctx1) {$ctx1.fill(self,"gruntInitThenDo:",{aBlock:aBlock,child:child,sanitizedTemplatePath:sanitizedTemplatePath})});
  2145. //>>excludeEnd("ctx");
  2146. }; }),
  2147. $globals.Initer);
  2148. $core.addMethod(
  2149. $core.method({
  2150. selector: "initProjectThenDo:",
  2151. protocol: "action",
  2152. //>>excludeStart("ide", pragmas.excludeIdeData);
  2153. args: ["aBlock"],
  2154. source: "initProjectThenDo: aBlock\x0a\x09| child |\x0a\x09child := childProcess\x0a\x09\x09exec: 'npm run init'\x0a\x09\x09thenDo: aBlock.\x0a\x09child stdout pipe: process stdout options: #{ 'end' -> false }",
  2155. referencedClasses: [],
  2156. //>>excludeEnd("ide");
  2157. pragmas: [],
  2158. messageSends: ["exec:thenDo:", "pipe:options:", "stdout"]
  2159. }, function ($methodClass){ return function (aBlock){
  2160. var self=this,$self=this;
  2161. var child;
  2162. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2163. return $core.withContext(function($ctx1) {
  2164. //>>excludeEnd("ctx");
  2165. child=$recv($self.childProcess)._exec_thenDo_("npm run init",aBlock);
  2166. $recv([$recv(child)._stdout()
  2167. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2168. ,$ctx1.sendIdx["stdout"]=1
  2169. //>>excludeEnd("ctx");
  2170. ][0])._pipe_options_($recv(process)._stdout(),$globals.HashedCollection._newFromPairs_(["end",false]));
  2171. return self;
  2172. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2173. }, function($ctx1) {$ctx1.fill(self,"initProjectThenDo:",{aBlock:aBlock,child:child})});
  2174. //>>excludeEnd("ctx");
  2175. }; }),
  2176. $globals.Initer);
  2177. $core.addMethod(
  2178. $core.method({
  2179. selector: "initialize",
  2180. protocol: "initialization",
  2181. //>>excludeStart("ide", pragmas.excludeIdeData);
  2182. args: [],
  2183. source: "initialize\x0a\x09super initialize.\x0a\x09childProcess := require value: 'child_process'.\x0a\x09nmPath := path join: self rootDirname with: 'node_modules'",
  2184. referencedClasses: [],
  2185. //>>excludeEnd("ide");
  2186. pragmas: [],
  2187. messageSends: ["initialize", "value:", "join:with:", "rootDirname"]
  2188. }, function ($methodClass){ return function (){
  2189. var self=this,$self=this;
  2190. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2191. return $core.withContext(function($ctx1) {
  2192. //>>excludeEnd("ctx");
  2193. [(
  2194. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2195. $ctx1.supercall = true,
  2196. //>>excludeEnd("ctx");
  2197. ($methodClass.superclass||$boot.nilAsClass).fn.prototype._initialize.call($self))
  2198. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2199. ,$ctx1.supercall = false
  2200. //>>excludeEnd("ctx");
  2201. ][0];
  2202. $self.childProcess=$recv(require)._value_("child_process");
  2203. $self.nmPath=$recv($self.path)._join_with_($self._rootDirname(),"node_modules");
  2204. return self;
  2205. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2206. }, function($ctx1) {$ctx1.fill(self,"initialize",{})});
  2207. //>>excludeEnd("ctx");
  2208. }; }),
  2209. $globals.Initer);
  2210. $core.addMethod(
  2211. $core.method({
  2212. selector: "npmScriptForModule:named:",
  2213. protocol: "npm",
  2214. //>>excludeStart("ide", pragmas.excludeIdeData);
  2215. args: ["aString", "anotherString"],
  2216. source: "npmScriptForModule: aString named: anotherString\x0a\x09| modulePath packageJson binSection scriptPath |\x0a\x09modulePath := path dirname: (\x0a\x09\x09require provided resolve: 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",
  2217. referencedClasses: ["Smalltalk"],
  2218. //>>excludeEnd("ide");
  2219. pragmas: [],
  2220. messageSends: ["dirname:", "resolve:", "provided", ",", "readJSObject:", "value:", "at:", "ifTrue:ifFalse:", "isString", "join:with:"]
  2221. }, function ($methodClass){ return function (aString,anotherString){
  2222. var self=this,$self=this;
  2223. var modulePath,packageJson,binSection,scriptPath;
  2224. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2225. return $core.withContext(function($ctx1) {
  2226. //>>excludeEnd("ctx");
  2227. modulePath=$recv($self.path)._dirname_($recv($recv(require)._provided())._resolve_([$recv(aString).__comma("/package.json")
  2228. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2229. ,$ctx1.sendIdx[","]=1
  2230. //>>excludeEnd("ctx");
  2231. ][0]));
  2232. packageJson=$recv($globals.Smalltalk)._readJSObject_($recv(require)._value_($recv(aString).__comma("/package.json")));
  2233. binSection=[$recv(packageJson)._at_("bin")
  2234. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2235. ,$ctx1.sendIdx["at:"]=1
  2236. //>>excludeEnd("ctx");
  2237. ][0];
  2238. if($core.assert($recv(binSection)._isString())){
  2239. scriptPath=binSection;
  2240. } else {
  2241. scriptPath=$recv(binSection)._at_(anotherString);
  2242. }
  2243. return $recv($self.path)._join_with_(modulePath,scriptPath);
  2244. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2245. }, function($ctx1) {$ctx1.fill(self,"npmScriptForModule:named:",{aString:aString,anotherString:anotherString,modulePath:modulePath,packageJson:packageJson,binSection:binSection,scriptPath:scriptPath})});
  2246. //>>excludeEnd("ctx");
  2247. }; }),
  2248. $globals.Initer);
  2249. $core.addMethod(
  2250. $core.method({
  2251. selector: "start",
  2252. protocol: "action",
  2253. //>>excludeStart("ide", pragmas.excludeIdeData);
  2254. args: [],
  2255. 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 initProjectThenDo: [ :error2 | error2\x0a\x09ifNotNil: [\x0a\x09\x09console log: 'npm run init exec error:'; log: error2.\x0a\x09\x09process exit: 105 ]\x0a\x09ifNil: [\x0a\x0a\x09self finishMessage.\x0a\x09process exit ]]]]",
  2256. referencedClasses: [],
  2257. //>>excludeEnd("ide");
  2258. pragmas: [],
  2259. messageSends: ["gruntInitThenDo:", "ifNotNil:ifNil:", "log:", "exit:", "initProjectThenDo:", "finishMessage", "exit"]
  2260. }, function ($methodClass){ return function (){
  2261. var self=this,$self=this;
  2262. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2263. return $core.withContext(function($ctx1) {
  2264. //>>excludeEnd("ctx");
  2265. var $1,$2;
  2266. $self._gruntInitThenDo_((function(error){
  2267. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2268. return $core.withContext(function($ctx2) {
  2269. //>>excludeEnd("ctx");
  2270. if(error == null || error.a$nil){
  2271. return $self._initProjectThenDo_((function(error2){
  2272. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2273. return $core.withContext(function($ctx3) {
  2274. //>>excludeEnd("ctx");
  2275. if(error2 == null || error2.a$nil){
  2276. $self._finishMessage();
  2277. return $recv(process)._exit();
  2278. } else {
  2279. $2=console;
  2280. [$recv($2)._log_("npm run init exec error:")
  2281. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2282. ,$ctx3.sendIdx["log:"]=3
  2283. //>>excludeEnd("ctx");
  2284. ][0];
  2285. $recv($2)._log_(error2);
  2286. return $recv(process)._exit_((105));
  2287. }
  2288. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2289. }, function($ctx3) {$ctx3.fillBlock({error2:error2},$ctx2,4)});
  2290. //>>excludeEnd("ctx");
  2291. }));
  2292. } else {
  2293. $1=console;
  2294. [$recv($1)._log_("grunt-init exec error:")
  2295. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2296. ,$ctx2.sendIdx["log:"]=1
  2297. //>>excludeEnd("ctx");
  2298. ][0];
  2299. [$recv($1)._log_(error)
  2300. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2301. ,$ctx2.sendIdx["log:"]=2
  2302. //>>excludeEnd("ctx");
  2303. ][0];
  2304. return [$recv(process)._exit_((101))
  2305. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2306. ,$ctx2.sendIdx["exit:"]=1
  2307. //>>excludeEnd("ctx");
  2308. ][0];
  2309. }
  2310. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2311. }, function($ctx2) {$ctx2.fillBlock({error:error},$ctx1,1)});
  2312. //>>excludeEnd("ctx");
  2313. }));
  2314. return self;
  2315. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2316. }, function($ctx1) {$ctx1.fill(self,"start",{})});
  2317. //>>excludeEnd("ctx");
  2318. }; }),
  2319. $globals.Initer);
  2320. $core.addClass("Repl", $globals.Object, ["readline", "interface", "util", "session", "resultCount", "commands"], "AmberCli");
  2321. //>>excludeStart("ide", pragmas.excludeIdeData);
  2322. $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.";
  2323. //>>excludeEnd("ide");
  2324. $core.addMethod(
  2325. $core.method({
  2326. selector: "addVariableNamed:to:",
  2327. protocol: "private",
  2328. //>>excludeStart("ide", pragmas.excludeIdeData);
  2329. args: ["aString", "anObject"],
  2330. 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",
  2331. referencedClasses: [],
  2332. //>>excludeEnd("ide");
  2333. pragmas: [],
  2334. messageSends: ["subclass:withVariable:", "class", "encapsulateVariable:withValue:in:", "new", "setPreviousVariablesFor:from:"]
  2335. }, function ($methodClass){ return function (aString,anObject){
  2336. var self=this,$self=this;
  2337. var newClass,newObject;
  2338. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2339. return $core.withContext(function($ctx1) {
  2340. //>>excludeEnd("ctx");
  2341. newClass=$self._subclass_withVariable_($recv(anObject)._class(),aString);
  2342. $self._encapsulateVariable_withValue_in_(aString,anObject,newClass);
  2343. newObject=$recv(newClass)._new();
  2344. $self._setPreviousVariablesFor_from_(newObject,anObject);
  2345. return newObject;
  2346. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2347. }, function($ctx1) {$ctx1.fill(self,"addVariableNamed:to:",{aString:aString,anObject:anObject,newClass:newClass,newObject:newObject})});
  2348. //>>excludeEnd("ctx");
  2349. }; }),
  2350. $globals.Repl);
  2351. $core.addMethod(
  2352. $core.method({
  2353. selector: "assignNewVariable:do:",
  2354. protocol: "private",
  2355. //>>excludeStart("ide", pragmas.excludeIdeData);
  2356. args: ["buffer", "aBlock"],
  2357. 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]",
  2358. referencedClasses: ["Error", "ConsoleErrorHandler"],
  2359. //>>excludeEnd("ide");
  2360. pragmas: [],
  2361. messageSends: ["parseAssignment:do:", "ifNil:", "nextResultName", "addVariableNamed:to:", "on:do:", "eval:on:", ",", "logError:", "new", "value:value:"]
  2362. }, function ($methodClass){ return function (buffer,aBlock){
  2363. var self=this,$self=this;
  2364. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2365. return $core.withContext(function($ctx1) {
  2366. //>>excludeEnd("ctx");
  2367. var $1,$2;
  2368. return $self._parseAssignment_do_(buffer,(function(name,expr){
  2369. var varName,value;
  2370. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2371. return $core.withContext(function($ctx2) {
  2372. //>>excludeEnd("ctx");
  2373. if(name == null || name.a$nil){
  2374. varName=$self._nextResultName();
  2375. } else {
  2376. varName=name;
  2377. }
  2378. $self.session=$self._addVariableNamed_to_(varName,$self.session);
  2379. $recv((function(){
  2380. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2381. return $core.withContext(function($ctx3) {
  2382. //>>excludeEnd("ctx");
  2383. $1=$recv(varName).__comma(" := ");
  2384. if(expr == null || expr.a$nil){
  2385. $2=buffer;
  2386. } else {
  2387. $2=expr;
  2388. }
  2389. value=$self._eval_on_([$recv($1).__comma($2)
  2390. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2391. ,$ctx3.sendIdx[","]=1
  2392. //>>excludeEnd("ctx");
  2393. ][0],$self.session);
  2394. return value;
  2395. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2396. }, function($ctx3) {$ctx3.fillBlock({},$ctx2,3)});
  2397. //>>excludeEnd("ctx");
  2398. }))._on_do_($globals.Error,(function(e){
  2399. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2400. return $core.withContext(function($ctx3) {
  2401. //>>excludeEnd("ctx");
  2402. $recv($recv($globals.ConsoleErrorHandler)._new())._logError_(e);
  2403. value=nil;
  2404. return value;
  2405. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2406. }, function($ctx3) {$ctx3.fillBlock({e:e},$ctx2,5)});
  2407. //>>excludeEnd("ctx");
  2408. }));
  2409. return $recv(aBlock)._value_value_(varName,value);
  2410. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2411. }, function($ctx2) {$ctx2.fillBlock({name:name,expr:expr,varName:varName,value:value},$ctx1,1)});
  2412. //>>excludeEnd("ctx");
  2413. }));
  2414. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2415. }, function($ctx1) {$ctx1.fill(self,"assignNewVariable:do:",{buffer:buffer,aBlock:aBlock})});
  2416. //>>excludeEnd("ctx");
  2417. }; }),
  2418. $globals.Repl);
  2419. $core.addMethod(
  2420. $core.method({
  2421. selector: "clearScreen",
  2422. protocol: "actions",
  2423. //>>excludeStart("ide", pragmas.excludeIdeData);
  2424. args: [],
  2425. 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",
  2426. referencedClasses: ["String"],
  2427. //>>excludeEnd("ide");
  2428. pragmas: [],
  2429. messageSends: ["fromCharCode:", ",", "write:", "stdout", "prompt"]
  2430. }, function ($methodClass){ return function (){
  2431. var self=this,$self=this;
  2432. var esc,cls;
  2433. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2434. return $core.withContext(function($ctx1) {
  2435. //>>excludeEnd("ctx");
  2436. esc=$recv($globals.String)._fromCharCode_((27));
  2437. cls=[$recv([$recv($recv(esc).__comma("[2J")).__comma(esc)
  2438. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2439. ,$ctx1.sendIdx[","]=2
  2440. //>>excludeEnd("ctx");
  2441. ][0]).__comma("[0;0f")
  2442. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2443. ,$ctx1.sendIdx[","]=1
  2444. //>>excludeEnd("ctx");
  2445. ][0];
  2446. $recv($recv(process)._stdout())._write_(cls);
  2447. $recv($self.interface)._prompt();
  2448. return self;
  2449. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2450. }, function($ctx1) {$ctx1.fill(self,"clearScreen",{esc:esc,cls:cls})});
  2451. //>>excludeEnd("ctx");
  2452. }; }),
  2453. $globals.Repl);
  2454. $core.addMethod(
  2455. $core.method({
  2456. selector: "close",
  2457. protocol: "actions",
  2458. //>>excludeStart("ide", pragmas.excludeIdeData);
  2459. args: [],
  2460. source: "close\x0a\x09process stdin destroy",
  2461. referencedClasses: [],
  2462. //>>excludeEnd("ide");
  2463. pragmas: [],
  2464. messageSends: ["destroy", "stdin"]
  2465. }, function ($methodClass){ return function (){
  2466. var self=this,$self=this;
  2467. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2468. return $core.withContext(function($ctx1) {
  2469. //>>excludeEnd("ctx");
  2470. $recv($recv(process)._stdin())._destroy();
  2471. return self;
  2472. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2473. }, function($ctx1) {$ctx1.fill(self,"close",{})});
  2474. //>>excludeEnd("ctx");
  2475. }; }),
  2476. $globals.Repl);
  2477. $core.addMethod(
  2478. $core.method({
  2479. selector: "commands",
  2480. protocol: "accessing",
  2481. //>>excludeStart("ide", pragmas.excludeIdeData);
  2482. args: [],
  2483. source: "commands\x0a\x09^ commands",
  2484. referencedClasses: [],
  2485. //>>excludeEnd("ide");
  2486. pragmas: [],
  2487. messageSends: []
  2488. }, function ($methodClass){ return function (){
  2489. var self=this,$self=this;
  2490. return $self.commands;
  2491. }; }),
  2492. $globals.Repl);
  2493. $core.addMethod(
  2494. $core.method({
  2495. selector: "createInterface",
  2496. protocol: "actions",
  2497. //>>excludeStart("ide", pragmas.excludeIdeData);
  2498. args: [],
  2499. 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",
  2500. referencedClasses: [],
  2501. //>>excludeEnd("ide");
  2502. pragmas: [],
  2503. messageSends: ["createInterface:stdout:", "stdin", "stdout", "on:do:", "processLine:", "close", "printWelcome", "setupHotkeys", "setPrompt", "prompt"]
  2504. }, function ($methodClass){ return function (){
  2505. var self=this,$self=this;
  2506. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2507. return $core.withContext(function($ctx1) {
  2508. //>>excludeEnd("ctx");
  2509. $self.interface=$recv($self.readline)._createInterface_stdout_($recv(process)._stdin(),$recv(process)._stdout());
  2510. [$recv($self.interface)._on_do_("line",(function(buffer){
  2511. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2512. return $core.withContext(function($ctx2) {
  2513. //>>excludeEnd("ctx");
  2514. return $self._processLine_(buffer);
  2515. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2516. }, function($ctx2) {$ctx2.fillBlock({buffer:buffer},$ctx1,1)});
  2517. //>>excludeEnd("ctx");
  2518. }))
  2519. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2520. ,$ctx1.sendIdx["on:do:"]=1
  2521. //>>excludeEnd("ctx");
  2522. ][0];
  2523. $recv($self.interface)._on_do_("close",(function(){
  2524. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2525. return $core.withContext(function($ctx2) {
  2526. //>>excludeEnd("ctx");
  2527. return $self._close();
  2528. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2529. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,2)});
  2530. //>>excludeEnd("ctx");
  2531. }));
  2532. $self._printWelcome();
  2533. $self._setupHotkeys();
  2534. $self._setPrompt();
  2535. $recv($self.interface)._prompt();
  2536. return self;
  2537. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2538. }, function($ctx1) {$ctx1.fill(self,"createInterface",{})});
  2539. //>>excludeEnd("ctx");
  2540. }; }),
  2541. $globals.Repl);
  2542. $core.addMethod(
  2543. $core.method({
  2544. selector: "encapsulateVariable:withValue:in:",
  2545. protocol: "private",
  2546. //>>excludeStart("ide", pragmas.excludeIdeData);
  2547. args: ["aString", "anObject", "aClass"],
  2548. 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'.",
  2549. referencedClasses: ["Compiler"],
  2550. //>>excludeEnd("ide");
  2551. pragmas: [],
  2552. messageSends: ["new", "install:forClass:protocol:", ","]
  2553. }, function ($methodClass){ return function (aString,anObject,aClass){
  2554. var self=this,$self=this;
  2555. var compiler;
  2556. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2557. return $core.withContext(function($ctx1) {
  2558. //>>excludeEnd("ctx");
  2559. compiler=$recv($globals.Compiler)._new();
  2560. [$recv(compiler)._install_forClass_protocol_([$recv([$recv([$recv(aString).__comma(": anObject ^ ")
  2561. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2562. ,$ctx1.sendIdx[","]=3
  2563. //>>excludeEnd("ctx");
  2564. ][0]).__comma(aString)
  2565. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2566. ,$ctx1.sendIdx[","]=2
  2567. //>>excludeEnd("ctx");
  2568. ][0]).__comma(" := anObject")
  2569. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2570. ,$ctx1.sendIdx[","]=1
  2571. //>>excludeEnd("ctx");
  2572. ][0],aClass,"session")
  2573. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2574. ,$ctx1.sendIdx["install:forClass:protocol:"]=1
  2575. //>>excludeEnd("ctx");
  2576. ][0];
  2577. $recv(compiler)._install_forClass_protocol_([$recv($recv(aString).__comma(" ^ ")).__comma(aString)
  2578. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2579. ,$ctx1.sendIdx[","]=4
  2580. //>>excludeEnd("ctx");
  2581. ][0],aClass,"session");
  2582. return self;
  2583. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2584. }, function($ctx1) {$ctx1.fill(self,"encapsulateVariable:withValue:in:",{aString:aString,anObject:anObject,aClass:aClass,compiler:compiler})});
  2585. //>>excludeEnd("ctx");
  2586. }; }),
  2587. $globals.Repl);
  2588. $core.addMethod(
  2589. $core.method({
  2590. selector: "eval:",
  2591. protocol: "actions",
  2592. //>>excludeStart("ide", pragmas.excludeIdeData);
  2593. args: ["buffer"],
  2594. source: "eval: buffer\x0a\x09^ self eval: buffer on: DoIt new.",
  2595. referencedClasses: ["DoIt"],
  2596. //>>excludeEnd("ide");
  2597. pragmas: [],
  2598. messageSends: ["eval:on:", "new"]
  2599. }, function ($methodClass){ return function (buffer){
  2600. var self=this,$self=this;
  2601. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2602. return $core.withContext(function($ctx1) {
  2603. //>>excludeEnd("ctx");
  2604. return $self._eval_on_(buffer,$recv($globals.DoIt)._new());
  2605. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2606. }, function($ctx1) {$ctx1.fill(self,"eval:",{buffer:buffer})});
  2607. //>>excludeEnd("ctx");
  2608. }; }),
  2609. $globals.Repl);
  2610. $core.addMethod(
  2611. $core.method({
  2612. selector: "eval:on:",
  2613. protocol: "actions",
  2614. //>>excludeStart("ide", pragmas.excludeIdeData);
  2615. args: ["buffer", "anObject"],
  2616. source: "eval: buffer on: anObject\x0a\x09| result |\x0a\x09buffer ifNotEmpty: [\x0a\x09\x09[result := Compiler new evaluateExpression: buffer on: anObject]\x0a\x09\x09\x09tryIfTrue: [ :e | (Smalltalk isError: e) not or: [ e context isNil ] ]\x0a\x09\x09\x09catch: [ :e | process stdout write: e jsStack ]].\x0a\x09^ result",
  2617. referencedClasses: ["Compiler", "Smalltalk"],
  2618. //>>excludeEnd("ide");
  2619. pragmas: [],
  2620. messageSends: ["ifNotEmpty:", "tryIfTrue:catch:", "evaluateExpression:on:", "new", "or:", "not", "isError:", "isNil", "context", "write:", "stdout", "jsStack"]
  2621. }, function ($methodClass){ return function (buffer,anObject){
  2622. var self=this,$self=this;
  2623. var result;
  2624. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2625. return $core.withContext(function($ctx1) {
  2626. //>>excludeEnd("ctx");
  2627. $recv(buffer)._ifNotEmpty_((function(){
  2628. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2629. return $core.withContext(function($ctx2) {
  2630. //>>excludeEnd("ctx");
  2631. return $recv((function(){
  2632. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2633. return $core.withContext(function($ctx3) {
  2634. //>>excludeEnd("ctx");
  2635. result=$recv($recv($globals.Compiler)._new())._evaluateExpression_on_(buffer,anObject);
  2636. return result;
  2637. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2638. }, function($ctx3) {$ctx3.fillBlock({},$ctx2,2)});
  2639. //>>excludeEnd("ctx");
  2640. }))._tryIfTrue_catch_((function(e){
  2641. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2642. return $core.withContext(function($ctx3) {
  2643. //>>excludeEnd("ctx");
  2644. return $recv($recv($recv($globals.Smalltalk)._isError_(e))._not())._or_((function(){
  2645. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2646. return $core.withContext(function($ctx4) {
  2647. //>>excludeEnd("ctx");
  2648. return $recv($recv(e)._context())._isNil();
  2649. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2650. }, function($ctx4) {$ctx4.fillBlock({},$ctx3,4)});
  2651. //>>excludeEnd("ctx");
  2652. }));
  2653. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2654. }, function($ctx3) {$ctx3.fillBlock({e:e},$ctx2,3)});
  2655. //>>excludeEnd("ctx");
  2656. }),(function(e){
  2657. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2658. return $core.withContext(function($ctx3) {
  2659. //>>excludeEnd("ctx");
  2660. return $recv($recv(process)._stdout())._write_($recv(e)._jsStack());
  2661. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2662. }, function($ctx3) {$ctx3.fillBlock({e:e},$ctx2,5)});
  2663. //>>excludeEnd("ctx");
  2664. }));
  2665. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2666. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)});
  2667. //>>excludeEnd("ctx");
  2668. }));
  2669. return result;
  2670. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2671. }, function($ctx1) {$ctx1.fill(self,"eval:on:",{buffer:buffer,anObject:anObject,result:result})});
  2672. //>>excludeEnd("ctx");
  2673. }; }),
  2674. $globals.Repl);
  2675. $core.addMethod(
  2676. $core.method({
  2677. selector: "executeCommand:",
  2678. protocol: "private",
  2679. //>>excludeStart("ide", pragmas.excludeIdeData);
  2680. args: ["aString"],
  2681. 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",
  2682. referencedClasses: [],
  2683. //>>excludeEnd("ide");
  2684. pragmas: [],
  2685. messageSends: ["keysAndValuesDo:", "commands", "ifTrue:", "includes:", "value"]
  2686. }, function ($methodClass){ return function (aString){
  2687. var self=this,$self=this;
  2688. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2689. return $core.withContext(function($ctx1) {
  2690. //>>excludeEnd("ctx");
  2691. var $early={};
  2692. try {
  2693. $recv($self._commands())._keysAndValuesDo_((function(names,cmd){
  2694. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2695. return $core.withContext(function($ctx2) {
  2696. //>>excludeEnd("ctx");
  2697. if($core.assert($recv(names)._includes_(aString))){
  2698. $recv(cmd)._value();
  2699. throw $early=[true];
  2700. }
  2701. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2702. }, function($ctx2) {$ctx2.fillBlock({names:names,cmd:cmd},$ctx1,1)});
  2703. //>>excludeEnd("ctx");
  2704. }));
  2705. return false;
  2706. }
  2707. catch(e) {if(e===$early)return e[0]; throw e}
  2708. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2709. }, function($ctx1) {$ctx1.fill(self,"executeCommand:",{aString:aString})});
  2710. //>>excludeEnd("ctx");
  2711. }; }),
  2712. $globals.Repl);
  2713. $core.addMethod(
  2714. $core.method({
  2715. selector: "initialize",
  2716. protocol: "initialization",
  2717. //>>excludeStart("ide", pragmas.excludeIdeData);
  2718. args: [],
  2719. source: "initialize\x0a\x09super initialize.\x0a\x09session := DoIt new.\x0a\x09readline := require value: 'readline'.\x0a\x09util := require value: 'util'.\x0a\x09self setupCommands",
  2720. referencedClasses: ["DoIt"],
  2721. //>>excludeEnd("ide");
  2722. pragmas: [],
  2723. messageSends: ["initialize", "new", "value:", "setupCommands"]
  2724. }, function ($methodClass){ return function (){
  2725. var self=this,$self=this;
  2726. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2727. return $core.withContext(function($ctx1) {
  2728. //>>excludeEnd("ctx");
  2729. [(
  2730. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2731. $ctx1.supercall = true,
  2732. //>>excludeEnd("ctx");
  2733. ($methodClass.superclass||$boot.nilAsClass).fn.prototype._initialize.call($self))
  2734. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2735. ,$ctx1.supercall = false
  2736. //>>excludeEnd("ctx");
  2737. ][0];
  2738. $self.session=$recv($globals.DoIt)._new();
  2739. $self.readline=[$recv(require)._value_("readline")
  2740. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2741. ,$ctx1.sendIdx["value:"]=1
  2742. //>>excludeEnd("ctx");
  2743. ][0];
  2744. $self.util=$recv(require)._value_("util");
  2745. $self._setupCommands();
  2746. return self;
  2747. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2748. }, function($ctx1) {$ctx1.fill(self,"initialize",{})});
  2749. //>>excludeEnd("ctx");
  2750. }; }),
  2751. $globals.Repl);
  2752. $core.addMethod(
  2753. $core.method({
  2754. selector: "instanceVariableNamesFor:",
  2755. protocol: "private",
  2756. //>>excludeStart("ide", pragmas.excludeIdeData);
  2757. args: ["aClass"],
  2758. 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]",
  2759. referencedClasses: [],
  2760. //>>excludeEnd("ide");
  2761. pragmas: [],
  2762. messageSends: ["ifNotNil:ifNil:", "superclass", "copyWithAll:", "instanceVariableNames", "instanceVariableNamesFor:"]
  2763. }, function ($methodClass){ return function (aClass){
  2764. var self=this,$self=this;
  2765. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2766. return $core.withContext(function($ctx1) {
  2767. //>>excludeEnd("ctx");
  2768. var $1;
  2769. $1=[$recv(aClass)._superclass()
  2770. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2771. ,$ctx1.sendIdx["superclass"]=1
  2772. //>>excludeEnd("ctx");
  2773. ][0];
  2774. if($1 == null || $1.a$nil){
  2775. return $recv(aClass)._instanceVariableNames();
  2776. } else {
  2777. return $recv([$recv(aClass)._instanceVariableNames()
  2778. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2779. ,$ctx1.sendIdx["instanceVariableNames"]=1
  2780. //>>excludeEnd("ctx");
  2781. ][0])._copyWithAll_($self._instanceVariableNamesFor_($recv(aClass)._superclass()));
  2782. }
  2783. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2784. }, function($ctx1) {$ctx1.fill(self,"instanceVariableNamesFor:",{aClass:aClass})});
  2785. //>>excludeEnd("ctx");
  2786. }; }),
  2787. $globals.Repl);
  2788. $core.addMethod(
  2789. $core.method({
  2790. selector: "isIdentifier:",
  2791. protocol: "private",
  2792. //>>excludeStart("ide", pragmas.excludeIdeData);
  2793. args: ["aString"],
  2794. source: "isIdentifier: aString\x0a\x09^ aString match: '^[a-z_]\x5cw*$' asRegexp",
  2795. referencedClasses: [],
  2796. //>>excludeEnd("ide");
  2797. pragmas: [],
  2798. messageSends: ["match:", "asRegexp"]
  2799. }, function ($methodClass){ return function (aString){
  2800. var self=this,$self=this;
  2801. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2802. return $core.withContext(function($ctx1) {
  2803. //>>excludeEnd("ctx");
  2804. return $recv(aString)._match_("^[a-z_]\x5cw*$"._asRegexp());
  2805. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2806. }, function($ctx1) {$ctx1.fill(self,"isIdentifier:",{aString:aString})});
  2807. //>>excludeEnd("ctx");
  2808. }; }),
  2809. $globals.Repl);
  2810. $core.addMethod(
  2811. $core.method({
  2812. selector: "isVariableDefined:",
  2813. protocol: "private",
  2814. //>>excludeStart("ide", pragmas.excludeIdeData);
  2815. args: ["aString"],
  2816. source: "isVariableDefined: aString\x0a\x09^ (self instanceVariableNamesFor: session class) includes: aString",
  2817. referencedClasses: [],
  2818. //>>excludeEnd("ide");
  2819. pragmas: [],
  2820. messageSends: ["includes:", "instanceVariableNamesFor:", "class"]
  2821. }, function ($methodClass){ return function (aString){
  2822. var self=this,$self=this;
  2823. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2824. return $core.withContext(function($ctx1) {
  2825. //>>excludeEnd("ctx");
  2826. return $recv($self._instanceVariableNamesFor_($recv($self.session)._class()))._includes_(aString);
  2827. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2828. }, function($ctx1) {$ctx1.fill(self,"isVariableDefined:",{aString:aString})});
  2829. //>>excludeEnd("ctx");
  2830. }; }),
  2831. $globals.Repl);
  2832. $core.addMethod(
  2833. $core.method({
  2834. selector: "nextResultName",
  2835. protocol: "private",
  2836. //>>excludeStart("ide", pragmas.excludeIdeData);
  2837. args: [],
  2838. source: "nextResultName\x0a\x09resultCount := resultCount\x0a \x09ifNotNil: [resultCount + 1]\x0a \x09ifNil: [1].\x0a ^ 'res', resultCount asString",
  2839. referencedClasses: [],
  2840. //>>excludeEnd("ide");
  2841. pragmas: [],
  2842. messageSends: ["ifNotNil:ifNil:", "+", ",", "asString"]
  2843. }, function ($methodClass){ return function (){
  2844. var self=this,$self=this;
  2845. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2846. return $core.withContext(function($ctx1) {
  2847. //>>excludeEnd("ctx");
  2848. var $1;
  2849. $1=$self.resultCount;
  2850. if($1 == null || $1.a$nil){
  2851. $self.resultCount=(1);
  2852. } else {
  2853. $self.resultCount=$recv($self.resultCount).__plus((1));
  2854. }
  2855. return "res".__comma($recv($self.resultCount)._asString());
  2856. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2857. }, function($ctx1) {$ctx1.fill(self,"nextResultName",{})});
  2858. //>>excludeEnd("ctx");
  2859. }; }),
  2860. $globals.Repl);
  2861. $core.addMethod(
  2862. $core.method({
  2863. selector: "onKeyPress:",
  2864. protocol: "private",
  2865. //>>excludeStart("ide", pragmas.excludeIdeData);
  2866. args: ["key"],
  2867. source: "onKeyPress: key\x0a\x09(key ctrl and: [key name = 'l'])\x0a\x09\x09ifTrue: [self clearScreen]",
  2868. referencedClasses: [],
  2869. //>>excludeEnd("ide");
  2870. pragmas: [],
  2871. messageSends: ["ifTrue:", "and:", "ctrl", "=", "name", "clearScreen"]
  2872. }, function ($methodClass){ return function (key){
  2873. var self=this,$self=this;
  2874. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2875. return $core.withContext(function($ctx1) {
  2876. //>>excludeEnd("ctx");
  2877. if($core.assert($recv($recv(key)._ctrl())._and_((function(){
  2878. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2879. return $core.withContext(function($ctx2) {
  2880. //>>excludeEnd("ctx");
  2881. return $recv($recv(key)._name()).__eq("l");
  2882. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2883. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)});
  2884. //>>excludeEnd("ctx");
  2885. })))){
  2886. $self._clearScreen();
  2887. }
  2888. return self;
  2889. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2890. }, function($ctx1) {$ctx1.fill(self,"onKeyPress:",{key:key})});
  2891. //>>excludeEnd("ctx");
  2892. }; }),
  2893. $globals.Repl);
  2894. $core.addMethod(
  2895. $core.method({
  2896. selector: "parseAssignment:do:",
  2897. protocol: "private",
  2898. //>>excludeStart("ide", pragmas.excludeIdeData);
  2899. args: ["aString", "aBlock"],
  2900. 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 ]",
  2901. referencedClasses: [],
  2902. //>>excludeEnd("ide");
  2903. pragmas: [],
  2904. messageSends: ["collect:", "tokenize:", "trimBoth", "ifTrue:ifFalse:", "and:", "=", "size", "isIdentifier:", "first", "value:value:", "last"]
  2905. }, function ($methodClass){ return function (aString,aBlock){
  2906. var self=this,$self=this;
  2907. var assignment;
  2908. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2909. return $core.withContext(function($ctx1) {
  2910. //>>excludeEnd("ctx");
  2911. assignment=$recv($recv(aString)._tokenize_(":="))._collect_((function(s){
  2912. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2913. return $core.withContext(function($ctx2) {
  2914. //>>excludeEnd("ctx");
  2915. return $recv(s)._trimBoth();
  2916. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2917. }, function($ctx2) {$ctx2.fillBlock({s:s},$ctx1,1)});
  2918. //>>excludeEnd("ctx");
  2919. }));
  2920. if($core.assert($recv($recv($recv(assignment)._size()).__eq((2)))._and_((function(){
  2921. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2922. return $core.withContext(function($ctx2) {
  2923. //>>excludeEnd("ctx");
  2924. return $self._isIdentifier_([$recv(assignment)._first()
  2925. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2926. ,$ctx2.sendIdx["first"]=1
  2927. //>>excludeEnd("ctx");
  2928. ][0]);
  2929. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2930. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,2)});
  2931. //>>excludeEnd("ctx");
  2932. })))){
  2933. return [$recv(aBlock)._value_value_($recv(assignment)._first(),$recv(assignment)._last())
  2934. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2935. ,$ctx1.sendIdx["value:value:"]=1
  2936. //>>excludeEnd("ctx");
  2937. ][0];
  2938. } else {
  2939. return $recv(aBlock)._value_value_(nil,nil);
  2940. }
  2941. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2942. }, function($ctx1) {$ctx1.fill(self,"parseAssignment:do:",{aString:aString,aBlock:aBlock,assignment:assignment})});
  2943. //>>excludeEnd("ctx");
  2944. }; }),
  2945. $globals.Repl);
  2946. $core.addMethod(
  2947. $core.method({
  2948. selector: "presentResultNamed:withValue:",
  2949. protocol: "private",
  2950. //>>excludeStart("ide", pragmas.excludeIdeData);
  2951. args: ["varName", "value"],
  2952. source: "presentResultNamed: varName withValue: value\x0a\x09Transcript show: varName, ': ', value class name, ' = ', value asString; cr.\x0a\x09interface prompt",
  2953. referencedClasses: ["Transcript"],
  2954. //>>excludeEnd("ide");
  2955. pragmas: [],
  2956. messageSends: ["show:", ",", "name", "class", "asString", "cr", "prompt"]
  2957. }, function ($methodClass){ return function (varName,value){
  2958. var self=this,$self=this;
  2959. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2960. return $core.withContext(function($ctx1) {
  2961. //>>excludeEnd("ctx");
  2962. var $1;
  2963. $1=$globals.Transcript;
  2964. $recv($1)._show_([$recv([$recv([$recv($recv(varName).__comma(": ")).__comma($recv($recv(value)._class())._name())
  2965. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2966. ,$ctx1.sendIdx[","]=3
  2967. //>>excludeEnd("ctx");
  2968. ][0]).__comma(" = ")
  2969. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2970. ,$ctx1.sendIdx[","]=2
  2971. //>>excludeEnd("ctx");
  2972. ][0]).__comma($recv(value)._asString())
  2973. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2974. ,$ctx1.sendIdx[","]=1
  2975. //>>excludeEnd("ctx");
  2976. ][0]);
  2977. $recv($1)._cr();
  2978. $recv($self.interface)._prompt();
  2979. return self;
  2980. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2981. }, function($ctx1) {$ctx1.fill(self,"presentResultNamed:withValue:",{varName:varName,value:value})});
  2982. //>>excludeEnd("ctx");
  2983. }; }),
  2984. $globals.Repl);
  2985. $core.addMethod(
  2986. $core.method({
  2987. selector: "printWelcome",
  2988. protocol: "actions",
  2989. //>>excludeStart("ide", pragmas.excludeIdeData);
  2990. args: [],
  2991. source: "printWelcome\x0a\x09Transcript show: 'Type :q to exit.'; cr.",
  2992. referencedClasses: ["Transcript"],
  2993. //>>excludeEnd("ide");
  2994. pragmas: [],
  2995. messageSends: ["show:", "cr"]
  2996. }, function ($methodClass){ return function (){
  2997. var self=this,$self=this;
  2998. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  2999. return $core.withContext(function($ctx1) {
  3000. //>>excludeEnd("ctx");
  3001. var $1;
  3002. $1=$globals.Transcript;
  3003. $recv($1)._show_("Type :q to exit.");
  3004. $recv($1)._cr();
  3005. return self;
  3006. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  3007. }, function($ctx1) {$ctx1.fill(self,"printWelcome",{})});
  3008. //>>excludeEnd("ctx");
  3009. }; }),
  3010. $globals.Repl);
  3011. $core.addMethod(
  3012. $core.method({
  3013. selector: "processLine:",
  3014. protocol: "private",
  3015. //>>excludeStart("ide", pragmas.excludeIdeData);
  3016. args: ["buffer"],
  3017. 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]]",
  3018. referencedClasses: [],
  3019. //>>excludeEnd("ide");
  3020. pragmas: [],
  3021. messageSends: ["presentResultNamed:withValue:", "ifFalse:", "executeCommand:", "ifTrue:ifFalse:", "isVariableDefined:", "value:value:", "perform:", "assignNewVariable:do:"]
  3022. }, function ($methodClass){ return function (buffer){
  3023. var self=this,$self=this;
  3024. var show;
  3025. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  3026. return $core.withContext(function($ctx1) {
  3027. //>>excludeEnd("ctx");
  3028. show=(function(varName,value){
  3029. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  3030. return $core.withContext(function($ctx2) {
  3031. //>>excludeEnd("ctx");
  3032. return $self._presentResultNamed_withValue_(varName,value);
  3033. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  3034. }, function($ctx2) {$ctx2.fillBlock({varName:varName,value:value},$ctx1,1)});
  3035. //>>excludeEnd("ctx");
  3036. });
  3037. if(!$core.assert($self._executeCommand_(buffer))){
  3038. if($core.assert($self._isVariableDefined_(buffer))){
  3039. $recv(show)._value_value_(buffer,$recv($self.session)._perform_(buffer));
  3040. } else {
  3041. $self._assignNewVariable_do_(buffer,show);
  3042. }
  3043. }
  3044. return self;
  3045. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  3046. }, function($ctx1) {$ctx1.fill(self,"processLine:",{buffer:buffer,show:show})});
  3047. //>>excludeEnd("ctx");
  3048. }; }),
  3049. $globals.Repl);
  3050. $core.addMethod(
  3051. $core.method({
  3052. selector: "prompt",
  3053. protocol: "accessing",
  3054. //>>excludeStart("ide", pragmas.excludeIdeData);
  3055. args: [],
  3056. source: "prompt\x0a\x09^ 'amber >> '",
  3057. referencedClasses: [],
  3058. //>>excludeEnd("ide");
  3059. pragmas: [],
  3060. messageSends: []
  3061. }, function ($methodClass){ return function (){
  3062. var self=this,$self=this;
  3063. return "amber >> ";
  3064. }; }),
  3065. $globals.Repl);
  3066. $core.addMethod(
  3067. $core.method({
  3068. selector: "setPreviousVariablesFor:from:",
  3069. protocol: "private",
  3070. //>>excludeStart("ide", pragmas.excludeIdeData);
  3071. args: ["newObject", "oldObject"],
  3072. source: "setPreviousVariablesFor: newObject from: oldObject\x0a\x09(self instanceVariableNamesFor: oldObject class) do: [:each |\x0a\x09\x09newObject perform: each, ':' withArguments: {oldObject perform: each}].",
  3073. referencedClasses: [],
  3074. //>>excludeEnd("ide");
  3075. pragmas: [],
  3076. messageSends: ["do:", "instanceVariableNamesFor:", "class", "perform:withArguments:", ",", "perform:"]
  3077. }, function ($methodClass){ return function (newObject,oldObject){
  3078. var self=this,$self=this;
  3079. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  3080. return $core.withContext(function($ctx1) {
  3081. //>>excludeEnd("ctx");
  3082. $recv($self._instanceVariableNamesFor_($recv(oldObject)._class()))._do_((function(each){
  3083. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  3084. return $core.withContext(function($ctx2) {
  3085. //>>excludeEnd("ctx");
  3086. return $recv(newObject)._perform_withArguments_($recv(each).__comma(":"),[$recv(oldObject)._perform_(each)]);
  3087. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  3088. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)});
  3089. //>>excludeEnd("ctx");
  3090. }));
  3091. return self;
  3092. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  3093. }, function($ctx1) {$ctx1.fill(self,"setPreviousVariablesFor:from:",{newObject:newObject,oldObject:oldObject})});
  3094. //>>excludeEnd("ctx");
  3095. }; }),
  3096. $globals.Repl);
  3097. $core.addMethod(
  3098. $core.method({
  3099. selector: "setPrompt",
  3100. protocol: "actions",
  3101. //>>excludeStart("ide", pragmas.excludeIdeData);
  3102. args: [],
  3103. source: "setPrompt\x0a\x09interface setPrompt: self prompt",
  3104. referencedClasses: [],
  3105. //>>excludeEnd("ide");
  3106. pragmas: [],
  3107. messageSends: ["setPrompt:", "prompt"]
  3108. }, function ($methodClass){ return function (){
  3109. var self=this,$self=this;
  3110. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  3111. return $core.withContext(function($ctx1) {
  3112. //>>excludeEnd("ctx");
  3113. $recv($self.interface)._setPrompt_($self._prompt());
  3114. return self;
  3115. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  3116. }, function($ctx1) {$ctx1.fill(self,"setPrompt",{})});
  3117. //>>excludeEnd("ctx");
  3118. }; }),
  3119. $globals.Repl);
  3120. $core.addMethod(
  3121. $core.method({
  3122. selector: "setupCommands",
  3123. protocol: "initialization",
  3124. //>>excludeStart("ide", pragmas.excludeIdeData);
  3125. args: [],
  3126. source: "setupCommands\x0a\x09commands := Dictionary from: {\x0a\x09\x09{':q'} -> [process exit].\x0a\x09\x09{''} -> [interface prompt]}",
  3127. referencedClasses: ["Dictionary"],
  3128. //>>excludeEnd("ide");
  3129. pragmas: [],
  3130. messageSends: ["from:", "->", "exit", "prompt"]
  3131. }, function ($methodClass){ return function (){
  3132. var self=this,$self=this;
  3133. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  3134. return $core.withContext(function($ctx1) {
  3135. //>>excludeEnd("ctx");
  3136. $self.commands=$recv($globals.Dictionary)._from_([[$recv([":q"]).__minus_gt((function(){
  3137. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  3138. return $core.withContext(function($ctx2) {
  3139. //>>excludeEnd("ctx");
  3140. return $recv(process)._exit();
  3141. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  3142. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)});
  3143. //>>excludeEnd("ctx");
  3144. }))
  3145. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  3146. ,$ctx1.sendIdx["->"]=1
  3147. //>>excludeEnd("ctx");
  3148. ][0],$recv([""]).__minus_gt((function(){
  3149. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  3150. return $core.withContext(function($ctx2) {
  3151. //>>excludeEnd("ctx");
  3152. return $recv($self.interface)._prompt();
  3153. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  3154. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,2)});
  3155. //>>excludeEnd("ctx");
  3156. }))]);
  3157. return self;
  3158. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  3159. }, function($ctx1) {$ctx1.fill(self,"setupCommands",{})});
  3160. //>>excludeEnd("ctx");
  3161. }; }),
  3162. $globals.Repl);
  3163. $core.addMethod(
  3164. $core.method({
  3165. selector: "setupHotkeys",
  3166. protocol: "initialization",
  3167. //>>excludeStart("ide", pragmas.excludeIdeData);
  3168. args: [],
  3169. source: "setupHotkeys\x0a\x09process stdin on: 'keypress' do: [:s :key | key ifNotNil: [self onKeyPress: key]].",
  3170. referencedClasses: [],
  3171. //>>excludeEnd("ide");
  3172. pragmas: [],
  3173. messageSends: ["on:do:", "stdin", "ifNotNil:", "onKeyPress:"]
  3174. }, function ($methodClass){ return function (){
  3175. var self=this,$self=this;
  3176. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  3177. return $core.withContext(function($ctx1) {
  3178. //>>excludeEnd("ctx");
  3179. $recv($recv(process)._stdin())._on_do_("keypress",(function(s,key){
  3180. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  3181. return $core.withContext(function($ctx2) {
  3182. //>>excludeEnd("ctx");
  3183. if(key == null || key.a$nil){
  3184. return key;
  3185. } else {
  3186. return $self._onKeyPress_(key);
  3187. }
  3188. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  3189. }, function($ctx2) {$ctx2.fillBlock({s:s,key:key},$ctx1,1)});
  3190. //>>excludeEnd("ctx");
  3191. }));
  3192. return self;
  3193. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  3194. }, function($ctx1) {$ctx1.fill(self,"setupHotkeys",{})});
  3195. //>>excludeEnd("ctx");
  3196. }; }),
  3197. $globals.Repl);
  3198. $core.addMethod(
  3199. $core.method({
  3200. selector: "subclass:withVariable:",
  3201. protocol: "private",
  3202. //>>excludeStart("ide", pragmas.excludeIdeData);
  3203. args: ["aClass", "varName"],
  3204. 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'",
  3205. referencedClasses: ["ClassBuilder"],
  3206. //>>excludeEnd("ide");
  3207. pragmas: [],
  3208. messageSends: ["addSubclassOf:named:instanceVariableNames:package:", "new", "asSymbol", "subclassNameFor:"]
  3209. }, function ($methodClass){ return function (aClass,varName){
  3210. var self=this,$self=this;
  3211. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  3212. return $core.withContext(function($ctx1) {
  3213. //>>excludeEnd("ctx");
  3214. return $recv($recv($globals.ClassBuilder)._new())._addSubclassOf_named_instanceVariableNames_package_(aClass,$recv($self._subclassNameFor_(aClass))._asSymbol(),[varName],"Compiler-Core");
  3215. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  3216. }, function($ctx1) {$ctx1.fill(self,"subclass:withVariable:",{aClass:aClass,varName:varName})});
  3217. //>>excludeEnd("ctx");
  3218. }; }),
  3219. $globals.Repl);
  3220. $core.addMethod(
  3221. $core.method({
  3222. selector: "subclassNameFor:",
  3223. protocol: "private",
  3224. //>>excludeStart("ide", pragmas.excludeIdeData);
  3225. args: ["aClass"],
  3226. 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'].",
  3227. referencedClasses: [],
  3228. //>>excludeEnd("ide");
  3229. pragmas: [],
  3230. messageSends: ["ifNotNil:ifNil:", "matchesOf:", "name", "+", "asNumber", "first", "replaceRegexp:with:", "asRegexp", "asString", ","]
  3231. }, function ($methodClass){ return function (aClass){
  3232. var self=this,$self=this;
  3233. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  3234. return $core.withContext(function($ctx1) {
  3235. //>>excludeEnd("ctx");
  3236. var $1;
  3237. $1=[$recv([$recv(aClass)._name()
  3238. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  3239. ,$ctx1.sendIdx["name"]=1
  3240. //>>excludeEnd("ctx");
  3241. ][0])._matchesOf_("\x5cd+$")
  3242. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  3243. ,$ctx1.sendIdx["matchesOf:"]=1
  3244. //>>excludeEnd("ctx");
  3245. ][0];
  3246. if($1 == null || $1.a$nil){
  3247. return $recv($recv(aClass)._name()).__comma("2");
  3248. } else {
  3249. var counter;
  3250. counter=$recv($recv($recv($recv([$recv(aClass)._name()
  3251. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  3252. ,$ctx1.sendIdx["name"]=2
  3253. //>>excludeEnd("ctx");
  3254. ][0])._matchesOf_("\x5cd+$"))._first())._asNumber()).__plus((1));
  3255. return $recv([$recv(aClass)._name()
  3256. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  3257. ,$ctx1.sendIdx["name"]=3
  3258. //>>excludeEnd("ctx");
  3259. ][0])._replaceRegexp_with_("\x5cd+$"._asRegexp(),$recv(counter)._asString());
  3260. }
  3261. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  3262. }, function($ctx1) {$ctx1.fill(self,"subclassNameFor:",{aClass:aClass})});
  3263. //>>excludeEnd("ctx");
  3264. }; }),
  3265. $globals.Repl);
  3266. $core.addMethod(
  3267. $core.method({
  3268. selector: "main",
  3269. protocol: "initialization",
  3270. //>>excludeStart("ide", pragmas.excludeIdeData);
  3271. args: [],
  3272. source: "main\x0a\x09self new createInterface",
  3273. referencedClasses: [],
  3274. //>>excludeEnd("ide");
  3275. pragmas: [],
  3276. messageSends: ["createInterface", "new"]
  3277. }, function ($methodClass){ return function (){
  3278. var self=this,$self=this;
  3279. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  3280. return $core.withContext(function($ctx1) {
  3281. //>>excludeEnd("ctx");
  3282. $recv($self._new())._createInterface();
  3283. return self;
  3284. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  3285. }, function($ctx1) {$ctx1.fill(self,"main",{})});
  3286. //>>excludeEnd("ctx");
  3287. }; }),
  3288. $globals.Repl.a$cls);
  3289. });