UNPKG

50.8 kBJavaScriptView Raw
1var __t;
2
3__t = function(ns) {
4 var curr, index, part, parts, _i, _len;
5 curr = null;
6 parts = [].concat = ns.split(".");
7 for (index = _i = 0, _len = parts.length; _i < _len; index = ++_i) {
8 part = parts[index];
9 if (curr === null) {
10 curr = eval(part);
11 continue;
12 } else {
13 if (curr[part] == null) {
14 curr = curr[part] = {};
15 } else {
16 curr = curr[part];
17 }
18 }
19 }
20 return curr;
21};
22
23var toaster = exports.toaster = {};
24
25(function() {
26 var Toaster, debug, error, growl, icon_error, icon_warn, interval, log, msgs, process_msgs, queue_msg, start_worker, stop_worker, warn,
27 __slice = [].slice,
28 __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
29 __hasProp = {}.hasOwnProperty,
30 __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
31
32 __t('toaster.generators').Question = (function() {
33
34 function Question() {}
35
36 Question.prototype.ask = function(question, format, fn) {
37 var stdin, stdout,
38 _this = this;
39 stdin = process.stdin;
40 stdout = process.stdout;
41 stdin.resume();
42 stdout.write("" + question + " ");
43 return stdin.once('data', function(data) {
44 var msg, rule;
45 data = data.toString().trim();
46 if (format.test(data)) {
47 return fn(data);
48 } else {
49 msg = "" + 'Invalid entry, it should match:'.red;
50 rule = "" + (format.toString().cyan);
51 stdout.write("\t" + msg + " " + rule + "\n");
52 return _this.ask(question, format, fn);
53 }
54 });
55 };
56
57 return Question;
58
59 })();
60
61 __t('toaster.utils').ArrayUtil = (function() {
62
63 function ArrayUtil() {}
64
65 ArrayUtil.find = function(source, search, by_property) {
66 var k, p, v, _i, _j, _k, _len, _len1, _len2;
67 if (!by_property) {
68 for (k = _i = 0, _len = source.length; _i < _len; k = ++_i) {
69 v = source[k];
70 if (v === search) {
71 return {
72 item: v,
73 index: k
74 };
75 }
76 }
77 } else {
78 by_property = [].concat(by_property);
79 for (k = _j = 0, _len1 = source.length; _j < _len1; k = ++_j) {
80 v = source[k];
81 for (_k = 0, _len2 = by_property.length; _k < _len2; _k++) {
82 p = by_property[_k];
83 if (search === v[p]) {
84 return {
85 item: v,
86 index: k
87 };
88 }
89 }
90 }
91 }
92 return null;
93 };
94
95 ArrayUtil.find_all = function(source, search, by_property, regexp, unique) {
96 var item, k, p, v, _i, _j, _k, _len, _len1, _len2, _output, _unique;
97 _output = [];
98 _unique = {};
99 if (by_property === null) {
100 for (k = _i = 0, _len = source.length; _i < _len; k = ++_i) {
101 v = source[k];
102 if (regexp) {
103 if (search.test(v)) {
104 item = {
105 item: v,
106 index: k
107 };
108 }
109 } else {
110 if (search === v) {
111 item = {
112 item: v,
113 index: k
114 };
115 }
116 }
117 if (item) {
118 _output.push(item);
119 }
120 }
121 } else {
122 by_property = [].concat(by_property);
123 for (k = _j = 0, _len1 = source.length; _j < _len1; k = ++_j) {
124 v = source[k];
125 for (_k = 0, _len2 = by_property.length; _k < _len2; _k++) {
126 p = by_property[_k];
127 item = null;
128 if (regexp) {
129 if (search.test(v[p])) {
130 if (unique && !_unique[k]) {
131 item = {
132 item: v,
133 index: k
134 };
135 } else if (unique === !true) {
136 item = {
137 item: v,
138 index: k
139 };
140 }
141 }
142 } else {
143 if (search === v[p]) {
144 item = {
145 item: v,
146 index: k
147 };
148 }
149 }
150 if (item) {
151 _unique[k] = true;
152 _output.push(item);
153 }
154 }
155 }
156 }
157 return _output;
158 };
159
160 ArrayUtil.diff = function(a, b, by_property) {
161 var diff, item, search, _i, _j, _len, _len1;
162 if (a == null) {
163 a = [];
164 }
165 if (b == null) {
166 b = [];
167 }
168 diff = [];
169 for (_i = 0, _len = a.length; _i < _len; _i++) {
170 item = a[_i];
171 search = by_property != null ? item[by_property] : item;
172 if (!ArrayUtil.has(b, search, by_property)) {
173 diff.push({
174 item: item,
175 action: "deleted"
176 });
177 }
178 }
179 for (_j = 0, _len1 = b.length; _j < _len1; _j++) {
180 item = b[_j];
181 search = by_property != null ? item[by_property] : item;
182 if (!ArrayUtil.has(a, search, by_property)) {
183 diff.push({
184 item: item,
185 action: "created"
186 });
187 }
188 }
189 return diff;
190 };
191
192 ArrayUtil.has = function(source, search, by_property) {
193 return ArrayUtil.find(source, search, by_property) != null;
194 };
195
196 ArrayUtil.replace_into = function(src, index, items) {
197 items = [].concat(items);
198 src.splice(index, 1);
199 while (items.length) {
200 src.splice(index++, 0, items.shift());
201 }
202 return src;
203 };
204
205 return ArrayUtil;
206
207 })();
208
209 __t('toaster.utils').FnUtil = (function() {
210
211 function FnUtil() {}
212
213 FnUtil.proxy = function() {
214 var fn, params;
215 fn = arguments[0], params = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
216 return function() {
217 var inner_params;
218 inner_params = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
219 return fn.apply(null, params.concat(inner_params));
220 };
221 };
222
223 return FnUtil;
224
225 })();
226
227 __t('toaster.utils').FsUtil = (function() {
228 var ArrayUtil, FnUtil, fs, path, pn;
229
230 function FsUtil() {}
231
232 path = require("path");
233
234 fs = require("fs");
235
236 pn = (require("path")).normalize;
237
238 FnUtil = toaster.utils.FnUtil;
239
240 ArrayUtil = toaster.utils.ArrayUtil;
241
242 FsUtil.rmdir_rf = function(folderpath, root) {
243 var file, files, stats, _i, _len;
244 if (root == null) {
245 root = true;
246 }
247 files = fs.readdirSync(folderpath);
248 for (_i = 0, _len = files.length; _i < _len; _i++) {
249 file = files[_i];
250 file = "" + folderpath + "/" + file;
251 stats = fs.lstatSync(file);
252 if (stats.isDirectory()) {
253 FsUtil.rmdir_rf(file, false);
254 fs.rmdirSync(file);
255 } else {
256 fs.unlinkSync(file);
257 }
258 }
259 if (root) {
260 return fs.rmdirSync(folderpath);
261 }
262 };
263
264 FsUtil.mkdir_p = function(folderpath) {
265 var exists, folder, folders, index, _i, _len;
266 if ((folderpath.slice(-1)) === "/") {
267 folderpath = folderpath.slice(0, -1);
268 }
269 folders = folderpath.split("/");
270 for (index = _i = 0, _len = folders.length; _i < _len; index = ++_i) {
271 folder = folders[index];
272 if ((folder = folders.slice(0, index + 1).join("/")) === "") {
273 continue;
274 }
275 exists = path.existsSync(folder);
276 if (exists && index === folders.length - 1) {
277 throw new Error(error("Folder exists: " + folder.red));
278 return false;
279 } else if (!exists) {
280 fs.mkdirSync(folder, '0755');
281 }
282 }
283 return true;
284 };
285
286 FsUtil.find = function(folderpath, pattern, include_dirs) {
287 var file, filepath, files, found, found_under, _i, _len;
288 if (include_dirs == null) {
289 include_dirs = false;
290 }
291 found = [];
292 files = fs.readdirSync(folderpath);
293 for (_i = 0, _len = files.length; _i < _len; _i++) {
294 file = files[_i];
295 filepath = pn("" + folderpath + "/" + file);
296 if (fs.lstatSync(filepath).isDirectory()) {
297 if (include_dirs && filepath.match(pattern)) {
298 found = found.concat(filepath);
299 }
300 found_under = FsUtil.find(filepath, pattern, include_dirs);
301 found = found.concat(found_under);
302 } else {
303 if (filepath.match(pattern)) {
304 found.push(filepath);
305 }
306 }
307 }
308 return found;
309 };
310
311 FsUtil.ls_folders = function(folderpath) {
312 var file, filepath, files, found, _i, _len;
313 found = [];
314 files = fs.readdirSync(folderpath);
315 for (_i = 0, _len = files.length; _i < _len; _i++) {
316 file = files[_i];
317 filepath = "" + folderpath + "/" + file;
318 if (fs.lstatSync(filepath).isDirectory()) {
319 found.push(filepath);
320 }
321 }
322 return found;
323 };
324
325 FsUtil.take_snapshot = function(folderpath) {
326 var file, filepath, files, found, type, _i, _len;
327 found = [];
328 files = fs.readdirSync(folderpath);
329 for (_i = 0, _len = files.length; _i < _len; _i++) {
330 file = files[_i];
331 filepath = "" + folderpath + "/" + file;
332 if (fs.lstatSync(filepath).isDirectory()) {
333 type = "folder";
334 } else {
335 type = "file";
336 }
337 found.push({
338 type: type,
339 path: filepath
340 });
341 }
342 return found;
343 };
344
345 FsUtil.watch_file = function(filepath, onchange, dispatch_create) {
346 var _this = this;
347 filepath = pn(filepath);
348 FsUtil.unwatch_file(filepath);
349 if (dispatch_create) {
350 if (typeof onchange === "function") {
351 onchange({
352 type: "file",
353 path: filepath,
354 action: "created"
355 });
356 }
357 }
358 if (typeof onchange === "function") {
359 onchange({
360 type: "file",
361 path: filepath,
362 action: "watching"
363 });
364 }
365 return fs.watchFile(filepath, {
366 interval: 250
367 }, function(curr, prev) {
368 var ctime, mtime;
369 mtime = curr.mtime.valueOf() !== prev.mtime.valueOf();
370 ctime = curr.ctime.valueOf() !== prev.ctime.valueOf();
371 if (mtime || ctime) {
372 return typeof onchange === "function" ? onchange({
373 type: "file",
374 path: filepath,
375 action: "updated"
376 }) : void 0;
377 }
378 });
379 };
380
381 FsUtil.unwatch_file = function(filepath, onchange) {
382 FsUtil.watched[filepath] = false;
383 return fs.unwatchFile(filepath);
384 };
385
386 FsUtil.snapshots = {};
387
388 FsUtil.watchers = {};
389
390 FsUtil.watched = {};
391
392 FsUtil.watch_folder = function(folderpath, filter_regexp, onchange, dispatch_create) {
393 var item, on_folder_change, watchers, _i, _len, _ref;
394 if (FsUtil.watchers[folderpath]) {
395 watchers = FsUtil.watchers[folderpath];
396 } else {
397 watchers = FsUtil.watchers[folderpath] = [];
398 }
399 folderpath = pn(folderpath);
400 if (typeof onchange === "function") {
401 onchange({
402 type: "folder",
403 path: folderpath,
404 action: "watching"
405 });
406 }
407 FsUtil.snapshots[folderpath] = FsUtil.take_snapshot(folderpath);
408 _ref = FsUtil.snapshots[folderpath];
409 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
410 item = _ref[_i];
411 if (item.type === "folder") {
412 if (dispatch_create) {
413 onchange({
414 type: item.type,
415 path: item.path,
416 action: "created"
417 });
418 }
419 FsUtil.watch_folder(item.path, filter_regexp, onchange, dispatch_create);
420 } else if (filter_regexp === null || filter_regexp.test(item.path)) {
421 if (dispatch_create) {
422 onchange({
423 type: item.type,
424 path: item.path,
425 action: "created"
426 });
427 }
428 FsUtil.watch_file(item.path, onchange);
429 }
430 }
431 watchers.push({
432 folderpath: folderpath,
433 filter: filter_regexp,
434 onchange: onchange,
435 dispatch_create: dispatch_create
436 });
437 if (!FsUtil.watched[folderpath]) {
438 FsUtil.watched[folderpath] = true;
439 on_folder_change = FnUtil.proxy(FsUtil._on_folder_change, folderpath);
440 fs.unwatchFile(folderpath);
441 return fs.watchFile(folderpath, {
442 interval: 250
443 }, on_folder_change);
444 }
445 };
446
447 FsUtil._on_folder_change = function(folderpath, curr, prev) {
448 var a, b, diff, info, item, watcher, watchers, _i, _j, _k, _len, _len1, _len2, _results;
449 if (!path.existsSync(folderpath)) {
450 return;
451 }
452 a = FsUtil.snapshots[folderpath];
453 b = FsUtil.snapshots[folderpath] = FsUtil.take_snapshot(folderpath);
454 diff = ArrayUtil.diff(a, b, "path");
455 if (!diff.length) {
456 return;
457 }
458 watchers = FsUtil.watchers[folderpath];
459 _results = [];
460 for (_i = 0, _len = diff.length; _i < _len; _i++) {
461 item = diff[_i];
462 info = item.item;
463 info.action = item.action;
464 if (info.action === "created") {
465 if (info.type === "file") {
466 _results.push((function() {
467 var _j, _len1, _results1;
468 _results1 = [];
469 for (_j = 0, _len1 = watchers.length; _j < _len1; _j++) {
470 watcher = watchers[_j];
471 if (watcher.filter.test(info.path)) {
472 if (typeof watcher.onchange === "function") {
473 watcher.onchange(info);
474 }
475 _results1.push(FsUtil.watch_file(info.path, watcher.onchange));
476 } else {
477 _results1.push(void 0);
478 }
479 }
480 return _results1;
481 })());
482 } else if (info.type === "folder") {
483 _results.push((function() {
484 var _j, _len1, _results1;
485 _results1 = [];
486 for (_j = 0, _len1 = watchers.length; _j < _len1; _j++) {
487 watcher = watchers[_j];
488 if (typeof watcher.onchange === "function") {
489 watcher.onchange(info);
490 }
491 _results1.push(FsUtil.watch_folder(info.path, watcher.filter, watcher.onchange, true));
492 }
493 return _results1;
494 })());
495 } else {
496 _results.push(void 0);
497 }
498 } else if (info.action === "deleted") {
499 if (info.type === "file") {
500 for (_j = 0, _len1 = watchers.length; _j < _len1; _j++) {
501 watcher = watchers[_j];
502 if (watcher.filter.test(info.path)) {
503 if (typeof watcher.onchange === "function") {
504 watcher.onchange(info);
505 }
506 }
507 }
508 fs.unwatchFile(info.path);
509 _results.push(FsUtil.watched[info.path] = false);
510 } else if (info.type === "folder") {
511 for (_k = 0, _len2 = watchers.length; _k < _len2; _k++) {
512 watcher = watchers[_k];
513 if (typeof watcher.onchange === "function") {
514 watcher.onchange(info);
515 }
516 }
517 _results.push(FsUtil.unwatch_folder(info.path));
518 } else {
519 _results.push(void 0);
520 }
521 } else {
522 _results.push(void 0);
523 }
524 }
525 return _results;
526 };
527
528 FsUtil.unwatch_folder = function(folderpath, onchange) {
529 var exists, item, list, watcher_path, _ref, _ref1, _results;
530 _ref = FsUtil.watchers;
531 for (watcher_path in _ref) {
532 list = _ref[watcher_path];
533 if (new RegExp("^" + folderpath).test(watcher_path)) {
534 FsUtil.watchers[watcher_path] = null;
535 }
536 }
537 _ref1 = FsUtil.watched;
538 _results = [];
539 for (item in _ref1) {
540 exists = _ref1[item];
541 if (exists && new RegExp("^" + folderpath).test(item)) {
542 FsUtil.watched[item] = false;
543 _results.push(fs.unwatchFile(item));
544 } else {
545 _results.push(void 0);
546 }
547 }
548 return _results;
549 };
550
551 return FsUtil;
552
553 }).call(this);
554
555 growl = require('growl');
556
557 icon_warn = '/Users/nybras/Dropbox/Workspace/serpentem/coffee-toaster/images/warning.png';
558
559 icon_error = '/Users/nybras/Dropbox/Workspace/serpentem/coffee-toaster/images/error.png';
560
561 log = function(msg, send_to_growl) {
562 if (send_to_growl == null) {
563 send_to_growl = false;
564 }
565 console.log(msg);
566 return msg;
567 };
568
569 debug = function(msg, send_to_growl) {
570 if (send_to_growl == null) {
571 send_to_growl = false;
572 }
573 msg = log("" + msg.magenta);
574 return msg;
575 };
576
577 error = function(msg, send_to_growl, file) {
578 if (send_to_growl == null) {
579 send_to_growl = true;
580 }
581 if (file == null) {
582 file = null;
583 }
584 msg = log("ERROR ".bold.red + msg);
585 if (send_to_growl) {
586 msg = msg.replace(/\[\d{2}m/g, "");
587 msg = msg.replace(/(\[\dm)([^\s]+)/ig, "<$2>$3");
588 queue_msg({
589 msg: msg,
590 opts: {
591 title: 'Coffee Toaster',
592 image: icon_error
593 }
594 });
595 }
596 return msg;
597 };
598
599 warn = function(msg, send_to_growl) {
600 if (send_to_growl == null) {
601 send_to_growl = true;
602 }
603 msg = log("WARNING ".bold.yellow + msg);
604 if (send_to_growl) {
605 msg = msg.replace(/\[\d{2}m/g, "");
606 msg = msg.replace(/(\[\dm)([^\s]+)/ig, "<$2>$3");
607 queue_msg({
608 msg: msg,
609 opts: {
610 title: 'Coffee Toaster',
611 image: icon_warn
612 }
613 });
614 }
615 return msg;
616 };
617
618 msgs = [];
619
620 interval = null;
621
622 start_worker = function() {
623 if (interval == null) {
624 interval = setInterval(process_msgs, 150);
625 return process_msgs();
626 }
627 };
628
629 stop_worker = function() {
630 if (interval != null) {
631 clearInterval(interval);
632 return interval = null;
633 }
634 };
635
636 queue_msg = function(msg) {
637 msgs.push(msg);
638 return start_worker();
639 };
640
641 process_msgs = function() {
642 var msg;
643 if (msgs.length) {
644 msg = msgs.shift();
645 return growl.notify(msg.msg, msg.opts);
646 } else {
647 return stop_worker();
648 }
649 };
650
651 __t('toaster.utils').StringUtil = (function() {
652
653 function StringUtil() {}
654
655 StringUtil.titleize = function(str) {
656 var index, word, words, _i, _len;
657 words = str.match(/[a-z]+/gi);
658 for (index = _i = 0, _len = words.length; _i < _len; index = ++_i) {
659 word = words[index];
660 words[index] = StringUtil.ucasef(word);
661 }
662 return words.join(" ");
663 };
664
665 StringUtil.ucasef = function(str) {
666 var output;
667 output = str.substr(0, 1).toUpperCase();
668 return output += str.substr(1).toLowerCase();
669 };
670
671 return StringUtil;
672
673 })();
674
675 __t('toaster.core').Script = (function() {
676 var ArrayUtil, cs, fs, path, pn;
677
678 fs = require("fs");
679
680 path = require('path');
681
682 pn = path.normalize;
683
684 cs = require("coffee-script");
685
686 ArrayUtil = toaster.utils.ArrayUtil;
687
688 function Script(builder, folderpath, realpath, alias, opts) {
689 this.builder = builder;
690 this.folderpath = folderpath;
691 this.realpath = realpath;
692 this.alias = alias;
693 this.opts = opts;
694 this.getinfo();
695 }
696
697 Script.prototype.getinfo = function() {
698 var baseclass, item, klass, repl, requirements, rgx, rgx_ext, _i, _j, _len, _len1, _ref, _ref1, _results;
699 this.raw = fs.readFileSync(this.realpath, "utf-8");
700 this.dependencies_collapsed = [];
701 this.baseclasses = [];
702 this.filepath = this.realpath.replace(this.folderpath, "").substr(1);
703 if (this.alias != null) {
704 this.filepath = pn("" + this.alias + "/" + this.filepath);
705 }
706 this.filename = /[\w-]+\.[\w-]+/.exec(this.filepath)[0];
707 this.filefolder = this.filepath.replace("/" + this.filename, "") + "/";
708 this.namespace = "";
709 if (this.filepath.indexOf("/") === -1) {
710 this.filefolder = "";
711 }
712 this.namespace = this.filefolder.replace(/\//g, ".").slice(0, -1);
713 rgx = /^\s*(class)+\s(\w+)(\s+(extends)\s+([\w.]+))?/gm;
714 rgx_ext = /(^|=\s*)(class)\s(\w+)\s(extends)\s(\\w+)\s*$/gm;
715 if (this.raw.match(rgx) != null) {
716 this.classpath = this.classname;
717 if (this.namespace !== "" && this.builder.packaging) {
718 repl = "$1 __t('" + this.namespace + "').$2$3";
719 this.raw = this.raw.replace(rgx, repl);
720 this.classpath = "" + this.namespace + "." + this.classname;
721 }
722 this.classname = this.raw.match(rgx)[3];
723 _ref1 = (_ref = this.raw.match(rgx_ext)) != null ? _ref : [];
724 for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
725 klass = _ref1[_i];
726 baseclass = klass.match(rgx_ext)[5];
727 this.baseclasses.push(baseclass);
728 }
729 }
730 if (/(#<<\s)(.*)/g.test(this.raw)) {
731 requirements = this.raw.match(/(#<<\s)(.*)/g);
732 _results = [];
733 for (_j = 0, _len1 = requirements.length; _j < _len1; _j++) {
734 item = requirements[_j];
735 item = /(#<<\s)(.*)/.exec(item)[2];
736 item = item.replace(/\s/g, "");
737 item = [].concat(item.split(","));
738 _results.push(this.dependencies_collapsed = this.dependencies_collapsed.concat(item));
739 }
740 return _results;
741 }
742 };
743
744 Script.prototype.expand_dependencies = function() {
745 var dependency, expanded, files, found, index, reg, _i, _j, _len, _len1, _ref;
746 files = this.builder.files;
747 this.dependencies = [];
748 _ref = this.dependencies_collapsed;
749 for (index = _i = 0, _len = _ref.length; _i < _len; index = ++_i) {
750 dependency = _ref[index];
751 if (dependency.substr(-1) !== "*") {
752 this.dependencies.push("" + dependency + ".coffee");
753 continue;
754 }
755 reg = new RegExp(dependency.replace(/(\/)/g, "\\$1"));
756 found = ArrayUtil.find_all(files, reg, "filepath", true, true);
757 if (found.length <= 0) {
758 warn(("Nothing found inside " + ("'" + dependency).white + "'").yellow);
759 continue;
760 }
761 for (_j = 0, _len1 = found.length; _j < _len1; _j++) {
762 expanded = found[_j];
763 if (expanded.item.filepath !== this.filepath) {
764 this.dependencies.push(expanded.item.filepath);
765 }
766 }
767 }
768 return this.dependencies;
769 };
770
771 return Script;
772
773 })();
774
775 __t('toaster').Cli = (function() {
776 var optimist;
777
778 optimist = require('optimist');
779
780 function Cli() {
781 var usage;
782 usage = "" + 'CoffeeToaster'.bold + "\n";
783 usage += " Minimalist dependency management for CoffeeScript\n\n".grey;
784 usage += "" + 'Usage:' + "\n";
785 usage += " toaster [" + 'options'.green + "] [" + 'path'.green + "]\n\n";
786 usage += "" + 'Examples:' + "\n";
787 usage += " toaster -n myawsomeapp (" + 'required'.red + ")\n";
788 usage += " toaster -i [myawsomeapp] (" + 'optional'.green + ")\n";
789 usage += " toaster -w [myawsomeapp] (" + 'optional'.green + ")";
790 this.argv = (this.opts = optimist.usage(usage).alias('n', 'new').describe('n', "Scaffold a very basic new App").alias('i', 'init').describe('i', "Create a config (toaster.coffee) file").alias('w', 'watch').describe('w', "Start watching/compiling your project").alias('c', 'compile').boolean('c').describe('c', "Compile the entire project, without watching it.").alias('d', 'debug').boolean('d')["default"]('d', false).describe('d', 'Debug mode (compile js files individually)').alias('j', 'config').string('j').describe('j', "Config file formatted as a json-string.").alias('f', 'config-file').string('f').describe('f', "Path to a different config file.").alias('v', 'version').describe('v', '').alias('h', 'help').describe('h', '')).argv;
791 }
792
793 return Cli;
794
795 })();
796
797 __t('toaster.core').Builder = (function() {
798 var ArrayUtil, FnUtil, FsUtil, Script, StringUtil, cs, fs, missing, path, uglify, uglify_parser;
799
800 fs = require('fs');
801
802 path = require('path');
803
804 cs = require("coffee-script");
805
806 uglify = require("uglify-js").uglify;
807
808 uglify_parser = require("uglify-js").parser;
809
810 Script = toaster.core.Script;
811
812 FnUtil = toaster.utils.FnUtil;
813
814 FsUtil = toaster.utils.FsUtil;
815
816 ArrayUtil = toaster.utils.ArrayUtil;
817
818 StringUtil = toaster.utils.StringUtil;
819
820 Builder.prototype._toaster_helper = "__t = ( ns )->\n curr = null\n parts = [].concat = ns.split \".\"\n for part, index in parts\n if curr == null\n curr = eval part\n continue\n else\n unless curr[ part ]?\n curr = curr[ part ] = {}\n else\n curr = curr[ part ]\n curr";
821
822 Builder.prototype._include_tmpl = "document.write('<scri'+'pt src=\"%SRC%\"></scr'+'ipt>')";
823
824 function Builder(toaster, cli, config) {
825 this.toaster = toaster;
826 this.cli = cli;
827 this.config = config;
828 this.merge_vendors = __bind(this.merge_vendors, this);
829
830 this.build_namespaces_declaration = __bind(this.build_namespaces_declaration, this);
831
832 this.build = __bind(this.build, this);
833
834 this.vendors = this.config.vendors;
835 this.bare = this.config.bare;
836 this.packaging = this.config.packaging;
837 this.expose = this.config.expose;
838 this.minify = this.config.minify;
839 this.exclude = [].concat(this.config.exclude);
840 this.httpfolder = this.config.httpfolder;
841 this.release = this.config.release;
842 this.debug = this.config.debug;
843 this.init();
844 if (this.cli.argv.w) {
845 this.watch();
846 }
847 }
848
849 Builder.prototype.init = function() {
850 var falias, file, folder, fpath, include, item, result, s, _i, _len, _ref, _results;
851 this.files = this.config.files;
852 _ref = this.config.src_folders;
853 _results = [];
854 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
855 folder = _ref[_i];
856 result = FsUtil.find(folder.path, /.coffee/);
857 fpath = folder.path;
858 falias = folder.alias;
859 _results.push((function() {
860 var _j, _k, _len1, _len2, _ref1, _results1;
861 _results1 = [];
862 for (_j = 0, _len1 = result.length; _j < _len1; _j++) {
863 file = result[_j];
864 include = true;
865 _ref1 = this.exclude;
866 for (_k = 0, _len2 = _ref1.length; _k < _len2; _k++) {
867 item = _ref1[_k];
868 include &= !(new RegExp(item).test(file));
869 }
870 if (include) {
871 s = new Script(this, fpath, file, falias, this.cli);
872 _results1.push(this.files.push(s));
873 } else {
874 _results1.push(void 0);
875 }
876 }
877 return _results1;
878 }).call(this));
879 }
880 return _results;
881 };
882
883 Builder.prototype.build = function(header_code, footer_code) {
884 var ast, contents, f, files, helper, i, include, namespaces, now, tmpl, vendors, _i, _len;
885 if (header_code == null) {
886 header_code = "";
887 }
888 if (footer_code == null) {
889 footer_code = "";
890 }
891 namespaces = this.build_namespaces();
892 if (this.packaging) {
893 helper = cs.compile(this._toaster_helper, {
894 bare: true
895 });
896 } else {
897 helper = "";
898 }
899 vendors = this.merge_vendors();
900 contents = [];
901 if (vendors !== "") {
902 contents.push(vendors);
903 }
904 if (this.packaging) {
905 contents.push(helper);
906 }
907 if (this.packaging) {
908 contents.push(namespaces);
909 }
910 if (header_code !== "") {
911 contents.push(header_code);
912 }
913 contents.push(this.compile());
914 if (header_code !== "") {
915 contents.push(footer_code);
916 }
917 contents = contents.join('\n');
918 if (this.minify) {
919 ast = uglify_parser.parse(contents);
920 ast = uglify.ast_mangle(ast);
921 ast = uglify.ast_squeeze(ast);
922 contents = uglify.gen_code(ast);
923 }
924 fs.writeFileSync(this.release, contents);
925 now = new Date();
926 now = "" + (now.getHours()) + ":" + (now.getMinutes()) + ":" + (now.getSeconds());
927 log(("" + 'Compiled'.bold + " " + this.release + " @ " + now).green);
928 if (this.cli.argv.d && (this.debug != null)) {
929 files = this.compile_for_debug();
930 for (i = _i = 0, _len = files.length; _i < _len; i = ++_i) {
931 f = files[i];
932 include = "" + this.httpfolder + "/toaster/" + f;
933 tmpl = this._include_tmpl.replace("%SRC%", include);
934 files[i] = tmpl;
935 }
936 contents = [];
937 if (vendors !== "") {
938 contents.push(vendors);
939 }
940 if (this.packaging) {
941 contents.push(helper);
942 }
943 if (this.packaging) {
944 contents.push(namespaces);
945 }
946 if (header_code !== "") {
947 contents.push(header_code);
948 }
949 contents.push(files.join("\n"));
950 if (header_code !== "") {
951 contents.push(footer_code);
952 }
953 contents = contents.join('\n');
954 fs.writeFileSync(this.debug, contents);
955 now = new Date();
956 now = "" + (now.getHours()) + ":" + (now.getMinutes()) + ":" + (now.getSeconds());
957 return log(("" + 'Compiled'.bold + " " + this.debug + " @ " + now).green);
958 }
959 };
960
961 Builder.prototype.build_namespaces = function(after_build_namespaces) {
962 var folder, name, namespaces, subfolder, subfolders, _i, _j, _len, _len1, _ref;
963 namespaces = "";
964 _ref = this.config.src_folders;
965 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
966 folder = _ref[_i];
967 if (folder.alias != null) {
968 namespaces += this.build_namespaces_declaration(folder.alias);
969 } else {
970 subfolders = FsUtil.ls_folders(folder.path);
971 for (_j = 0, _len1 = subfolders.length; _j < _len1; _j++) {
972 subfolder = subfolders[_j];
973 name = subfolder.match(/[^\/]+$/m);
974 namespaces += this.build_namespaces_declaration(name);
975 }
976 }
977 }
978 return namespaces;
979 };
980
981 Builder.prototype.build_namespaces_declaration = function(name) {
982 var declaration;
983 declaration = "";
984 if (this.packaging) {
985 declaration += "var " + name + " = ";
986 }
987 if (this.expose != null) {
988 declaration += "" + this.expose + "." + name + " = ";
989 }
990 if (declaration.length) {
991 declaration += "{};\n";
992 }
993 return declaration;
994 };
995
996 Builder.prototype.watch = function() {
997 var src, _i, _len, _ref, _results,
998 _this = this;
999 _ref = this.config.src_folders;
1000 _results = [];
1001 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
1002 src = _ref[_i];
1003 _results.push(FsUtil.watch_folder(src.path, /.coffee$/, FnUtil.proxy(function(src, info) {
1004 var falias, file, fpath, ipath, msg, relative_path, s, type;
1005 if (info.action === "watching") {
1006 return;
1007 }
1008 if (info.type === "folder" && info.action === "created") {
1009 return;
1010 }
1011 ipath = info.path;
1012 fpath = src.path;
1013 falias = src.alias || "";
1014 type = StringUtil.titleize(info.type);
1015 relative_path = info.path.replace("" + fpath + "/", "" + falias + "/");
1016 if (relative_path.substr(0, 1) === "/") {
1017 relative_path = relative_path.substr(1);
1018 }
1019 switch (info.action) {
1020 case "created":
1021 if (info.type === "file") {
1022 s = new Script(_this, fpath, ipath, falias, _this.cli);
1023 _this.files.push(s);
1024 }
1025 msg = "" + ('New ' + info.type + ' created').bold.cyan;
1026 log("" + msg + " " + info.path.green);
1027 break;
1028 case "deleted":
1029 file = ArrayUtil.find(_this.files, relative_path, "filepath");
1030 if (file === null) {
1031 return;
1032 }
1033 _this.files.splice(file.index, 1);
1034 msg = "" + (type + ' deleted, stop watching').bold.red;
1035 log("" + msg + " " + info.path.red);
1036 break;
1037 case "updated":
1038 file = ArrayUtil.find(_this.files, relative_path, "filepath");
1039 file.item.getinfo();
1040 msg = "" + (type + ' changed').bold.cyan;
1041 log("" + msg + " " + info.path.cyan);
1042 }
1043 _this.build();
1044 return typeof after_watch === "function" ? after_watch() : void 0;
1045 }, src)));
1046 }
1047 return _results;
1048 };
1049
1050 Builder.prototype.compile = function() {
1051 var file, msg, output, _i, _j, _len, _len1, _ref, _ref1;
1052 _ref = this.files;
1053 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
1054 file = _ref[_i];
1055 try {
1056 cs.compile(file.raw);
1057 } catch (err) {
1058 msg = err.message.replace('"', '\\"');
1059 msg = ("" + msg.white + " at file: ") + ("" + file.filepath).bold.red;
1060 error(msg);
1061 return null;
1062 }
1063 }
1064 _ref1 = this.files;
1065 for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
1066 file = _ref1[_j];
1067 file.expand_dependencies();
1068 }
1069 this.reorder();
1070 output = ((function() {
1071 var _k, _len2, _ref2, _results;
1072 _ref2 = this.files;
1073 _results = [];
1074 for (_k = 0, _len2 = _ref2.length; _k < _len2; _k++) {
1075 file = _ref2[_k];
1076 _results.push(file.raw);
1077 }
1078 return _results;
1079 }).call(this)).join("\n");
1080 return output = cs.compile(output, {
1081 bare: this.bare
1082 });
1083 };
1084
1085 Builder.prototype.compile_for_debug = function() {
1086 var absolute_path, file, files, folder_path, index, msg, relative_path, release_path, _i, _len, _ref;
1087 release_path = this.release.split("/").slice(0, -1).join("/");
1088 release_path += "/toaster";
1089 if (path.existsSync(release_path)) {
1090 FsUtil.rmdir_rf(release_path);
1091 }
1092 FsUtil.mkdir_p(release_path);
1093 files = [];
1094 _ref = this.files;
1095 for (index = _i = 0, _len = _ref.length; _i < _len; index = ++_i) {
1096 file = _ref[index];
1097 relative_path = file.filepath.replace(".coffee", ".js");
1098 absolute_path = "" + release_path + "/" + relative_path;
1099 folder_path = absolute_path.split('/').slice(0, -1).join("/");
1100 if (!path.existsSync(folder_path)) {
1101 FsUtil.mkdir_p(folder_path);
1102 }
1103 try {
1104 fs.writeFileSync(absolute_path, cs.compile(file.raw, {
1105 bare: this.bare
1106 }));
1107 } catch (err) {
1108 msg = err.message.replace('"', '\\"');
1109 console.log("MSG:::: " + msg);
1110 msg = ("" + msg.white + " at file: ") + ("" + file.filepath).bold.red;
1111 error(msg);
1112 continue;
1113 }
1114 files.push(relative_path);
1115 }
1116 return files;
1117 };
1118
1119 missing = {};
1120
1121 Builder.prototype.reorder = function(cycling) {
1122 var bc, dependency, dependency_index, file, file_index, filepath, found, i, index, not_found, _i, _j, _len, _len1, _ref, _ref1, _results;
1123 if (cycling == null) {
1124 cycling = false;
1125 }
1126 if (cycling === false) {
1127 this.missing = {};
1128 }
1129 _ref = this.files;
1130 _results = [];
1131 for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) {
1132 file = _ref[i];
1133 if (!file.dependencies.length && !file.baseclasses.length) {
1134 continue;
1135 }
1136 _ref1 = file.dependencies;
1137 for (index = _j = 0, _len1 = _ref1.length; _j < _len1; index = ++_j) {
1138 filepath = _ref1[index];
1139 dependency = ArrayUtil.find(this.files, filepath, "filepath");
1140 if (dependency != null) {
1141 dependency_index = dependency.index;
1142 }
1143 if (dependency_index < i && (dependency != null)) {
1144 continue;
1145 }
1146 if (dependency != null) {
1147 if (ArrayUtil.has(dependency.item.dependencies, file.filepath)) {
1148 file.dependencies.splice(index, 1);
1149 warn("Circular dependency found between ".yellow + filepath.grey.bold + " and ".yellow + file.filepath.grey.bold);
1150 continue;
1151 } else {
1152 this.files.splice(index, 0, dependency.item);
1153 this.files.splice(dependency.index + 1, 1);
1154 this.reorder(true);
1155 break;
1156 }
1157 } else if (this.missing[filepath] !== true) {
1158 this.missing[filepath] = true;
1159 file.dependencies.push(filepath);
1160 file.dependencies.splice(index, 1);
1161 warn(("" + 'Dependency'.yellow + " " + filepath.bold.grey + " ") + ("" + 'not found for file'.yellow + " ") + file.filepath.grey.bold);
1162 }
1163 }
1164 file_index = ArrayUtil.find(this.files, file.filepath, "filepath");
1165 file_index = file_index.index;
1166 _results.push((function() {
1167 var _k, _len2, _ref2, _results1;
1168 _ref2 = file.baseclasses;
1169 _results1 = [];
1170 for (_k = 0, _len2 = _ref2.length; _k < _len2; _k++) {
1171 bc = _ref2[_k];
1172 found = ArrayUtil.find(this.files, bc, "classname");
1173 not_found = (found === null) || (found.index > file_index);
1174 if (not_found && !this.missing[bc]) {
1175 this.missing[bc] = true;
1176 _results1.push(warn("Base class ".yellow + ("" + bc + " ").bold.grey + "not found for class ".yellow + ("" + file.classname + " ").bold.grey + "in file ".yellow + file.filepath.bold.grey));
1177 } else {
1178 _results1.push(void 0);
1179 }
1180 }
1181 return _results1;
1182 }).call(this));
1183 }
1184 return _results;
1185 };
1186
1187 Builder.prototype.merge_vendors = function() {
1188 var buffer, vendor, _i, _len, _ref;
1189 buffer = [];
1190 _ref = this.vendors;
1191 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
1192 vendor = _ref[_i];
1193 if (path.existsSync(vendor)) {
1194 buffer.push(fs.readFileSync(vendor, 'utf-8'));
1195 } else {
1196 warn("Vendor not found at ".white + vendor.yellow.bold);
1197 }
1198 }
1199 return buffer.join("\n");
1200 };
1201
1202 return Builder;
1203
1204 })();
1205
1206 __t('toaster.generators').Config = (function(_super) {
1207 var fs, path, pn;
1208
1209 __extends(Config, _super);
1210
1211 path = require("path");
1212
1213 pn = path.normalize;
1214
1215 fs = require("fs");
1216
1217 Config.prototype.tpl = "# => SRC FOLDER\ntoast '%src%'\n\n # EXCLUDED FOLDERS (optional)\n # exclude: ['folder/to/exclude', 'another/folder/to/exclude', ... ]\n\n # => VENDORS (optional)\n # vendors: ['vendors/x.js', 'vendors/y.js', ... ]\n\n # => OPTIONS (optional, default values listed)\n # bare: false\n # packaging: true\n # expose: ''\n # minify: false\n\n # => HTTPFOLDER (optional), RELEASE / DEBUG (required)\n httpfolder: '%httpfolder%'\n release: '%release%'\n debug: '%debug%'";
1218
1219 function Config(basepath) {
1220 this.basepath = basepath;
1221 this.write = __bind(this.write, this);
1222
1223 this.create = __bind(this.create, this);
1224
1225 }
1226
1227 Config.prototype.create = function(folderpath) {
1228 var q1, q2, q3,
1229 _this = this;
1230 if ((folderpath != null) && folderpath !== true) {
1231 this.basepath = "" + this.basepath + "/" + folderpath;
1232 }
1233 log("" + 'Let\'s toast this sly little project! :)'.grey.bold);
1234 log(". With this as your basepath: " + this.basepath.cyan);
1235 log(". Please, tell me:");
1236 q1 = "\tWhere's your src folder? (i.e. src): ";
1237 q2 = "\tWhere do you want your release file? (i.e. www/js/app.js) : ";
1238 q3 = "\tStarting from your webroot '/', what's the folderpath to " + "reach your release file? (i.e. js) (optional) : ";
1239 return this.ask(q1.magenta, /.+/, function(src) {
1240 return _this.ask(q2.magenta, /.+/, function(release) {
1241 return _this.ask(q3.cyan, /.*/, function(httpfolder) {
1242 return _this.write(src, release, httpfolder);
1243 });
1244 });
1245 });
1246 };
1247
1248 Config.prototype.write = function(src, release, httpfolder) {
1249 var buffer, filename, filepath, parts, question, rgx,
1250 _this = this;
1251 filepath = pn("" + this.basepath + "/toaster.coffee");
1252 rgx = /(\/)?((\w+)(\.*)(\w+$))/;
1253 parts = rgx.exec(release);
1254 filename = parts[2];
1255 if (filename.indexOf(".") > 0) {
1256 debug = release.replace(rgx, "$1$3-debug$4$5");
1257 } else {
1258 debug = "" + release + "-debug";
1259 }
1260 buffer = this.tpl.replace("%src%", src);
1261 buffer = buffer.replace("%release%", release);
1262 buffer = buffer.replace("%debug%", debug);
1263 buffer = buffer.replace("%httpfolder%", httpfolder);
1264 if (path.existsSync(filepath)) {
1265 question = "\tDo you want to overwrite the file: " + filepath.yellow;
1266 question += " ? [y/N] : ".white;
1267 return this.ask(question, /.*?/, function(overwrite) {
1268 if (overwrite.match(/y/i)) {
1269 _this.save(filepath, buffer);
1270 return process.exit();
1271 }
1272 });
1273 } else {
1274 this.save(filepath, buffer);
1275 return process.exit();
1276 }
1277 };
1278
1279 Config.prototype.save = function(filepath, contents) {
1280 fs.writeFileSync(filepath, contents);
1281 log("" + 'Created'.green.bold + " " + filepath);
1282 return process.exit();
1283 };
1284
1285 return Config;
1286
1287 })(toaster.generators.Question);
1288
1289 __t('toaster.generators').Project = (function(_super) {
1290 var FsUtil, fs, path, pn;
1291
1292 __extends(Project, _super);
1293
1294 path = require("path");
1295
1296 pn = path.normalize;
1297
1298 fs = require("fs");
1299
1300 FsUtil = toaster.utils.FsUtil;
1301
1302 function Project(basepath) {
1303 this.basepath = basepath;
1304 this.scaffold = __bind(this.scaffold, this);
1305
1306 }
1307
1308 Project.prototype.create = function(folderpath, name, src, release) {
1309 var q1, q2, q3, target,
1310 _this = this;
1311 if (!folderpath || folderpath === true) {
1312 return error("You need to inform a target path!\n" + "\ttoaster -n myawesomeapp".green);
1313 }
1314 if (folderpath.substr(0, 1) !== "/") {
1315 target = "" + this.basepath + "/" + folderpath;
1316 } else {
1317 target = folderpath;
1318 }
1319 if ((name != null) && (src != null) && (release != null)) {
1320 return this.scaffold(target, name, src, release);
1321 }
1322 log("" + 'Let\'s toast something fresh! :)'.grey.bold);
1323 log(". With this as your basepath: " + target.cyan);
1324 log(". Please tell me:");
1325 q1 = "\tWhere do you want your src folder? [src] : ";
1326 q2 = "\tWhere do you want your release file? [www/js/app.js] : ";
1327 q3 = "\tStarting from your webroot '/', what's the folderpath to " + "reach your release file? (i.e. javascript) (optional) : ";
1328 return this.ask(q1.magenta, /.*/, function(src) {
1329 if (src == null) {
1330 src = null;
1331 }
1332 return _this.ask(q2.magenta, /.*/, function(release) {
1333 if (release == null) {
1334 release = null;
1335 }
1336 return _this.ask(q3.cyan, /.*/, function(httpfolder) {
1337 var $httpfolder, $release, $src;
1338 if (httpfolder == null) {
1339 httpfolder = null;
1340 }
1341 $src = src || "src";
1342 $release = release || "www/js/app.js";
1343 if (src === '' && release === '' && httpfolder === '') {
1344 $httpfolder = 'js';
1345 } else {
1346 $httpfolder = httpfolder || "";
1347 }
1348 _this.scaffold(target, $src, $release, $httpfolder);
1349 return process.exit();
1350 });
1351 });
1352 });
1353 };
1354
1355 Project.prototype.scaffold = function(target, src, release, httpfolder) {
1356 var releasedir, releasefile, srcdir, vendorsdir;
1357 srcdir = pn("" + target + "/" + src);
1358 vendorsdir = pn("" + target + "/vendors");
1359 releasefile = pn("" + target + "/" + release);
1360 releasedir = releasefile.split("/").slice(0, -1).join("/");
1361 if (FsUtil.mkdir_p(target)) {
1362 log("" + 'Created'.green.bold + " " + target);
1363 }
1364 if (FsUtil.mkdir_p(srcdir)) {
1365 log("" + 'Created'.green.bold + " " + srcdir);
1366 }
1367 if (FsUtil.mkdir_p(vendorsdir)) {
1368 log("" + 'Created'.green.bold + " " + vendorsdir);
1369 }
1370 if (FsUtil.mkdir_p(releasedir)) {
1371 log("" + 'Created'.green.bold + " " + releasedir);
1372 }
1373 srcdir = srcdir.replace(target, "").substr(1);
1374 releasefile = releasefile.replace(target, "").substr(1);
1375 return new toaster.generators.Config(target).write(srcdir, releasefile, httpfolder);
1376 };
1377
1378 return Project;
1379
1380 })(toaster.generators.Question);
1381
1382 __t('toaster').Toast = (function() {
1383 var colors, cs, exec, fs, path, pn;
1384
1385 fs = require("fs");
1386
1387 path = require("path");
1388
1389 pn = path.normalize;
1390
1391 exec = (require("child_process")).exec;
1392
1393 colors = require('colors');
1394
1395 cs = require("coffee-script");
1396
1397 Toast.prototype.builders = [];
1398
1399 function Toast(toaster) {
1400 var code, config, config_file, contents, filepath, fix_scope, item, _i, _len, _ref;
1401 this.toaster = toaster;
1402 this.toast = __bind(this.toast, this);
1403
1404 this.basepath = this.toaster.basepath;
1405 if ((config = this.toaster.cli.argv["config"]) != null) {
1406 if (!(config instanceof Object)) {
1407 config = JSON.parse(config);
1408 }
1409 _ref = [].concat(config);
1410 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
1411 item = _ref[_i];
1412 this.toast(item);
1413 }
1414 } else {
1415 config_file = this.toaster.cli.argv["config-file"];
1416 filepath = config_file || pn("" + this.basepath + "/toaster.coffee");
1417 if (path.existsSync(filepath)) {
1418 contents = fs.readFileSync(filepath, "utf-8");
1419 fix_scope = /(^[\s\t]?)(toast)+(\()/mg;
1420 code = cs.compile(contents, {
1421 bare: 1
1422 });
1423 code = code.replace(fix_scope, "$1this.$2$3");
1424 eval(code);
1425 } else {
1426 error("File not found: ".yellow + (" " + filepath.red + "\n") + "Try running:".yellow + " toaster -i".green + " or type".yellow + (" " + 'toaster -h'.green + " ") + "for more info".yellow);
1427 }
1428 }
1429 }
1430
1431 Toast.prototype.toast = function(srcpath, params) {
1432 var alias, config, folder, item, _i, _len, _ref, _ref1, _ref2, _ref3, _ref4, _ref5, _ref6, _ref7, _ref8;
1433 if (params == null) {
1434 params = {};
1435 }
1436 if (srcpath instanceof Object) {
1437 params = srcpath;
1438 } else if (srcpath.substr(0, 1) !== "/") {
1439 srcpath = "" + this.toaster.basepath + "/" + srcpath;
1440 }
1441 debug = params.debug ? pn("" + this.basepath + "/" + params.debug) : null;
1442 config = {
1443 is_building: false,
1444 basepath: this.basepath,
1445 src_folders: [],
1446 files: [],
1447 vendors: (_ref = params.vendors) != null ? _ref : [],
1448 exclude: (_ref1 = params.exclude) != null ? _ref1 : [],
1449 bare: (_ref2 = params.bare) != null ? _ref2 : false,
1450 packaging: (_ref3 = params.packaging) != null ? _ref3 : true,
1451 expose: (_ref4 = params.expose) != null ? _ref4 : null,
1452 minify: (_ref5 = params.minify) != null ? _ref5 : false,
1453 httpfolder: (_ref6 = params.httpfolder) != null ? _ref6 : "",
1454 release: pn("" + this.basepath + "/" + params.release),
1455 debug: debug
1456 };
1457 if (!(srcpath instanceof Object)) {
1458 config.src_folders.push({
1459 path: srcpath,
1460 alias: params.alias || null
1461 });
1462 }
1463 if (params.folders != null) {
1464 _ref7 = params.folders;
1465 for (folder in _ref7) {
1466 alias = _ref7[folder];
1467 if (folder.substr(0, 1 === !"/")) {
1468 folder = pn("" + this.basepath + "/" + folder + "/");
1469 }
1470 config.src_folders.push({
1471 path: folder,
1472 alias: alias
1473 });
1474 }
1475 }
1476 _ref8 = config.src_folders;
1477 for (_i = 0, _len = _ref8.length; _i < _len; _i++) {
1478 item = _ref8[_i];
1479 if (!path.existsSync(item.path)) {
1480 error(("Source folder doens't exist:\n\t" + item.path.red + "\n") + ("Check your " + 'toaster.coffee'.yellow + " and try again.") + "\n\t" + pn("" + this.basepath + "/toaster.coffee").yellow);
1481 return process.exit();
1482 }
1483 }
1484 return this.builders.push(new toaster.core.Builder(this.toaster, this.toaster.cli, config));
1485 };
1486
1487 return Toast;
1488
1489 })();
1490
1491 exports.run = function() {
1492 return new Toaster;
1493 };
1494
1495 exports.toaster = toaster;
1496
1497 exports.Toaster = Toaster = (function() {
1498 var colors, exec, fs, path, pn;
1499
1500 fs = require("fs");
1501
1502 path = require("path");
1503
1504 pn = path.normalize;
1505
1506 exec = (require("child_process")).exec;
1507
1508 colors = require('colors');
1509
1510 function Toaster(basedir, options, skip_initial_build) {
1511 var config, contents, filepath, k, schema, v;
1512 if (options == null) {
1513 options = null;
1514 }
1515 if (skip_initial_build == null) {
1516 skip_initial_build = false;
1517 }
1518 this.basepath = basedir || path.resolve(".");
1519 this.cli = new toaster.Cli(options);
1520 if (options != null) {
1521 for (k in options) {
1522 v = options[k];
1523 this.cli.argv[k] = v;
1524 }
1525 }
1526 if (this.cli.argv.v) {
1527 filepath = pn(__dirname + "/../package.json");
1528 contents = fs.readFileSync(filepath, "utf-8");
1529 schema = JSON.parse(contents);
1530 return log(schema.version);
1531 } else if (this.cli.argv.n) {
1532 new toaster.generators.Project(this.basepath).create(this.cli.argv.n);
1533 } else if (this.cli.argv.i) {
1534 new toaster.generators.Config(this.basepath).create(this.cli.argv.i);
1535 } else if (this.cli.argv.w) {
1536 config = options && options.config ? options.config : null;
1537 this.toast = new toaster.Toast(this);
1538 if (!skip_initial_build) {
1539 this.build();
1540 }
1541 } else {
1542 return log(this.cli.opts.help());
1543 }
1544 }
1545
1546 Toaster.prototype.build = function(header_code, footer_code) {
1547 var builder, _i, _len, _ref, _results;
1548 if (header_code == null) {
1549 header_code = "";
1550 }
1551 if (footer_code == null) {
1552 footer_code = "";
1553 }
1554 _ref = this.toast.builders;
1555 _results = [];
1556 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
1557 builder = _ref[_i];
1558 _results.push(builder.build(header_code, footer_code));
1559 }
1560 return _results;
1561 };
1562
1563 return Toaster;
1564
1565 })();
1566
1567}).call(this);