1 |
|
2 | TaskFactory = require "./factory"
|
3 | crc32 = require "crc32"
|
4 | plugin = require "plugin"
|
5 | require "colors"
|
6 | path = require "path"
|
7 |
|
8 |
|
9 | fileRegexp = /(\s+\/([^\/\s]+\/)+[^\/\s]+)/;
|
10 | fileRegexp2 = /(\s+\/([^\/\s]+\/)+[^\/\s]+)/g;
|
11 |
|
12 |
|
13 | require("colorcode").
|
14 | code(/\==> (\w+)/, "==>".cyan+" $1".magenta).
|
15 | code(/\==> load (.*)/, "==> ".cyan+"load".magenta.bold+" $1".bold).
|
16 | code(/( -> )/, "$1".yellow).
|
17 | code(/( \+ )/g, "$1".yellow).
|
18 | code(fileRegexp, (value) ->
|
19 | value.match(fileRegexp2).forEach (file) ->
|
20 | value = value.replace file, " " + path.relative(process.cwd(), file.replace(/\s+/g,""))
|
21 |
|
22 | value
|
23 |
|
24 | ).
|
25 | error( (msg) ->
|
26 | return String(msg).stripColors.bold.red
|
27 | )
|
28 | .info( (msg) ->
|
29 | return String(msg).stripColors.grey
|
30 | )
|
31 | .export(console)
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 | class RootTask
|
40 |
|
41 |
|
42 | |
43 |
|
44 |
|
45 | constructor: (rawTasks) ->
|
46 |
|
47 |
|
48 | @taskFactory = new TaskFactory @
|
49 | @_loadPlugins @taskFactory, __dirname + "/tasks"
|
50 |
|
51 |
|
52 | @entryTask = @taskFactory.newTask null, rawTasks
|
53 |
|
54 |
|
55 | |
56 |
|
57 |
|
58 |
|
59 |
|
60 | run: (target, complete) ->
|
61 |
|
62 | if typeof target == 'function'
|
63 | complete = target
|
64 | target = {}
|
65 |
|
66 | target.buildId = crc32 String Date.now()
|
67 |
|
68 | @entryTask.run target, complete
|
69 |
|
70 |
|
71 | |
72 |
|
73 |
|
74 |
|
75 | _loadPlugins: (factory, directories) ->
|
76 |
|
77 | plugin.
|
78 | loader().
|
79 | factory (plugin) ->
|
80 | factory.add plugin
|
81 | .
|
82 | require(directories).
|
83 | load()
|
84 |
|
85 |
|
86 |
|
87 | exports.make = () -> new RootTask Array.apply [], arguments
|
88 |
|
89 |
|
90 |
|
91 |
|
92 |
|
93 |
|
94 |
|
95 |
|
96 | |
\ | No newline at end of file |