Search code examples
javascriptcoffeescripthubot

Can I write scripts for hubot in Javascript?


Hubot is Github's chatroom robot. It's a great tool, except that no one at our company wants to write in Coffeescript....but it appears that we can't write scripts for Hubot in plain old Javascript.
Is this true? Is there something I'm missing here? Coffeescript is "just javascript" but I can't use Javascript with it?
EDIT
I was making 2 absurdly simple mistakes:
- I copied the CoffeeScript comment syntax into my JS file
- I had the script under the hubot-scripts node_module, instead of just under the /scripts/ directory in the main project.

Works perfectly now.


Solution

  • CoffeeScript is compiled into JavaScript, but it's not a superset of JavaScript, so JavaScript code isn't necessarily valid CoffeeScript code.

    Nevertheless, after looking at the source, it looks like Hubot can accept both:

      # Public: Loads a file in path.
      #
      # path - A String path on the filesystem.
      # file - A String filename in path on the filesystem.
      #
      # Returns nothing.
      loadFile: (path, file) ->
        ext  = Path.extname file
        full = Path.join path, Path.basename(file, ext)
        if ext is '.coffee' or ext is '.js'
          try
            require(full) @
            @parseHelp "#{path}/#{file}"
          catch error
            @logger.error "Unable to load #{full}: #{error.stack}"
            process.exit(1)
    

    This method is called by loadHubotScripts.