2023-07-25 20:32:57 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2023-11-27 22:11:22 +01:00
|
|
|
require "fileutils"
|
|
|
|
require "lockf"
|
2023-07-25 20:32:57 +02:00
|
|
|
build_dir = Ryo.from(YAML.load_file("./nanoc.yaml")).output_dir
|
2023-11-27 22:11:22 +01:00
|
|
|
lockp = File.join Dir.getwd, "tmp", "build.lock"
|
2023-12-04 13:37:03 +01:00
|
|
|
FileUtils.mkdir_p File.dirname(lockp)
|
2023-11-27 22:11:22 +01:00
|
|
|
FileUtils.touch(lockp)
|
|
|
|
lockf = LockFile.new(lockp)
|
|
|
|
|
2023-07-25 20:32:57 +02:00
|
|
|
namespace :nanoc do
|
2023-11-28 16:44:05 +01:00
|
|
|
task compile: %w[clean:css] do
|
2023-11-27 22:11:22 +01:00
|
|
|
warn "[build] Acquire lock..."
|
|
|
|
lockf.lock
|
2023-07-25 20:32:57 +02:00
|
|
|
ENV["SASS_PATH"] = "./src/css/"
|
|
|
|
sh "bundle exec nanoc co"
|
2023-11-27 22:11:22 +01:00
|
|
|
rescue Interrupt
|
|
|
|
warn "SIGINT: exit"
|
|
|
|
exit
|
|
|
|
ensure
|
|
|
|
warn "[build] Release lock..."
|
|
|
|
lockf.release
|
2023-07-25 20:32:57 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
task :clean do
|
2023-11-27 22:11:22 +01:00
|
|
|
warn "[build] Acquire lock..."
|
|
|
|
lockf.lock
|
2023-07-25 20:32:57 +02:00
|
|
|
sh "rm -rf #{build_dir}"
|
2023-11-27 22:11:22 +01:00
|
|
|
ensure
|
|
|
|
warn "[build] Release lock..."
|
|
|
|
lockf.release
|
2023-07-25 20:32:57 +02:00
|
|
|
end
|
|
|
|
|
2023-11-28 16:44:05 +01:00
|
|
|
task "clean:css" do
|
2023-11-27 22:11:22 +01:00
|
|
|
warn "[build] Acquire lock..."
|
|
|
|
lockf.lock
|
2023-10-28 15:47:43 +02:00
|
|
|
cssdir = File.join(build_dir, "css")
|
2023-11-27 22:11:22 +01:00
|
|
|
sh "rm -rf #{cssdir}" if Dir.exist?(cssdir)
|
|
|
|
ensure
|
|
|
|
warn "[build] Release lock..."
|
|
|
|
lockf.release
|
2023-10-28 15:47:43 +02:00
|
|
|
end
|
|
|
|
|
2023-11-28 16:44:05 +01:00
|
|
|
task watch: %w[build] do
|
2023-07-25 20:32:57 +02:00
|
|
|
require "listen"
|
|
|
|
Listen.to File.join(Dir.getwd, "src"), force_polling: true do
|
|
|
|
sh "rake build"
|
|
|
|
end.start
|
|
|
|
sleep
|
2023-11-27 22:11:22 +01:00
|
|
|
rescue Interrupt
|
|
|
|
warn "SIGINT: exit"
|
2023-11-27 22:18:10 +01:00
|
|
|
exit
|
2023-07-25 20:32:57 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
desc "Build the website"
|
2023-11-28 16:44:05 +01:00
|
|
|
task build: %w[nanoc:compile]
|
2023-10-28 15:47:43 +02:00
|
|
|
|
2023-07-25 20:32:57 +02:00
|
|
|
desc "Trigger a build when src/ is modified"
|
|
|
|
task "build:watch" => "nanoc:watch"
|
|
|
|
|
|
|
|
desc "Clean the build directory"
|
|
|
|
task clean: "nanoc:clean"
|