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

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

Overview

Create a local site.

Instance Method Summary collapse

Instance Method Details

#callObject



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
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
# File 'lib/utopia/command/site.rb', line 51

def call
	destination_root = parent.root
	
	$stderr.puts "Setting up initial site in #{destination_root} for Utopia v#{Utopia::VERSION}..."
	
	DIRECTORIES.each do |directory|
		FileUtils.mkdir_p(File.join(destination_root, directory))
	end
	
	Find.find(ROOT) do |source_path|
		# What is this doing?
		destination_path = File.join(destination_root, source_path[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
	
	CONFIGURATION_FILES.each do |configuration_file|
		destination_path = File.join(destination_root, configuration_file)
		
		if File.exist?(destination_path)
			buffer = File.read(destination_path).gsub('$UTOPIA_VERSION', Utopia::VERSION)
			File.open(destination_path, "w") { |file| file.write(buffer) }
		else
			warn "Could not open #{destination_path}, maybe it should be removed from CONFIGURATION_FILES?"
		end
	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") or fail "could not install bundled gems"
		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") or fail "could not create git repository"
			system("git", "add", ".") or fail "could not add all files"
			system("git", "commit", "-q", "-m", "Initial Utopia v#{Utopia::VERSION} site.") or fail "could not commit files"
		end
	end
	
	Environment.defaults(destination_root)
	
	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