Rakefile in ro-1.4.6 vs Rakefile in ro-4.2.0

- old
+ new

@@ -1,10 +1,14 @@ -This.rubyforge_project = 'codeforpeople' This.author = "Ara T. Howard" This.email = "ara.t.howard@gmail.com" -This.homepage = "https://github.com/ahoward/#{ This.lib }" +This.github = "ahoward" +This.homepage = "https://github.com/#{ This.github }/#{ This.basename }" +This.repo = "https://github.com/#{ This.github }/#{ This.basename }" +task :license do + open('LICENSE', 'w'){|fd| fd.puts "Ruby"} +end task :default do puts((Rake::Task.tasks.map{|task| task.name.gsub(/::/,':')} - ['default']).sort) end @@ -27,11 +31,11 @@ div = ('=' * 119) line = ('-' * 119) test_rbs.each_with_index do |test_rb, index| testno = index + 1 - command = "#{ File.basename(This.ruby) } -I ./lib -I ./test/lib #{ test_rb }" + command = "#{ This.ruby } -w -I ./lib -I ./test/lib #{ test_rb }" puts say(div, :color => :cyan, :bold => true) say("@#{ testno } => ", :bold => true, :method => :print) say(command, :color => :cyan, :bold => true) @@ -57,62 +61,52 @@ end task :gemspec do ignore_extensions = ['git', 'svn', 'tmp', /sw./, 'bak', 'gem'] - ignore_directories = ['pkg', 'db'] - ignore_files = ['test/log', 'test/db.yml', 'a.rb', 'b.rb'] + Dir['db/*'] + %w'db' + ignore_directories = ['pkg'] + ignore_files = ['test/log'] shiteless = lambda do |list| list.delete_if do |entry| next unless test(?e, entry) extension = File.basename(entry).split(%r/[.]/).last ignore_extensions.any?{|ext| ext === extension} end + list.delete_if do |entry| next unless test(?d, entry) dirname = File.expand_path(entry) ignore_directories.any?{|dir| File.expand_path(dir) == dirname} end + list.delete_if do |entry| next unless test(?f, entry) filename = File.expand_path(entry) ignore_files.any?{|file| File.expand_path(file) == filename} end end - lib = This.lib + name = This.basename object = This.object version = This.version - files = shiteless[Dir::glob("**/**")].select{|path| test(?f, path)} + files = shiteless[Dir::glob("**/**")] executables = shiteless[Dir::glob("bin/*")].map{|exe| File.basename(exe)} - #has_rdoc = true #File.exist?('doc') - test_files = test(?e, "test/#{ lib }.rb") ? "test/#{ lib }.rb" : nil - summary = object.respond_to?(:summary) ? object.summary : "summary: #{ lib } kicks the ass" - description = object.respond_to?(:description) ? object.description : "description: #{ lib } kicks the ass" - license = object.respond_to?(:license) ? object.license : nil + summary = Util.unindent(This.summary).strip + description = Util.unindent(This.description).strip + license = This.license.strip - if license.nil? - license = - begin - IO.binread('LICENSE') - rescue - "Same As Ruby's" - end - end - if This.extensions.nil? This.extensions = [] extensions = This.extensions %w( Makefile configure extconf.rb ).each do |ext| - extensions << ext if File.exists?(ext) + extensions << ext if File.exist?(ext) end end extensions = [extensions].flatten.compact -# TODO if This.dependencies.nil? dependencies = [] else case This.dependencies when Hash @@ -126,45 +120,43 @@ if test(?e, 'gemspec.erb') Template{ IO.read('gemspec.erb') } else Template { <<-__ - ## <%= lib %>.gemspec + ## <%= name %>.gemspec # Gem::Specification::new do |spec| - spec.name = <%= lib.inspect %> + spec.name = <%= name.inspect %> spec.version = <%= version.inspect %> + spec.required_ruby_version = '>= 3.0' spec.platform = Gem::Platform::RUBY - spec.summary = <%= lib.inspect %> + spec.summary = <%= summary.inspect %> spec.description = <%= description.inspect %> spec.license = <%= license.inspect %> spec.files =\n<%= files.sort.pretty_inspect %> spec.executables = <%= executables.inspect %> spec.require_path = "lib" - spec.test_files = <%= test_files.inspect %> - <% dependencies.each do |lib_version| %> spec.add_dependency(*<%= Array(lib_version).flatten.inspect %>) <% end %> spec.extensions.push(*<%= extensions.inspect %>) - spec.rubyforge_project = <%= This.rubyforge_project.inspect %> spec.author = <%= This.author.inspect %> spec.email = <%= This.email.inspect %> spec.homepage = <%= This.homepage.inspect %> end __ } end Fu.mkdir_p(This.pkgdir) - gemspec = "#{ lib }.gemspec" + gemspec = "#{ name }.gemspec" open(gemspec, "w"){|fd| fd.puts(template)} This.gemspec = gemspec end task :gem => [:clean, :gemspec] do @@ -176,33 +168,54 @@ gem = ((after - before).first || after.first) or abort('no gem!') Fu.mv(gem, This.pkgdir) This.gem = File.join(This.pkgdir, File.basename(gem)) end +task :README => [:readme] + task :readme do samples = '' prompt = '~ > ' lib = This.lib version = This.version - Dir['sample*/*'].sort.each do |sample| - samples << "\n" << " <========< #{ sample } >========>" << "\n\n" + Dir['sample*/**/**.rb'].sort.each do |sample| + link = "[#{ sample }](#{ This.repo }/blob/main/#{ sample })" + samples << " #### <========< #{ link } >========>\n" cmd = "cat #{ sample }" - samples << Util.indent(prompt + cmd, 2) << "\n\n" - samples << Util.indent(`#{ cmd }`, 4) << "\n" + samples << "```sh\n" + samples << Util.indent(prompt + cmd, 2) << "\n" + samples << "```\n" + samples << "```ruby\n" + samples << Util.indent(IO.binread(sample), 4) << "\n" + samples << "```\n" + samples << "\n" + cmd = "ruby #{ sample }" - samples << Util.indent(prompt + cmd, 2) << "\n\n" + samples << "```sh\n" + samples << Util.indent(prompt + cmd, 2) << "\n" + samples << "```\n" cmd = "ruby -e'STDOUT.sync=true; exec %(ruby -I ./lib #{ sample })'" - samples << Util.indent(`#{ cmd } 2>&1`, 4) << "\n" + oe = `#{ cmd } 2>&1` + samples << "```txt\n" + samples << Util.indent(oe, 4) << "\n" + samples << "```\n" + + samples << "\n" end + This.samples = samples + template = - if test(?e, 'readme.erb') - Template{ IO.read('readme.erb') } + case + when test(?e, 'README.md.erb') + Template{ IO.read('README.md.erb') } + when test(?e, 'README.erb') + Template{ IO.read('README.erb') } else Template { <<-__ NAME #{ lib } @@ -216,35 +229,27 @@ #{ samples } __ } end - open("README", "w"){|fd| fd.puts template} + IO.binwrite('README.md', template) end - task :clean do Dir[File.join(This.pkgdir, '**/**')].each{|entry| Fu.rm_rf(entry)} end - -task :release => [:clean, :gemspec, :gem] do +task :release => [:dist, :gem] do gems = Dir[File.join(This.pkgdir, '*.gem')].flatten - raise "which one? : #{ gems.inspect }" if gems.size > 1 - raise "no gems?" if gems.size < 1 + abort "which one? : #{ gems.inspect }" if gems.size > 1 + abort "no gems?" if gems.size < 1 cmd = "gem push #{ This.gem }" puts cmd puts system(cmd) abort("cmd(#{ cmd }) failed with (#{ $?.inspect })") unless $?.exitstatus.zero? - - cmd = "rubyforge login && rubyforge add_release #{ This.rubyforge_project } #{ This.lib } #{ This.version } #{ This.gem }" - puts cmd - puts - system(cmd) - abort("cmd(#{ cmd }) failed with (#{ $?.inspect })") unless $?.exitstatus.zero? end @@ -258,62 +263,70 @@ require 'erb' require 'fileutils' require 'rbconfig' require 'pp' -# fu shortcut +# fu shortcut! # Fu = FileUtils -# cache a bunch of stuff about this rakefile/environment +# guess a bunch of stuff about this rakefile/environment based on the # This = OpenStruct.new This.file = File.expand_path(__FILE__) This.dir = File.dirname(This.file) This.pkgdir = File.join(This.dir, 'pkg') + This.basename = File.basename(This.dir) -# grok lib +# load actual shit _lib # - lib = ENV['LIB'] - unless lib - lib = File.basename(Dir.pwd).sub(/[-].*$/, '') - end - This.lib = lib + _libpath = ["./lib/#{ This.basename }/_lib.rb", "./lib/#{ This.basename }.rb"] + _lib = _libpath.detect{|l| test(?s, l)} -# grok version -# - version = ENV['VERSION'] - unless version - require "./lib/#{ This.lib }" - This.name = lib.capitalize - This.object = eval(This.name) - version = This.object.send(:version) - end - This.version = version + abort "could not find a _lib in ./lib/ via #{ _libpath.join(':') }" unless _lib -# see if dependencies are export by the module + This._lib = _lib + require This._lib + +# extract the name from the _lib # - if This.object.respond_to?(:dependencies) - This.dependencies = This.object.dependencies + lines = IO.binread(This._lib).split("\n") + re = %r`\A \s* (module|class) \s+ ([^\s]+) \s* \z`iomx + name = nil + lines.each do |line| + match = line.match(re) + if match + name = match.to_a.last + break + end end + unless name + abort "could not extract `name` from #{ This._lib }" + end + This.name = name + This.basename = This.name.downcase -# we need to know the name of the lib an it's version +# now, fully grok This # - abort('no lib') unless This.lib - abort('no version') unless This.version + This.object = eval(This.name) + This.version = This.object.version + This.dependencies = This.object.dependencies + This.summary = This.object.summary + This.description = This.respond_to?(:description) ? This.description : This.summary + This.license = This.respond_to?(:license) ? This.license : IO.binread('LICENSE').strip # discover full path to this ruby executable # - c = Config::CONFIG + c = RbConfig::CONFIG bindir = c["bindir"] || c['BINDIR'] ruby_install_name = c['ruby_install_name'] || c['RUBY_INSTALL_NAME'] || 'ruby' ruby_ext = c['EXEEXT'] || '' ruby = File.join(bindir, (ruby_install_name + ruby_ext)) This.ruby = ruby -# some utils +# some utils, alwayze teh utils... # module Util def indent(s, n = 2) s = unindent(s) ws = ' ' * n @@ -324,27 +337,65 @@ indent = nil s.each_line do |line| next if line =~ %r/^\s*$/ indent = line[%r/^\s*/] and break end - indent ? s.gsub(%r/^#{ indent }/, "") : s + unindented = indent ? s.gsub(%r/^#{ indent }/, "") : s + unindented.strip end extend self end # template support # class Template + def Template.indent(string, n = 2) + string = string.to_s + n = n.to_i + padding = (42 - 10).chr * n + initial = %r/^#{ Regexp.escape(padding) }/ + #require 'debug' + #binding.break + Util.indent(string, n).sub(initial, '') + end def initialize(&block) @block = block @template = block.call.to_s end def expand(b=nil) - ERB.new(Util.unindent(@template)).result((b||@block).binding) + ERB.new(Util.unindent(@template), trim_mode: '%<>-').result((b||@block).binding) end alias_method 'to_s', 'expand' end def Template(*args, &block) Template.new(*args, &block) end + +# os / platform support +# + module Platform + def Platform.windows? + (/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM) != nil + end + + def Platform.darwin? + (/darwin/ =~ RUBY_PLATFORM) != nil + end + + def Platform.mac? + Platform.darwin? + end + + def Platform.unix? + !Platform.windows? + end + + def Platform.linux? + Platform.unix? and not Platform.darwin? + end + + def Platform.jruby? + RUBY_ENGINE == 'jruby' + end + end # colored console output support # This.ansi = { :clear => "\e[0m",