al-quran.reflectslight.io/rake/tasks/server.rake

29 lines
738 B
Ruby
Raw Normal View History

2024-06-19 23:36:03 +02:00
# frozen_string_literal: true
cwd = File.realpath File.join(__dir__, "..", "..", ".")
2024-06-19 22:56:38 +02:00
desc "Start web server"
task :server, [:protocol] do |_t, args|
require "server"
nanoc = Ryo.from_yaml(path: File.join(cwd, "nanoc.yaml"))
2024-06-19 22:56:38 +02:00
h = args.to_h
p = h[:protocol] || "tcp"
n = File.basename(cwd)
2024-06-19 22:56:38 +02:00
o = if p == "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)
Process.setproctitle "rake server[#{p}] [#{n}]"
if p == "unix"
t = s.start(block: false)
unix = nanoc.server.unix
chmod(unix.mode, unix.path, verbose: false)
t.join
2024-06-19 23:36:03 +02:00
else
s.start(block: true)
2024-06-19 23:36:03 +02:00
end
2024-06-19 22:56:38 +02:00
rescue Interrupt
s.stop
end