-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
36 lines (33 loc) · 957 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
var zsf = require('@zombiec0rn/zombie-service-format')
var clone = require('clone')
var scaleUp = function(config) {
return config.reduce(function(containers, container) {
containers.push(container)
if (!container.scale) return containers
if (typeof container.scale != 'number') return containers
var i = 1
while(i < container.scale) {
var scale = clone(container)
delete scale.scale
scale.id = scale.id+'-scale-'+i
containers.push(scale)
i++
}
return containers
}, [])
}
var scaleDown = function(config) {
return config.reduce(function(containers, container) {
if (container.id.indexOf('-scale-') > 0) return containers
containers.push(container)
return containers
}, [])
}
module.exports = {
up : function(config) {
return scaleUp(zsf.validate((config instanceof Array) ? config : [config]))
},
down : function(config) {
return scaleDown(zsf.validate((config instanceof Array) ? config : [config]))
}
}