| 1 | #! /usr/bin/perl |
| 2 | |
| 3 | use autodie; |
| 4 | use JSON; |
| 5 | |
| 6 | use Data::Dumper; |
| 7 | |
| 8 | my $NOW = time; |
| 9 | |
| 10 | my ($dir) = @ARGV; |
| 11 | my $j = []; |
| 12 | my $seq = 0; |
| 13 | opendir my $dh, $dir; |
| 14 | FILE: while (my $f = readdir $dh) { |
| 15 | next if $f eq "." || $f eq ".."; |
| 16 | next unless $f =~ /\.css$/; |
| 17 | (my $name = $f) =~ s/\.css$//; |
| 18 | my @s = (); |
| 19 | my $s = {}; |
| 20 | my $c = ""; |
| 21 | open my $fh, "<", "$dir/$f"; |
| 22 | while (<$fh>) { |
| 23 | if (m{/\* -\*-css-\*- \*/}) { |
| 24 | next; |
| 25 | } elsif (m{/\*\@END\*/}) { |
| 26 | $s->{code} = $c; |
| 27 | push @s, $s; |
| 28 | $s = {}; $c = ""; |
| 29 | } elsif (m{/\*\@ \s* ([^:]+) \s* : \s* ( | \S | \S .* \S) \s* \*/}x) { |
| 30 | $s->{$1} = [split /\s*,\s*/, $2]; |
| 31 | } else { |
| 32 | $c .= $_; |
| 33 | } |
| 34 | } |
| 35 | push @$j, { enabled => JSON::true, |
| 36 | updateUrl => undef, |
| 37 | md5Url => undef, |
| 38 | url => undef, |
| 39 | originalMd5 => undef, |
| 40 | installDate => $NOW, |
| 41 | name => $name, |
| 42 | id => ++$seq, |
| 43 | sections => \@s }; |
| 44 | } |
| 45 | print encode_json($j), "\n"; |