Created
January 6, 2013 23:05
-
-
Save javierav/4470934 to your computer and use it in GitHub Desktop.
Development with Rake Pipeline and Guard
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# vim: filetype=ruby | |
require 'rake-pipeline-web-filters' | |
require 'rake-pipeline-i18n-filters' | |
class Minispade < Rake::Pipeline::Web::Filters::MinispadeFilter | |
def initialize(options = {}) | |
super | |
@sourceURL = options[:source_url] | |
end | |
def generate_output(inputs, output) | |
inputs.each do |input| | |
code = input.read | |
code.gsub!(%r{\s*require\s*\(\s*}, 'minispade.require(') if @rewrite_requires | |
code.gsub!(%r{\s*requireAll\s*\(\s*}, 'minispade.requireAll(') if @rewrite_requires | |
code = %["use strict";\n] + code if @use_strict | |
module_id = @module_id_generator.call(input) | |
source = @sourceURL ? "\n//@ sourceURL=#{module_id}" : "" | |
if @string_module | |
contents = %{(function() {#{code}\n})();#{source}}.to_json | |
else | |
contents = "function() {#{code}\n}" | |
end | |
ret = "minispade.register('#{module_id}', #{contents});" | |
output.write ret | |
end | |
end | |
end | |
production = ENV['FRONTENV'] == 'production' | |
# create a concatenated file with vendor libraries | |
input 'app/frontend/libraries' do | |
output 'public' | |
match '**/*.js' do | |
concat ['jquery.js', 'handlebars.js', 'ember.js', 'ember-data.js'], 'libraries.js' | |
end | |
match 'libraries.js' do | |
uglify :copyright => false | |
end if production | |
end | |
# create a minispade version of the application used for development for better debbugin | |
input 'app/frontend' do | |
output 'public' | |
# compose templates | |
match '**/*.handlebars' do | |
handlebars :key_name_proc => proc { |input| | |
File.join(File.dirname(input.path), File.basename(input.path, File.extname(input.path))) | |
} | |
end | |
# compose translations | |
match '**/i18n/*.yml' do | |
i18n_js { 'translations.js' } | |
end | |
# compose application | |
match '**/*.js' do | |
reject /^tests|libraries/ | |
reject '**/tests/**/*.js' | |
uglify :copyright => false do |input| | |
input | |
end if production | |
filter Minispade, :rewrite_requires => true, :string => true, :source_url => !production, | |
:module_id_generator => proc { |input| | |
id = input.path.dup | |
id.sub!(/\.js$/, '') | |
id.sub!(/\/main$/, '') | |
id | |
} | |
concat 'application.js' | |
uglify if production | |
end | |
end | |
# create a minispade version of the tests | |
input 'app/frontend' do | |
output 'app/frontend/tests' | |
match '**/tests/**/*.js' do | |
reject /^tests/ | |
minispade :rewrite_requires => true, :string => true, :source_url => !production, | |
:module_id_generator => proc { |input| | |
id = input.path.dup | |
id.sub!(/\.js$/, '') | |
id.sub!(/\/tests\//, '/') | |
"/~tests/#{id}" | |
} | |
concat 'application-tests.js' | |
end | |
end if !production |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# vim: filetype=ruby | |
interactor :off | |
notification :growl if /darwin/ =~ RUBY_PLATFORM | |
notification :libnotify if /linux/ =~ RUBY_PLATFORM | |
group :frontend do | |
guard :shell do | |
watch %r{^app/frontend/(?!tests).*(js|yml|handlebars)$} do | |
# rebuild frontend app when change any *.js, *.handlebars, *.yml | |
UI.info 'Start frontend build process' | |
`bundle exec rakep` | |
UI.info 'End frontend build process' | |
message = $?.success? ? 'The build was done successfully' : 'The build is failed' | |
Notifier.notify message, :title => 'Frontend App', | |
:image => ( $?.success? ? :success : :failed ) | |
# exec unit tests | |
UI.info 'Start tests for frontend app' | |
output = `mocha-phantomjs -R json app/frontend/tests/index.html` | |
UI.info 'End tests for frontend app' | |
if $?.success? | |
message = 'All tests pass!' | |
else | |
errors = output.match(/"failures": (\d+),/)[1].to_i | |
message = "#{errors} #{(errors > 1) ? 'tests' : 'test'} failed!" | |
end | |
Notifier.notify message, :title => 'Mocha Frontend Tests', | |
:image => ( $?.success? ? :success : :failed ) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Using the built-in ember.js and ember-data.js packages in your build process prevent you to debug correctly the Ember code, which is sometimes a requirement when API is not mature.
I would recommend you importing the whole Ember and Ember-Data repo as for example git submodules and building them with a group of filters in your pipeline configuration, this setup has bring as many advantages during our dev process as finding ember bugs, better fw understanding ...