 # FUNCTIONS
 toJson = (obj) -> JSON.stringify(obj, null, 2)
 
-parsedToObj = (parsed) -> 
+parsedToObj = (parsed, codeTransformer) -> 
   switch parsed.type
     when "Literal"
       return parsed.value

      obj = {}
      for property in parsed.properties
        propertyName = property.key.name || property.key.value
        obj[propertyName] = parsedToObj(property.value)
      return obj
    when "FunctionExpression" 
      # Don't include the upper-level BlockStatement
      return (escodegen.generate(body, CODE_GENERATION_OPTIONS) for body in parsed.body.body).join("\n")
    else
      util.error("How do I handle parsed type #{parsed.type}?")
      process.exit(2)


# Actions are a JS file that needs to be parsed
parsedActions = esprima.parse(fs.readFileSync(path.join(inputDir, "actions.js"), { encoding: "utf8" }))
# Remove references to "this"
outputObj.actions = parsedToObj(parsedActions.body[0].expression, (code) -> code.replace(/this./g, ""))

# Copy over layout JSON
outputObj.layout = JSON.parse(fs.readFileSync(path.join(inputDir, "layout.json"), { encoding: "utf8" }))
