UNPKG

986 Btext/coffeescriptView Raw
1fs = require "fs"
2path = require "path"
3step = require "stepc"
4outcome = require "outcome"
5Commands = require "./commands"
6
7
8
9###
10 creates new builders based on configs given
11###
12
13module.exports = class Factory
14
15 ###
16 ###
17
18 constructor: () ->
19 @_classes = []
20 @commands = new Commands @
21
22 ###
23 adds a builder class - must also be a tester
24 ###
25
26 add: (clazz) ->
27
28 clazz.priority = 0 if not clazz.priority
29
30 @_classes.push clazz
31
32 @_classes = @_classes.sort (a, b) ->
33 if a.priority > b.priority
34 return -1
35 else
36 return 1
37
38 ###
39 returns a new builder based on the options given. CWD is also
40 important since SOME builders may load from disc
41 ###
42
43 newTask: (route, ops, parent) ->
44
45
46 for clazz in @_classes
47
48 if clazz.test ops
49
50 # new builder
51 task = new clazz route, @, parent
52
53 # load it with the options given
54 task.load ops
55
56 # return the builder
57 return task
58
59 # no builder? return null
60 null
\No newline at end of file