Merge pull request #108 from harvesthq/build_system

Build system
This commit is contained in:
Patrick Filler 2011-07-31 10:34:41 -07:00
commit dd04343481
9 changed files with 241 additions and 153 deletions

133
Cakefile Normal file
View file

@ -0,0 +1,133 @@
# Building Chosen requires coffee-script and uglify-js. For
# help installing, try:
#
# `npm -g install coffee-script uglify-js`
#
fs = require 'fs'
path = require 'path'
{spawn, exec} = require 'child_process'
CoffeeScript = require 'coffee-script'
{parser, uglify} = require 'uglify-js'
javascripts = {
'chosen/chosen.jquery.js': [
'coffee/chosen.jquery.coffee'
'coffee/lib/select-parser.coffee'
]
'chosen/chosen.proto.js': [
'coffee/chosen.proto.coffee'
'coffee/lib/select-parser.coffee'
]
}
Array::unique = ->
output = {}
output[@[key]] = @[key] for key in [0...@length]
value for key, value of output
# Gather a list of unique source files.
#
source_files = ->
all_sources = []
for javascript, sources of javascripts
for source in sources
all_sources.push source
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, a Select Box Enhancer for jQuery and Protoype
// by Patrick Filler for Harvest, http://getharvest.com
//
// Version #{version()}
// Full source at 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.
#
task 'build', 'build Chosen from source', build = (cb) ->
for javascript, sources of javascripts
code = ''
for source in sources
code += CoffeeScript.compile "#{fs.readFileSync source}"
write_chosen_javascript javascript, code
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'
task 'watch', 'watch coffee/ for changes and build Chosen', ->
console.log "Watching for changes in coffee/"
for file in source_files()
# Coffeescript wasn't scoping file correctly-
# without this closure the file name displayed
# is incorrect.
((file) ->
fs.watchFile file, (curr, prev) ->
if +curr.mtime isnt +prev.mtime
console.log "Saw change in #{file}"
invoke 'build'
)(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

1
VERSION Normal file
View file

@ -0,0 +1 @@
0.9

View file

@ -1,14 +1,19 @@
// Chosen, a Select Box Enhancer for jQuery and Protoype
// by Patrick Filler for Harvest, http://getharvest.com
//
// Version 0.9
// Full source at 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.
(function() { (function() {
/* /*
Chosen, a Select Box Enhancer for jQuery and Protoype Chosen source: generate output using 'cake build'
by Patrick Filler for Harvest, http://getharvest.com
Available for use under the MIT License, http://en.wikipedia.org/wiki/MIT_License
Copyright (c) 2011 by Harvest Copyright (c) 2011 by Harvest
*/ var $, Chosen, SelectParser, get_side_border_padding, root; */ var $, Chosen, get_side_border_padding, root;
var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }; var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
root = typeof exports !== "undefined" && exports !== null ? exports : this; root = this;
$ = jQuery; $ = jQuery;
$.fn.extend({ $.fn.extend({
chosen: function(data, options) { chosen: function(data, options) {
@ -211,7 +216,7 @@
var content, data, startTime, _i, _len, _ref; var content, data, startTime, _i, _len, _ref;
startTime = new Date(); startTime = new Date();
this.parsing = true; this.parsing = true;
this.results_data = SelectParser.select_to_array(this.form_field); this.results_data = root.SelectParser.select_to_array(this.form_field);
if (this.is_multiple && this.choices > 0) { if (this.is_multiple && this.choices > 0) {
this.search_choices.find("li.search-choice").remove(); this.search_choices.find("li.search-choice").remove();
this.choices = 0; this.choices = 0;
@ -706,6 +711,9 @@
return side_border_padding = elmt.outerWidth() - elmt.width(); return side_border_padding = elmt.outerWidth() - elmt.width();
}; };
root.get_side_border_padding = get_side_border_padding; root.get_side_border_padding = get_side_border_padding;
}).call(this);
(function() {
var SelectParser;
SelectParser = (function() { SelectParser = (function() {
function SelectParser() { function SelectParser() {
this.options_index = 0; this.options_index = 0;
@ -774,5 +782,5 @@
} }
return parser.parsed; return parser.parsed;
}; };
root.SelectParser = SelectParser; this.SelectParser = SelectParser;
}).call(this); }).call(this);

File diff suppressed because one or more lines are too long

View file

@ -1,14 +1,19 @@
// Chosen, a Select Box Enhancer for jQuery and Protoype
// by Patrick Filler for Harvest, http://getharvest.com
//
// Version 0.9
// Full source at 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.
(function() { (function() {
/* /*
Chosen, a Select Box Enhancer for jQuery and Protoype Chosen source: generate output using 'cake build'
by Patrick Filler for Harvest, http://getharvest.com
Available for use under the MIT License, http://en.wikipedia.org/wiki/MIT_License
Copyright (c) 2011 by Harvest Copyright (c) 2011 by Harvest
*/ var Chosen, SelectParser, get_side_border_padding, root; */ var Chosen, get_side_border_padding, root;
var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }; var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
root = typeof exports !== "undefined" && exports !== null ? exports : this; root = this;
Chosen = (function() { Chosen = (function() {
function Chosen(elmn) { function Chosen(elmn) {
this.set_default_values(); this.set_default_values();
@ -199,7 +204,7 @@
var content, data, startTime, _i, _len, _ref; var content, data, startTime, _i, _len, _ref;
startTime = new Date(); startTime = new Date();
this.parsing = true; this.parsing = true;
this.results_data = SelectParser.select_to_array(this.form_field); this.results_data = root.SelectParser.select_to_array(this.form_field);
if (this.is_multiple && this.choices > 0) { if (this.is_multiple && this.choices > 0) {
this.search_choices.select("li.search-choice").invoke("remove"); this.search_choices.select("li.search-choice").invoke("remove");
this.choices = 0; this.choices = 0;
@ -694,7 +699,9 @@
return side_border_padding = layout.get("border-left") + layout.get("border-right") + layout.get("padding-left") + layout.get("padding-right"); return side_border_padding = layout.get("border-left") + layout.get("border-right") + layout.get("padding-left") + layout.get("padding-right");
}; };
root.get_side_border_padding = get_side_border_padding; root.get_side_border_padding = get_side_border_padding;
root = typeof exports !== "undefined" && exports !== null ? exports : this; }).call(this);
(function() {
var SelectParser;
SelectParser = (function() { SelectParser = (function() {
function SelectParser() { function SelectParser() {
this.options_index = 0; this.options_index = 0;
@ -763,5 +770,5 @@
} }
return parser.parsed; return parser.parsed;
}; };
root.SelectParser = SelectParser; this.SelectParser = SelectParser;
}).call(this); }).call(this);

File diff suppressed because one or more lines are too long

View file

@ -1,13 +1,8 @@
### ###
Chosen, a Select Box Enhancer for jQuery and Protoype Chosen source: generate output using 'cake build'
by Patrick Filler for Harvest, http://getharvest.com
Available for use under the MIT License, http://en.wikipedia.org/wiki/MIT_License
Copyright (c) 2011 by Harvest Copyright (c) 2011 by Harvest
### ###
root = this
root = exports ? this
$ = jQuery $ = jQuery
$.fn.extend({ $.fn.extend({
@ -180,7 +175,7 @@ class Chosen
results_build: -> results_build: ->
startTime = new Date() startTime = new Date()
@parsing = true @parsing = true
@results_data = SelectParser.select_to_array @form_field @results_data = root.SelectParser.select_to_array @form_field
if @is_multiple and @choices > 0 if @is_multiple and @choices > 0
@search_choices.find("li.search-choice").remove() @search_choices.find("li.search-choice").remove()
@ -600,53 +595,3 @@ get_side_border_padding = (elmt) ->
side_border_padding = elmt.outerWidth() - elmt.width() side_border_padding = elmt.outerWidth() - elmt.width()
root.get_side_border_padding = get_side_border_padding root.get_side_border_padding = get_side_border_padding
class SelectParser
constructor: ->
@options_index = 0
@parsed = []
add_node: (child) ->
if child.nodeName is "OPTGROUP"
this.add_group child
else
this.add_option child
add_group: (group) ->
group_position = @parsed.length
@parsed.push
array_index: group_position
group: true
label: group.label
children: 0
disabled: group.disabled
this.add_option( option, group_position, group.disabled ) for option in group.childNodes
add_option: (option, group_position, group_disabled) ->
if option.nodeName is "OPTION"
if option.text != ""
if group_position?
@parsed[group_position].children += 1
@parsed.push
array_index: @parsed.length
options_index: @options_index
value: option.value
text: option.text
html: option.innerHTML
selected: option.selected
disabled: if group_disabled is true then group_disabled else option.disabled
group_array_index: group_position
else
@parsed.push
array_index: @parsed.length
options_index: @options_index
empty: true
@options_index += 1
SelectParser.select_to_array = (select) ->
parser = new SelectParser()
parser.add_node( child ) for child in select.childNodes
parser.parsed
root.SelectParser = SelectParser

View file

@ -1,13 +1,8 @@
### ###
Chosen, a Select Box Enhancer for jQuery and Protoype Chosen source: generate output using 'cake build'
by Patrick Filler for Harvest, http://getharvest.com
Available for use under the MIT License, http://en.wikipedia.org/wiki/MIT_License
Copyright (c) 2011 by Harvest Copyright (c) 2011 by Harvest
### ###
root = this
root = exports ? this
class Chosen class Chosen
@ -173,7 +168,7 @@ class Chosen
results_build: -> results_build: ->
startTime = new Date() startTime = new Date()
@parsing = true @parsing = true
@results_data = SelectParser.select_to_array @form_field @results_data = root.SelectParser.select_to_array @form_field
if @is_multiple and @choices > 0 if @is_multiple and @choices > 0
@search_choices.select("li.search-choice").invoke("remove") @search_choices.select("li.search-choice").invoke("remove")
@ -581,55 +576,3 @@ get_side_border_padding = (elmt) ->
side_border_padding = layout.get("border-left") + layout.get("border-right") + layout.get("padding-left") + layout.get("padding-right") side_border_padding = layout.get("border-left") + layout.get("border-right") + layout.get("padding-left") + layout.get("padding-right")
root.get_side_border_padding = get_side_border_padding root.get_side_border_padding = get_side_border_padding
root = exports ? this
class SelectParser
constructor: ->
@options_index = 0
@parsed = []
add_node: (child) ->
if child.nodeName is "OPTGROUP"
this.add_group child
else
this.add_option child
add_group: (group) ->
group_position = @parsed.length
@parsed.push
array_index: group_position
group: true
label: group.label
children: 0
disabled: group.disabled
this.add_option( option, group_position, group.disabled ) for option in group.childNodes
add_option: (option, group_position, group_disabled) ->
if option.nodeName is "OPTION"
if option.text != ""
if group_position?
@parsed[group_position].children += 1
@parsed.push
array_index: @parsed.length
options_index: @options_index
value: option.value
text: option.text
html: option.innerHTML
selected: option.selected
disabled: if group_disabled is true then group_disabled else option.disabled
group_array_index: group_position
else
@parsed.push
array_index: @parsed.length
options_index: @options_index
empty: true
@options_index += 1
SelectParser.select_to_array = (select) ->
parser = new SelectParser()
parser.add_node( child ) for child in select.childNodes
parser.parsed
root.SelectParser = SelectParser

View file

@ -0,0 +1,49 @@
class SelectParser
constructor: ->
@options_index = 0
@parsed = []
add_node: (child) ->
if child.nodeName is "OPTGROUP"
this.add_group child
else
this.add_option child
add_group: (group) ->
group_position = @parsed.length
@parsed.push
array_index: group_position
group: true
label: group.label
children: 0
disabled: group.disabled
this.add_option( option, group_position, group.disabled ) for option in group.childNodes
add_option: (option, group_position, group_disabled) ->
if option.nodeName is "OPTION"
if option.text != ""
if group_position?
@parsed[group_position].children += 1
@parsed.push
array_index: @parsed.length
options_index: @options_index
value: option.value
text: option.text
html: option.innerHTML
selected: option.selected
disabled: if group_disabled is true then group_disabled else option.disabled
group_array_index: group_position
else
@parsed.push
array_index: @parsed.length
options_index: @options_index
empty: true
@options_index += 1
SelectParser.select_to_array = (select) ->
parser = new SelectParser()
parser.add_node( child ) for child in select.childNodes
parser.parsed
this.SelectParser = SelectParser