2 # ---------------------------------------------------------------
3 # Copyright © 2020 MOBIUS
4 # Blake Graham-Henderson <blake@mobiusconsortium.org>
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 # ---------------------------------------------------------------
24 my $tmp_space = './build';
25 my $html_output = './output';
26 my $antoraui_git = 'git://git.evergreen-ils.org/eg-antora.git';
27 my $antoraui_git_branch = 'master';
28 my $antora_version = '2.3';
34 "base-url=s" => \$base_url,
35 "tmp-space=s" => \$tmp_space,
36 "html-output=s" => \$html_output,
37 "antora-ui-repo=s" => \$antoraui_git,
38 "antora-ui-repo-branch=s" => \$antoraui_git_branch,
39 "antora-version=s" => \$antora_version,
47 --base-url http://example.com
49 --html-output /var/www/html
50 --antora-ui-repo git://git.evergreen-ils.org/eg-antora.git
54 --base-url [URL where html output is expected to be available eg: http//examplesite.org/docs]
55 --tmp-space [Writable path for staging the antora UI repo and build files, defaults to ./build]
56 --html-output [Path for the generated HTML files, defaults to ./output]
57 --antora-ui-repo [Antora-UI repository for the built UI, defaults to git://git.evergreen-ils.org/eg-antora.git]
58 --antora-ui-repo-branch [OPTIONAL: Antora-UI repository checkout branch, Defaults to "master"]
59 --antora-version [Target version of antora, defaults to 2.3]
65 # Make sure the user supplied ALL of the options
66 help() if(!$base_url || !$tmp_space || !$html_output || !$antoraui_git || !$antora_version);
68 # make sure the URL is "right"
69 $base_url = lc ($base_url);
70 $base_url =~ s/^[\s\t]*//g;
71 $base_url =~ s/[\s\t]*$//g;
72 if ( !($base_url =~ m/^https?:\/\/.+\..+$/))
74 print "Please specify a proper URL starting with http(s)\n";
79 # deal with destination folders
80 if (-d "$tmp_space/antora-ui") {
81 print "cleaning $tmp_space/antora-ui/\n";
82 rmtree("$tmp_space/antora-ui/");
85 if (-d "$html_output") {
86 print "cleaning $html_output/\n";
87 rmtree("$html_output/");
90 # make sure the temp folder is good
91 mkdir $tmp_space unless ( -d $tmp_space );
93 # make sure the output folder is good
94 mkdir $html_output unless ( -d $html_output );
96 die "Both " . $tmp_space . " and " . $html_output . " must be writable!" unless ( -w $tmp_space && -w $html_output );
99 exec_system_cmd("git clone $antoraui_git $tmp_space/antora-ui");
101 exec_system_cmd("cd $tmp_space/antora-ui && git checkout $antoraui_git_branch");
103 exec_system_cmd("cd $tmp_space/antora-ui && npm install gulp-cli");
105 exec_system_cmd("cd $tmp_space/antora-ui && npm install");
107 exec_system_cmd("cd $tmp_space/antora-ui && ./node_modules/.bin/gulp build && ./node_modules/.bin/gulp pack");
110 exec_system_cmd("cp site.yml site-working.yml");
112 # Deal with root URL Antora configuration
113 rewrite_yml($base_url,"site/url","site-working.yml");
114 rewrite_yml("$html_output","output/dir","site-working.yml");
115 rewrite_yml("$tmp_space/antora-ui/build/ui-bundle.zip","ui/bundle/url","site-working.yml");
118 exec_system_cmd('npm install @antora/cli@' . $antora_version . ' @antora/site-generator-default@' . $antora_version . ' antora-lunr antora-site-generator-lunr');
120 # Now, finally, let's build the site
121 exec_system_cmd('DOCSEARCH_INDEX_VERSION=latest DOCSEARCH_ENABLED=true DOCSEARCH_ENGINE=lunr NODE_PATH="$(npm root)" ./node_modules/@antora/cli/bin/antora --generator antora-site-generator-lunr site-working.yml');
123 print "Success: your site files are available at " . $html_output . " and can be moved into place for access at " . $base_url . "\n";
127 my $replacement = shift;
128 my $yml_path = shift;
130 my $contents = replace_yml($replacement,$yml_path,$file);
131 $contents =~ s/[\n\t]*$//g;
132 write_file($file, $contents) if ($contents =~ m/$replacement/);
138 my $contents = shift;
141 open(OUTPUT, '> '.$file) or $ret=0;
142 binmode(OUTPUT, ":utf8");
143 print OUTPUT "$contents\n";
150 my $replacement = shift;
151 my $yml_path = shift;
153 my @path = split(/\//,$yml_path);
154 my @lines = @{read_file($file)};
159 my $line = shift @lines;
162 my $preceed_space = $depth * 2;
163 my $exp = '\s{'.$preceed_space.'}';
164 $exp = '[^\s#]' if $preceed_space == 0;
165 # print "testing $exp\n";
166 if($line =~ m/^$exp.*/)
168 if($line =~ m/^\s*@path[0].*/)
173 # print "replacing '$line'\n";
175 $line =~ s/^(.*?$t[^\s]*).*$/\1 $replacement/g;
176 # print "now: '$line'\n";
182 $line =~ s/[\n\t]*$//g;
192 print "executing $cmd\n";
194 or die "system @args failed: $?";
203 #print "Attempting open\n";
206 my $worked = open (inputfile, '< '. $file);
209 print "******************Failed to read file*************\n";
211 binmode(inputfile, ":utf8");
212 while (!(open (inputfile, '< '. $file)) && $trys<100)
214 print "Trying again attempt $trys\n";
220 #print "Finally worked... now reading\n";
221 @lines = <inputfile>;
226 print "Attempted $trys times. COULD NOT READ FILE: $file\n";
232 print "File does not exist: $file\n";