AmberCli.js 160 KB

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