simonmenke-gm 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. data/README.textile +1 -39
  2. data/gm_commands/build_command.rb +14 -0
  3. data/gm_commands/clean_command.rb +12 -0
  4. data/gm_commands/create_command.rb +15 -0
  5. data/gm_commands/gen_command.rb +16 -0
  6. data/gm_commands/help_command.rb +14 -0
  7. data/gm_commands/install_command.rb +15 -0
  8. data/gm_commands/spec_command.rb +15 -0
  9. data/gm_generators/bin/bin_generator.rb +22 -0
  10. data/gm_generators/bin/templates/bin/bin.rb +3 -0
  11. data/gm_generators/gem/gem_generator.rb +38 -0
  12. data/gm_generators/gem/templates/README.textile +0 -0
  13. data/gm_generators/gem/templates/gmfile.yml +3 -0
  14. data/gm_generators/gem/templates/lib/module.rb +4 -0
  15. data/gm_generators/rails/rails_generator.rb +20 -0
  16. data/gm_generators/rails/templates/rails/init.rb +1 -0
  17. data/gm_generators/test/templates/test/test_case.rb +5 -0
  18. data/gm_generators/test/templates/test/test_helper.rb +6 -0
  19. data/gm_generators/test/test_generator.rb +24 -0
  20. data/{lib/passes → gm_passes}/configatron.rb +0 -0
  21. data/{lib/passes → gm_passes}/defaults.rb +0 -0
  22. data/{lib/passes → gm_passes}/executables.rb +0 -0
  23. data/{lib/passes → gm_passes}/files.rb +0 -0
  24. data/{lib/passes → gm_passes}/github.rb +0 -0
  25. data/gm_passes/gm.rb +7 -0
  26. data/{lib/passes → gm_passes}/rails.rb +0 -0
  27. data/gm_passes/rubigen.rb +9 -0
  28. data/{lib/passes → gm_passes}/specs.rb +0 -0
  29. data/{lib/passes/tests.rb → gm_passes/test.rb} +0 -0
  30. data/lib/extentions/gem.rb +15 -0
  31. data/lib/gm.rb +5 -0
  32. data/lib/gm/app.rb +42 -75
  33. data/lib/gm/command.rb +54 -0
  34. metadata +59 -10
data/README.textile CHANGED
@@ -2,42 +2,4 @@ h1. GM (gem make)
2
2
 
3
3
  GM is a gem and gemspec builder for use with github.
4
4
 
5
-
6
- h2. Configuration
7
-
8
- ~/.gmrc.yml
9
-
10
- author:
11
- name: [your name]
12
- email: [your email adres]
13
- github:
14
- username: [your github username]
15
-
16
- paths/to/gem/gmfile.yml
17
-
18
- general:
19
- name: [name of the gem]
20
- version: [version]
21
- summary: [a short description]
22
- dependencies:
23
- - gem-name version-requirement
24
- - gem2-name version-requirement
25
-
26
- h2. Example
27
-
28
- ~/.gmrc.yml
29
-
30
- author:
31
- name: Simon Menke
32
- email: simon.menke@gmail.com
33
- github:
34
- username: simonmenke
35
-
36
- paths/to/gem/gmfile.yml
37
-
38
- general:
39
- name: gm
40
- version: 0.0.1
41
- summary: Build gems with ease.
42
- dependencies:
43
- - configatron >= 2.2.1
5
+ For more info/docs go to http://simonmenke.github.com/gm
@@ -0,0 +1,14 @@
1
+
2
+ module GM
3
+
4
+ class BuildCommand < Command
5
+
6
+ def run
7
+ app.emulate = true
8
+ app.build_gemspec
9
+ app.build_gem
10
+ end
11
+
12
+ end
13
+
14
+ end
@@ -0,0 +1,12 @@
1
+
2
+ module GM
3
+
4
+ class CleanCommand < Command
5
+
6
+ def run
7
+ system("rm -rf pkg/* *.gemspec")
8
+ end
9
+
10
+ end
11
+
12
+ end
@@ -0,0 +1,15 @@
1
+
2
+ module GM
3
+
4
+ class CreateCommand < Command
5
+
6
+ def run
7
+ @gen_options = ARGV
8
+
9
+ RubiGen::Base.use_component_sources!(:gm)
10
+ RubiGen::Scripts::Generate.new.run(ARGV, :generator => 'gem')
11
+ end
12
+
13
+ end
14
+
15
+ end
@@ -0,0 +1,16 @@
1
+
2
+ module GM
3
+
4
+ class GenCommand < Command
5
+
6
+ def run
7
+ @gen_name = ARGV.shift
8
+ @gen_options = ARGV
9
+
10
+ RubiGen::Base.use_component_sources!(:gm)
11
+ RubiGen::Scripts::Generate.new.run(ARGV, :generator => @gen_name)
12
+ end
13
+
14
+ end
15
+
16
+ end
@@ -0,0 +1,14 @@
1
+
2
+ module GM
3
+
4
+ class HelpCommand < Command
5
+
6
+ def run
7
+ puts "#{File.basename($0)} <command> <options>"
8
+ puts "Commands: #{App.instance.command_names.join(' ')}"
9
+ puts options.to_s
10
+ end
11
+
12
+ end
13
+
14
+ end
@@ -0,0 +1,15 @@
1
+
2
+ module GM
3
+
4
+ class InstallCommand < Command
5
+
6
+ def run
7
+ app.emulate = true
8
+ app.build_gemspec
9
+ app.build_gem
10
+ system("sudo gem install pkg/#{app.gem_file_name}")
11
+ end
12
+
13
+ end
14
+
15
+ end
@@ -0,0 +1,15 @@
1
+
2
+ module GM
3
+
4
+ class SpecCommand < Command
5
+
6
+ def run
7
+ app.build_gemspec
8
+ File.open("#{app.gemspec.name}.gemspec", 'w+') do |f|
9
+ f.write app.gemspec.to_ruby
10
+ end
11
+ end
12
+
13
+ end
14
+
15
+ end
@@ -0,0 +1,22 @@
1
+
2
+ class BinGenerator < RubiGen::Base
3
+
4
+ attr_reader :bin_name
5
+
6
+ def initialize(runtime_args, runtime_options = {})
7
+ super
8
+ @destination_root = '.'
9
+ @bin_name = args.shift
10
+ end
11
+
12
+ def manifest
13
+ record do |m|
14
+
15
+ m.directory ''
16
+ %w( bin ).each { |path| m.directory path }
17
+
18
+ m.template "bin/bin.rb", "bin/#{@bin_name}"
19
+ end
20
+ end
21
+
22
+ end
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # call your app code here
@@ -0,0 +1,38 @@
1
+
2
+ class GemGenerator < RubiGen::Base
3
+
4
+ attr_reader :app_name, :module_name
5
+
6
+ def initialize(runtime_args, runtime_options = {})
7
+ super
8
+ usage if args.empty?
9
+ @destination_root = args.shift
10
+ @app_name = File.basename(File.expand_path(@destination_root))
11
+ @module_name = app_name.camelize
12
+ end
13
+
14
+ def manifest
15
+ record do |m|
16
+
17
+ # Root directory and all subdirectories.
18
+ m.directory ''
19
+ %w( lib ).each { |path| m.directory path }
20
+
21
+ # Root
22
+ m.template_copy_each %w( gmfile.yml )
23
+ m.file_copy_each %w( README.textile )
24
+
25
+ m.template "lib/module.rb", "lib/#{app_name}.rb"
26
+ end
27
+ end
28
+
29
+ protected
30
+
31
+ def banner
32
+ <<-EOS
33
+ Create a stub gem for #{File.basename $0} to get started.
34
+
35
+ Usage: #{File.basename $0} gen gm /path/to/your/gem"
36
+ EOS
37
+ end
38
+ end
File without changes
@@ -0,0 +1,3 @@
1
+ general:
2
+ name: <%= app_name %>
3
+ version: 0.0.1
@@ -0,0 +1,4 @@
1
+
2
+ module <%= module_name %>
3
+
4
+ end
@@ -0,0 +1,20 @@
1
+
2
+ class RailsGenerator < RubiGen::Base
3
+
4
+ attr_reader :file_name, :test_case_name
5
+
6
+ def initialize(runtime_args, runtime_options = {})
7
+ super
8
+ @destination_root = '.'
9
+ end
10
+
11
+ def manifest
12
+ record do |m|
13
+ m.directory ''
14
+ m.directory 'rails'
15
+
16
+ m.template "rails/init.rb", "rails/init.rb"
17
+ end
18
+ end
19
+
20
+ end
@@ -0,0 +1 @@
1
+ # initialize your rails plugin here
@@ -0,0 +1,5 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ class <%= test_case_name %>Test < Test::Unit::TestCase
4
+
5
+ end
@@ -0,0 +1,6 @@
1
+
2
+ class Test::Unit::TestCase
3
+
4
+ # put your helpers here
5
+
6
+ end
@@ -0,0 +1,24 @@
1
+
2
+ class TestGenerator < RubiGen::Base
3
+
4
+ attr_reader :file_name, :test_case_name
5
+
6
+ def initialize(runtime_args, runtime_options = {})
7
+ super
8
+ @destination_root = '.'
9
+ @file_name = args.shift
10
+ @test_case_name = file_name.camelize unless @file_name.nil?
11
+ end
12
+
13
+ def manifest
14
+ record do |m|
15
+
16
+ m.directory ''
17
+ %w( test ).each { |path| m.directory path }
18
+
19
+ m.template "test/test_helper.rb", "test/test_helper.rb"
20
+ m.template "test/test_case.rb", "test/#{@file_name}_test.rb" unless @file_name.nil?
21
+ end
22
+ end
23
+
24
+ end
File without changes
File without changes
File without changes
File without changes
File without changes
data/gm_passes/gm.rb ADDED
@@ -0,0 +1,7 @@
1
+
2
+ pass :gm_passes do |spec|
3
+
4
+ spec.files += Dir.glob('gm_commands/*_command.rb')
5
+ spec.files += Dir.glob('gm_passes/*.rb')
6
+
7
+ end
File without changes
@@ -0,0 +1,9 @@
1
+
2
+ pass :rubigen do |spec|
3
+
4
+ paths = Dir.glob('*generators/**/*')
5
+ paths.reject! { |path| File.directory? path }
6
+ paths.reject! { |path| File.basename(path)[0,1] == "." }
7
+ spec.files += paths
8
+
9
+ end
File without changes
File without changes
@@ -0,0 +1,15 @@
1
+
2
+ module Gem # :nodoc:
3
+
4
+ class Specification # :nodoc:
5
+
6
+ alias_method :ruby_code_old, :ruby_code
7
+
8
+ def ruby_code(obj)
9
+ obj = nil if obj.is_a? Configatron::Store
10
+ ruby_code_old(obj)
11
+ end
12
+
13
+ end
14
+
15
+ end
data/lib/gm.rb CHANGED
@@ -1,6 +1,10 @@
1
1
 
2
2
  begin
3
+ require 'clip'
4
+ require 'singleton'
3
5
  require 'configatron'
6
+ require 'rubigen'
7
+ require 'rubigen/scripts/generate'
4
8
  rescue LoadError
5
9
  retry if require 'rubygems'
6
10
  end
@@ -9,6 +13,7 @@ module GM
9
13
  end
10
14
 
11
15
  require File.dirname(__FILE__)+'/gm/app'
16
+ require File.dirname(__FILE__)+'/gm/command'
12
17
  require File.dirname(__FILE__)+'/gm/configuration_pass'
13
18
  require File.dirname(__FILE__)+'/gm/configuration_pass_queue'
14
19
  require File.dirname(__FILE__)+'/gm/dsl'
data/lib/gm/app.rb CHANGED
@@ -1,4 +1,3 @@
1
- require 'singleton'
2
1
 
3
2
  module GM
4
3
 
@@ -6,113 +5,81 @@ module GM
6
5
  include Singleton
7
6
 
8
7
  attr_accessor :configuration_passes
8
+ attr_accessor :commands
9
+ attr_accessor :options
10
+ attr_accessor :gemspec
11
+ attr_accessor :emulate
12
+ attr_accessor :gem_file_name
9
13
 
10
- COMMANDS = %w( help build spec install clean )
11
-
12
- def initialize
14
+ def initialize # :nodoc:
13
15
  @configuration_passes = Hash.new { |h, k| h[k] = {} }
16
+ @commands = {}
14
17
  end
15
18
 
19
+ # exclude a pass from the configuration fase
16
20
  def exclude_pass(name, fase=:normal)
17
21
  @configuration_passes[fase.to_sym].delete(name.to_sym)
18
22
  end
19
23
 
20
- def parse_options
21
- @command = ARGV.shift unless ARGV.empty?
22
- @command = nil unless COMMANDS.include? @command
23
- @command = 'help' if @command.nil?
24
+ # extra options provided by the app.
25
+ def extra_options(options)
26
+ options.flag 'v', 'verbose', :desc => 'Print more information.'
24
27
  end
25
28
 
29
+ # run the app
26
30
  def run
27
31
  load_passes
28
- parse_options
29
- send "run_#{@command}"
30
- end
31
-
32
- def run_help
33
- puts "#{File.basename($0)} #{COMMANDS.join('|')}"
34
- end
35
-
36
- def run_spec
37
- build_gemspec
38
- write_spec_file
32
+ load_commands
33
+ Command.build(self).run
39
34
  end
40
35
 
41
- def run_build
42
- @emulate = true
43
- build_gemspec
44
- build_spec
45
- end
46
-
47
- def run_install
48
- @emulate = true
49
- build_gemspec
50
- build_spec
51
- install_gem
52
- end
53
-
54
- def run_clean
55
- system("rm -rf pkg/* *.gemspec")
36
+ # ge a list of all the command names
37
+ def command_names
38
+ commands.keys.collect do |name|
39
+ name.to_s.gsub(/[A-Z]/){|m|'_'+m.downcase}.sub(/^_/, '').sub('_command', '')
40
+ end.sort
56
41
  end
57
42
 
43
+ # should we emulate github?
58
44
  def self.emulate?
59
- instance.emulate?
60
- end
61
-
62
- def emulate?
63
- @emulate || false
45
+ instance.emulate || false
64
46
  end
65
47
 
66
- private
67
-
68
- def load_passes
69
- Dir.glob(File.dirname(__FILE__)+'/../passes/*.rb') do |path|
70
- GM::DSL.load_pass path
48
+ def build_gemspec
49
+ @gemspec = Gem::Specification.new do |s|
50
+ ConfigurationPassQueue.new(:init).run(s)
51
+ ConfigurationPassQueue.new(:pre).run(s)
52
+ ConfigurationPassQueue.new(:normal).run(s)
53
+ ConfigurationPassQueue.new(:post).run(s)
71
54
  end
55
+ @gemspec.validate
72
56
  end
73
57
 
74
- def install_gem
75
- system("sudo gem install pkg/#{@gem_file_name}")
76
- end
77
-
78
- def build_spec
79
- builder = Gem::Builder.new @spec
58
+ def build_gem
59
+ builder = Gem::Builder.new @gemspec
80
60
  @gem_file_name = builder.build
81
61
  system("rm -f pkg/#{@gem_file_name}")
82
62
  system("mkdir -p pkg && mv #{@gem_file_name} pkg/")
83
63
  end
84
64
 
85
- def write_spec_file
86
- File.open("#{@spec.name}.gemspec", 'w+') do |f|
87
- f.write @spec.to_ruby
65
+ private
66
+
67
+ # load all passes
68
+ def load_passes
69
+ require 'reverse_require'
70
+ Gem.find_resources('gm_passes/*.rb').uniq.each do |path|
71
+ GM::DSL.load_pass path
88
72
  end
89
73
  end
90
74
 
91
- def build_gemspec
92
- @spec = Gem::Specification.new do |s|
93
- ConfigurationPassQueue.new(:init).run(s)
94
- ConfigurationPassQueue.new(:pre).run(s)
95
- ConfigurationPassQueue.new(:normal).run(s)
96
- ConfigurationPassQueue.new(:post).run(s)
75
+ # load all commands
76
+ def load_commands
77
+ require 'reverse_require'
78
+ Gem.find_resources('gm_commands/*_command.rb').uniq.each do |path|
79
+ GM::Command.load_command path
97
80
  end
98
- @spec.validate
99
81
  end
100
82
 
101
83
  end
102
84
 
103
85
  end
104
-
105
- module Gem
106
-
107
- class Specification
108
-
109
- alias_method :ruby_code_old, :ruby_code
110
-
111
- def ruby_code(obj)
112
- obj = nil if obj.is_a? Configatron::Store
113
- ruby_code_old(obj)
114
- end
115
-
116
- end
117
-
118
- end
data/lib/gm/command.rb ADDED
@@ -0,0 +1,54 @@
1
+
2
+ module GM
3
+
4
+ class Command
5
+
6
+ attr_accessor :app
7
+ attr_accessor :options
8
+
9
+ # load a command from a file
10
+ def self.load_command(path)
11
+ cmd_name = File.basename(path, '.rb')
12
+ cmd_name = cmd_name.gsub(/(^|_)([a-z])/i) { |m| $2.upcase }
13
+
14
+ mod = Module.new
15
+ mod.module_eval IO.read(path)
16
+
17
+ cmd_class = (mod.module_eval("GM::"+cmd_name) rescue nil)
18
+
19
+ return nil if cmd_class.nil?
20
+
21
+ GM::App.instance.commands[cmd_name.to_sym] = cmd_class
22
+ end
23
+
24
+ # build a command
25
+ def self.build(app)
26
+ cmd_name = (ARGV.detect {|i| not i =~ /^--?/ } || 'help')
27
+ ARGV.delete(cmd_name)
28
+ cmd_name = cmd_name + '_command'
29
+ cmd_name = cmd_name.gsub(/(^|_)([a-z])/i) { |m| $2.upcase }
30
+ cmd_class = GM::App.instance.commands[cmd_name.to_sym] || GM::App.instance.commands[:HelpCommand]
31
+ cmd = cmd_class.new
32
+ cmd.app = app
33
+ cmd.options = app.options = Clip do |p|
34
+ app.extra_options(p)
35
+ cmd.extra_options(p)
36
+ end
37
+ ARGV.clear
38
+ ARGV.concat(cmd.options.remainder)
39
+ cmd
40
+ end
41
+
42
+ # A command can overwrite this method in order to add extra command line options.
43
+ def extra_options(options)
44
+
45
+ end
46
+
47
+ # A command must overwrite this method.
48
+ def run
49
+
50
+ end
51
+
52
+ end
53
+
54
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simonmenke-gm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simon Menke
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-01-12 00:00:00 -08:00
12
+ date: 2009-01-14 00:00:00 -08:00
13
13
  default_executable: gm
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -21,6 +21,33 @@ dependencies:
21
21
  - !ruby/object:Gem::Version
22
22
  version: 2.2.1
23
23
  version:
24
+ - !ruby/object:Gem::Dependency
25
+ name: clip
26
+ version_requirement:
27
+ version_requirements: !ruby/object:Gem::Requirement
28
+ requirements:
29
+ - - ">="
30
+ - !ruby/object:Gem::Version
31
+ version: 1.0.0
32
+ version:
33
+ - !ruby/object:Gem::Dependency
34
+ name: rubigen
35
+ version_requirement:
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 1.5.1
41
+ version:
42
+ - !ruby/object:Gem::Dependency
43
+ name: reverse-require
44
+ version_requirement:
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: 0.3.1
50
+ version:
24
51
  description:
25
52
  email: simon.menke@gmail.com
26
53
  executables:
@@ -31,20 +58,42 @@ extra_rdoc_files: []
31
58
 
32
59
  files:
33
60
  - bin/gm
61
+ - lib/extentions/gem.rb
34
62
  - lib/gm/app.rb
63
+ - lib/gm/command.rb
35
64
  - lib/gm/configuration_pass.rb
36
65
  - lib/gm/configuration_pass_queue.rb
37
66
  - lib/gm/dsl.rb
38
67
  - lib/gm.rb
39
- - lib/passes/configatron.rb
40
- - lib/passes/defaults.rb
41
- - lib/passes/executables.rb
42
- - lib/passes/files.rb
43
- - lib/passes/github.rb
44
- - lib/passes/rails.rb
45
- - lib/passes/specs.rb
46
- - lib/passes/tests.rb
47
68
  - README.textile
69
+ - gm_generators/bin/bin_generator.rb
70
+ - gm_generators/bin/templates/bin/bin.rb
71
+ - gm_generators/gem/gem_generator.rb
72
+ - gm_generators/gem/templates/gmfile.yml
73
+ - gm_generators/gem/templates/lib/module.rb
74
+ - gm_generators/gem/templates/README.textile
75
+ - gm_generators/rails/rails_generator.rb
76
+ - gm_generators/rails/templates/rails/init.rb
77
+ - gm_generators/test/templates/test/test_case.rb
78
+ - gm_generators/test/templates/test/test_helper.rb
79
+ - gm_generators/test/test_generator.rb
80
+ - gm_commands/build_command.rb
81
+ - gm_commands/clean_command.rb
82
+ - gm_commands/create_command.rb
83
+ - gm_commands/gen_command.rb
84
+ - gm_commands/help_command.rb
85
+ - gm_commands/install_command.rb
86
+ - gm_commands/spec_command.rb
87
+ - gm_passes/configatron.rb
88
+ - gm_passes/defaults.rb
89
+ - gm_passes/executables.rb
90
+ - gm_passes/files.rb
91
+ - gm_passes/github.rb
92
+ - gm_passes/gm.rb
93
+ - gm_passes/rails.rb
94
+ - gm_passes/rubigen.rb
95
+ - gm_passes/specs.rb
96
+ - gm_passes/test.rb
48
97
  has_rdoc: true
49
98
  homepage: http://github.com/simonmenke/gm
50
99
  post_install_message: