aboutsummaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authorMatthew Somerville <matthew@mysociety.org>2014-03-14 14:40:58 +0000
committerMatthew Somerville <matthew@mysociety.org>2014-03-14 14:40:58 +0000
commit73ae75d491058d6897dcc1e440f01d79adac88b9 (patch)
tree06d4a946c9c635ef6d7fd77dd68b7b3a565344fd /bin
parent9cc48219d3b55b5f658b17bbd4fd8223c8aa4861 (diff)
parentcb2580600bb39c546641d4bced4a988c0df89b2e (diff)
Merge branch 'css-watcher'
Diffstat (limited to 'bin')
-rwxr-xr-xbin/make_css_watch78
1 files changed, 78 insertions, 0 deletions
diff --git a/bin/make_css_watch b/bin/make_css_watch
new file mode 100755
index 000000000..d46ee8997
--- /dev/null
+++ b/bin/make_css_watch
@@ -0,0 +1,78 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use feature 'say';
+use File::ChangeNotify;
+use File::Find::Rule;
+use Path::Tiny;
+
+my @exts = qw/
+ scss
+/;
+
+my @dirs = qw/
+ web
+/;
+
+my $filter = do {
+ my $exts = join '|', @exts;
+ qr/\.(?:$exts)$/
+};
+
+my $watcher = File::ChangeNotify->instantiate_watcher(
+ directories => \@dirs,
+ filter => $filter,
+);
+
+sub title {
+ my $what = shift;
+ # TODO, check if xtitle is installed and if so, run following command:
+ # system 'xtitle', $what;
+}
+
+say sprintf "Watching [%s] for %s", (join ',' => @dirs), $filter;
+title 'watching';
+
+while ( my @events = $watcher->wait_for_events() ) {
+ my %seen;
+ my @update_dirs;
+ title 'updating';
+ for my $event (@events) {
+ my $file = path( $event->path );
+ say "$file was updated...";
+ my $dir = $file->dirname;
+ next if $seen{$dir}++;
+
+ if ($dir eq 'web/cobrands/sass/') {
+ # contains only partials, so we don't need to update
+ # this directory, but we *do* need to update everything else
+ push @update_dirs,
+ grep {
+ ! ($seen{$_}++)
+ }
+ map {
+ path($_)->dirname
+ }
+ File::Find::Rule->file->name($filter)->in( @dirs );
+ }
+ else {
+ push @update_dirs, $dir;
+ }
+ }
+ for my $dir (@update_dirs) {
+ if (-e "$dir/config.rb") {
+ system compass =>
+ 'compile',
+ '--output-style' => 'compressed',
+ $dir;
+ }
+ else {
+ system sass =>
+ '--scss',
+ '--update',
+ '--style' => 'compressed',
+ $dir;
+ }
+ }
+ title 'watching';
+}