diff --git a/Gemfile b/Gemfile index 58886e1..6cf20c4 100644 --- a/Gemfile +++ b/Gemfile @@ -19,8 +19,9 @@ gem "server.rb", path: "./packages/ruby/server" ## # Everything else -gem "ryo.rb", "~> 0.3", github: "0x1eef/ryo.rb", tag: "v0.3.0" -gem "test-cmd.rb", "~> 0.3", github: "0x1eef/test-cmd.rb", tag: "v0.3.0" +gem "ryo.rb", github: "0x1eef/ryo.rb", tag: "v0.3.0" +gem "test-cmd.rb", github: "0x1eef/test-cmd.rb", tag: "v0.3.0" +gem "lockf.rb", github: "0x1eef/lockf.rb", tag: "v0.12.0" gem "standard", "~> 1.24" gem "paint", "~> 2.3" gem "dotenv", "~> 2.8" diff --git a/Gemfile.lock b/Gemfile.lock index 4f94c4d..8f092c9 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,3 +1,10 @@ +GIT + remote: https://github.com/0x1eef/lockf.rb.git + revision: fd79284a8d3af8562654742a23b39288a0e4e24f + tag: v0.12.0 + specs: + lockf.rb (0.12.0) + GIT remote: https://github.com/0x1eef/nanoc-gzip.rb.git revision: 3bb1719ad11d983a25945c1017df76aa2f6b8540 @@ -172,6 +179,7 @@ PLATFORMS DEPENDENCIES dotenv (~> 2.8) listen (~> 3.0) + lockf.rb! memoize (~> 1.3) nanoc (~> 4.12) nanoc-gzip.rb! @@ -180,11 +188,11 @@ DEPENDENCIES paint (~> 2.3) rainpress (~> 1.0) rake - ryo.rb (~> 0.3)! + ryo.rb! sass (~> 3.7) server.rb! standard (~> 1.24) - test-cmd.rb (~> 0.3)! + test-cmd.rb! BUNDLED WITH 2.4.10 diff --git a/tasks/nanoc.rake b/tasks/nanoc.rake index 29f1a60..e78faf4 100644 --- a/tasks/nanoc.rake +++ b/tasks/nanoc.rake @@ -1,34 +1,63 @@ # frozen_string_literal: true +require "fileutils" +require "lockf" 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) + namespace :nanoc do task :compile do + warn "[build] Acquire lock..." + lockf.lock ENV["SASS_PATH"] = "./src/css/" sh "bundle exec nanoc co" + rescue Interrupt + warn "SIGINT: exit" + exit + ensure + warn "[build] Release lock..." + lockf.release end task :clean do + warn "[build] Acquire lock..." + lockf.lock sh "rm -rf #{build_dir}" + ensure + warn "[build] Release lock..." + lockf.release end task :clean_css do + warn "[build] Acquire lock..." + lockf.lock cssdir = File.join(build_dir, "css") - if Dir.exist?(cssdir) - sh "rm -rf #{cssdir}" - end + sh "rm -rf #{cssdir}" if Dir.exist?(cssdir) + ensure + warn "[build] Release lock..." + lockf.release end - task watch: [:compile] do + task watch: ['build'] do + warn "[build] Acquire lock..." + lockf.lock 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 end end desc "Build the website" -task build: ["nanoc:clean_css", "nanoc:compile"] +task build: ["nanoc:compile"] desc "Trigger a build when src/ is modified" task "build:watch" => "nanoc:watch"