Use handlebars from npm.

This commit is contained in:
dblock
2014-09-15 18:58:08 -04:00
parent 264ba2910d
commit 0cdcbfb70b

View File

@@ -2,6 +2,7 @@ fs = require 'fs'
path = require 'path' path = require 'path'
{exec} = require 'child_process' {exec} = require 'child_process'
less = require 'less' less = require 'less'
handlebars = require 'handlebars'
sourceFiles = [ sourceFiles = [
'SwaggerUi' 'SwaggerUi'
@@ -41,19 +42,18 @@ task 'dist', 'Build a distribution', ->
templateContents = new Array remaining = templateFiles.length templateContents = new Array remaining = templateFiles.length
for file, index in templateFiles then do (file, index) -> for file, index in templateFiles then do (file, index) ->
console.log " : Compiling src/main/template/#{file}" console.log " : Compiling src/main/template/#{file}"
exec "handlebars src/main/template/#{file} -f dist/_#{file}.js", (err, stdout, stderr) -> fs.readFile "src/main/template/#{file}", 'utf8', (err, source) ->
throw err if err throw err if err
fs.readFile 'dist/_' + file + '.js', 'utf8', (err, fileContents) -> compiled = handlebars.precompile(source)
throw err if err templateContents[index] = '(function() {\n var template = Handlebars.template, templates = Handlebars.templates = Handlebars.templates || {};\ntemplates[\'' + file.replace('.handlebars', '') + '\'] = template(' + compiled + ');\n})();'
templateContents[index] = fileContents fs.unlink 'dist/_' + file + '.js', (err) ->
fs.unlink 'dist/_' + file + '.js' console.log "#{err.code}: #{err.path}" unless err.code == 'ENOENT'
if --remaining is 0 if --remaining is 0
templateContents.push '\n\n' templateContents.push '\n\n'
fs.writeFile 'dist/_swagger-ui-templates.js', templateContents.join('\n\n'), 'utf8', (err) -> fs.writeFile 'dist/_swagger-ui-templates.js', templateContents.join('\n\n'), 'utf8', (err) ->
throw err if err throw err if err
build() build()
build = -> build = ->
console.log ' : Collecting Coffeescript source...' console.log ' : Collecting Coffeescript source...'