Better report compilation errors during build

This commit is contained in:
Matthew Beale 2011-08-19 11:41:59 -04:00
parent 1d6df98c4e
commit df6345465a

View file

@ -57,20 +57,27 @@ write_chosen_javascript = (filename, body) ->
// This file is generated by `cake build`, do not edit it by hand. // This file is generated by `cake build`, do not edit it by hand.
#{body} #{body}
""" """
console.log "Wrote #{filename}"
# Build Chosen. # Build Chosen.
# #
task 'build', 'build Chosen from source', build = (cb) -> task 'build', 'build Chosen from source', build = (cb) ->
file_name = null; file_contents = null
try
for javascript, sources of javascripts for javascript, sources of javascripts
code = '' code = ''
for source in sources for source in sources
code += CoffeeScript.compile "#{fs.readFileSync source}" file_name = source
file_contents = "#{fs.readFileSync source}"
code += CoffeeScript.compile file_contents
write_chosen_javascript javascript, code write_chosen_javascript javascript, code
unless process.env.MINIFY is 'false' unless process.env.MINIFY is 'false'
write_chosen_javascript javascript.replace(/\.js$/,'.min.js'), ( write_chosen_javascript javascript.replace(/\.js$/,'.min.js'), (
uglify.gen_code uglify.ast_squeeze uglify.ast_mangle parser.parse code uglify.gen_code uglify.ast_squeeze uglify.ast_mangle parser.parse code
) )
cb() if typeof cb is 'function' cb() if typeof cb is 'function'
catch e
print_error e, file_name, file_contents
task 'watch', 'watch coffee/ for changes and build Chosen', -> task 'watch', 'watch coffee/ for changes and build Chosen', ->
console.log "Watching for changes in coffee/" console.log "Watching for changes in coffee/"
@ -118,6 +125,28 @@ untag_release = (e) ->
push_repo = (args=[], cb, cb_err) -> push_repo = (args=[], cb, cb_err) ->
run 'git', ['push'].concat(args), cb, cb_err run 'git', ['push'].concat(args), cb, cb_err
print_error = (error, file_name, file_contents) ->
line = error.message.match /line ([0-9]+):/
if line && line[1] && line = parseInt(line[1])
contents_lines = file_contents.split "\n"
first = if line-4 < 0 then 0 else line-4
last = if line+3 > contents_lines.size then contents_lines.size else line+3
console.log "Error compiling #{file_name}. \"#{error.message}\"\n"
index = 0
for line in contents_lines[first...last]
index++
line_number = first + 1 + index
console.log "#{(' ' for [0..(3-(line_number.toString().length))]).join('')} #{line}"
else
console.log """
Error compiling #{file_name}:
#{error.message}
"""
task 'release', 'build, tag the current release, and push', -> task 'release', 'build, tag the current release, and push', ->
console.log "Trying to tag #{version_tag()}..." console.log "Trying to tag #{version_tag()}..."
with_clean_repo -> with_clean_repo ->