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

67 lines
1.4 KiB
Ruby
Raw Normal View History

2023-07-25 20:32:57 +02:00
# frozen_string_literal: true
require "fileutils"
require "lockf"
2023-07-25 20:32:57 +02:00
build_dir = Ryo.from(YAML.load_file("./nanoc.yaml")).output_dir
lockp = File.join Dir.getwd, "tmp", "build.lock"
FileUtils.touch(lockp)
lockf = LockFile.new(lockp)
2023-07-25 20:32:57 +02:00
namespace :nanoc do
task :compile do
warn "[build] Acquire lock..."
lockf.lock
2023-07-25 20:32:57 +02:00
ENV["SASS_PATH"] = "./src/css/"
sh "bundle exec nanoc co"
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
warn "[build] Acquire lock..."
lockf.lock
2023-07-25 20:32:57 +02:00
sh "rm -rf #{build_dir}"
ensure
warn "[build] Release lock..."
lockf.release
2023-07-25 20:32:57 +02:00
end
task :clean_css do
warn "[build] Acquire lock..."
lockf.lock
cssdir = File.join(build_dir, "css")
sh "rm -rf #{cssdir}" if Dir.exist?(cssdir)
ensure
warn "[build] Release lock..."
lockf.release
end
task watch: ['build'] do
warn "[build] Acquire lock..."
lockf.lock
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
rescue Interrupt
warn "SIGINT: exit"
warn "[build] Release lock..."
lockf.release
exit
2023-07-25 20:32:57 +02:00
end
end
desc "Build the website"
task build: ["nanoc:compile"]
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"