UNPKG

1.63 kBtext/coffeescriptView Raw
1
2TaskFactory = require "./factory"
3crc32 = require "crc32"
4plugin = require "plugin"
5require "colors"
6path = require "path"
7
8
9fileRegexp = /(\s+\/([^\/\s]+\/)+[^\/\s]+)/;
10fileRegexp2 = /(\s+\/([^\/\s]+\/)+[^\/\s]+)/g;
11
12
13require("colorcode").
14code(/\==> (\w+)/, "==>".cyan+" $1".magenta).
15code(/\==> load (.*)/, "==> ".cyan+"load".magenta.bold+" $1".bold).
16code(/( -> )/, "$1".yellow).
17code(/( \+ )/g, "$1".yellow).
18code(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).
25error( (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 the mesh config value object
37###
38
39class RootTask
40
41
42 ###
43 ###
44
45 constructor: (rawTasks) ->
46
47 # makes new tasks based on config data
48 @taskFactory = new TaskFactory @
49 @_loadPlugins @taskFactory, __dirname + "/tasks"
50
51 # the entry task
52 @entryTask = @taskFactory.newTask null, rawTasks
53
54
55 ###
56 loads a config from disc - important because they MAY contain
57 scripts - in which case we'll need the CWD
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 loads plugins for task factory, or config loader
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
87exports.make = () -> new RootTask Array.apply [], arguments
88
89
90
91
92
93
94
95
96
\No newline at end of file