Use handlebars from npm.
This commit is contained in:
22
Cakefile
22
Cakefile
@@ -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,18 +42,17 @@ 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...'
|
||||||
|
|||||||
Reference in New Issue
Block a user