+sub gen_package_manifest_json() {
+ my $json;
+ parse_package_metadata($ARGV[0]) or exit 1;
+ foreach my $name (sort {uc($a) cmp uc($b)} keys %package) {
+ my %depends;
+ my $pkg = $package{$name};
+ foreach my $dep (@{$pkg->{depends} || []}) {
+ if ($dep =~ m!^\+?(?:[^:]+:)?([^@]+)$!) {
+ $depends{$1}++;
+ }
+ }
+ my @depends = sort keys %depends;
+ my $pkg_deps = join ' ', map { qq/"$_",/ } @depends;
+ $pkg_deps =~ s/\,$//;
+
+ my $pkg_maintainer = join ' ', map { qq/"$_",/ } @{$pkg->{maintainer} || []};
+ $pkg_maintainer =~ s/\,$//;
+
+ $json = <<"END_JSON";
+${json}{
+"name":"$name",
+"version":"$pkg->{version}",
+"category":"$pkg->{category}",
+"license":"$pkg->{license}",
+"maintainer": [$pkg_maintainer],
+"depends":[$pkg_deps]},
+END_JSON
+ }
+
+ $json =~ s/[\n\r]//g;
+ $json =~ s/\,$//;
+ print "[$json]";
+}
+