78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
|
# File 'lib/adhearsion/cli.rb', line 78
def create(*args)
if args.size.zero?
raise CommandHandler::UnknownCommand.new("Must specify something to create!")
elsif args.size == 1
path = args.first
require 'rubigen'
require 'rubigen/scripts/generate'
source = RubiGen::PathSource.new(:application,
File.join(File.dirname(__FILE__), "../../app_generators"))
RubiGen::Base.reset_sources
RubiGen::Base.append_sources source
RubiGen::Scripts::Generate.new.run([path], :generator => 'ahn')
elsif args.size == 2
feature_type, component_name = args
if feature_type != "component"
raise CommandHandler::UnknownCommand.new("Don't know how to create '#{feature_type}'")
end
if component_name !~ /^[a-z][\w_]+$/
raise CommandHandler::ComponentError.new("Component name must be lowercase alphanumeric characters " +
"and begin with a character")
end
app_path = PathString.from_application_subdirectory Dir.pwd
if app_path.nil?
new_component_dir = File.join Dir.pwd, component_name
else
puts "Adhearsion application detected. Creating new component at components/#{component_name}"
new_component_dir = File.join app_path, "components", component_name
end
raise ComponentError.new("Component #{component_name} already exists!") if File.exists?(new_component_dir)
Dir.mkdir new_component_dir
Dir.mkdir File.join(new_component_dir, "lib")
fn = File.join("lib", "#{component_name}.rb")
puts "- #{fn}: Initial component code file"
File.open(File.join(new_component_dir, fn),"w") do |file|
file.puts <<-RUBY
# See http://docs.adhearsion.com for more information on how to write components or
# look at the examples in newly-created projects.
RUBY
end
Dir.mkdir File.join(new_component_dir, "config")
fn = File.join("config", "#{component_name}.yml")
puts "- #{fn}: Example component configuration YAML"
File.open(File.join(new_component_dir, fn),"w") do |file|
file.puts '# You can use this file for component-specific configuration.'
end
fn = File.join("#{component_name}.gemspec")
puts "- #{fn}: Example component gemspec"
File.open(File.join(new_component_dir, fn), "w") do |file|
file.puts <<-RUBY
GEM_FILES = %w{
#{component_name}.gemspec
lib/#{component_name}.rb
config/#{component_name}.yml
}
Gem::Specification.new do |s|
s.name = "#{component_name}"
s.version = "0.0.1"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Your Name Here!"]
s.date = Date.today.to_s
s.description = "This Adhearsion component gem has not yet been described."
s.email = "[email protected]"
s.files = GEM_FILES
s.has_rdoc = false
s.homepage = "http://adhearsion.com"
s.require_paths = ["lib"]
s.rubygems_version = "1.2.0"
s.summary = "This Adhearsion component gem has no summary."
s.specification_version = 2
end
RUBY
end
Dir.mkdir File.join(new_component_dir, "spec")
fn = File.join("spec", "#{component_name}_spec.rb")
puts "- #{fn}: Example component spec"
File.open(File.join(new_component_dir, fn), "w") do |file|
file.puts <<-RUBY
require 'rubygems'
require 'bundler'
Bundler.setup
Bundler.require
require 'adhearsion/component_manager/spec_framework'
component_name.upcase = ComponentTester.new("#{component_name}", File.dirname(__FILE__) + "/../..")
RUBY
end
puts "Created blank component '#{component_name}' at #{new_component_dir}"
else
raise CommandHandler::UnknownCommand.new("Provided too many arguments to 'create'")
end
end
|