Class: Utopia::Command::Site::Create

Inherits:
Samovar::Command
  • Object
show all
Defined in:
lib/utopia/command.rb

Instance Method Summary collapse

Instance Method Details

#invoke(parent) ⇒ Object

self.example = “utopia –in www.example.com site create”



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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
# File 'lib/utopia/command.rb', line 162

def invoke(parent)
	destination_root = parent.root
	
	$stderr.puts "Setting up initial site in #{destination_root} for Utopia v#{Utopia::VERSION}..."
	
	Setup::Site::DIRECTORIES.each do |directory|
		FileUtils.mkdir_p(File.join(destination_root, directory))
	end
	
	Find.find(Setup::Site::ROOT) do |source_path|
		# What is this doing?
		destination_path = File.join(destination_root, source_path[Setup::Site::ROOT.size..-1])
		
		if File.directory?(source_path)
			FileUtils.mkdir_p(destination_path)
		else
			unless File.exist? destination_path
				FileUtils.copy_entry(source_path, destination_path)
			end
		end
	end
	
	Setup::Site::CONFIGURATION_FILES.each do |configuration_file|
		destination_path = File.join(destination_root, configuration_file)
		
		buffer = File.read(destination_path).gsub('$UTOPIA_VERSION', Utopia::VERSION)
		
		File.open(destination_path, "w") { |file| file.write(buffer) }
	end
	
	Dir.chdir(destination_root) do
		puts "Setting up site in #{destination_root}..."
		
		if `which bundle`.strip != ''
			puts "Generating initial package list with bundle..."
			system("bundle", "install", "--binstubs")
		end
		
		if `which git`.strip == ""
			$stderr.puts "Now is a good time to learn about git: http://git-scm.com/"
		elsif !File.exist?('.git')
			puts "Setting up git repository..."
			system("git", "init")
			system("git", "add", ".")
			system("git", "commit", "-q", "-m", "Initial Utopia v#{Utopia::VERSION} site.")
		end
	end
	
	name = `git config user.name || whoami`.chomp
	
	puts
	puts "  #{name},".ljust(78)
	puts "Thank you for using Utopia!".center(78)
	puts "We sincerely hope that Utopia helps to".center(78)
	puts "make your life easier and more enjoyable.".center(78)
	puts ""
	puts "To start the development server, run:".center(78)
	puts "rake server".center(78)
	puts ""
	puts "For extreme productivity, please consult the online documentation".center(78)
	puts "https://github.com/ioquatix/utopia".center(78)
	puts " ~ Samuel.  ".rjust(78)
end