Last active
August 29, 2015 14:20
-
-
Save IceDragon200/171094a1a1f5968c85b0 to your computer and use it in GitHub Desktop.
My scripts for syntax checking, bundle updating, bundle testing, installing local gems
This file contains hidden or 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
#!/usr/bin/env bash | |
crawl_ruby_check . && | |
bundle update --local && | |
bundle exec rspec && | |
gemmy |
This file contains hidden or 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
#!/usr/bin/env ruby | |
require 'ostruct' | |
require 'optparse' | |
class Array | |
def presence | |
empty? ? nil : self | |
end | |
end | |
module CrawlRubyCheck | |
module Version | |
MAJOR, MINOR, TEENY, PATCH = 0, 4, 0, nil | |
STRING = [MAJOR, MINOR, TEENY, PATCH].compact.join('.').freeze | |
end | |
VERSION = Version::STRING | |
# copied from dragontk | |
def self.crawl(name, context = nil, depth = 0, depth_limit = 30, &block) | |
return if depth > depth_limit | |
if File.directory?(name) | |
(Dir.entries(name) - [".", ".."]).each do |fn| | |
crawl(File.join(name, fn), context, depth + 1, depth_limit, &block) | |
end | |
else | |
yield name, context, depth | |
end | |
context | |
end | |
end | |
@ruby_files = [ | |
'Basaltmods', | |
'Gemfile', | |
'Guardfile', | |
'Rakefile', | |
] | |
@extensions = [ | |
'.gemspec', | |
'.rb', | |
'.rabl', | |
] | |
def ruby_file?(filename) | |
return true if @ruby_files.include?(File.basename(filename)) | |
return true if @extensions.include?(File.extname(filename)) | |
false | |
end | |
options = OpenStruct.new | |
parser = OptionParser.new do |opts| | |
opts.on '-e', '--ext', String, 'Add a ruby extension' do |v| | |
@extensions << v | |
end | |
opts.on '-f', '--filename', String, 'Add full filename to treat as a ruby file' do |v| | |
@ruby_files << v | |
end | |
opts.on '-v', '--[no-]verbose', 'Verbose ouput' do |v| | |
options.verbose = v | |
end | |
opts.on '', '--version', 'Display version number before executing' do | |
puts "#{File.dirname(__FILE__)} v#{CrawlRubyCheck::VERSION}" | |
end | |
opts.on '-h', '--help', 'Display this help message' do | |
puts opts | |
exit | |
end | |
end | |
argv = parser.parse(ARGV.dup) | |
checks = {} | |
dirs = argv.presence || [Dir.getwd] | |
dirs.each do |dir| | |
CrawlRubyCheck.crawl dir, checks do |filename, context| | |
unless ruby_file?(filename) | |
puts "Skipping #{filename}" if options.verbose | |
next | |
end | |
print '%-060s CHECK: ' % filename | |
context[filename] = system("ruby -c \"#{filename}\"") | |
end | |
end | |
STDERR.puts "\n\nChecked #{checks.size} files" | |
failed = checks.any? { |_, v| !v } | |
exit(failed ? 1 : 0) |
This file contains hidden or 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
#!/usr/bin/env ruby | |
require 'optparse' | |
VERSION = '0.4.0' | |
def sh(command) | |
STDERR.puts command | |
system command | |
end | |
options = { | |
directory: '.' | |
} | |
parser = OptionParser.new do |opts| | |
opts.on '-d', '--directory DIRNAME', String, 'directory to look in for gemspecs' do |v| | |
options[:directory] = v | |
end | |
opts.on '', '--version' do | |
STDERR.puts "#{File.basename(__FILE__)} v#{VERSION}" | |
end | |
opts.on '-h', '--help' do | |
puts opts | |
exit | |
end | |
end | |
parser.parse(ARGV.dup) | |
Dir.chdir(options[:directory]) do | |
Dir.glob('*.gemspec').each do |gemspec| | |
STDERR.puts "Building #{gemspec}" | |
sh "gem build -V \"#{gemspec}\"" | |
gems = Dir.glob('*.gem').map do |filename| | |
if filename =~ /\S+-(.*)\.gem/ | |
[$1.split(".").map(&:to_i), filename] | |
else | |
nil | |
end | |
end.compact | |
if lastestgem = gems.sort.last | |
STDERR.puts "Installing #{lastestgem[1]}" | |
sh "sudo gem install -V --conservative -l #{lastestgem[1]}" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment