forked from timoxley/functional-javascript-workshop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
input.js
42 lines (36 loc) · 900 Bytes
/
input.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
37
38
39
40
41
42
var path = require('path')
var serialize = function(input) {
if (typeof input !== 'function') return JSON.stringify(input)
return JSON.stringify({
isFunction: true,
body: input.toString()
})
}
var deserialize = function(input) {
var out = JSON.parse(input)
if (!out.isFunction) return out
eval('out = (' + out.body + ')')
return out
}
module.exports = function() {
var args = Array.prototype.slice.call(arguments).map(serialize)
function input() {
var opts = {
args: args,
solutionExecWrap: __filename,
execWrap: __filename,
}
return opts
}
input.wrap = function(fn) {
args.push(serialize(fn))
return input
}
return input
}
module.exports.init = function() {
var mod = require(path.resolve(process.cwd(), process.argv[3]))
var args = process.argv.slice(4).map(deserialize)
var wrap = args.pop()
wrap(args, mod)
}