1
0

AmberCli.deploy.js 65 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348
  1. smalltalk.addPackage('AmberCli');
  2. smalltalk.addClass('AmberCli', smalltalk.Object, [], 'AmberCli');
  3. smalltalk.addMethod(
  4. smalltalk.method({
  5. selector: "commandLineSwitches",
  6. fn: function (){
  7. var self=this;
  8. var switches;
  9. return smalltalk.withContext(function($ctx1) {
  10. var $1;
  11. switches=_st(_st(self._class())._methodsInProtocol_("commands"))._collect_((function(each){
  12. return smalltalk.withContext(function($ctx2) {
  13. return _st(each)._selector();
  14. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
  15. switches=_st(switches)._select_((function(each){
  16. return smalltalk.withContext(function($ctx2) {
  17. return _st(each)._match_("^[^:]*:$");
  18. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
  19. switches=_st(switches)._collect_((function(each){
  20. return smalltalk.withContext(function($ctx2) {
  21. return _st(_st(_st(each)._allButLast())._replace_with_("([A-Z])","-$1"))._asLowercase();
  22. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
  23. $1=switches;
  24. return $1;
  25. }, function($ctx1) {$ctx1.fill(self,"commandLineSwitches",{switches:switches},smalltalk.AmberCli.klass)})},
  26. messageSends: ["collect:", "selector", "methodsInProtocol:", "class", "select:", "match:", "asLowercase", "replace:with:", "allButLast"]}),
  27. smalltalk.AmberCli.klass);
  28. smalltalk.addMethod(
  29. smalltalk.method({
  30. selector: "handleArguments:",
  31. fn: function (args){
  32. var self=this;
  33. var selector;
  34. function $Array(){return smalltalk.Array||(typeof Array=="undefined"?nil:Array)}
  35. return smalltalk.withContext(function($ctx1) {
  36. selector=self._selectorForCommandLineSwitch_(_st(args)._first());
  37. _st(args)._remove_(_st(args)._first());
  38. self._perform_withArguments_(selector,_st($Array())._with_(args));
  39. return self}, function($ctx1) {$ctx1.fill(self,"handleArguments:",{args:args,selector:selector},smalltalk.AmberCli.klass)})},
  40. messageSends: ["selectorForCommandLineSwitch:", "first", "remove:", "perform:withArguments:", "with:"]}),
  41. smalltalk.AmberCli.klass);
  42. smalltalk.addMethod(
  43. smalltalk.method({
  44. selector: "help:",
  45. fn: function (args){
  46. var self=this;
  47. return smalltalk.withContext(function($ctx1) {
  48. _st(console)._log_("Available Commands:");
  49. _st(self._commandLineSwitches())._do_((function(each){
  50. return smalltalk.withContext(function($ctx2) {
  51. return _st(console)._log_(each);
  52. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
  53. return self}, function($ctx1) {$ctx1.fill(self,"help:",{args:args},smalltalk.AmberCli.klass)})},
  54. messageSends: ["log:", "do:", "commandLineSwitches"]}),
  55. smalltalk.AmberCli.klass);
  56. smalltalk.addMethod(
  57. smalltalk.method({
  58. selector: "main",
  59. fn: function (){
  60. var self=this;
  61. var args,nodeMinorVersion;
  62. return smalltalk.withContext(function($ctx1) {
  63. var $1,$2,$3;
  64. nodeMinorVersion=_st(_st(_st(_st(process)._version())._tokenize_("."))._second())._asNumber();
  65. $1=_st(nodeMinorVersion).__lt((8));
  66. if(smalltalk.assert($1)){
  67. _st(console)._log_("You are currently using Node.js ".__comma(_st(process)._version()));
  68. _st(console)._log_("Required is at least Node.js v0.8.x or greater.");
  69. return (-1);
  70. };
  71. args=_st(process)._argv();
  72. _st(args)._removeFrom_to_((1),(3));
  73. $2=_st(args)._isEmpty();
  74. if(smalltalk.assert($2)){
  75. self._help_(nil);
  76. } else {
  77. $3=self._handleArguments_(args);
  78. return $3;
  79. };
  80. return self}, function($ctx1) {$ctx1.fill(self,"main",{args:args,nodeMinorVersion:nodeMinorVersion},smalltalk.AmberCli.klass)})},
  81. messageSends: ["asNumber", "second", "tokenize:", "version", "ifTrue:", "log:", ",", "<", "argv", "removeFrom:to:", "ifTrue:ifFalse:", "help:", "handleArguments:", "isEmpty"]}),
  82. smalltalk.AmberCli.klass);
  83. smalltalk.addMethod(
  84. smalltalk.method({
  85. selector: "repl:",
  86. fn: function (args){
  87. var self=this;
  88. function $Repl(){return smalltalk.Repl||(typeof Repl=="undefined"?nil:Repl)}
  89. return smalltalk.withContext(function($ctx1) {
  90. var $1;
  91. $1=_st(_st($Repl())._new())._createInterface();
  92. return $1;
  93. }, function($ctx1) {$ctx1.fill(self,"repl:",{args:args},smalltalk.AmberCli.klass)})},
  94. messageSends: ["createInterface", "new"]}),
  95. smalltalk.AmberCli.klass);
  96. smalltalk.addMethod(
  97. smalltalk.method({
  98. selector: "selectorForCommandLineSwitch:",
  99. fn: function (aSwitch){
  100. var self=this;
  101. var command,selector;
  102. return smalltalk.withContext(function($ctx1) {
  103. var $1,$2;
  104. $1=_st(self._commandLineSwitches())._includes_(aSwitch);
  105. if(smalltalk.assert($1)){
  106. selector=_st(_st(aSwitch)._replace_with_("-[a-z]",(function(each){
  107. return smalltalk.withContext(function($ctx2) {
  108. return _st(_st(each)._second())._asUppercase();
  109. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}))).__comma(":");
  110. selector;
  111. } else {
  112. selector="help:";
  113. selector;
  114. };
  115. $2=selector;
  116. return $2;
  117. }, function($ctx1) {$ctx1.fill(self,"selectorForCommandLineSwitch:",{aSwitch:aSwitch,command:command,selector:selector},smalltalk.AmberCli.klass)})},
  118. messageSends: ["ifTrue:ifFalse:", ",", "replace:with:", "asUppercase", "second", "includes:", "commandLineSwitches"]}),
  119. smalltalk.AmberCli.klass);
  120. smalltalk.addMethod(
  121. smalltalk.method({
  122. selector: "serve:",
  123. fn: function (args){
  124. var self=this;
  125. function $FileServer(){return smalltalk.FileServer||(typeof FileServer=="undefined"?nil:FileServer)}
  126. return smalltalk.withContext(function($ctx1) {
  127. var $1;
  128. $1=_st(_st($FileServer())._createServerWithArguments_(args))._start();
  129. return $1;
  130. }, function($ctx1) {$ctx1.fill(self,"serve:",{args:args},smalltalk.AmberCli.klass)})},
  131. messageSends: ["start", "createServerWithArguments:"]}),
  132. smalltalk.AmberCli.klass);
  133. smalltalk.addClass('FileServer', smalltalk.Object, ['path', 'http', 'fs', 'url', 'host', 'port', 'basePath', 'util', 'username', 'password', 'fallbackPage'], 'AmberCli');
  134. smalltalk.addMethod(
  135. smalltalk.method({
  136. selector: "base64Decode:",
  137. fn: function (aString){
  138. var self=this;
  139. return smalltalk.withContext(function($ctx1) {
  140. return (new Buffer(aString, 'base64').toString());
  141. return self}, function($ctx1) {$ctx1.fill(self,"base64Decode:",{aString:aString},smalltalk.FileServer)})},
  142. messageSends: []}),
  143. smalltalk.FileServer);
  144. smalltalk.addMethod(
  145. smalltalk.method({
  146. selector: "basePath",
  147. fn: function (){
  148. var self=this;
  149. return smalltalk.withContext(function($ctx1) {
  150. var $2,$1;
  151. $2=self["@basePath"];
  152. if(($receiver = $2) == nil || $receiver == undefined){
  153. $1="./";
  154. } else {
  155. $1=$2;
  156. };
  157. return $1;
  158. }, function($ctx1) {$ctx1.fill(self,"basePath",{},smalltalk.FileServer)})},
  159. messageSends: ["ifNil:"]}),
  160. smalltalk.FileServer);
  161. smalltalk.addMethod(
  162. smalltalk.method({
  163. selector: "basePath:",
  164. fn: function (aString){
  165. var self=this;
  166. return smalltalk.withContext(function($ctx1) {
  167. self["@basePath"]=aString;
  168. return self}, function($ctx1) {$ctx1.fill(self,"basePath:",{aString:aString},smalltalk.FileServer)})},
  169. messageSends: []}),
  170. smalltalk.FileServer);
  171. smalltalk.addMethod(
  172. smalltalk.method({
  173. selector: "checkDirectoryLayout",
  174. fn: function (){
  175. var self=this;
  176. return smalltalk.withContext(function($ctx1) {
  177. var $1,$2,$3;
  178. $1=_st(self["@fs"])._existsSync_(_st(self._basePath()).__comma("index.html"));
  179. if(! smalltalk.assert($1)){
  180. _st(console)._warn_("Warning: project directory does not contain index.html");
  181. };
  182. $2=_st(self["@fs"])._existsSync_(_st(self._basePath()).__comma("st"));
  183. if(! smalltalk.assert($2)){
  184. _st(console)._warn_("Warning: project directory is missing an \x22st\x22 directory");
  185. };
  186. $3=_st(self["@fs"])._existsSync_(_st(self._basePath()).__comma("js"));
  187. if(! smalltalk.assert($3)){
  188. _st(console)._warn_("Warning: project directory is missing a \x22js\x22 directory");
  189. };
  190. return self}, function($ctx1) {$ctx1.fill(self,"checkDirectoryLayout",{},smalltalk.FileServer)})},
  191. messageSends: ["ifFalse:", "warn:", "existsSync:", ",", "basePath"]}),
  192. smalltalk.FileServer);
  193. smalltalk.addMethod(
  194. smalltalk.method({
  195. selector: "fallbackPage",
  196. fn: function (){
  197. var self=this;
  198. return smalltalk.withContext(function($ctx1) {
  199. var $1;
  200. $1=self["@fallbackPage"];
  201. return $1;
  202. }, function($ctx1) {$ctx1.fill(self,"fallbackPage",{},smalltalk.FileServer)})},
  203. messageSends: []}),
  204. smalltalk.FileServer);
  205. smalltalk.addMethod(
  206. smalltalk.method({
  207. selector: "fallbackPage:",
  208. fn: function (aString){
  209. var self=this;
  210. return smalltalk.withContext(function($ctx1) {
  211. self["@fallbackPage"]=aString;
  212. return self}, function($ctx1) {$ctx1.fill(self,"fallbackPage:",{aString:aString},smalltalk.FileServer)})},
  213. messageSends: []}),
  214. smalltalk.FileServer);
  215. smalltalk.addMethod(
  216. smalltalk.method({
  217. selector: "handleGETRequest:respondTo:",
  218. fn: function (aRequest,aResponse){
  219. var self=this;
  220. var uri,filename;
  221. return smalltalk.withContext(function($ctx1) {
  222. var $1;
  223. uri=_st(_st(self["@url"])._parse_(_st(aRequest)._url()))._pathname();
  224. filename=_st(self["@path"])._join_with_(self._basePath(),uri);
  225. _st(self["@fs"])._exists_do_(filename,(function(aBoolean){
  226. return smalltalk.withContext(function($ctx2) {
  227. $1=aBoolean;
  228. if(smalltalk.assert($1)){
  229. return self._respondFileNamed_to_(filename,aResponse);
  230. } else {
  231. return self._respondNotFoundTo_(aResponse);
  232. };
  233. }, function($ctx2) {$ctx2.fillBlock({aBoolean:aBoolean},$ctx1)})}));
  234. return self}, function($ctx1) {$ctx1.fill(self,"handleGETRequest:respondTo:",{aRequest:aRequest,aResponse:aResponse,uri:uri,filename:filename},smalltalk.FileServer)})},
  235. messageSends: ["pathname", "parse:", "url", "join:with:", "basePath", "exists:do:", "ifFalse:ifTrue:", "respondNotFoundTo:", "respondFileNamed:to:"]}),
  236. smalltalk.FileServer);
  237. smalltalk.addMethod(
  238. smalltalk.method({
  239. selector: "handleOPTIONSRequest:respondTo:",
  240. fn: function (aRequest,aResponse){
  241. var self=this;
  242. return smalltalk.withContext(function($ctx1) {
  243. _st(aResponse)._writeHead_options_((200),smalltalk.HashedCollection._from_(["Access-Control-Allow-Origin".__minus_gt("*"),"Access-Control-Allow-Methods".__minus_gt("GET, PUT, POST, DELETE, OPTIONS"),"Access-Control-Allow-Headers".__minus_gt("Content-Type, Accept"),"Content-Length".__minus_gt((0)),"Access-Control-Max-Age".__minus_gt((10))]));
  244. _st(aResponse)._end();
  245. return self}, function($ctx1) {$ctx1.fill(self,"handleOPTIONSRequest:respondTo:",{aRequest:aRequest,aResponse:aResponse},smalltalk.FileServer)})},
  246. messageSends: ["writeHead:options:", "->", "end"]}),
  247. smalltalk.FileServer);
  248. smalltalk.addMethod(
  249. smalltalk.method({
  250. selector: "handlePUTRequest:respondTo:",
  251. fn: function (aRequest,aResponse){
  252. var self=this;
  253. var file,stream;
  254. return smalltalk.withContext(function($ctx1) {
  255. var $1,$2;
  256. $1=self._isAuthenticated_(aRequest);
  257. if(! smalltalk.assert($1)){
  258. self._respondAuthenticationRequiredTo_(aResponse);
  259. return nil;
  260. };
  261. file=".".__comma(_st(aRequest)._url());
  262. stream=_st(self["@fs"])._createWriteStream_(file);
  263. _st(stream)._on_do_("error",(function(error){
  264. return smalltalk.withContext(function($ctx2) {
  265. _st(console)._warn_("Error creating WriteStream for file ".__comma(file));
  266. _st(console)._warn_(" Did you forget to create the necessary js/ or st/ directory in your project?");
  267. _st(console)._warn_(" The exact error is: ".__comma(error));
  268. return self._respondNotCreatedTo_(aResponse);
  269. }, function($ctx2) {$ctx2.fillBlock({error:error},$ctx1)})}));
  270. _st(stream)._on_do_("close",(function(){
  271. return smalltalk.withContext(function($ctx2) {
  272. return self._respondCreatedTo_(aResponse);
  273. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  274. _st(aRequest)._setEncoding_("utf8");
  275. _st(aRequest)._on_do_("data",(function(data){
  276. return smalltalk.withContext(function($ctx2) {
  277. return _st(stream)._write_(data);
  278. }, function($ctx2) {$ctx2.fillBlock({data:data},$ctx1)})}));
  279. _st(aRequest)._on_do_("end",(function(){
  280. return smalltalk.withContext(function($ctx2) {
  281. $2=_st(stream)._writable();
  282. if(smalltalk.assert($2)){
  283. return _st(stream)._end();
  284. };
  285. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  286. return self}, function($ctx1) {$ctx1.fill(self,"handlePUTRequest:respondTo:",{aRequest:aRequest,aResponse:aResponse,file:file,stream:stream},smalltalk.FileServer)})},
  287. messageSends: ["ifFalse:", "respondAuthenticationRequiredTo:", "isAuthenticated:", ",", "url", "createWriteStream:", "on:do:", "warn:", "respondNotCreatedTo:", "respondCreatedTo:", "setEncoding:", "write:", "ifTrue:", "end", "writable"]}),
  288. smalltalk.FileServer);
  289. smalltalk.addMethod(
  290. smalltalk.method({
  291. selector: "handleRequest:respondTo:",
  292. fn: function (aRequest,aResponse){
  293. var self=this;
  294. return smalltalk.withContext(function($ctx1) {
  295. var $1,$2,$3;
  296. $1=_st(_st(aRequest)._method()).__eq("PUT");
  297. if(smalltalk.assert($1)){
  298. self._handlePUTRequest_respondTo_(aRequest,aResponse);
  299. };
  300. $2=_st(_st(aRequest)._method()).__eq("GET");
  301. if(smalltalk.assert($2)){
  302. self._handleGETRequest_respondTo_(aRequest,aResponse);
  303. };
  304. $3=_st(_st(aRequest)._method()).__eq("OPTIONS");
  305. if(smalltalk.assert($3)){
  306. self._handleOPTIONSRequest_respondTo_(aRequest,aResponse);
  307. };
  308. return self}, function($ctx1) {$ctx1.fill(self,"handleRequest:respondTo:",{aRequest:aRequest,aResponse:aResponse},smalltalk.FileServer)})},
  309. messageSends: ["ifTrue:", "handlePUTRequest:respondTo:", "=", "method", "handleGETRequest:respondTo:", "handleOPTIONSRequest:respondTo:"]}),
  310. smalltalk.FileServer);
  311. smalltalk.addMethod(
  312. smalltalk.method({
  313. selector: "host",
  314. fn: function (){
  315. var self=this;
  316. return smalltalk.withContext(function($ctx1) {
  317. var $1;
  318. $1=self["@host"];
  319. return $1;
  320. }, function($ctx1) {$ctx1.fill(self,"host",{},smalltalk.FileServer)})},
  321. messageSends: []}),
  322. smalltalk.FileServer);
  323. smalltalk.addMethod(
  324. smalltalk.method({
  325. selector: "host:",
  326. fn: function (hostname){
  327. var self=this;
  328. return smalltalk.withContext(function($ctx1) {
  329. self["@host"]=hostname;
  330. return self}, function($ctx1) {$ctx1.fill(self,"host:",{hostname:hostname},smalltalk.FileServer)})},
  331. messageSends: []}),
  332. smalltalk.FileServer);
  333. smalltalk.addMethod(
  334. smalltalk.method({
  335. selector: "initialize",
  336. fn: function (){
  337. var self=this;
  338. return smalltalk.withContext(function($ctx1) {
  339. smalltalk.Object.fn.prototype._initialize.apply(_st(self), []);
  340. self["@path"]=self._require_("path");
  341. self["@http"]=self._require_("http");
  342. self["@fs"]=self._require_("fs");
  343. self["@util"]=self._require_("util");
  344. self["@url"]=self._require_("url");
  345. self["@host"]=_st(self._class())._defaultHost();
  346. self["@port"]=_st(self._class())._defaultPort();
  347. self["@username"]=nil;
  348. self["@password"]=nil;
  349. self["@fallbackPage"]=nil;
  350. return self}, function($ctx1) {$ctx1.fill(self,"initialize",{},smalltalk.FileServer)})},
  351. messageSends: ["initialize", "require:", "defaultHost", "class", "defaultPort"]}),
  352. smalltalk.FileServer);
  353. smalltalk.addMethod(
  354. smalltalk.method({
  355. selector: "isAuthenticated:",
  356. fn: function (aRequest){
  357. var self=this;
  358. var header,token,auth,parts;
  359. return smalltalk.withContext(function($ctx1) {
  360. var $1,$2,$3,$4,$5;
  361. $1=_st(_st(self["@username"])._isNil())._and_((function(){
  362. return smalltalk.withContext(function($ctx2) {
  363. return _st(self["@password"])._isNil();
  364. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  365. if(smalltalk.assert($1)){
  366. return true;
  367. };
  368. $2=_st(_st(aRequest)._headers())._at_("authorization");
  369. if(($receiver = $2) == nil || $receiver == undefined){
  370. header="";
  371. } else {
  372. header=$2;
  373. };
  374. $3=_st(header)._isEmpty();
  375. if(smalltalk.assert($3)){
  376. return false;
  377. } else {
  378. $4=_st(header)._tokenize_(" ");
  379. if(($receiver = $4) == nil || $receiver == undefined){
  380. token="";
  381. } else {
  382. token=$4;
  383. };
  384. token;
  385. auth=self._base64Decode_(_st(token)._at_((2)));
  386. auth;
  387. parts=_st(auth)._tokenize_(":");
  388. parts;
  389. $5=_st(_st(self["@username"]).__eq(_st(parts)._at_((1))))._and_((function(){
  390. return smalltalk.withContext(function($ctx2) {
  391. return _st(self["@password"]).__eq(_st(parts)._at_((2)));
  392. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  393. if(smalltalk.assert($5)){
  394. return true;
  395. } else {
  396. return false;
  397. };
  398. };
  399. return self}, function($ctx1) {$ctx1.fill(self,"isAuthenticated:",{aRequest:aRequest,header:header,token:token,auth:auth,parts:parts},smalltalk.FileServer)})},
  400. messageSends: ["ifTrue:", "and:", "isNil", "ifNil:", "at:", "headers", "ifTrue:ifFalse:", "tokenize:", "base64Decode:", "=", "isEmpty"]}),
  401. smalltalk.FileServer);
  402. smalltalk.addMethod(
  403. smalltalk.method({
  404. selector: "password:",
  405. fn: function (aPassword){
  406. var self=this;
  407. return smalltalk.withContext(function($ctx1) {
  408. self["@password"]=aPassword;
  409. return self}, function($ctx1) {$ctx1.fill(self,"password:",{aPassword:aPassword},smalltalk.FileServer)})},
  410. messageSends: []}),
  411. smalltalk.FileServer);
  412. smalltalk.addMethod(
  413. smalltalk.method({
  414. selector: "port",
  415. fn: function (){
  416. var self=this;
  417. return smalltalk.withContext(function($ctx1) {
  418. var $1;
  419. $1=self["@port"];
  420. return $1;
  421. }, function($ctx1) {$ctx1.fill(self,"port",{},smalltalk.FileServer)})},
  422. messageSends: []}),
  423. smalltalk.FileServer);
  424. smalltalk.addMethod(
  425. smalltalk.method({
  426. selector: "port:",
  427. fn: function (aNumber){
  428. var self=this;
  429. return smalltalk.withContext(function($ctx1) {
  430. self["@port"]=aNumber;
  431. return self}, function($ctx1) {$ctx1.fill(self,"port:",{aNumber:aNumber},smalltalk.FileServer)})},
  432. messageSends: []}),
  433. smalltalk.FileServer);
  434. smalltalk.addMethod(
  435. smalltalk.method({
  436. selector: "require:",
  437. fn: function (aModuleString){
  438. var self=this;
  439. return smalltalk.withContext(function($ctx1) {
  440. var $1;
  441. $1=_st(require)._value_(aModuleString);
  442. return $1;
  443. }, function($ctx1) {$ctx1.fill(self,"require:",{aModuleString:aModuleString},smalltalk.FileServer)})},
  444. messageSends: ["value:"]}),
  445. smalltalk.FileServer);
  446. smalltalk.addMethod(
  447. smalltalk.method({
  448. selector: "respondAuthenticationRequiredTo:",
  449. fn: function (aResponse){
  450. var self=this;
  451. return smalltalk.withContext(function($ctx1) {
  452. var $1,$2;
  453. $1=aResponse;
  454. _st($1)._writeHead_options_((401),smalltalk.HashedCollection._from_(["WWW-Authenticate".__minus_gt("Basic realm=\x22Secured Developer Area\x22")]));
  455. _st($1)._write_("<html><body>Authentication needed</body></html>");
  456. $2=_st($1)._end();
  457. return self}, function($ctx1) {$ctx1.fill(self,"respondAuthenticationRequiredTo:",{aResponse:aResponse},smalltalk.FileServer)})},
  458. messageSends: ["writeHead:options:", "->", "write:", "end"]}),
  459. smalltalk.FileServer);
  460. smalltalk.addMethod(
  461. smalltalk.method({
  462. selector: "respondCreatedTo:",
  463. fn: function (aResponse){
  464. var self=this;
  465. return smalltalk.withContext(function($ctx1) {
  466. var $1,$2;
  467. $1=aResponse;
  468. _st($1)._writeHead_options_((201),smalltalk.HashedCollection._from_(["Content-Type".__minus_gt("text/plain"),"Access-Control-Allow-Origin".__minus_gt("*")]));
  469. $2=_st($1)._end();
  470. return self}, function($ctx1) {$ctx1.fill(self,"respondCreatedTo:",{aResponse:aResponse},smalltalk.FileServer)})},
  471. messageSends: ["writeHead:options:", "->", "end"]}),
  472. smalltalk.FileServer);
  473. smalltalk.addMethod(
  474. smalltalk.method({
  475. selector: "respondFileNamed:to:",
  476. fn: function (aFilename,aResponse){
  477. var self=this;
  478. var type,filename;
  479. return smalltalk.withContext(function($ctx1) {
  480. var $1,$2,$3,$4,$5;
  481. filename=aFilename;
  482. $1=_st(_st(self["@fs"])._statSync_(aFilename))._isDirectory();
  483. if(smalltalk.assert($1)){
  484. filename=_st(filename).__comma("index.html");
  485. filename;
  486. };
  487. _st(self["@fs"])._readFile_do_(filename,(function(ex,file){
  488. return smalltalk.withContext(function($ctx2) {
  489. $2=_st(ex)._notNil();
  490. if(smalltalk.assert($2)){
  491. _st(console)._log_(_st(filename).__comma(" does not exist"));
  492. return self._respondInternalErrorTo_(aResponse);
  493. } else {
  494. type=_st(self._class())._mimeTypeFor_(filename);
  495. type;
  496. $3=_st(type).__eq("application/javascript");
  497. if(smalltalk.assert($3)){
  498. type=_st(type).__comma(";charset=utf-8");
  499. type;
  500. };
  501. $4=aResponse;
  502. _st($4)._writeHead_options_((200),smalltalk.HashedCollection._from_(["Content-Type".__minus_gt(type)]));
  503. _st($4)._write_encoding_(file,"binary");
  504. $5=_st($4)._end();
  505. return $5;
  506. };
  507. }, function($ctx2) {$ctx2.fillBlock({ex:ex,file:file},$ctx1)})}));
  508. return self}, function($ctx1) {$ctx1.fill(self,"respondFileNamed:to:",{aFilename:aFilename,aResponse:aResponse,type:type,filename:filename},smalltalk.FileServer)})},
  509. messageSends: ["ifTrue:", ",", "isDirectory", "statSync:", "readFile:do:", "ifTrue:ifFalse:", "log:", "respondInternalErrorTo:", "mimeTypeFor:", "class", "=", "writeHead:options:", "->", "write:encoding:", "end", "notNil"]}),
  510. smalltalk.FileServer);
  511. smalltalk.addMethod(
  512. smalltalk.method({
  513. selector: "respondInternalErrorTo:",
  514. fn: function (aResponse){
  515. var self=this;
  516. return smalltalk.withContext(function($ctx1) {
  517. var $1,$2;
  518. $1=aResponse;
  519. _st($1)._writeHead_options_((500),smalltalk.HashedCollection._from_(["Content-Type".__minus_gt("text/plain")]));
  520. _st($1)._write_("500 Internal server error");
  521. $2=_st($1)._end();
  522. return self}, function($ctx1) {$ctx1.fill(self,"respondInternalErrorTo:",{aResponse:aResponse},smalltalk.FileServer)})},
  523. messageSends: ["writeHead:options:", "->", "write:", "end"]}),
  524. smalltalk.FileServer);
  525. smalltalk.addMethod(
  526. smalltalk.method({
  527. selector: "respondNotCreatedTo:",
  528. fn: function (aResponse){
  529. var self=this;
  530. return smalltalk.withContext(function($ctx1) {
  531. var $1,$2;
  532. $1=aResponse;
  533. _st($1)._writeHead_options_((400),smalltalk.HashedCollection._from_(["Content-Type".__minus_gt("text/plain")]));
  534. _st($1)._write_("File could not be created. Did you forget to create the st/js directories on the server?");
  535. $2=_st($1)._end();
  536. return self}, function($ctx1) {$ctx1.fill(self,"respondNotCreatedTo:",{aResponse:aResponse},smalltalk.FileServer)})},
  537. messageSends: ["writeHead:options:", "->", "write:", "end"]}),
  538. smalltalk.FileServer);
  539. smalltalk.addMethod(
  540. smalltalk.method({
  541. selector: "respondNotFoundTo:",
  542. fn: function (aResponse){
  543. var self=this;
  544. return smalltalk.withContext(function($ctx1) {
  545. var $1,$2,$3,$4;
  546. $1=_st(self._fallbackPage())._isNil();
  547. if(! smalltalk.assert($1)){
  548. $2=self._respondFileNamed_to_(self._fallbackPage(),aResponse);
  549. return $2;
  550. };
  551. $3=aResponse;
  552. _st($3)._writeHead_options_((404),smalltalk.HashedCollection._from_(["Content-Type".__minus_gt("text/plain")]));
  553. _st($3)._write_("404 Not found");
  554. $4=_st($3)._end();
  555. return self}, function($ctx1) {$ctx1.fill(self,"respondNotFoundTo:",{aResponse:aResponse},smalltalk.FileServer)})},
  556. messageSends: ["ifFalse:", "respondFileNamed:to:", "fallbackPage", "isNil", "writeHead:options:", "->", "write:", "end"]}),
  557. smalltalk.FileServer);
  558. smalltalk.addMethod(
  559. smalltalk.method({
  560. selector: "respondOKTo:",
  561. fn: function (aResponse){
  562. var self=this;
  563. return smalltalk.withContext(function($ctx1) {
  564. var $1,$2;
  565. $1=aResponse;
  566. _st($1)._writeHead_options_((200),smalltalk.HashedCollection._from_(["Content-Type".__minus_gt("text/plain"),"Access-Control-Allow-Origin".__minus_gt("*")]));
  567. $2=_st($1)._end();
  568. return self}, function($ctx1) {$ctx1.fill(self,"respondOKTo:",{aResponse:aResponse},smalltalk.FileServer)})},
  569. messageSends: ["writeHead:options:", "->", "end"]}),
  570. smalltalk.FileServer);
  571. smalltalk.addMethod(
  572. smalltalk.method({
  573. selector: "start",
  574. fn: function (){
  575. var self=this;
  576. return smalltalk.withContext(function($ctx1) {
  577. var $1,$2;
  578. self._checkDirectoryLayout();
  579. $1=_st(self["@http"])._createServer_((function(request,response){
  580. return smalltalk.withContext(function($ctx2) {
  581. return self._handleRequest_respondTo_(request,response);
  582. }, function($ctx2) {$ctx2.fillBlock({request:request,response:response},$ctx1)})}));
  583. _st($1)._on_do_("error",(function(error){
  584. return smalltalk.withContext(function($ctx2) {
  585. return _st(console)._log_("Error starting server: ".__comma(error));
  586. }, function($ctx2) {$ctx2.fillBlock({error:error},$ctx1)})}));
  587. _st($1)._on_do_("listening",(function(){
  588. return smalltalk.withContext(function($ctx2) {
  589. return _st(console)._log_(_st(_st("Starting file server on http://".__comma(self._host())).__comma(":")).__comma(_st(self._port())._asString()));
  590. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  591. $2=_st($1)._listen_host_(self._port(),self._host());
  592. return self}, function($ctx1) {$ctx1.fill(self,"start",{},smalltalk.FileServer)})},
  593. messageSends: ["checkDirectoryLayout", "on:do:", "log:", ",", "createServer:", "handleRequest:respondTo:", "asString", "port", "host", "listen:host:"]}),
  594. smalltalk.FileServer);
  595. smalltalk.addMethod(
  596. smalltalk.method({
  597. selector: "startOn:",
  598. fn: function (aPort){
  599. var self=this;
  600. return smalltalk.withContext(function($ctx1) {
  601. self._port_(aPort);
  602. self._start();
  603. return self}, function($ctx1) {$ctx1.fill(self,"startOn:",{aPort:aPort},smalltalk.FileServer)})},
  604. messageSends: ["port:", "start"]}),
  605. smalltalk.FileServer);
  606. smalltalk.addMethod(
  607. smalltalk.method({
  608. selector: "username:",
  609. fn: function (aUsername){
  610. var self=this;
  611. return smalltalk.withContext(function($ctx1) {
  612. self["@username"]=aUsername;
  613. return self}, function($ctx1) {$ctx1.fill(self,"username:",{aUsername:aUsername},smalltalk.FileServer)})},
  614. messageSends: []}),
  615. smalltalk.FileServer);
  616. smalltalk.addMethod(
  617. smalltalk.method({
  618. selector: "writeData:toFileNamed:",
  619. fn: function (data,aFilename){
  620. var self=this;
  621. return smalltalk.withContext(function($ctx1) {
  622. _st(console)._log_(aFilename);
  623. return self}, function($ctx1) {$ctx1.fill(self,"writeData:toFileNamed:",{data:data,aFilename:aFilename},smalltalk.FileServer)})},
  624. messageSends: ["log:"]}),
  625. smalltalk.FileServer);
  626. smalltalk.FileServer.klass.iVarNames = ['mimeTypes'];
  627. smalltalk.addMethod(
  628. smalltalk.method({
  629. selector: "commandLineSwitches",
  630. fn: function (){
  631. var self=this;
  632. var switches;
  633. return smalltalk.withContext(function($ctx1) {
  634. var $1;
  635. switches=_st(self._methodsInProtocol_("accessing"))._collect_((function(each){
  636. return smalltalk.withContext(function($ctx2) {
  637. return _st(each)._selector();
  638. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
  639. switches=_st(switches)._select_((function(each){
  640. return smalltalk.withContext(function($ctx2) {
  641. return _st(each)._match_("^[^:]*:$");
  642. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
  643. switches=_st(switches)._collect_((function(each){
  644. return smalltalk.withContext(function($ctx2) {
  645. return _st(_st(_st(_st(each)._allButLast())._replace_with_("([A-Z])","-$1"))._asLowercase())._replace_with_("^([a-z])","--$1");
  646. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
  647. $1=switches;
  648. return $1;
  649. }, function($ctx1) {$ctx1.fill(self,"commandLineSwitches",{switches:switches},smalltalk.FileServer.klass)})},
  650. messageSends: ["collect:", "selector", "methodsInProtocol:", "select:", "match:", "replace:with:", "asLowercase", "allButLast"]}),
  651. smalltalk.FileServer.klass);
  652. smalltalk.addMethod(
  653. smalltalk.method({
  654. selector: "createServerWithArguments:",
  655. fn: function (options){
  656. var self=this;
  657. var server,popFront,front,optionName,optionValue,switches;
  658. function $Array(){return smalltalk.Array||(typeof Array=="undefined"?nil:Array)}
  659. return smalltalk.withContext(function($ctx1) {
  660. var $1,$2,$3,$4,$5;
  661. var $early={};
  662. try {
  663. switches=self._commandLineSwitches();
  664. server=self._new();
  665. _st(options)._ifEmpty_((function(){
  666. return smalltalk.withContext(function($ctx2) {
  667. $1=server;
  668. throw $early=[$1];
  669. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  670. $2=_st(_st(options)._size())._even();
  671. if(! smalltalk.assert($2)){
  672. _st(console)._log_("Using default parameters.");
  673. _st(console)._log_("Wrong commandline options or not enough arguments for: ".__comma(options));
  674. _st(console)._log_("Use any of the following ones: ".__comma(switches));
  675. $3=server;
  676. return $3;
  677. };
  678. popFront=(function(args){
  679. return smalltalk.withContext(function($ctx2) {
  680. front=_st(args)._first();
  681. front;
  682. _st(args)._remove_(front);
  683. return front;
  684. }, function($ctx2) {$ctx2.fillBlock({args:args},$ctx1)})});
  685. _st((function(){
  686. return smalltalk.withContext(function($ctx2) {
  687. return _st(options)._notEmpty();
  688. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}))._whileTrue_((function(){
  689. return smalltalk.withContext(function($ctx2) {
  690. optionName=_st(popFront)._value_(options);
  691. optionName;
  692. optionValue=_st(popFront)._value_(options);
  693. optionValue;
  694. $4=_st(switches)._includes_(optionName);
  695. if(smalltalk.assert($4)){
  696. optionName=self._selectorForCommandLineSwitch_(optionName);
  697. optionName;
  698. return _st(server)._perform_withArguments_(optionName,_st($Array())._with_(optionValue));
  699. } else {
  700. _st(console)._log_(_st(optionName).__comma(" is not a valid commandline option"));
  701. return _st(console)._log_("Use any of the following ones: ".__comma(switches));
  702. };
  703. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  704. $5=server;
  705. return $5;
  706. }
  707. catch(e) {if(e===$early)return e[0]; throw e}
  708. }, function($ctx1) {$ctx1.fill(self,"createServerWithArguments:",{options:options,server:server,popFront:popFront,front:front,optionName:optionName,optionValue:optionValue,switches:switches},smalltalk.FileServer.klass)})},
  709. messageSends: ["commandLineSwitches", "new", "ifEmpty:", "ifFalse:", "log:", ",", "even", "size", "first", "remove:", "whileTrue:", "value:", "ifTrue:ifFalse:", "selectorForCommandLineSwitch:", "perform:withArguments:", "with:", "includes:", "notEmpty"]}),
  710. smalltalk.FileServer.klass);
  711. smalltalk.addMethod(
  712. smalltalk.method({
  713. selector: "defaultHost",
  714. fn: function (){
  715. var self=this;
  716. return smalltalk.withContext(function($ctx1) {
  717. return "127.0.0.1";
  718. }, function($ctx1) {$ctx1.fill(self,"defaultHost",{},smalltalk.FileServer.klass)})},
  719. messageSends: []}),
  720. smalltalk.FileServer.klass);
  721. smalltalk.addMethod(
  722. smalltalk.method({
  723. selector: "defaultMimeTypes",
  724. fn: function (){
  725. var self=this;
  726. return smalltalk.withContext(function($ctx1) {
  727. var $1;
  728. $1=smalltalk.HashedCollection._from_(["%".__minus_gt("application/x-trash"),"323".__minus_gt("text/h323"),"abw".__minus_gt("application/x-abiword"),"ai".__minus_gt("application/postscript"),"aif".__minus_gt("audio/x-aiff"),"aifc".__minus_gt("audio/x-aiff"),"aiff".__minus_gt("audio/x-aiff"),"alc".__minus_gt("chemical/x-alchemy"),"art".__minus_gt("image/x-jg"),"asc".__minus_gt("text/plain"),"asf".__minus_gt("video/x-ms-asf"),"asn".__minus_gt("chemical/x-ncbi-asn1-spec"),"aso".__minus_gt("chemical/x-ncbi-asn1-binary"),"asx".__minus_gt("video/x-ms-asf"),"au".__minus_gt("audio/basic"),"avi".__minus_gt("video/x-msvideo"),"b".__minus_gt("chemical/x-molconn-Z"),"bak".__minus_gt("application/x-trash"),"bat".__minus_gt("application/x-msdos-program"),"bcpio".__minus_gt("application/x-bcpio"),"bib".__minus_gt("text/x-bibtex"),"bin".__minus_gt("application/octet-stream"),"bmp".__minus_gt("image/x-ms-bmp"),"book".__minus_gt("application/x-maker"),"bsd".__minus_gt("chemical/x-crossfire"),"c".__minus_gt("text/x-csrc"),"c++".__minus_gt("text/x-c++src"),"c3d".__minus_gt("chemical/x-chem3d"),"cac".__minus_gt("chemical/x-cache"),"cache".__minus_gt("chemical/x-cache"),"cascii".__minus_gt("chemical/x-cactvs-binary"),"cat".__minus_gt("application/vnd.ms-pki.seccat"),"cbin".__minus_gt("chemical/x-cactvs-binary"),"cc".__minus_gt("text/x-c++src"),"cdf".__minus_gt("application/x-cdf"),"cdr".__minus_gt("image/x-coreldraw"),"cdt".__minus_gt("image/x-coreldrawtemplate"),"cdx".__minus_gt("chemical/x-cdx"),"cdy".__minus_gt("application/vnd.cinderella"),"cef".__minus_gt("chemical/x-cxf"),"cer".__minus_gt("chemical/x-cerius"),"chm".__minus_gt("chemical/x-chemdraw"),"chrt".__minus_gt("application/x-kchart"),"cif".__minus_gt("chemical/x-cif"),"class".__minus_gt("application/java-vm"),"cls".__minus_gt("text/x-tex"),"cmdf".__minus_gt("chemical/x-cmdf"),"cml".__minus_gt("chemical/x-cml"),"cod".__minus_gt("application/vnd.rim.cod"),"com".__minus_gt("application/x-msdos-program"),"cpa".__minus_gt("chemical/x-compass"),"cpio".__minus_gt("application/x-cpio"),"cpp".__minus_gt("text/x-c++src"),"cpt".__minus_gt("image/x-corelphotopaint"),"crl".__minus_gt("application/x-pkcs7-crl"),"crt".__minus_gt("application/x-x509-ca-cert"),"csf".__minus_gt("chemical/x-cache-csf"),"csh".__minus_gt("text/x-csh"),"csm".__minus_gt("chemical/x-csml"),"csml".__minus_gt("chemical/x-csml"),"css".__minus_gt("text/css"),"csv".__minus_gt("text/comma-separated-values"),"ctab".__minus_gt("chemical/x-cactvs-binary"),"ctx".__minus_gt("chemical/x-ctx"),"cu".__minus_gt("application/cu-seeme"),"cub".__minus_gt("chemical/x-gaussian-cube"),"cxf".__minus_gt("chemical/x-cxf"),"cxx".__minus_gt("text/x-c++src"),"dat".__minus_gt("chemical/x-mopac-input"),"dcr".__minus_gt("application/x-director"),"deb".__minus_gt("application/x-debian-package"),"dif".__minus_gt("video/dv"),"diff".__minus_gt("text/plain"),"dir".__minus_gt("application/x-director"),"djv".__minus_gt("image/vnd.djvu"),"djvu".__minus_gt("image/vnd.djvu"),"dl".__minus_gt("video/dl"),"dll".__minus_gt("application/x-msdos-program"),"dmg".__minus_gt("application/x-apple-diskimage"),"dms".__minus_gt("application/x-dms"),"doc".__minus_gt("application/msword"),"dot".__minus_gt("application/msword"),"dv".__minus_gt("video/dv"),"dvi".__minus_gt("application/x-dvi"),"dx".__minus_gt("chemical/x-jcamp-dx"),"dxr".__minus_gt("application/x-director"),"emb".__minus_gt("chemical/x-embl-dl-nucleotide"),"embl".__minus_gt("chemical/x-embl-dl-nucleotide"),"ent".__minus_gt("chemical/x-pdb"),"eps".__minus_gt("application/postscript"),"etx".__minus_gt("text/x-setext"),"exe".__minus_gt("application/x-msdos-program"),"ez".__minus_gt("application/andrew-inset"),"fb".__minus_gt("application/x-maker"),"fbdoc".__minus_gt("application/x-maker"),"fch".__minus_gt("chemical/x-gaussian-checkpoint"),"fchk".__minus_gt("chemical/x-gaussian-checkpoint"),"fig".__minus_gt("application/x-xfig"),"flac".__minus_gt("application/x-flac"),"fli".__minus_gt("video/fli"),"fm".__minus_gt("application/x-maker"),"frame".__minus_gt("application/x-maker"),"frm".__minus_gt("application/x-maker"),"gal".__minus_gt("chemical/x-gaussian-log"),"gam".__minus_gt("chemical/x-gamess-input"),"gamin".__minus_gt("chemical/x-gamess-input"),"gau".__minus_gt("chemical/x-gaussian-input"),"gcd".__minus_gt("text/x-pcs-gcd"),"gcf".__minus_gt("application/x-graphing-calculator"),"gcg".__minus_gt("chemical/x-gcg8-sequence"),"gen".__minus_gt("chemical/x-genbank"),"gf".__minus_gt("application/x-tex-gf"),"gif".__minus_gt("image/gif"),"gjc".__minus_gt("chemical/x-gaussian-input"),"gjf".__minus_gt("chemical/x-gaussian-input"),"gl".__minus_gt("video/gl"),"gnumeric".__minus_gt("application/x-gnumeric"),"gpt".__minus_gt("chemical/x-mopac-graph"),"gsf".__minus_gt("application/x-font"),"gsm".__minus_gt("audio/x-gsm"),"gtar".__minus_gt("application/x-gtar"),"h".__minus_gt("text/x-chdr"),"h++".__minus_gt("text/x-c++hdr"),"hdf".__minus_gt("application/x-hdf"),"hh".__minus_gt("text/x-c++hdr"),"hin".__minus_gt("chemical/x-hin"),"hpp".__minus_gt("text/x-c++hdr"),"hqx".__minus_gt("application/mac-binhex40"),"hs".__minus_gt("text/x-haskell"),"hta".__minus_gt("application/hta"),"htc".__minus_gt("text/x-component"),"htm".__minus_gt("text/html"),"html".__minus_gt("text/html"),"hxx".__minus_gt("text/x-c++hdr"),"ica".__minus_gt("application/x-ica"),"ice".__minus_gt("x-conference/x-cooltalk"),"ico".__minus_gt("image/x-icon"),"ics".__minus_gt("text/calendar"),"icz".__minus_gt("text/calendar"),"ief".__minus_gt("image/ief"),"iges".__minus_gt("model/iges"),"igs".__minus_gt("model/iges"),"iii".__minus_gt("application/x-iphone"),"inp".__minus_gt("chemical/x-gamess-input"),"ins".__minus_gt("application/x-internet-signup"),"iso".__minus_gt("application/x-iso9660-image"),"isp".__minus_gt("application/x-internet-signup"),"ist".__minus_gt("chemical/x-isostar"),"istr".__minus_gt("chemical/x-isostar"),"jad".__minus_gt("text/vnd.sun.j2me.app-descriptor"),"jar".__minus_gt("application/java-archive"),"java".__minus_gt("text/x-java"),"jdx".__minus_gt("chemical/x-jcamp-dx"),"jmz".__minus_gt("application/x-jmol"),"jng".__minus_gt("image/x-jng"),"jnlp".__minus_gt("application/x-java-jnlp-file"),"jpe".__minus_gt("image/jpeg"),"jpeg".__minus_gt("image/jpeg"),"jpg".__minus_gt("image/jpeg"),"js".__minus_gt("application/javascript"),"kar".__minus_gt("audio/midi"),"key".__minus_gt("application/pgp-keys"),"kil".__minus_gt("application/x-killustrator"),"kin".__minus_gt("chemical/x-kinemage"),"kpr".__minus_gt("application/x-kpresenter"),"kpt".__minus_gt("application/x-kpresenter"),"ksp".__minus_gt("application/x-kspread"),"kwd".__minus_gt("application/x-kword"),"kwt".__minus_gt("application/x-kword"),"latex".__minus_gt("application/x-latex"),"lha".__minus_gt("application/x-lha"),"lhs".__minus_gt("text/x-literate-haskell"),"lsf".__minus_gt("video/x-la-asf"),"lsx".__minus_gt("video/x-la-asf"),"ltx".__minus_gt("text/x-tex"),"lzh".__minus_gt("application/x-lzh"),"lzx".__minus_gt("application/x-lzx"),"m3u".__minus_gt("audio/x-mpegurl"),"m4a".__minus_gt("audio/mpeg"),"maker".__minus_gt("application/x-maker"),"man".__minus_gt("application/x-troff-man"),"mcif".__minus_gt("chemical/x-mmcif"),"mcm".__minus_gt("chemical/x-macmolecule"),"mdb".__minus_gt("application/msaccess"),"me".__minus_gt("application/x-troff-me"),"mesh".__minus_gt("model/mesh"),"mid".__minus_gt("audio/midi"),"midi".__minus_gt("audio/midi"),"mif".__minus_gt("application/x-mif"),"mm".__minus_gt("application/x-freemind"),"mmd".__minus_gt("chemical/x-macromodel-input"),"mmf".__minus_gt("application/vnd.smaf"),"mml".__minus_gt("text/mathml"),"mmod".__minus_gt("chemical/x-macromodel-input"),"mng".__minus_gt("video/x-mng"),"moc".__minus_gt("text/x-moc"),"mol".__minus_gt("chemical/x-mdl-molfile"),"mol2".__minus_gt("chemical/x-mol2"),"moo".__minus_gt("chemical/x-mopac-out"),"mop".__minus_gt("chemical/x-mopac-input"),"mopcrt".__minus_gt("chemical/x-mopac-input"),"mov".__minus_gt("video/quicktime"),"movie".__minus_gt("video/x-sgi-movie"),"mp2".__minus_gt("audio/mpeg"),"mp3".__minus_gt("audio/mpeg"),"mp4".__minus_gt("video/mp4"),"mpc".__minus_gt("chemical/x-mopac-input"),"mpe".__minus_gt("video/mpeg"),"mpeg".__minus_gt("video/mpeg"),"mpega".__minus_gt("audio/mpeg"),"mpg".__minus_gt("video/mpeg"),"mpga".__minus_gt("audio/mpeg"),"ms".__minus_gt("application/x-troff-ms"),"msh".__minus_gt("model/mesh"),"msi".__minus_gt("application/x-msi"),"mvb".__minus_gt("chemical/x-mopac-vib"),"mxu".__minus_gt("video/vnd.mpegurl"),"nb".__minus_gt("application/mathematica"),"nc".__minus_gt("application/x-netcdf"),"nwc".__minus_gt("application/x-nwc"),"o".__minus_gt("application/x-object"),"oda".__minus_gt("application/oda"),"odb".__minus_gt("application/vnd.oasis.opendocument.database"),"odc".__minus_gt("application/vnd.oasis.opendocument.chart"),"odf".__minus_gt("application/vnd.oasis.opendocument.formula"),"odg".__minus_gt("application/vnd.oasis.opendocument.graphics"),"odi".__minus_gt("application/vnd.oasis.opendocument.image"),"odm".__minus_gt("application/vnd.oasis.opendocument.text-master"),"odp".__minus_gt("application/vnd.oasis.opendocument.presentation"),"ods".__minus_gt("application/vnd.oasis.opendocument.spreadsheet"),"odt".__minus_gt("application/vnd.oasis.opendocument.text"),"ogg".__minus_gt("application/ogg"),"old".__minus_gt("application/x-trash"),"oth".__minus_gt("application/vnd.oasis.opendocument.text-web"),"oza".__minus_gt("application/x-oz-application"),"p".__minus_gt("text/x-pascal"),"p7r".__minus_gt("application/x-pkcs7-certreqresp"),"pac".__minus_gt("application/x-ns-proxy-autoconfig"),"pas".__minus_gt("text/x-pascal"),"pat".__minus_gt("image/x-coreldrawpattern"),"pbm".__minus_gt("image/x-portable-bitmap"),"pcf".__minus_gt("application/x-font"),"pcf.Z".__minus_gt("application/x-font"),"pcx".__minus_gt("image/pcx"),"pdb".__minus_gt("chemical/x-pdb"),"pdf".__minus_gt("application/pdf"),"pfa".__minus_gt("application/x-font"),"pfb".__minus_gt("application/x-font"),"pgm".__minus_gt("image/x-portable-graymap"),"pgn".__minus_gt("application/x-chess-pgn"),"pgp".__minus_gt("application/pgp-signature"),"pk".__minus_gt("application/x-tex-pk"),"pl".__minus_gt("text/x-perl"),"pls".__minus_gt("audio/x-scpls"),"pm".__minus_gt("text/x-perl"),"png".__minus_gt("image/png"),"pnm".__minus_gt("image/x-portable-anymap"),"pot".__minus_gt("text/plain"),"ppm".__minus_gt("image/x-portable-pixmap"),"pps".__minus_gt("application/vnd.ms-powerpoint"),"ppt".__minus_gt("application/vnd.ms-powerpoint"),"prf".__minus_gt("application/pics-rules"),"prt".__minus_gt("chemical/x-ncbi-asn1-ascii"),"ps".__minus_gt("application/postscript"),"psd".__minus_gt("image/x-photoshop"),"psp".__minus_gt("text/x-psp"),"py".__minus_gt("text/x-python"),"pyc".__minus_gt("application/x-python-code"),"pyo".__minus_gt("application/x-python-code"),"qt".__minus_gt("video/quicktime"),"qtl".__minus_gt("application/x-quicktimeplayer"),"ra".__minus_gt("audio/x-realaudio"),"ram".__minus_gt("audio/x-pn-realaudio"),"rar".__minus_gt("application/rar"),"ras".__minus_gt("image/x-cmu-raster"),"rd".__minus_gt("chemical/x-mdl-rdfile"),"rdf".__minus_gt("application/rdf+xml"),"rgb".__minus_gt("image/x-rgb"),"rm".__minus_gt("audio/x-pn-realaudio"),"roff".__minus_gt("application/x-troff"),"ros".__minus_gt("chemical/x-rosdal"),"rpm".__minus_gt("application/x-redhat-package-manager"),"rss".__minus_gt("application/rss+xml"),"rtf".__minus_gt("text/rtf"),"rtx".__minus_gt("text/richtext"),"rxn".__minus_gt("chemical/x-mdl-rxnfile"),"sct".__minus_gt("text/scriptlet"),"sd".__minus_gt("chemical/x-mdl-sdfile"),"sd2".__minus_gt("audio/x-sd2"),"sda".__minus_gt("application/vnd.stardivision.draw"),"sdc".__minus_gt("application/vnd.stardivision.calc"),"sdd".__minus_gt("application/vnd.stardivision.impress"),"sdf".__minus_gt("chemical/x-mdl-sdfile"),"sdp".__minus_gt("application/vnd.stardivision.impress"),"sdw".__minus_gt("application/vnd.stardivision.writer"),"ser".__minus_gt("application/java-serialized-object"),"sgf".__minus_gt("application/x-go-sgf"),"sgl".__minus_gt("application/vnd.stardivision.writer-global"),"sh".__minus_gt("text/x-sh"),"shar".__minus_gt("application/x-shar"),"shtml".__minus_gt("text/html"),"sid".__minus_gt("audio/prs.sid"),"sik".__minus_gt("application/x-trash"),"silo".__minus_gt("model/mesh"),"sis".__minus_gt("application/vnd.symbian.install"),"sit".__minus_gt("application/x-stuffit"),"skd".__minus_gt("application/x-koan"),"skm".__minus_gt("application/x-koan"),"skp".__minus_gt("application/x-koan"),"skt".__minus_gt("application/x-koan"),"smf".__minus_gt("application/vnd.stardivision.math"),"smi".__minus_gt("application/smil"),"smil".__minus_gt("application/smil"),"snd".__minus_gt("audio/basic"),"spc".__minus_gt("chemical/x-galactic-spc"),"spl".__minus_gt("application/x-futuresplash"),"src".__minus_gt("application/x-wais-source"),"stc".__minus_gt("application/vnd.sun.xml.calc.template"),"std".__minus_gt("application/vnd.sun.xml.draw.template"),"sti".__minus_gt("application/vnd.sun.xml.impress.template"),"stl".__minus_gt("application/vnd.ms-pki.stl"),"stw".__minus_gt("application/vnd.sun.xml.writer.template"),"sty".__minus_gt("text/x-tex"),"sv4cpio".__minus_gt("application/x-sv4cpio"),"sv4crc".__minus_gt("application/x-sv4crc"),"svg".__minus_gt("image/svg+xml"),"svgz".__minus_gt("image/svg+xml"),"sw".__minus_gt("chemical/x-swissprot"),"swf".__minus_gt("application/x-shockwave-flash"),"swfl".__minus_gt("application/x-shockwave-flash"),"sxc".__minus_gt("application/vnd.sun.xml.calc"),"sxd".__minus_gt("application/vnd.sun.xml.draw"),"sxg".__minus_gt("application/vnd.sun.xml.writer.global"),"sxi".__minus_gt("application/vnd.sun.xml.impress"),"sxm".__minus_gt("application/vnd.sun.xml.math"),"sxw".__minus_gt("application/vnd.sun.xml.writer"),"t".__minus_gt("application/x-troff"),"tar".__minus_gt("application/x-tar"),"taz".__minus_gt("application/x-gtar"),"tcl".__minus_gt("text/x-tcl"),"tex".__minus_gt("text/x-tex"),"texi".__minus_gt("application/x-texinfo"),"texinfo".__minus_gt("application/x-texinfo"),"text".__minus_gt("text/plain"),"tgf".__minus_gt("chemical/x-mdl-tgf"),"tgz".__minus_gt("application/x-gtar"),"tif".__minus_gt("image/tiff"),"tiff".__minus_gt("image/tiff"),"tk".__minus_gt("text/x-tcl"),"tm".__minus_gt("text/texmacs"),"torrent".__minus_gt("application/x-bittorrent"),"tr".__minus_gt("application/x-troff"),"ts".__minus_gt("text/texmacs"),"tsp".__minus_gt("application/dsptype"),"tsv".__minus_gt("text/tab-separated-values"),"txt".__minus_gt("text/plain"),"udeb".__minus_gt("application/x-debian-package"),"uls".__minus_gt("text/iuls"),"ustar".__minus_gt("application/x-ustar"),"val".__minus_gt("chemical/x-ncbi-asn1-binary"),"vcd".__minus_gt("application/x-cdlink"),"vcf".__minus_gt("text/x-vcard"),"vcs".__minus_gt("text/x-vcalendar"),"vmd".__minus_gt("chemical/x-vmd"),"vms".__minus_gt("chemical/x-vamas-iso14976"),"vor".__minus_gt("application/vnd.stardivision.writer"),"vrm".__minus_gt("x-world/x-vrml"),"vrml".__minus_gt("x-world/x-vrml"),"vsd".__minus_gt("application/vnd.visio"),"wad".__minus_gt("application/x-doom"),"wav".__minus_gt("audio/x-wav"),"wax".__minus_gt("audio/x-ms-wax"),"wbmp".__minus_gt("image/vnd.wap.wbmp"),"wbxml".__minus_gt("application/vnd.wap.wbxml"),"wk".__minus_gt("application/x-123"),"wm".__minus_gt("video/x-ms-wm"),"wma".__minus_gt("audio/x-ms-wma"),"wmd".__minus_gt("application/x-ms-wmd"),"wml".__minus_gt("text/vnd.wap.wml"),"wmlc".__minus_gt("application/vnd.wap.wmlc"),"wmls".__minus_gt("text/vnd.wap.wmlscript"),"wmlsc".__minus_gt("application/vnd.wap.wmlscriptc"),"wmv".__minus_gt("video/x-ms-wmv"),"wmx".__minus_gt("video/x-ms-wmx"),"wmz".__minus_gt("application/x-ms-wmz"),"wp5".__minus_gt("application/wordperfect5.1"),"wpd".__minus_gt("application/wordperfect"),"wrl".__minus_gt("x-world/x-vrml"),"wsc".__minus_gt("text/scriptlet"),"wvx".__minus_gt("video/x-ms-wvx"),"wz".__minus_gt("application/x-wingz"),"xbm".__minus_gt("image/x-xbitmap"),"xcf".__minus_gt("application/x-xcf"),"xht".__minus_gt("application/xhtml+xml"),"xhtml".__minus_gt("application/xhtml+xml"),"xlb".__minus_gt("application/vnd.ms-excel"),"xls".__minus_gt("application/vnd.ms-excel"),"xlt".__minus_gt("application/vnd.ms-excel"),"xml".__minus_gt("application/xml"),"xpi".__minus_gt("application/x-xpinstall"),"xpm".__minus_gt("image/x-xpixmap"),"xsl".__minus_gt("application/xml"),"xtel".__minus_gt("chemical/x-xtel"),"xul".__minus_gt("application/vnd.mozilla.xul+xml"),"xwd".__minus_gt("image/x-xwindowdump"),"xyz".__minus_gt("chemical/x-xyz"),"zip".__minus_gt("application/zip"),"zmt".__minus_gt("chemical/x-mopac-input"),"~".__minus_gt("application/x-trash")]);
  729. return $1;
  730. }, function($ctx1) {$ctx1.fill(self,"defaultMimeTypes",{},smalltalk.FileServer.klass)})},
  731. messageSends: ["->"]}),
  732. smalltalk.FileServer.klass);
  733. smalltalk.addMethod(
  734. smalltalk.method({
  735. selector: "defaultPort",
  736. fn: function (){
  737. var self=this;
  738. return smalltalk.withContext(function($ctx1) {
  739. return (4000);
  740. }, function($ctx1) {$ctx1.fill(self,"defaultPort",{},smalltalk.FileServer.klass)})},
  741. messageSends: []}),
  742. smalltalk.FileServer.klass);
  743. smalltalk.addMethod(
  744. smalltalk.method({
  745. selector: "main",
  746. fn: function (){
  747. var self=this;
  748. var fileServer,args;
  749. function $FileServer(){return smalltalk.FileServer||(typeof FileServer=="undefined"?nil:FileServer)}
  750. return smalltalk.withContext(function($ctx1) {
  751. var $1,$2;
  752. var $early={};
  753. try {
  754. args=_st(process)._argv();
  755. _st(args)._removeFrom_to_((1),(3));
  756. _st(args)._detect_ifNone_((function(each){
  757. return smalltalk.withContext(function($ctx2) {
  758. $1=_st(each).__eq("--help");
  759. if(smalltalk.assert($1)){
  760. return _st($FileServer())._printHelp();
  761. };
  762. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}),(function(){
  763. return smalltalk.withContext(function($ctx2) {
  764. fileServer=_st($FileServer())._createServerWithArguments_(args);
  765. fileServer;
  766. $2=_st(fileServer)._start();
  767. throw $early=[$2];
  768. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  769. return self}
  770. catch(e) {if(e===$early)return e[0]; throw e}
  771. }, function($ctx1) {$ctx1.fill(self,"main",{fileServer:fileServer,args:args},smalltalk.FileServer.klass)})},
  772. messageSends: ["argv", "removeFrom:to:", "detect:ifNone:", "ifTrue:", "printHelp", "=", "createServerWithArguments:", "start"]}),
  773. smalltalk.FileServer.klass);
  774. smalltalk.addMethod(
  775. smalltalk.method({
  776. selector: "mimeTypeFor:",
  777. fn: function (aString){
  778. var self=this;
  779. return smalltalk.withContext(function($ctx1) {
  780. var $1;
  781. $1=_st(self._mimeTypes())._at_ifAbsent_(_st(aString)._replace_with_(".*[\x5c.]",""),(function(){
  782. return smalltalk.withContext(function($ctx2) {
  783. return "text/plain";
  784. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  785. return $1;
  786. }, function($ctx1) {$ctx1.fill(self,"mimeTypeFor:",{aString:aString},smalltalk.FileServer.klass)})},
  787. messageSends: ["at:ifAbsent:", "replace:with:", "mimeTypes"]}),
  788. smalltalk.FileServer.klass);
  789. smalltalk.addMethod(
  790. smalltalk.method({
  791. selector: "mimeTypes",
  792. fn: function (){
  793. var self=this;
  794. return smalltalk.withContext(function($ctx1) {
  795. var $2,$1;
  796. $2=self["@mimeTypes"];
  797. if(($receiver = $2) == nil || $receiver == undefined){
  798. self["@mimeTypes"]=self._defaultMimeTypes();
  799. $1=self["@mimeTypes"];
  800. } else {
  801. $1=$2;
  802. };
  803. return $1;
  804. }, function($ctx1) {$ctx1.fill(self,"mimeTypes",{},smalltalk.FileServer.klass)})},
  805. messageSends: ["ifNil:", "defaultMimeTypes"]}),
  806. smalltalk.FileServer.klass);
  807. smalltalk.addMethod(
  808. smalltalk.method({
  809. selector: "printHelp",
  810. fn: function (){
  811. var self=this;
  812. return smalltalk.withContext(function($ctx1) {
  813. _st(console)._log_("Available commandline options are:");
  814. _st(console)._log_("--help");
  815. _st(self._commandLineSwitches())._do_((function(each){
  816. return smalltalk.withContext(function($ctx2) {
  817. return _st(console)._log_(_st(each).__comma(" <parameter>"));
  818. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
  819. return self}, function($ctx1) {$ctx1.fill(self,"printHelp",{},smalltalk.FileServer.klass)})},
  820. messageSends: ["log:", "do:", ",", "commandLineSwitches"]}),
  821. smalltalk.FileServer.klass);
  822. smalltalk.addMethod(
  823. smalltalk.method({
  824. selector: "selectorForCommandLineSwitch:",
  825. fn: function (aSwitch){
  826. var self=this;
  827. return smalltalk.withContext(function($ctx1) {
  828. var $1;
  829. $1=_st(_st(_st(aSwitch)._replace_with_("^--",""))._replace_with_("-[a-z]",(function(each){
  830. return smalltalk.withContext(function($ctx2) {
  831. return _st(_st(each)._second())._asUppercase();
  832. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}))).__comma(":");
  833. return $1;
  834. }, function($ctx1) {$ctx1.fill(self,"selectorForCommandLineSwitch:",{aSwitch:aSwitch},smalltalk.FileServer.klass)})},
  835. messageSends: [",", "replace:with:", "asUppercase", "second"]}),
  836. smalltalk.FileServer.klass);
  837. smalltalk.addClass('Repl', smalltalk.Object, ['readline', 'interface', 'util', 'session', 'resultCount'], 'AmberCli');
  838. smalltalk.addMethod(
  839. smalltalk.method({
  840. selector: "addVariableNamed:to:",
  841. fn: function (aString,anObject){
  842. var self=this;
  843. var newClass,newObject;
  844. return smalltalk.withContext(function($ctx1) {
  845. var $1;
  846. newClass=self._subclass_withVariable_(_st(anObject)._class(),aString);
  847. self._encapsulateVariable_withValue_in_(aString,anObject,newClass);
  848. newObject=_st(newClass)._new();
  849. self._setPreviousVariablesFor_from_(newObject,anObject);
  850. $1=newObject;
  851. return $1;
  852. }, function($ctx1) {$ctx1.fill(self,"addVariableNamed:to:",{aString:aString,anObject:anObject,newClass:newClass,newObject:newObject},smalltalk.Repl)})},
  853. messageSends: ["subclass:withVariable:", "class", "encapsulateVariable:withValue:in:", "new", "setPreviousVariablesFor:from:"]}),
  854. smalltalk.Repl);
  855. smalltalk.addMethod(
  856. smalltalk.method({
  857. selector: "assignNewVariable:do:",
  858. fn: function (buffer,aBlock){
  859. var self=this;
  860. return smalltalk.withContext(function($ctx1) {
  861. var $2,$3,$5,$7,$6,$4,$1;
  862. $1=self._parseAssignment_do_(buffer,(function(name,expr){
  863. var varName,value;
  864. return smalltalk.withContext(function($ctx2) {
  865. $2=name;
  866. if(($receiver = $2) == nil || $receiver == undefined){
  867. varName=self._nextResultName();
  868. } else {
  869. varName=$2;
  870. };
  871. varName;
  872. self["@session"]=self._addVariableNamed_to_(varName,self["@session"]);
  873. self["@session"];
  874. $3=self;
  875. $5=_st(varName).__comma(" := ");
  876. $7=expr;
  877. if(($receiver = $7) == nil || $receiver == undefined){
  878. $6=buffer;
  879. } else {
  880. $6=$7;
  881. };
  882. $4=_st($5).__comma($6);
  883. value=_st($3)._eval_on_($4,self["@session"]);
  884. value;
  885. return _st(aBlock)._value_value_(varName,value);
  886. }, function($ctx2) {$ctx2.fillBlock({name:name,expr:expr,varName:varName,value:value},$ctx1)})}));
  887. return $1;
  888. }, function($ctx1) {$ctx1.fill(self,"assignNewVariable:do:",{buffer:buffer,aBlock:aBlock},smalltalk.Repl)})},
  889. messageSends: ["parseAssignment:do:", "ifNil:", "nextResultName", "addVariableNamed:to:", "eval:on:", ",", "value:value:"]}),
  890. smalltalk.Repl);
  891. smalltalk.addMethod(
  892. smalltalk.method({
  893. selector: "close",
  894. fn: function (){
  895. var self=this;
  896. return smalltalk.withContext(function($ctx1) {
  897. _st(_st(process)._stdin())._destroy();
  898. return self}, function($ctx1) {$ctx1.fill(self,"close",{},smalltalk.Repl)})},
  899. messageSends: ["destroy", "stdin"]}),
  900. smalltalk.Repl);
  901. smalltalk.addMethod(
  902. smalltalk.method({
  903. selector: "createInterface",
  904. fn: function (){
  905. var self=this;
  906. return smalltalk.withContext(function($ctx1) {
  907. var $1,$2;
  908. self["@interface"]=_st(self["@readline"])._createInterface_stdout_(_st(process)._stdin(),_st(process)._stdout());
  909. _st(self["@interface"])._on_do_("line",(function(buffer){
  910. return smalltalk.withContext(function($ctx2) {
  911. return self._processLine_(buffer);
  912. }, function($ctx2) {$ctx2.fillBlock({buffer:buffer},$ctx1)})}));
  913. _st(self["@interface"])._on_do_("close",(function(){
  914. return smalltalk.withContext(function($ctx2) {
  915. return self._close();
  916. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  917. $1=self;
  918. _st($1)._printWelcome();
  919. _st($1)._setupHotkeys();
  920. $2=_st($1)._setPrompt();
  921. _st(self["@interface"])._prompt();
  922. return self}, function($ctx1) {$ctx1.fill(self,"createInterface",{},smalltalk.Repl)})},
  923. messageSends: ["createInterface:stdout:", "stdin", "stdout", "on:do:", "processLine:", "close", "printWelcome", "setupHotkeys", "setPrompt", "prompt"]}),
  924. smalltalk.Repl);
  925. smalltalk.addMethod(
  926. smalltalk.method({
  927. selector: "encapsulateVariable:withValue:in:",
  928. fn: function (aString,anObject,aClass){
  929. var self=this;
  930. var compiler;
  931. function $Compiler(){return smalltalk.Compiler||(typeof Compiler=="undefined"?nil:Compiler)}
  932. return smalltalk.withContext(function($ctx1) {
  933. compiler=_st($Compiler())._new();
  934. _st(compiler)._install_forClass_category_(_st(_st(_st(aString).__comma(": anObject ^ ")).__comma(aString)).__comma(" := anObject"),aClass,"session");
  935. _st(compiler)._install_forClass_category_(_st(_st(aString).__comma(" ^ ")).__comma(aString),aClass,"session");
  936. return self}, function($ctx1) {$ctx1.fill(self,"encapsulateVariable:withValue:in:",{aString:aString,anObject:anObject,aClass:aClass,compiler:compiler},smalltalk.Repl)})},
  937. messageSends: ["new", "install:forClass:category:", ","]}),
  938. smalltalk.Repl);
  939. smalltalk.addMethod(
  940. smalltalk.method({
  941. selector: "eval:",
  942. fn: function (buffer){
  943. var self=this;
  944. function $DoIt(){return smalltalk.DoIt||(typeof DoIt=="undefined"?nil:DoIt)}
  945. return smalltalk.withContext(function($ctx1) {
  946. var $1;
  947. $1=self._eval_on_(buffer,_st($DoIt())._new());
  948. return $1;
  949. }, function($ctx1) {$ctx1.fill(self,"eval:",{buffer:buffer},smalltalk.Repl)})},
  950. messageSends: ["eval:on:", "new"]}),
  951. smalltalk.Repl);
  952. smalltalk.addMethod(
  953. smalltalk.method({
  954. selector: "eval:on:",
  955. fn: function (buffer,anObject){
  956. var self=this;
  957. var result;
  958. function $Compiler(){return smalltalk.Compiler||(typeof Compiler=="undefined"?nil:Compiler)}
  959. function $ErrorHandler(){return smalltalk.ErrorHandler||(typeof ErrorHandler=="undefined"?nil:ErrorHandler)}
  960. return smalltalk.withContext(function($ctx1) {
  961. var $1,$2,$3;
  962. $1=_st(buffer)._isEmpty();
  963. if(! smalltalk.assert($1)){
  964. self._try_catch_((function(){
  965. return smalltalk.withContext(function($ctx2) {
  966. result=_st(_st($Compiler())._new())._evaluateExpression_on_(buffer,anObject);
  967. return result;
  968. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}),(function(e){
  969. return smalltalk.withContext(function($ctx2) {
  970. $2=_st(e)._isSmalltalkError();
  971. if(smalltalk.assert($2)){
  972. return _st(_st($ErrorHandler())._new())._handleError_(e);
  973. } else {
  974. return _st(_st(process)._stdout())._write_(_st(e)._jsStack());
  975. };
  976. }, function($ctx2) {$ctx2.fillBlock({e:e},$ctx1)})}));
  977. };
  978. $3=result;
  979. return $3;
  980. }, function($ctx1) {$ctx1.fill(self,"eval:on:",{buffer:buffer,anObject:anObject,result:result},smalltalk.Repl)})},
  981. messageSends: ["ifFalse:", "try:catch:", "evaluateExpression:on:", "new", "ifTrue:ifFalse:", "handleError:", "write:", "jsStack", "stdout", "isSmalltalkError", "isEmpty"]}),
  982. smalltalk.Repl);
  983. smalltalk.addMethod(
  984. smalltalk.method({
  985. selector: "executeCommand:",
  986. fn: function (aString){
  987. var self=this;
  988. return smalltalk.withContext(function($ctx1) {
  989. var $2,$1;
  990. $2=_st(aString).__eq(":q");
  991. if(smalltalk.assert($2)){
  992. $1=_st(process)._exit();
  993. } else {
  994. $1=false;
  995. };
  996. return $1;
  997. }, function($ctx1) {$ctx1.fill(self,"executeCommand:",{aString:aString},smalltalk.Repl)})},
  998. messageSends: ["ifTrue:ifFalse:", "exit", "="]}),
  999. smalltalk.Repl);
  1000. smalltalk.addMethod(
  1001. smalltalk.method({
  1002. selector: "initialize",
  1003. fn: function (){
  1004. var self=this;
  1005. function $DoIt(){return smalltalk.DoIt||(typeof DoIt=="undefined"?nil:DoIt)}
  1006. return smalltalk.withContext(function($ctx1) {
  1007. smalltalk.Object.fn.prototype._initialize.apply(_st(self), []);
  1008. self["@session"]=_st($DoIt())._new();
  1009. self["@readline"]=_st(require)._value_("readline");
  1010. self["@util"]=_st(require)._value_("util");
  1011. return self}, function($ctx1) {$ctx1.fill(self,"initialize",{},smalltalk.Repl)})},
  1012. messageSends: ["initialize", "new", "value:"]}),
  1013. smalltalk.Repl);
  1014. smalltalk.addMethod(
  1015. smalltalk.method({
  1016. selector: "instanceVariableNamesFor:",
  1017. fn: function (aClass){
  1018. var self=this;
  1019. return smalltalk.withContext(function($ctx1) {
  1020. var $2,$1;
  1021. $2=_st(aClass)._superclass();
  1022. if(($receiver = $2) == nil || $receiver == undefined){
  1023. $1=_st(aClass)._instanceVariableNames();
  1024. } else {
  1025. $1=_st(_st(aClass)._instanceVariableNames())._copyWithAll_(self._instanceVariableNamesFor_(_st(aClass)._superclass()));
  1026. };
  1027. return $1;
  1028. }, function($ctx1) {$ctx1.fill(self,"instanceVariableNamesFor:",{aClass:aClass},smalltalk.Repl)})},
  1029. messageSends: ["ifNotNil:ifNil:", "copyWithAll:", "instanceVariableNamesFor:", "superclass", "instanceVariableNames"]}),
  1030. smalltalk.Repl);
  1031. smalltalk.addMethod(
  1032. smalltalk.method({
  1033. selector: "isIdentifier:",
  1034. fn: function (aString){
  1035. var self=this;
  1036. return smalltalk.withContext(function($ctx1) {
  1037. var $1;
  1038. $1=_st(aString)._match_("^[a-z_]\x5cw+$"._asRegexp());
  1039. return $1;
  1040. }, function($ctx1) {$ctx1.fill(self,"isIdentifier:",{aString:aString},smalltalk.Repl)})},
  1041. messageSends: ["match:", "asRegexp"]}),
  1042. smalltalk.Repl);
  1043. smalltalk.addMethod(
  1044. smalltalk.method({
  1045. selector: "isVariableDefined:",
  1046. fn: function (aString){
  1047. var self=this;
  1048. return smalltalk.withContext(function($ctx1) {
  1049. var $1;
  1050. $1=_st(self._instanceVariableNamesFor_(_st(self["@session"])._class()))._includes_(aString);
  1051. return $1;
  1052. }, function($ctx1) {$ctx1.fill(self,"isVariableDefined:",{aString:aString},smalltalk.Repl)})},
  1053. messageSends: ["includes:", "instanceVariableNamesFor:", "class"]}),
  1054. smalltalk.Repl);
  1055. smalltalk.addMethod(
  1056. smalltalk.method({
  1057. selector: "nextResultName",
  1058. fn: function (){
  1059. var self=this;
  1060. return smalltalk.withContext(function($ctx1) {
  1061. var $1,$2;
  1062. $1=self["@resultCount"];
  1063. if(($receiver = $1) == nil || $receiver == undefined){
  1064. self["@resultCount"]=(1);
  1065. } else {
  1066. self["@resultCount"]=_st(self["@resultCount"]).__plus((1));
  1067. };
  1068. $2="res".__comma(_st(self["@resultCount"])._asString());
  1069. return $2;
  1070. }, function($ctx1) {$ctx1.fill(self,"nextResultName",{},smalltalk.Repl)})},
  1071. messageSends: ["ifNotNil:ifNil:", "+", ",", "asString"]}),
  1072. smalltalk.Repl);
  1073. smalltalk.addMethod(
  1074. smalltalk.method({
  1075. selector: "onKeyPress:",
  1076. fn: function (key){
  1077. var self=this;
  1078. function $String(){return smalltalk.String||(typeof String=="undefined"?nil:String)}
  1079. return smalltalk.withContext(function($ctx1) {
  1080. var $1;
  1081. $1=_st(_st(key)._ctrl())._and_((function(){
  1082. return smalltalk.withContext(function($ctx2) {
  1083. return _st(_st(key)._name()).__eq("l");
  1084. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  1085. if(smalltalk.assert($1)){
  1086. var esc,cls;
  1087. esc=_st($String())._fromCharCode_((27));
  1088. esc;
  1089. cls=_st(_st(_st(esc).__comma("[2J")).__comma(esc)).__comma("[0;0f");
  1090. cls;
  1091. _st(_st(process)._stdout())._write_(cls);
  1092. _st(self["@interface"])._prompt();
  1093. };
  1094. return self}, function($ctx1) {$ctx1.fill(self,"onKeyPress:",{key:key},smalltalk.Repl)})},
  1095. messageSends: ["ifTrue:", "fromCharCode:", ",", "write:", "stdout", "prompt", "and:", "=", "name", "ctrl"]}),
  1096. smalltalk.Repl);
  1097. smalltalk.addMethod(
  1098. smalltalk.method({
  1099. selector: "parseAssignment:do:",
  1100. fn: function (aString,aBlock){
  1101. var self=this;
  1102. var assignment;
  1103. return smalltalk.withContext(function($ctx1) {
  1104. var $2,$1;
  1105. assignment=_st(_st(aString)._tokenize_(":="))._collect_((function(s){
  1106. return smalltalk.withContext(function($ctx2) {
  1107. return _st(s)._trimBoth();
  1108. }, function($ctx2) {$ctx2.fillBlock({s:s},$ctx1)})}));
  1109. $2=_st(_st(_st(assignment)._size()).__eq((2)))._and_((function(){
  1110. return smalltalk.withContext(function($ctx2) {
  1111. return self._isIdentifier_(_st(assignment)._first());
  1112. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  1113. if(smalltalk.assert($2)){
  1114. $1=_st(aBlock)._value_value_(_st(assignment)._first(),_st(assignment)._last());
  1115. } else {
  1116. $1=_st(aBlock)._value_value_(nil,nil);
  1117. };
  1118. return $1;
  1119. }, function($ctx1) {$ctx1.fill(self,"parseAssignment:do:",{aString:aString,aBlock:aBlock,assignment:assignment},smalltalk.Repl)})},
  1120. messageSends: ["collect:", "trimBoth", "tokenize:", "ifTrue:ifFalse:", "value:value:", "first", "last", "and:", "isIdentifier:", "=", "size"]}),
  1121. smalltalk.Repl);
  1122. smalltalk.addMethod(
  1123. smalltalk.method({
  1124. selector: "presentResultNamed:withValue:",
  1125. fn: function (varName,value){
  1126. var self=this;
  1127. function $Transcript(){return smalltalk.Transcript||(typeof Transcript=="undefined"?nil:Transcript)}
  1128. return smalltalk.withContext(function($ctx1) {
  1129. var $1,$2;
  1130. $1=$Transcript();
  1131. _st($1)._show_(_st(_st(_st(_st(varName).__comma(": ")).__comma(_st(_st(value)._class())._name())).__comma(" = ")).__comma(_st(value)._asString()));
  1132. $2=_st($1)._cr();
  1133. _st(self["@interface"])._prompt();
  1134. return self}, function($ctx1) {$ctx1.fill(self,"presentResultNamed:withValue:",{varName:varName,value:value},smalltalk.Repl)})},
  1135. messageSends: ["show:", ",", "asString", "name", "class", "cr", "prompt"]}),
  1136. smalltalk.Repl);
  1137. smalltalk.addMethod(
  1138. smalltalk.method({
  1139. selector: "printWelcome",
  1140. fn: function (){
  1141. var self=this;
  1142. function $Smalltalk(){return smalltalk.Smalltalk||(typeof Smalltalk=="undefined"?nil:Smalltalk)}
  1143. function $Transcript(){return smalltalk.Transcript||(typeof Transcript=="undefined"?nil:Transcript)}
  1144. return smalltalk.withContext(function($ctx1) {
  1145. var $1,$2;
  1146. _st($Transcript())._show_(_st(_st(_st("Welcome to Amber version ".__comma(_st(_st($Smalltalk())._current())._version())).__comma(" (NodeJS ")).__comma(_st(_st(process)._versions())._node())).__comma(")."));
  1147. $1=$Transcript();
  1148. _st($1)._show_("Type :q to exit.");
  1149. $2=_st($1)._cr();
  1150. return self}, function($ctx1) {$ctx1.fill(self,"printWelcome",{},smalltalk.Repl)})},
  1151. messageSends: ["show:", ",", "node", "versions", "version", "current", "cr"]}),
  1152. smalltalk.Repl);
  1153. smalltalk.addMethod(
  1154. smalltalk.method({
  1155. selector: "processLine:",
  1156. fn: function (buffer){
  1157. var self=this;
  1158. var show;
  1159. return smalltalk.withContext(function($ctx1) {
  1160. var $1,$2;
  1161. show=(function(varName,value){
  1162. return smalltalk.withContext(function($ctx2) {
  1163. return self._presentResultNamed_withValue_(varName,value);
  1164. }, function($ctx2) {$ctx2.fillBlock({varName:varName,value:value},$ctx1)})});
  1165. $1=self._executeCommand_(buffer);
  1166. if(! smalltalk.assert($1)){
  1167. $2=self._isVariableDefined_(buffer);
  1168. if(smalltalk.assert($2)){
  1169. _st(show)._value_value_(buffer,_st(self["@session"])._perform_(buffer));
  1170. } else {
  1171. self._assignNewVariable_do_(buffer,show);
  1172. };
  1173. };
  1174. return self}, function($ctx1) {$ctx1.fill(self,"processLine:",{buffer:buffer,show:show},smalltalk.Repl)})},
  1175. messageSends: ["presentResultNamed:withValue:", "ifFalse:", "ifTrue:ifFalse:", "value:value:", "perform:", "assignNewVariable:do:", "isVariableDefined:", "executeCommand:"]}),
  1176. smalltalk.Repl);
  1177. smalltalk.addMethod(
  1178. smalltalk.method({
  1179. selector: "prompt",
  1180. fn: function (){
  1181. var self=this;
  1182. return smalltalk.withContext(function($ctx1) {
  1183. return "amber >> ";
  1184. }, function($ctx1) {$ctx1.fill(self,"prompt",{},smalltalk.Repl)})},
  1185. messageSends: []}),
  1186. smalltalk.Repl);
  1187. smalltalk.addMethod(
  1188. smalltalk.method({
  1189. selector: "setPreviousVariablesFor:from:",
  1190. fn: function (newObject,oldObject){
  1191. var self=this;
  1192. return smalltalk.withContext(function($ctx1) {
  1193. _st(self._instanceVariableNamesFor_(_st(oldObject)._class()))._do_((function(each){
  1194. return smalltalk.withContext(function($ctx2) {
  1195. return _st(newObject)._perform_withArguments_(_st(each).__comma(":"),[_st(oldObject)._perform_(each)]);
  1196. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
  1197. return self}, function($ctx1) {$ctx1.fill(self,"setPreviousVariablesFor:from:",{newObject:newObject,oldObject:oldObject},smalltalk.Repl)})},
  1198. messageSends: ["do:", "perform:withArguments:", ",", "perform:", "instanceVariableNamesFor:", "class"]}),
  1199. smalltalk.Repl);
  1200. smalltalk.addMethod(
  1201. smalltalk.method({
  1202. selector: "setPrompt",
  1203. fn: function (){
  1204. var self=this;
  1205. return smalltalk.withContext(function($ctx1) {
  1206. _st(self["@interface"])._setPrompt_(self._prompt());
  1207. return self}, function($ctx1) {$ctx1.fill(self,"setPrompt",{},smalltalk.Repl)})},
  1208. messageSends: ["setPrompt:", "prompt"]}),
  1209. smalltalk.Repl);
  1210. smalltalk.addMethod(
  1211. smalltalk.method({
  1212. selector: "setupHotkeys",
  1213. fn: function (){
  1214. var self=this;
  1215. return smalltalk.withContext(function($ctx1) {
  1216. var $1;
  1217. _st(_st(process)._stdin())._on_do_("keypress",(function(s,key){
  1218. return smalltalk.withContext(function($ctx2) {
  1219. $1=key;
  1220. if(($receiver = $1) == nil || $receiver == undefined){
  1221. return $1;
  1222. } else {
  1223. return self._onKeyPress_(key);
  1224. };
  1225. }, function($ctx2) {$ctx2.fillBlock({s:s,key:key},$ctx1)})}));
  1226. return self}, function($ctx1) {$ctx1.fill(self,"setupHotkeys",{},smalltalk.Repl)})},
  1227. messageSends: ["on:do:", "ifNotNil:", "onKeyPress:", "stdin"]}),
  1228. smalltalk.Repl);
  1229. smalltalk.addMethod(
  1230. smalltalk.method({
  1231. selector: "subclass:withVariable:",
  1232. fn: function (aClass,varName){
  1233. var self=this;
  1234. function $ClassBuilder(){return smalltalk.ClassBuilder||(typeof ClassBuilder=="undefined"?nil:ClassBuilder)}
  1235. return smalltalk.withContext(function($ctx1) {
  1236. var $1;
  1237. $1=_st(_st($ClassBuilder())._new())._addSubclassOf_named_instanceVariableNames_package_(aClass,_st(self._subclassNameFor_(aClass))._asSymbol(),[varName],"Compiler-Core");
  1238. return $1;
  1239. }, function($ctx1) {$ctx1.fill(self,"subclass:withVariable:",{aClass:aClass,varName:varName},smalltalk.Repl)})},
  1240. messageSends: ["addSubclassOf:named:instanceVariableNames:package:", "asSymbol", "subclassNameFor:", "new"]}),
  1241. smalltalk.Repl);
  1242. smalltalk.addMethod(
  1243. smalltalk.method({
  1244. selector: "subclassNameFor:",
  1245. fn: function (aClass){
  1246. var self=this;
  1247. return smalltalk.withContext(function($ctx1) {
  1248. var $2,$1;
  1249. $2=_st(_st(aClass)._name())._matchesOf_("\x5cd+$");
  1250. if(($receiver = $2) == nil || $receiver == undefined){
  1251. $1=_st(_st(aClass)._name()).__comma("2");
  1252. } else {
  1253. var counter;
  1254. counter=_st(_st(_st(_st(_st(aClass)._name())._matchesOf_("\x5cd+$"))._first())._asNumber()).__plus((1));
  1255. counter;
  1256. $1=_st(_st(aClass)._name())._replaceRegexp_with_("\x5cd+$"._asRegexp(),_st(counter)._asString());
  1257. };
  1258. return $1;
  1259. }, function($ctx1) {$ctx1.fill(self,"subclassNameFor:",{aClass:aClass},smalltalk.Repl)})},
  1260. messageSends: ["ifNotNil:ifNil:", "+", "asNumber", "first", "matchesOf:", "name", "replaceRegexp:with:", "asRegexp", "asString", ","]}),
  1261. smalltalk.Repl);
  1262. smalltalk.addMethod(
  1263. smalltalk.method({
  1264. selector: "main",
  1265. fn: function (){
  1266. var self=this;
  1267. return smalltalk.withContext(function($ctx1) {
  1268. _st(self._new())._createInterface();
  1269. return self}, function($ctx1) {$ctx1.fill(self,"main",{},smalltalk.Repl.klass)})},
  1270. messageSends: ["createInterface", "new"]}),
  1271. smalltalk.Repl.klass);