Add "server" rake task

This commit is contained in:
0x1eef 2023-06-30 16:14:21 -03:00
parent 9b25556084
commit fe108563fa
2 changed files with 13 additions and 9 deletions

View file

@ -2,6 +2,9 @@
require "bundler/setup"
require "ryo"
require "yaml"
build_dir = Ryo.from(YAML.load_file("./nanoc.yaml")).output_dir
namespace :nanoc do
desc "Compile the website"
@ -12,8 +15,6 @@ namespace :nanoc do
desc "Delete the build directory"
task :clean do
require "yaml"
build_dir = Ryo.from(YAML.load_file("./nanoc.yaml")).output_dir
sh "rm -rf #{build_dir}"
end
end
@ -24,11 +25,13 @@ task build: "nanoc:compile"
desc "Clean the build directory"
task clean: "nanoc:clean"
desc "Start a Ruby web server on localhost"
task server: ["nanoc:compile"] do
Dir.chdir(File.join(Dir.getwd, "build", "al-quran")) do
sh "bundle exec adsf"
end
desc "Serve the website on localhost"
task :server do
require "server"
s = Server.for_dir(build_dir)
s.start(block: true)
rescue Interrupt
s.stop
end
namespace :watch do

View file

@ -23,9 +23,10 @@ class Server
@server = Puma::Server.new(@app, @events, @options)
end
def start
def start(block: false)
@server.binder.parse(@options[:binds])
@server.run
thr = @server.run
block ? thr.join : thr
end
def stop