From c99584bb85f8c86ff2f19c2f0f6ea2a506e6eae1 Mon Sep 17 00:00:00 2001 From: Nick Roma Date: Tue, 13 Apr 2021 01:08:53 +0900 Subject: [PATCH] 3rd anniversary update --- a.gemspec | 27 +++--- bin/a | 79 ++++++++-------- lib/a.rb | 8 +- lib/commands/gem.rb | 213 +++++++++++++++++++++++--------------------- rakefile.rb | 27 +++--- 5 files changed, 177 insertions(+), 177 deletions(-) diff --git a/a.gemspec b/a.gemspec index 93b9952..a165e0c 100644 --- a/a.gemspec +++ b/a.gemspec @@ -1,18 +1,17 @@ Gem::Specification.new do |s| - s.name = "a" - s.version = "0.2.8" - s.summary = "a gem generator etc." - s.authors = ['author'] + s.name = 'a' + s.version = '0.2.8' + s.summary = 'a gem generator etc.' + s.authors = ['author'] - s.license = 'MIT' - s.email = 'degcat@126.com' - s.homepage = 'https://github.com/axgle/a' + s.license = 'MIT' + s.email = 'degcat@126.com' + s.homepage = 'https://github.com/axgle/a' - s.files = ["README.md","a.gemspec","rakefile.rb","lib/a.rb"] - s.files += Dir["lib/commands/*.rb"] - s.executables << "a" + s.files = ['README.md', 'a.gemspec', 'rakefile.rb', 'lib/a.rb'] + s.files += Dir['lib/commands/*.rb'] + s.executables << 'a' - s.require_paths << 'lib' - s.required_ruby_version = '>= 2.0.0' - -end \ No newline at end of file + s.require_paths << 'lib' + s.required_ruby_version = '>= 2.0.0' +end diff --git a/bin/a b/bin/a index f1a3588..6912139 100755 --- a/bin/a +++ b/bin/a @@ -1,55 +1,46 @@ #!/usr/bin/env ruby - - #ex: gem - def target - unless $*[0] - puts <<-EOT -example: - a gem mytest -will create new gem project named mytest directory +# ex: gem +def target + unless $ARGV[0] + puts <<~EOT + example: + a gem mytest + will create new gem project named mytest directory -EOT + EOT exit 1 - end - t = String.new $*[0] - t.capitalize! - t - end - -#ex: mytest - def dir - - unless $*[1] - puts "must have mtarget_dir\nfor example:\n a gem mytest " - exit 2 - end + end + t = String.new $ARGV[0] + t.capitalize! + t +end - t = String.new $*[1] +# ex: mytest +def dir + unless $ARGV[1] + puts "must have mtarget_dir\nfor example:\n a gem mytest " + exit 2 + end - # t.capitalize! - t - end + String.new $ARGV[1] + # t.capitalize! +end def main - - begin - #require 'pathname' - #require(File.join(File.dirname(__FILE__),'..','lib','commands',target.downcase)) - require File.join('commands',target.downcase) - rescue LoadError - - puts "the #{target} not exist" - exit 4 - - end - -target_class = Object.const_get('A::'+target) - - -target_class.index(dir: dir,target: target) - + begin + # require 'pathname' + # require(File.join(File.dirname(__FILE__),'..','lib','commands',target.downcase)) + require File.join('commands', target.downcase) + rescue LoadError + puts "the #{target} not exist" + exit 4 + end + + target_class = Object.const_get("A::#{target}") + + target_class.index(dir: dir, target: target) end -main() \ No newline at end of file +main diff --git a/lib/a.rb b/lib/a.rb index 4c3a5e3..4209bc4 100644 --- a/lib/a.rb +++ b/lib/a.rb @@ -1,7 +1,7 @@ module A - class << self - def info - puts rand - end + class << self + def info + puts rand end + end end diff --git a/lib/commands/gem.rb b/lib/commands/gem.rb index 829622f..0086363 100644 --- a/lib/commands/gem.rb +++ b/lib/commands/gem.rb @@ -1,105 +1,118 @@ module A - class Gem - class << self - - def make_dirs(config) - dir = config[:dir] - - Dir.mkdir dir rescue nil - - Dir.chdir dir - Dir.mkdir 'lib' rescue nil - Dir.mkdir 'bin' rescue nil - end - - def make_rakefile(config) - dir = config[:dir] - - rakefile = <<-eot -def latest_gem - Dir["*.gem"].sort.last -end - -task :default do - puts `gem build #{dir}.gemspec` - if $?.success? - puts "\\nyou can install it with:" - puts "rake install\\n" - puts "then run your app with:\\n#{dir}\\n" - - end -end -task :run do - puts `gem build #{dir}.gemspec` - puts `gem install --local \#{latest_gem}` - puts "===output===" - puts `#{dir}` - -end - -task :install do - puts `gem install --local \#{latest_gem}` -end - -task :push do - puts "pusing \#{latest_gem}..." - puts `gem push \#{latest_gem}` - if $?.success? - puts "https://rubygems.org/gems/#{dir}" - end -end - -task :i=>:install - -eot - IO.write "rakefile.rb",rakefile - end - - def make_specfile(config) - dir = config[:dir] - gemspec = <<-eot - -Gem::Specification.new do |s| - s.name = "#{dir}" - s.version = "0.0.1" - s.summary = "summary" - s.authors = ['authors'] - - s.license = 'MIT' - s.email = 'degcat@126.com' - s.homepage = 'https://rubygems.org/gems/a' - - s.files = Dir["lib/*.rb"] - s.executables << "#{dir}" -end - -eot - IO.write "#{dir}.gemspec",gemspec - end - def index(config) - dir = config[:dir] - target = config[:target] - - self.make_dirs(config) - - self.make_rakefile(config) - self.make_specfile(config) - - IO.write "lib/#{dir}.rb",'' - - binfile=<<-eot -#!/usr/bin/env ruby -puts "hello world!" -eot - IO.write "bin/#{dir}",binfile - - FileUtils.chmod "u=wrx","bin/#{dir}" rescue nil - - - -#puts gemspec + class Gem + class << self + def make_dirs(config) + dir = config[:dir] + + begin + Dir.mkdir dir + rescue StandardError + nil + end - end + Dir.chdir dir + begin + Dir.mkdir 'lib' + rescue StandardError + nil end + begin + Dir.mkdir 'bin' + rescue StandardError + nil + end + end + + def make_rakefile(config) + dir = config[:dir] + + rakefile = <<~eot + def latest_gem + Dir["*.gem"].sort.last + end + + task :default do + puts `gem build #{dir}.gemspec` + if $?.success? + puts "\\nyou can install it with:" + puts "rake install\\n" + puts "then run your app with:\\n#{dir}\\n" + + end + end + task :run do + puts `gem build #{dir}.gemspec` + puts `gem install --local \#{latest_gem}` + puts "===output===" + puts `#{dir}` + + end + + task :install do + puts `gem install --local \#{latest_gem}` + end + + task :push do + puts "pusing \#{latest_gem}..." + puts `gem push \#{latest_gem}` + if $?.success? + puts "https://rubygems.org/gems/#{dir}" + end + end + + task :i=>:install + + eot + IO.write 'rakefile.rb', rakefile + end + + def make_specfile(config) + dir = config[:dir] + gemspec = <<~eot + + Gem::Specification.new do |s| + s.name = "#{dir}" + s.version = "0.0.1" + s.summary = "summary" + s.authors = ['authors'] + + s.license = 'MIT' + s.email = 'degcat@126.com' + s.homepage = 'https://rubygems.org/gems/a' + + s.files = Dir["lib/*.rb"] + s.executables << "#{dir}" + end + + eot + IO.write "#{dir}.gemspec", gemspec + end + + def index(config) + dir = config[:dir] + target = config[:target] + + make_dirs(config) + + make_rakefile(config) + make_specfile(config) + + IO.write "lib/#{dir}.rb", '' + + binfile = <<~eot + #!/usr/bin/env ruby + puts "hello world!" + eot + IO.write "bin/#{dir}", binfile + + begin + FileUtils.chmod 'u=wrx', "bin/#{dir}" + rescue StandardError + nil + end + + # puts gemspec + end end + end end diff --git a/rakefile.rb b/rakefile.rb index 0faad25..daa1a0d 100644 --- a/rakefile.rb +++ b/rakefile.rb @@ -1,25 +1,22 @@ task :default do - puts `gem build a.gemspec` - puts `gem install --local #{latest_gem}` - puts `ruby -e '' -ra` - puts `a gem mytest` + puts `gem build a.gemspec` + puts `gem install --local #{latest_gem}` + puts `ruby -e '' -ra` + puts `a gem mytest` end task :install do - puts `gem install --local #{latest_gem}` + puts `gem install --local #{latest_gem}` end task :push do - puts "pusing #{latest_gem}..." - exec "gem push #{latest_gem}" - if $?.success? - puts "https://rubygems.org/gems/a" - end -end - -task :i=>:install + puts "pusing #{latest_gem}..." + exec "gem push #{latest_gem}" + puts 'https://rubygems.org/gems/a' if $CHILD_STATUS.success? +end +task i: :install def latest_gem - Dir["*.gem"].sort.last -end \ No newline at end of file + Dir['*.gem'].max +end