Skip to content

Instantly share code, notes, and snippets.

@killercup
Last active December 12, 2015 10:49
Show Gist options
  • Save killercup/4761737 to your computer and use it in GitHub Desktop.
Save killercup/4761737 to your computer and use it in GitHub Desktop.
Simple Rake file for compiling and deploying a Jekyll site along with CoffeeScript and Compass. Expects the following commands to be present: jekyll, coffee, compass, sleep, open

Compile, Watch and Deploy a Jekyll Site

Make sure to have the required settings set in _config.yml.

This will compile SASS/SCSS using compass and a config.rb and compile CoffeeScript file found using static/**/*.coffee.

Deploy to Specific Env

Make sure you have an entry for each of your environments set in the config file.

rake deploy env=production
# The following settings need to be present
# Part of Jekyll settings
server_port: 3636
destination: '_site'
# Deploy
environments:
stage:
url: http://beta.google.com/
remote:
connection: user@ssh-host.com
path: /path/to/deploy/to
production:
url: http://google.com/
require 'yaml'
config_file = '_config.yml'
config = YAML.load_file(config_file)
class JekyllOutput
def self.compile
Process.spawn "jekyll --no-server --no-auto"
end
def self.watch
Process.spawn "jekyll"
end
end
class CoffeeScriptOutput
def self.compile
Process.spawn "coffee --compile static/**/*.coffee"
end
def self.watch
Process.spawn "coffee --watch --compile static/**/*.coffee"
end
end
class CompassOutput
def self.compile
Process.spawn "compass compile"
end
def self.watch
Process.spawn "compass watch"
end
end
desc "Generate Jekyll site"
task :compile do
coffeePid = CoffeeScriptOutput::compile
compassPid = CompassOutput::compile
pre = Process.wait()
jekyllPid = JekyllOutput::compile
trap("INT") {
[compassPid, compassPid].each { |pid| Process.kill(9, pid) rescue Errno::ESRCH }
exit 0
}
Process.wait jekyllPid
end
desc "Generate Jekyll site and watch for changes"
task :watch do
coffeePid = CoffeeScriptOutput::watch
compassPid = CompassOutput::watch
jekyllPid = JekyllOutput::watch
sh "sleep 2 && open http://localhost:#{config['server_port']}/"
trap("INT") {
[jekyllPid, compassPid, compassPid].each { |pid| Process.kill(9, pid) rescue Errno::ESRCH }
exit 0
}
[jekyllPid, compassPid, compassPid].each { |pid| Process.wait(pid) }
end
desc "Deploy Jekyll site"
task :deploy do
env = ENV['env'] || 'stage'
Rake::Task["compile"].invoke
sh "scp -rp #{config['destination']}/* #{config['environments'][env]['remote']['connection']}:#{config['environments'][env]['remote']['path']} && open #{config['environments'][env]['url']}"
end
task :default => 'watch'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment