Permalink
Browse files

Manage and report livereload.js version number

  • Loading branch information...
andreyvit committed Oct 22, 2011
1 parent 8db527f commit 8bc353e290439c5e0d8a45fa94cbdf7187e13d86
Showing with 60 additions and 0 deletions.
  1. +56 −0 Rakefile
  2. +1 −0 VERSION
  3. +3 −0 src/connector.coffee
View
@@ -4,6 +4,10 @@ DIST = 'dist/livereload.js'
COFFEE = FileList['src/*.coffee']
JS = []
+VERSION_FILES = %w(
+ src/connector.coffee
+)
+
COFFEE.each do |coffee|
JS << (js = File.join('lib', File.basename(coffee).ext('js')))
end
@@ -37,6 +41,32 @@ class JSModule
end
end
+def version
+ File.read('VERSION').strip
+end
+
+def subst_version_refs_in_file file, ver
+ puts file
+ orig = File.read(file)
+ prev_line = ""
+ anything_matched = false
+ data = orig.lines.map do |line|
+ if line =~ /\d\.\d\.\d/ && (line =~ /version/i || prev_line =~ /CFBundleShortVersionString|CFBundleVersion/)
+ anything_matched = true
+ new_line = line.gsub /\d\.\d\.\d/, ver
+ puts " #{new_line.strip}"
+ else
+ new_line = line
+ end
+ prev_line = line
+ new_line
+ end.join('')
+
+ raise "Error: no substitutions made in #{file}" unless anything_matched
+
+ File.open(file, 'w') { |f| f.write data }
+end
+
file DIST => JS do
modules = {}
@@ -67,6 +97,32 @@ end
desc "Build livereload.js"
task :build => DIST
+desc "Embed version number where it belongs"
+task :version do
+ ver = version
+ VERSION_FILES.each { |file| subst_version_refs_in_file(file, ver) }
+ Rake::Task[:build].invoke
+end
+
+desc "Increase version number"
+task :bump do
+ prev = version
+ components = File.read('VERSION').strip.split('.')
+ components[-1] = (components[-1].to_i + 1).to_s
+ File.open('VERSION', 'w') { |f| f.write "#{components.join('.')}\n" }
+ puts "#{prev} => #{version}"
+ Rake::Task[:version].invoke
+end
+
+desc "Tag the current version"
+task :tag do
+ sh 'git', 'tag', "v#{version}"
+end
+desc "Move (git tag -f) the tag for the current version"
+task :retag do
+ sh 'git', 'tag', '-f', "v#{version}"
+end
+
task :default => :build
CLOBBER << DIST
View
@@ -0,0 +1 @@
+2.0.1
View
@@ -1,5 +1,7 @@
{ Parser, PROTOCOL_6, PROTOCOL_7 } = require 'protocol'
+Version = '2.0.1'
+
exports.Connector = class Connector
constructor: (@options, @WebSocket, @Timer, @handlers) ->
@@ -83,6 +85,7 @@ exports.Connector = class Connector
# start handshake
hello = { command: 'hello', protocols: [PROTOCOL_6, PROTOCOL_7] }
+ hello.ver = Version
hello.ext = @options.ext if @options.ext
hello.extver = @options.extver if @options.extver
hello.snipver = @options.snipver if @options.snipver

0 comments on commit 8bc353e

Please sign in to comment.