-
Notifications
You must be signed in to change notification settings - Fork 0
/
jsonBenny.js
executable file
·27 lines (24 loc) · 920 Bytes
/
jsonBenny.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
module.exports = jsonBenny
function jsonBenny (parsedBenny) {
return parsedBenny.map(function (cmd) {
var prefix = cmd.force ? 'FORCE ' : ''
switch (cmd.type) {
case 'via':
if (cmd.path) return prefix + 'VIA ' + JSON.stringify(cmd.path) + '\n'
return prefix + 'VIA ' + cmd.image + (cmd.version ? ':' + cmd.version : '') + '\n'
case 'go':
return prefix + 'GO ' + cmd.command + '\n'
case 'in':
return prefix + 'IN ' + cmd.env.map(toKeyValue).join(' ') + '\n'
case 'do':
return prefix + 'DO ' + cmd.key + (cmd.value ? '=' + JSON.stringify(cmd.value) : '') + '\n'
case 'to':
return prefix + 'TO ' + JSON.stringify(cmd.from) + ' ' + JSON.stringify(cmd.to) + '\n'
default:
throw new Error('Unknown type: ' + cmd.type)
}
}).join('')
}
function toKeyValue (env) {
return env.key + '=' + JSON.stringify(env.value)
}