Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
148 lines (122 sloc) 3.79 KB
require 'crxmake'
desc "Install whence"
task :install => 'install:all'
namespace :install do
task :all => [ :prompt, :chrome, :agent, :daemon, :done ]
task :prompt do
puts "\e[1m\e[32mwhence\e[0m"
puts "\e[1m-----\e[0m"
puts "I will install:", ""
puts "1. The 'whence' Google Chrome Extension"
puts "2. djsd(1) in /usr/local/bin"
puts "3. com.github.whence in ~/Library/LaunchAgents",""
print "Ok? (y/n) "
begin
until %w( k ok y yes n no ).include?(answer = $stdin.gets.chomp.downcase)
puts "(psst... please type y or n)"
puts "Install whence? (y/n)"
end
rescue Interrupt
exit 1
end
exit 1 if answer =~ /n/
end
task :done do
if system("curl http://localhost:3131 &> /dev/null")
puts "\e[1m\e[32mwhence installation worked\e[0m"
puts "drop files like google.com.js in ~/.js and enjoy hacking the web"
else
puts "\e[31mwhence installation failed\e[0m"
puts "check console.app or open an issue"
end
end
desc "Install launch agent"
task :agent do
plist = "com.github.whence.plist"
agent = File.expand_path("~/Library/LaunchAgents/#{plist}")
cp plist, agent, :verbose => true
chmod 0644, agent
puts "starting djdb..."
sh "launchctl load -w #{agent}"
# wait for server to start
sleep 5
end
desc "Install whence daemon"
task :daemon do
cp "bin/djsd", "/usr/local/bin", :verbose => true, :preserve => true
end
desc "Install Google Chrome extension"
task :chrome do
puts "Building Google Chrome extension..."
CrxMake.make(
:ex_dir => "./ext",
:pkey => "./ext.pem",
:crx_output => "./builds/whence.crx",
:verbose => true,
:ignorefile => /\.swp/,
:ignoredir => /\.(?:svn|git|cvs)/
)
# Dir.chdir("ext") do
# files = Dir.glob("*.{js,json,png}")
# Kernel.exec "rm ../builds/whence.crx"
# cmd = "zip ../builds/whence.crx #{files.join(' ')}"
# Kernel.exec cmd
# end
puts "Installing Google Chrome extension..."
sh "open -a 'Google Chrome' builds/whence.crx &"
end
end
desc "Uninstall whence"
task :uninstall => 'uninstall:all'
namespace :uninstall do
task :all => [ :prompt, :daemon, :agent, :chrome, :done ]
task :prompt do
puts "\e[1m\e[32mwhence\e[0m"
puts "\e[1m-----\e[0m"
puts "I will remove:", ""
puts "1. djsd(1) from /usr/local/bin"
puts "2. com.github.whence from ~/Library/LaunchAgents"
puts "3. The 'whence' Google Chrome Extension",""
puts "I will not remove:", ""
puts "1. ~/.js", ""
print "Ok? (y/n) "
begin
until %w( k ok y yes n no ).include?(answer = $stdin.gets.chomp.downcase)
puts "(psst... please type y or n)"
puts "Uninstall whence? (y/n)"
end
rescue Interrupt
exit 1
end
exit 1 if answer =~ /n/
end
task :done do
if system("curl http://localhost:3131 &> /dev/null")
puts "\e[31mwhence uninstall failed\e[0m"
puts "djsd is still running"
else
puts "\e[1m\e[32mwhence uninstall worked\e[0m"
puts "your ~/.js was not touched"
end
end
desc "Uninstall launch agent"
task :agent do
plist = "com.github.whence.plist"
agent = File.expand_path("~/Library/LaunchAgents/#{plist}")
sh "launchctl unload #{agent}"
rm agent, :verbose => true
end
desc "Uninstall whence daemon"
task :daemon do
rm "/usr/local/bin/djsd", :verbose => true
end
desc "Uninstall Google Chrome extension"
task :chrome do
puts "\e[1mplease uninstall the google chrome extension manually:\e[0m"
puts "google chrome > window > extensions > whence > uninstall"
end
end
desc "Tail the Couchbase log"
task :tail do
exec "tail -f /Applications/Couchbase\\ Server.app/Contents/Resources/couchdbx-core/var/log/couchdb/couch.log"
end