Add rake/tasks/server.rake

This commit is contained in:
0x1eef 2024-06-19 17:56:38 -03:00
parent 1399039985
commit 8f3a245f9a
2 changed files with 21 additions and 18 deletions

View file

@ -4,8 +4,6 @@ require "bundler/setup"
require "ryo"
require "yaml"
##
# Rake tasks
begin
load "rake/tasks/deploy.rake"
rescue LoadError
@ -15,20 +13,5 @@ load "rake/tasks/format.rake"
load "rake/tasks/nanoc.rake"
load "rake/tasks/t.rake"
load "rake/tasks/ci.rake"
desc "Start HTTP server"
task :server, [:protocol] do |_t, args|
require "server"
nanoc = Ryo.from(YAML.load_file("./nanoc.yaml"))
h = args.to_h
o = if h[:protocol] == "unix"
{unix: nanoc.server.unix.path}
else
{host: nanoc.server.tcp.host, port: nanoc.server.tcp.port}
end
s = Server.dir(nanoc.output_dir, o)
s.start(block: true)
rescue Interrupt
s.stop
end
load "rake/tasks/server.rake"
task default: "nanoc:build"

20
rake/tasks/server.rake Normal file
View file

@ -0,0 +1,20 @@
desc "Start web server"
task :server, [:protocol] do |_t, args|
require "yaml"
require "ryo"
require "server"
nanoc = Ryo.from(YAML.load_file("./nanoc.yaml"))
h = args.to_h
p = h[:protocol] || "tcp"
n = File.basename File.realpath(File.join(__dir__, "..", "..", "."))
o = if p == "unix"
{unix: nanoc.server.unix.path}
else
{host: nanoc.server.tcp.host, port: nanoc.server.tcp.port}
end
Process.setproctitle "rake server[#{p}] [#{n}]"
s = Server.dir(nanoc.output_dir, o)
s.start(block: true)
rescue Interrupt
s.stop
end