Better report compilation errors during build

abstract-chosen
Matthew Beale 2011-08-19 11:41:59 -04:00
parent 1d6df98c4e
commit df6345465a
1 changed files with 39 additions and 10 deletions

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) ->
for javascript, sources of javascripts file_name = null; file_contents = null
code = '' try
for source in sources for javascript, sources of javascripts
code += CoffeeScript.compile "#{fs.readFileSync source}" code = ''
write_chosen_javascript javascript, code for source in sources
unless process.env.MINIFY is 'false' file_name = source
write_chosen_javascript javascript.replace(/\.js$/,'.min.js'), ( file_contents = "#{fs.readFileSync source}"
uglify.gen_code uglify.ast_squeeze uglify.ast_mangle parser.parse code code += CoffeeScript.compile file_contents
) write_chosen_javascript javascript, code
cb() if typeof cb is 'function' unless process.env.MINIFY is 'false'
write_chosen_javascript javascript.replace(/\.js$/,'.min.js'), (
uglify.gen_code uglify.ast_squeeze uglify.ast_mangle parser.parse code
)
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 ->