tools: separate script to convert perl data to json
authorMischa POSLAWSKY <perl@shiar.org>
Sat, 14 May 2022 13:34:50 +0000 (15:34 +0200)
committerMischa POSLAWSKY <perl@shiar.org>
Sun, 25 Feb 2024 15:03:30 +0000 (16:03 +0100)
Replace inline code in make rules for consistency and maintainability.

Makefile
tools/mkjson [new file with mode: 0755]

index 942727c6199883a2e5b2c811fedf100891f23573..806e5be18c1cc0cfde73473b31ae3f23ebc923cd 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -86,9 +86,9 @@ data/wordlist.version.txt: force
 data/wordlist.%.inc.pl: tools/mkwordlist data/wordlist.version.txt
        $(call cmdsave,$< $*)
 data/word%.json: data/word%.inc.pl
-       $(call cmdsave,perl -MJSON=encode_json -E "print encode_json(do \$$ARGV[0])" ./$<)
+       $(call cmdsave,tools/mkjson $<)
 data/%.json: %.inc.pl
-       $(call cmdsave,perl -MJSON -E "print JSON->new->utf8->canonical->encode(do \$$ARGV[0])" ./$<)
+       $(call cmdsave,tools/mkjson $<)
 
 data/wordpairs.inc.pl: data/wordlist.version.txt
        tools/wordpairs >$@
diff --git a/tools/mkjson b/tools/mkjson
new file mode 100755 (executable)
index 0000000..6a7d948
--- /dev/null
@@ -0,0 +1,7 @@
+#!/usr/bin/env perl
+use 5.012;
+use warnings;
+use JSON;
+
+my $data = do "./$ARGV[0]" or die $@;
+print JSON->new->utf8->canonical->encode($data);