 {render} = require './renderer'
 {runGenerator} = require './generator'
 
-{readJSON} = utils
+{readJSON, readJSONSync} = utils
 
 class Environment
   ### The Wintersmith environment. ###

      groups.push generator.group unless generator.group in groups
    return groups

  loadModule: (module, callback) ->
    ### Load a *module*, from the current working directory. ###
    require 'coffee-script' if module[-7..] is '.coffee'
    @logger.silly "loading module: #{ module }"
    try
      id = @resolveModule module
      @logger.silly "resolved: #{ id }"
      callback null, require id
      @loadedModules.push id
    catch error
      callback error

  loadPluginModule: (module, callback) ->
    ### Load a plugin *module*. ###
    async.waterfall [
      (callback) =>
        if typeof module is 'string'
          @loadModule module, callback
        else
          callback null, module
      (fn, callback) =>
        try
          fn this, callback
        catch error
          callback error
    ], (error) ->
      error.message = "Error loading plugin '#{ module }': #{ error.message }" if error?
      callback error

  loadViewModule: (module, callback) ->
    ### Load a view *module* and add it to the environment. ###
    @logger.verbose "loading view: #{ module }"
    async.waterfall [
      (callback) => @loadModule module, callback
      (fn, callback) =>
        @registerView path.basename(module), fn
        callback()
    ], (error) ->
      error.message = "Error loading view '#{ module }': #{ error.message }" if error?
      callback error

  loadPlugins: (callback) ->
    ### Loads any plugin found in *@config.plugins*. ###

    loadTemplates this, callback

  getLocals: (callback) ->
    ### Returns locals. ###
    # TODO: locals are no longer loaded async, this method should eventually be removed
    callback null, @locals

  load: (callback) ->
    ### Convenience method to load plugins, views, contents, templates and locals. ###
