1# Copyright (c) 2013 Brandon Jones, Colin MacKenzie IV 2# 3# This software is provided 'as-is', without any express or implied 4# warranty. In no event will the authors be held liable for any damages 5# arising from the use of this software. 6# 7# Permission is granted to anyone to use this software for any purpose, 8# including commercial applications, and to alter it and redistribute it 9# freely, subject to the following restrictions: 10# 11# 1. The origin of this software must not be misrepresented; you must not 12# claim that you wrote the original software. If you use this software 13# in a product, an acknowledgment in the product documentation would be 14# appreciated but is not required. 15# 16# 2. Altered source versions must be plainly marked as such, and must not 17# be misrepresented as being the original software. 18# 19# 3. This notice may not be removed or altered from any source distribution. 20# 21$:.unshift File.expand_path('.', File.dirname(__FILE__)) 22require 'sprockets' 23require 'jasmine' 24 25class Jasmine::Config 26 def simple_config_file 27 File.expand_path GLMatrix.base_path.join('spec/jasmine.yml') 28 end 29end 30 31class Rack::Jasmine::Runner 32 alias_method :jasmine_call, :call 33 def call(env) 34 GLMatrix.compile 35 jasmine_call env 36 end 37end 38 39module GLMatrix 40 autoload :ReleaseHelper, 'gl-matrix/release_helper' 41 autoload :Version, 'gl-matrix/version' 42 autoload :VERSION, 'gl-matrix/version' 43 44 module_function 45 46 def release(&block) 47 GLMatrix::ReleaseHelper.release &block 48 end 49 50 def sprockets 51 env = Sprockets::Environment.new base_path 52 env.append_path base_path.join('src') 53 env 54 end 55 56 def base_path 57 Pathname.new File.expand_path('../..', File.dirname(__FILE__)) 58 end 59 60 # Compiles the source file to the dest file. If a block 61 # is given, the source file is yielded and replaced with 62 # the result. Returns the destination as a Pathname. 63 def compile(source = 'gl-matrix.js', dest = 'dist/gl-matrix.js') 64 dest = base_path.join dest 65 js = sprockets[source] 66 js = yield js if block_given? 67 68 File.open dest, "w" do |f| 69 f.puts js 70 end 71 72 puts "compiled #{source} to #{dest.relative_path_from base_path}" 73 dest 74 end 75 76 def minify(source = 'gl-matrix.js', dest = 'dist/gl-matrix-min.js') 77 dest = compile source, dest do |js| 78 Uglifier.compile js 79 end 80 81 puts "minified #{source} to #{dest.relative_path_from base_path}" 82 end 83 84end 85