Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 13 additions & 14 deletions a.gemspec
Original file line number Diff line number Diff line change
@@ -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
s.require_paths << 'lib'
s.required_ruby_version = '>= 2.0.0'
end
79 changes: 35 additions & 44 deletions bin/a
Original file line number Diff line number Diff line change
@@ -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()
main
8 changes: 4 additions & 4 deletions lib/a.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module A
class << self
def info
puts rand
end
class << self
def info
puts rand
end
end
end
213 changes: 113 additions & 100 deletions lib/commands/gem.rb
Original file line number Diff line number Diff line change
@@ -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
27 changes: 12 additions & 15 deletions rakefile.rb
Original file line number Diff line number Diff line change
@@ -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
Dir['*.gem'].max
end