Add "server" rake task
This commit is contained in:
parent
9b25556084
commit
fe108563fa
2 changed files with 13 additions and 9 deletions
17
Rakefile.rb
17
Rakefile.rb
|
@ -2,6 +2,9 @@
|
||||||
|
|
||||||
require "bundler/setup"
|
require "bundler/setup"
|
||||||
require "ryo"
|
require "ryo"
|
||||||
|
require "yaml"
|
||||||
|
|
||||||
|
build_dir = Ryo.from(YAML.load_file("./nanoc.yaml")).output_dir
|
||||||
|
|
||||||
namespace :nanoc do
|
namespace :nanoc do
|
||||||
desc "Compile the website"
|
desc "Compile the website"
|
||||||
|
@ -12,8 +15,6 @@ namespace :nanoc do
|
||||||
|
|
||||||
desc "Delete the build directory"
|
desc "Delete the build directory"
|
||||||
task :clean do
|
task :clean do
|
||||||
require "yaml"
|
|
||||||
build_dir = Ryo.from(YAML.load_file("./nanoc.yaml")).output_dir
|
|
||||||
sh "rm -rf #{build_dir}"
|
sh "rm -rf #{build_dir}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -24,11 +25,13 @@ task build: "nanoc:compile"
|
||||||
desc "Clean the build directory"
|
desc "Clean the build directory"
|
||||||
task clean: "nanoc:clean"
|
task clean: "nanoc:clean"
|
||||||
|
|
||||||
desc "Start a Ruby web server on localhost"
|
desc "Serve the website on localhost"
|
||||||
task server: ["nanoc:compile"] do
|
task :server do
|
||||||
Dir.chdir(File.join(Dir.getwd, "build", "al-quran")) do
|
require "server"
|
||||||
sh "bundle exec adsf"
|
s = Server.for_dir(build_dir)
|
||||||
end
|
s.start(block: true)
|
||||||
|
rescue Interrupt
|
||||||
|
s.stop
|
||||||
end
|
end
|
||||||
|
|
||||||
namespace :watch do
|
namespace :watch do
|
||||||
|
|
|
@ -23,9 +23,10 @@ class Server
|
||||||
@server = Puma::Server.new(@app, @events, @options)
|
@server = Puma::Server.new(@app, @events, @options)
|
||||||
end
|
end
|
||||||
|
|
||||||
def start
|
def start(block: false)
|
||||||
@server.binder.parse(@options[:binds])
|
@server.binder.parse(@options[:binds])
|
||||||
@server.run
|
thr = @server.run
|
||||||
|
block ? thr.join : thr
|
||||||
end
|
end
|
||||||
|
|
||||||
def stop
|
def stop
|
||||||
|
|
Loading…
Reference in a new issue