Merge branch 'version_system' into build_system
This commit is contained in:
commit
eb30cd3b33
74
Cakefile
74
Cakefile
|
@ -34,19 +34,38 @@ source_files = ->
|
||||||
all_sources.push source
|
all_sources.push source
|
||||||
all_sources.unique()
|
all_sources.unique()
|
||||||
|
|
||||||
|
# Get the version number
|
||||||
|
#
|
||||||
|
version = ->
|
||||||
|
"#{fs.readFileSync('VERSION')}".replace /[^0-9a-zA-Z.]*/gm, ''
|
||||||
|
|
||||||
|
version_tag = ->
|
||||||
|
"v#{version()}"
|
||||||
|
|
||||||
|
# Write chosen files with a header
|
||||||
|
#
|
||||||
|
write_chosen_javascript = (filename, body) ->
|
||||||
|
fs.writeFileSync filename, """
|
||||||
|
// Chosen #{version()} https://github.com/harvesthq/chosen
|
||||||
|
// Copyright (c) 2011 Harvest http://getharvest.com
|
||||||
|
// MIT License, https://github.com/harvesthq/chosen/blob/master/LICENSE.md
|
||||||
|
// This file is generated by `cake build`, do not edit it by hand.
|
||||||
|
#{body}
|
||||||
|
"""
|
||||||
|
|
||||||
# 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
|
for javascript, sources of javascripts
|
||||||
code = ''
|
code = ''
|
||||||
for source in sources
|
for source in sources
|
||||||
code += CoffeeScript.compile "\n#{fs.readFileSync source}"
|
code += CoffeeScript.compile "#{fs.readFileSync source}"
|
||||||
fs.writeFileSync javascript, code
|
write_chosen_javascript javascript, code
|
||||||
unless process.env.MINIFY is 'false'
|
unless process.env.MINIFY is 'false'
|
||||||
fs.writeFileSync 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'
|
||||||
|
|
||||||
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/"
|
||||||
|
@ -60,3 +79,50 @@ task 'watch', 'watch coffee/ for changes and build Chosen', ->
|
||||||
console.log "Saw change in #{file}"
|
console.log "Saw change in #{file}"
|
||||||
invoke 'build'
|
invoke 'build'
|
||||||
)(file)
|
)(file)
|
||||||
|
|
||||||
|
run = (cmd, args, cb, err_cb) ->
|
||||||
|
exec "#{cmd} #{args.join(' ')}", (err, stdout, stderr) ->
|
||||||
|
if err isnt null
|
||||||
|
console.error stderr
|
||||||
|
if typeof err_cb is 'function'
|
||||||
|
err_cb()
|
||||||
|
else
|
||||||
|
throw "Failed command execution (#{err})."
|
||||||
|
else
|
||||||
|
cb(stdout) if typeof cb is 'function'
|
||||||
|
|
||||||
|
with_clean_repo = (cb) ->
|
||||||
|
run 'git', ['diff', '--exit-code'], cb, ->
|
||||||
|
throw 'There are files that need to be committed first.'
|
||||||
|
|
||||||
|
without_existing_tag = (cb) ->
|
||||||
|
run 'git', ['tag'], (stdout) ->
|
||||||
|
if stdout.split("\n").indexOf( version_tag() ) >= 0
|
||||||
|
throw 'This tag has already been committed to the repo.'
|
||||||
|
else
|
||||||
|
cb()
|
||||||
|
|
||||||
|
tag_release = (cb, cb_err) ->
|
||||||
|
run 'git', ['tag', '-a', '-m', "\"Version #{version()}\"", version_tag()], cb, cb_err
|
||||||
|
|
||||||
|
untag_release = (e) ->
|
||||||
|
console.log "Failure to tag caught: #{e}"
|
||||||
|
console.log "Removing tag #{version_tag()}"
|
||||||
|
run 'git', ['tag', '-d', version_tag()]
|
||||||
|
|
||||||
|
push_repo = (args=[], cb, cb_err) ->
|
||||||
|
run 'git', ['push'].concat(args), cb, cb_err
|
||||||
|
|
||||||
|
task 'release', 'build, tag the current release, and push', ->
|
||||||
|
console.log "Trying to tag #{version_tag()}..."
|
||||||
|
with_clean_repo ->
|
||||||
|
without_existing_tag ->
|
||||||
|
build ->
|
||||||
|
tag_release ->
|
||||||
|
push_repo [], ->
|
||||||
|
push_repo ['--tags'], ->
|
||||||
|
console.log "Successfully tagged #{version_tag()}: https://github.com/harvesthq/chosen/tree/#{version_tag()}"
|
||||||
|
|
||||||
|
, untag_release
|
||||||
|
, untag_release
|
||||||
|
, untag_release
|
||||||
|
|
Loading…
Reference in a new issue