#!/usr/bin/env ruby # Prepare ARGV ARGS = ARGV.map {|a| a.strip.chomp } if !(DIRNAME = ARGS[0]) puts "Usage: serious DIRNAME (--views) (--public) (--heroku) (--no-git)" puts "Note: Only lowercase letters and dashes ('-') are allowed for DIRNAME" puts "Options:" puts " --views: Copies the default views into your site so you can modify them and sets" puts " config accordingly. By default your site will use the views supplied with" puts " the serious gem" puts " --public: Copies the default public folder into your site and sets config accordingly" puts " By default your site will use the public folder supplied with the serious gem" puts " --no-git: Will not create a new git repository (by default, it does)" puts " --heroku: Creates a heroku app named with dirname and pushes your site to it." puts " Requires the heroku gem to be installed" exit 1 end if File.exist?(DIRNAME) puts "#{DIRNAME} exists!" exit 1 end unless DIRNAME =~ /^[a-z][a-z\-]*$/ puts "Only lowercase-letters and '-' allowed in dirname!" exit 1 end require 'fileutils' puts "Creating directory #{DIRNAME}" ORIGINAL_DIR = Dir.getwd FileUtils.mkdir_p(File.join(DIRNAME, 'articles')) FileUtils.mkdir_p(File.join(DIRNAME, 'pages')) Dir.chdir(DIRNAME) GEM_ROOT = File.join(File.dirname(__FILE__), '..') def copy_public puts 'Copying public dir' FileUtils.cp_r File.join(GEM_ROOT, 'lib', 'site', 'public'), './' end def copy_views puts 'Copying views dir' FileUtils.cp_r File.join(GEM_ROOT, 'lib', 'site', 'views'), './' end def views? ARGS.include?('--views') end def public? ARGS.include?('--public') end def heroku? ARGS.include?('--heroku') end def git? !ARGS.include?('--no-git') end copy_views if views? copy_public if public? puts "Writing about page" File.open('pages/about.txt', "w+") do |about| about.puts "title: About" about.puts about.puts "Something about you" end puts "Writing config.ru" File.open('config.ru', 'w+') do |config| config.puts "require 'serious'" config.puts "Serious.set :title, '#{DIRNAME}'" config.puts "Serious.set :author, 'Your Name here'" config.puts "Serious.set :url, 'http://#{DIRNAME}.heroku.com'" if public? and views? config.puts "Serious.set :root, Dir.getwd" elsif public? config.puts "Serious.set :public, File.join(Dir.getwd, 'public')" elsif views? config.puts "Serious.set :views, File.join(Dir.getwd, 'views')" end config.puts 'run Serious' end puts "Creating bundler Gemfile" File.open("Gemfile", "w+") do |gems| gems.puts "source :rubygems" gems.puts 'gem "serious"' end puts "Creating Rakefile" File.open('Rakefile', "w+") do |rake| rake.puts "require 'serious'" rake.puts "require 'serious/tasks'" end if git? puts "Creating git repo" system "git init" system "git add . && git commit -m 'Initial commit'" end if heroku? if git? puts "Creating heroku app" if system "heroku create #{DIRNAME} --stack bamboo-mri-1.9.1" puts "Pushing to heroku - in 5 seconds" sleep 5 if system 'git push heroku master' puts "Your app now lives at http://#{DIRNAME}.heroku.com" else puts "Failed to push to heroku!" end else puts "ERROR: Failed to create heroku app" end else puts "ERROR: Can't create heroku app without git!" end end puts "Done!" Dir.chdir(ORIGINAL_DIR)