From df9f7936e77c0925332dc03665498e7922bd61f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Pollak?= Date: Thu, 19 Dec 2024 18:56:54 -0300 Subject: [PATCH 1/2] WIP: Support for tailwind cli when running 'themes watch' command --- lib/bootic_cli/commands/themes.rb | 2 +- lib/bootic_cli/themes/workflows.rb | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/bootic_cli/commands/themes.rb b/lib/bootic_cli/commands/themes.rb index 71ead81..04b9098 100644 --- a/lib/bootic_cli/commands/themes.rb +++ b/lib/bootic_cli/commands/themes.rb @@ -157,7 +157,7 @@ def watch write_lockfile at_exit { remove_lockfile } - workflows.watch(current_dir, remote_theme) + workflows.watch(current_dir, remote_theme, local_theme) end end diff --git a/lib/bootic_cli/themes/workflows.rb b/lib/bootic_cli/themes/workflows.rb index ee5ef59..015166d 100644 --- a/lib/bootic_cli/themes/workflows.rb +++ b/lib/bootic_cli/themes/workflows.rb @@ -189,7 +189,7 @@ def publish(local_theme, remote_theme) end end - def watch(dir, remote_theme, watcher: Listen) + def watch(dir, remote_theme, local_theme, watcher: Listen) listener = watcher.to(dir) do |modified, added, removed| if modified.any? @@ -217,6 +217,18 @@ def watch(dir, remote_theme, watcher: Listen) notice "Watching #{File.expand_path(dir)} for changes..." listener.start + if local_theme && File.exists?(File.join(dir, 'tailwind.config.js')) + source = local_theme.templates.find { |t| t.name['css'] && t.name['input'] } + target = local_theme.templates.find { |t| t.name['css'] && t.name['output'] } + + if source && target + notice "Tailwind config found! Firing the CLI in watch mode.." + run_tailwind_cli(source, target) + else + notice "Tailwind config found, but couldn't determine the source and target files" + end + end + # ctrl-c Signal.trap('INT') { begin @@ -235,6 +247,10 @@ def watch(dir, remote_theme, watcher: Listen) private attr_reader :prompt + def run_tailwind_cli(source_css, target_css) + `npx tailwindcss -i #{source_css} -o #{target_css} --watch` + end + def check_dupes!(list) names = list.map { |f| f.file_name.downcase } dupes = names.group_by { |e| e }.select { |k, v| v.size > 1 }.map(&:first) From c0df5762d91785fae90c6b58b44488d01037d485 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Pollak?= Date: Thu, 19 Dec 2024 18:58:28 -0300 Subject: [PATCH 2/2] Update lib/bootic_cli/themes/workflows.rb --- lib/bootic_cli/themes/workflows.rb | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/lib/bootic_cli/themes/workflows.rb b/lib/bootic_cli/themes/workflows.rb index 015166d..9026432 100644 --- a/lib/bootic_cli/themes/workflows.rb +++ b/lib/bootic_cli/themes/workflows.rb @@ -217,18 +217,6 @@ def watch(dir, remote_theme, local_theme, watcher: Listen) notice "Watching #{File.expand_path(dir)} for changes..." listener.start - if local_theme && File.exists?(File.join(dir, 'tailwind.config.js')) - source = local_theme.templates.find { |t| t.name['css'] && t.name['input'] } - target = local_theme.templates.find { |t| t.name['css'] && t.name['output'] } - - if source && target - notice "Tailwind config found! Firing the CLI in watch mode.." - run_tailwind_cli(source, target) - else - notice "Tailwind config found, but couldn't determine the source and target files" - end - end - # ctrl-c Signal.trap('INT') { begin @@ -241,6 +229,21 @@ def watch(dir, remote_theme, local_theme, watcher: Listen) } prompt.say "Preview changes at #{remote_theme.path} -- Hit Ctrl-C to stop watching for changes.", :cyan + + + if local_theme && File.exists?(File.join(dir, 'tailwind.config.js')) + source = local_theme.templates.find { |t| t.name['css'] && t.name['input'] } + target = local_theme.templates.find { |t| t.name['css'] && t.name['output'] } + + if source && target + notice "Tailwind config found! Firing the CLI in watch mode.." + run_tailwind_cli(source, target) # blocks + return + else + notice "Tailwind config found, but couldn't determine the source/input and target/output files..." + end + end + Kernel.sleep end