     # return a buffer
     return new Buffer(output)
 
+  rename = (file) ->
+    ext = it.options.templateName ? path.basename(it.options.templatePath, path.extename(it.options.templatePath))
+    if ext
+      file.basename = path.basename(file.basename, path.extname(file.basename)) + '.' + ext + path.extname(file.basename)
+    return
+
   if gutil.isStream(file.contents)
     es.wait((err, contents) ->
       file.contents = render(contents)
+      rename(file)
       cb(null, file)
       return
     )
     return
   else
     file.contents = render(file.contents)
+    rename(file)
     cb(null, file)
     return
 

    options.namespace ?= name

    if options.templateName? and not options.templatePath?
      options.templatePath = path.join(__dirname, '../templates', options.templateName)

    if options.templatePath?
      if options.templateCache and cache[options.templatePath]?


defaultOptions = {
  templateCache: true
  templateName: 'amd'
  modes: ['cjs', 'amd', 'global', 'default']
  indent: true
}
