Debian Codegraph @

debian/combiner/combineMJlist-unpacked

raw
1 #! /usr/bin/perl
2
3 #
4 # Combine scripts in the MathJax project into single-file-load
5 # configuration files.
6 #
7 # Usage: ./combineMJlist-unpacked proj-dir [files.lis]
8 #
9
10 use Cwd;
11 use FindBin;
12
13 $DIR = $FindBin::Bin;
14 $MJX = shift || getcwd;
15
16 $name = $ARGV[0]; $name =~ s!.*/!!;
17 die "Usage: ./combineMJlist srcdir files.lis\n" unless $name =~ m/\S/;
18 die "Project directory must contain an unpacked/config directory\n" unless -d "$MJX/unpacked/config";
19
20 $outfile = "config/$name"; $outfile =~ s/\.[^.]*/.js/;
21
22 @files = ();
23 while ($file = <>) {
24 chomp($file);
25 if ($file =~ m/\S/) {
26 push (@files,$file);
27 } else {
28 @config = <>;
29 chomp(@config);
30 @config = grep {!/^extensions:/} @config;
31 while (scalar(@config) && $config[-1] !~ m/\S/) {pop(@config)}
32 $config[-1] =~ s/,$// if scalar(@config);
33 last;
34 }
35 }
36
37 @CONFIG = ();
38 @JAX = ();
39 @EXTENSIONS = ();
40
41 foreach $file (@files) {
42 if ($file =~ m!^jax/(.*)/config.js!) {push(@JAX,"\"$1\"")}
43 if ($file =~ m!^extensions/a11y/(.*)!) {push(@EXTENSIONS,"\"[a11y]/$1\"")}
44 elsif ($file =~ m!^extensions/(.*)!) {push(@EXTENSIONS,"\"$1\"")}
45 if ($file =~ m!^config/(.*)!) {push(@CONFIG,"\"$1\"")}
46 }
47
48 @HUB = ();
49 push(@HUB,"config: [".join(",",@CONFIG)."]") if scalar(@CONFIG);
50 push(@HUB,"extensions: [".join(",",@EXTENSIONS)."]") if scalar(@EXTENSIONS);
51 push(@HUB,"jax: [".join(",",@JAX)."]") if scalar(@JAX);
52 push(@HUB,join("\n ",@config)) if scalar(@config);
53
54 open(CONFIG,"<","$DIR/template-unpacked.js") || die "Can't open $DIR/template-unpacked.js: $!\n";
55 @lines = <CONFIG>;
56 close(CONFIG);
57 $config = join("",@lines);
58
59 $config =~ s!%%% NAME %%%!/MathJax/unpacked/$outfile!;
60
61 print "Creating $outfile\n";
62 open(CONFIG,">","$MJX/unpacked/$outfile") || die "Can't write $MJX/$outfile: $!\n";
63 print CONFIG $config;
64
65 print CONFIG "MathJax.Hub.Config({\n";
66 print CONFIG " ",join(",\n ",@HUB);
67 print CONFIG "\n});\n\n";
68
69 print CONFIG "MathJax.Ajax.loadComplete(\"[MathJax]/$outfile\");\n";
70
71 close(CONFIG);
72
73 1;