class Utopia::Command::Site::Create
Create
a local site.
Public Instance Methods
call()
click to toggle source
# 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 "bake utopia:development".center(78) puts "" puts "For extreme productivity, please consult the online documentation".center(78) puts "https://github.com/socketry/utopia".center(78) puts " ~ Samuel. ".rjust(78) end