Rakefile in nodepile-0.1.1 vs Rakefile in nodepile-0.1.2

- old
+ new

@@ -1,12 +1,102 @@ # frozen_string_literal: true +require 'rake' +require 'yard' require "bundler/gem_tasks" -require "rspec/core/rake_task" +require 'rspec/core/rake_task' RSpec::Core::RakeTask.new(:spec) +begin + require 'bundler/setup' + Bundler::GemHelper.install_tasks +rescue LoadError + puts 'although not required, bundler is recommended for running the tests' +end + require "rubocop/rake_task" -RuboCop::RakeTask.new +RuboCop::RakeTask.new do |task| + task.requires << 'rubocop-performance' + task.requires << 'rubocop-rspec' +end + task default: %i[spec rubocop] + +# Dave's Dev trinkets below +LINE_LEVEL_SWEEP_TESTS = [ + Proc.new {|line| line.match(/^[^#]*binding\.pry/) && "found uncommented binding.pry"}, + Proc.new {|line| line.match(/^[^#]*binding\.irb/) && "found uncommented binding.irb"}, + Proc.new {|line| line.match(/^[^#]*debugger/) && "found uncommented debugger invocation"}, + Proc.new {|line| line.match(/^.*#\s*DEBUG/) && "found debug line"}, + Proc.new {|line| line.match(/^[^#]*require[^#]+['"]pry/) && "uncommented require of 'pry' code"}, + Proc.new {|line| line.match(/^[^#]*TDOUT\.puts ([^\s]+)\.inspect/) && "verbose obj going to stdout"}, + Proc.new {|line| line.match(/^[^#]*debug_mode\s+:console/) && "sentry set with debug_mode :console"}, +] + + +# rake yard #to generate documentation +YARD::Rake::YardocTask.new do |t| + t.files = ['lib/**/*.rb', 'README','LICENSE'] # optional + #t.options = ['--any', '--extra', '--opts'] # optional + t.stats_options = ['--list-undoc'] # optional +end + +def simplify_dir(target_path) + this_root = Pathname.new(File.dirname(__FILE__)) + target = Pathname.new(target_path) + target.relative_path_from(this_root) +end + +desc "Serve yard docs on port 8080 with automatic reload" +task :yardserv do + puts "You probably want to run this directly from the command line with:" + puts "yard server --reload -p 8080" +end + + +desc "Build the gem and deploy to rubygems" +task :publish => :build do + File.open(File.join(__dir__,'lib','nodepile','version.rb')){|f| + f.each{|line| + if /\s*VERSION\s*=\s*"([^"]+)"/ =~ line + system 'gem push ' + 'pkg/nodepile' + "-" + $1 + ".gem" + break + end + } + } +end + +desc "Pre-release sweep of code" +task :sweep do + + a = Dir["#{File.dirname(__FILE__)}/**/*.rb"] + alert_was_triggered = nil + a.each{|fname| + num = 0 + File.open(fname,"r") do |f| + next if fname.match(/\/tests\//) + f.each_line do |line| + num+= 1 + LINE_LEVEL_SWEEP_TESTS.each{|proc| + err_msg = proc.call(line) + if err_msg + if !alert_was_triggered + puts "\nSweep found problems in source code..." + alert_was_triggered = true + end + puts "{#{simplify_dir(fname)} : #{num}} - #{err_msg}" + end + } + end # loop over lines in file + end # loop over files + + } # end loop over sourcecode + puts "Hurray! No active debug code found in the project." unless alert_was_triggered + + # Clean up code elements that may linger + FileUtils.rm(Dir["#{File.dirname(__FILE__)}/test/tmp/*"]) +end # sweep task + +