From 9cfab6441233136f461ea65dbff1689697a76186 Mon Sep 17 00:00:00 2001 From: 0x1eef <0x1eef@protonmail.com> Date: Sat, 13 Jan 2024 22:50:37 -0300 Subject: [PATCH] frontend: add rake tasks, improve performance in 'watch' mode --- twenty-frontend/Gemfile | 8 ++++++++ twenty-frontend/Gemfile.lock | 3 +++ twenty-frontend/Rakefile.rb | 1 + twenty-frontend/tasks/nanoc.rake | 17 +++++++++++++++++ 4 files changed, 29 insertions(+) create mode 100644 twenty-frontend/tasks/nanoc.rake diff --git a/twenty-frontend/Gemfile b/twenty-frontend/Gemfile index 359ed7b..f16a03e 100644 --- a/twenty-frontend/Gemfile +++ b/twenty-frontend/Gemfile @@ -6,3 +6,11 @@ gem "nanoc-live", "~> 1.0" gem "nanoc-webpack.rb", "~> 0.5" gem "sass", "~> 3.7" gem "rainpress", "~> 1.0" + +require 'rbconfig' +case RbConfig::CONFIG['target_os'] +when /(?i-mx:bsd|dragonfly)/ + gem 'rb-kqueue', '>= 0.2' +else + # Poll +end diff --git a/twenty-frontend/Gemfile.lock b/twenty-frontend/Gemfile.lock index 4d14c1a..cfd2c1e 100644 --- a/twenty-frontend/Gemfile.lock +++ b/twenty-frontend/Gemfile.lock @@ -94,6 +94,8 @@ GEM rb-fsevent (0.11.2) rb-inotify (0.10.1) ffi (~> 1.0) + rb-kqueue (0.2.8) + ffi (>= 0.5.0) rbtree (0.4.6) ryo.rb (0.4.5) sass (3.7.4) @@ -126,6 +128,7 @@ DEPENDENCIES nanoc-webpack.rb (~> 0.5) rainpress (~> 1.0) rake (~> 13.0) + rb-kqueue (>= 0.2) sass (~> 3.7) twenty-frontend! diff --git a/twenty-frontend/Rakefile.rb b/twenty-frontend/Rakefile.rb index 1903d8e..b96a24e 100644 --- a/twenty-frontend/Rakefile.rb +++ b/twenty-frontend/Rakefile.rb @@ -1,4 +1,5 @@ require "bundler/setup" +load 'tasks/nanoc.rake' namespace :schema do desc "Generate src/js/types/schema.ts" task :regen do diff --git a/twenty-frontend/tasks/nanoc.rake b/twenty-frontend/tasks/nanoc.rake new file mode 100644 index 0000000..03415ce --- /dev/null +++ b/twenty-frontend/tasks/nanoc.rake @@ -0,0 +1,17 @@ +namespace :nanoc do + desc "Produce the build/ directory" + task :build do + sh "nanoc co" + end + + desc "Produce the build/ directory on-demand" + task watch: ['nanoc:build'] do + require "listen" + path = File.join(Dir.getwd, "src") + Listen.to(path) { sh "rake nanoc:build" }.start + sleep + rescue Interrupt + warn "SIGINT: exit" + exit + end +end