diff --git a/README.md b/README.md index 73b2720..ad79106 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,10 @@ Update config/karma.conf.js to load the files you want to test and run `rake kar ## Changelog +### 0.1.3 +- adding [angularjs-rails-resource](https://github.com/FineLinePrototyping/angularjs-rails-resource) +- adding test spec so rake karma works straight after install + ### 0.1.2 - fixing error with shell command installing karma diff --git a/files/karma.conf.js b/files/karma.conf.js index 6e450c5..2beafe6 100644 --- a/files/karma.conf.js +++ b/files/karma.conf.js @@ -4,13 +4,12 @@ files = [ JASMINE, JASMINE_ADAPTER, - //libs + //angular 'vendor/assets/javascripts/rails_karma/angular.js', - 'vendor/assets/javascripts/rails_karma/angular-cookies.js', - 'vendor/assets/javascripts/rails_karma/angular-loader.js', - 'vendor/assets/javascripts/rails_karma/angular-resource.js', - 'vendor/assets/javascripts/rails_karma/angular-sanitize.js', - 'vendor/assets/javascripts/rails_karma/angular-mocks.js', + 'vendor/assets/javascripts/rails_karma/*.js', + + //angular rails resource + 'vendor/assets/javascripts/rails_karma/angularjs-rails-resource/**', //our app! 'app/assets/angular/**', diff --git a/files/karma_test.coffee b/files/karma_test.coffee new file mode 100644 index 0000000..0c6af7a --- /dev/null +++ b/files/karma_test.coffee @@ -0,0 +1,3 @@ +describe "Karma", -> + it "should pass", -> + expect(true).toBe(true) \ No newline at end of file diff --git a/lib/rails_karma/tasks.rb b/lib/rails_karma/tasks.rb index 71060da..cbe3f6f 100644 --- a/lib/rails_karma/tasks.rb +++ b/lib/rails_karma/tasks.rb @@ -7,9 +7,14 @@ desc 'Install karma files' task :install do puts 'Generating Karma files' - RailsKarma::Installer.karma - RailsKarma::Installer.angular_files - RailsKarma::Installer.karma_config + RailsKarma::Installer.install_karma_lib + RailsKarma::Installer.ignore_node_modules + RailsKarma::Installer.make_vendor_dir + RailsKarma::Installer.copy_angularjs_files + RailsKarma::Installer.copy_angularjs_resource_files + RailsKarma::Installer.copy_karma_config + RailsKarma::Installer.create_karma_dir + RailsKarma::Installer.copy_test_spec end desc 'Uninstall karma files' @@ -20,7 +25,7 @@ files.each do |f| if File.exists? f - puts f + puts "rm -rf #{f}" FileUtils.rm_rf f end end @@ -32,7 +37,7 @@ module RailsKarma class Installer - def self.karma + def self.install_karma_lib unless File.exists?('package.json') puts './package.json' File.open('package.json', 'w') {|f| f.write '{}'} @@ -41,37 +46,71 @@ def self.karma puts 'installing karma' puts `npm install karma --save-dev` end + end + + def self.ignore_node_modules unless File.open('.gitignore') {|f| f.read.include? 'node_modules'} puts 'adding node_modules to .gitignore' File.open('.gitignore', 'a') {|f| f.write "node_modules\n"} end end - def self.angular_files - vendor_dir = File.join('vendor', 'assets', 'javascripts', 'rails_karma') + def self.vendor_dir + File.join('vendor', 'assets', 'javascripts', 'rails_karma') + end + + def self.rails_resource_dir + File.join(vendor_dir, 'angularjs-rails-resource') + end + + def self.make_vendor_dir unless Dir.exists?(vendor_dir) - puts vendor_dir + puts "mkdir #{vendor_dir}" Dir.mkdir vendor_dir end + unless Dir.exists?(rails_resource_dir) + puts "mkdir #{rails_resource_dir}" + Dir.mkdir rails_resource_dir + end + end - angular_glob = File.join(Gem.loaded_specs['angularjs-rails'].full_gem_path, 'vendor', 'assets', 'javascripts', '*.js') - Dir.glob(angular_glob).each do |file| - FileUtils.cp file, File.join(vendor_dir,File.basename(file)) + def self.copy_angularjs_files + angular_files = ['angular.js', 'angular-cookies.js', 'angular-loader.js', 'angular-resource.js', 'angular-sanitize.js', 'angular-mocks.js'] + angular_files.each do |file_name| + path = File.join(Gem.loaded_specs['angularjs-rails'].full_gem_path, 'vendor', 'assets', 'javascripts', file_name) + FileUtils.cp path, File.join(vendor_dir,File.basename(path)) end end - def self.karma_config + def self.copy_angularjs_resource_files + rails_resource_lib = File.join(Gem.loaded_specs['angularjs-rails-resource'].full_gem_path, 'vendor', 'assets', 'javascripts', 'angularjs', 'rails', 'resource') + FileUtils.cp_r rails_resource_lib, rails_resource_dir + end + + def self.copy_karma_config config_source = File.join(Gem.loaded_specs['rails_karma'].full_gem_path, 'files', 'karma.conf.js') config_target = File.join(Rails.root, 'config', 'karma.conf.js') unless File.exists?(config_target) puts './config/karma.conf.js' FileUtils.cp_r config_source, config_target end + end + + def self.create_karma_dir unless Dir.exists?('karma') puts './karma' Dir.mkdir 'karma' end end + + def self.copy_test_spec + test_spec = File.join(Gem.loaded_specs['rails_karma'].full_gem_path, 'files', 'karma_test.coffee') + target = File.join(Rails.root, 'karma', 'karma_test.coffee') + unless File.exists?(target) + puts './karma/karma_test.coffee' + FileUtils.cp test_spec, target + end + end end end diff --git a/lib/rails_karma/version.rb b/lib/rails_karma/version.rb index 4f9f1a9..79f4a27 100644 --- a/lib/rails_karma/version.rb +++ b/lib/rails_karma/version.rb @@ -1,3 +1,3 @@ module RailsKarma - VERSION = "0.1.2" + VERSION = "0.1.3" end diff --git a/rails_karma.gemspec b/rails_karma.gemspec index ebc178f..7f18531 100644 --- a/rails_karma.gemspec +++ b/rails_karma.gemspec @@ -21,4 +21,5 @@ Gem::Specification.new do |spec| spec.add_development_dependency 'bundler', '~> 1.3' spec.add_development_dependency 'rake' spec.add_dependency 'angularjs-rails', '~>1.0.7' + spec.add_dependency 'angularjs-rails-resource', '~> 0.2.0' end