style: nested scss selectors
[sheet.git] / tools / mkjson
1 #!/usr/bin/env perl
2 use 5.012;
3 use warnings;
4 use re '/msx';
5 use JSON;
6
7 our $VERSION = '1.00';
8
9 our %get;
10 while (@ARGV) {
11         $ARGV[0] =~ s/^--// or last;  # --flag
12         my ($name, $val) = split /=/, shift, 2 or last;  # set until empty
13         $get{$name} = $val // 1;
14 }
15 my $file = shift or die "Usage: $0 [--options] <input>\n";
16
17 my $jsonify = JSON->new->utf8->canonical;
18 $jsonify->pretty if $get{pretty};
19
20 my $data = do "./$file" or die $@;
21 print $jsonify->encode($data)
22         =~ s{\[ \K\n ([^][]+) (?=\])}{$1 =~ s/(?:\A|\n) \s*//gr}reg;