2024-06-19 23:36:03 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2024-09-15 10:37:22 +02:00
|
|
|
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"
|
2024-09-15 10:37:22 +02:00
|
|
|
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"
|
2024-09-15 10:37:22 +02:00
|
|
|
n = File.basename(cwd)
|
2024-06-19 22:56:38 +02:00
|
|
|
o = if p == "unix"
|
2024-09-16 23:02:46 +02:00
|
|
|
{unix: nanoc.server.unix.path}
|
|
|
|
else
|
|
|
|
{host: nanoc.server.tcp.host, port: nanoc.server.tcp.port}
|
|
|
|
end
|
2024-09-15 10:37:22 +02:00
|
|
|
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
|
2024-09-15 10:37:22 +02:00
|
|
|
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
|