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 # ---------------------------------------------------------------
17 # To run this script on Windows:
18 # 1. Install Strawberry Perl from https://strawberryperl.com/
19 # 2. Install Node from https://nodejs.org
20 # 3. Open a new cmd window
21 # 4. Clone the Evergreen git repository if you don't have it already. Instructions
22 # can be found at https://wiki.evergreen-ils.org/doku.php?id=newdevs:git:install
23 # 5. In your cmd window, `cd` into the Evergreen docs directory. For example, if
24 # your local copy of the Evergreen repo is at C:\Users\me\projects\Evergreen, type
25 # `cd \Users\me\projects\Evergreen\docs` (without the backticks) into the cmd window.
26 # 6. In your cmd window, type: perl generate_docs.pl --base-url http://example.com
27 # 7. In a browser, open the docs/output/index.html file. For examle, if your local
28 # copy of the Evergreen repo is at C:\Users\me\projects\Evergreen, type
29 # file:///C:/Users/me/projects/Evergreen/docs/output/index.html
30 # into your browser's URL bar.
31 # 8. If you click on the "Evergreen Documentation" phrase at the top, you will get an
32 # error because it will link you to "example.com". Don't click on that :)
41 my $tmp_space = './build';
42 my $html_output = './output';
43 my $antoraui_git = 'git://git.evergreen-ils.org/eg-antora.git';
44 my $antoraui_git_branch = 'main';
45 my $antora_version = '3.1.7';
51 "base-url=s" => \$base_url,
52 "tmp-space=s" => \$tmp_space,
53 "html-output=s" => \$html_output,
54 "antora-ui-repo=s" => \$antoraui_git,
55 "antora-ui-repo-branch=s" => \$antoraui_git_branch,
56 "antora-version=s" => \$antora_version,
64 --base-url http://example.com
66 --html-output /var/www/html
67 --antora-ui-repo git://git.evergreen-ils.org/eg-antora.git
68 --antora-version 3.1.7
71 --base-url [URL where html output is expected to be available eg: http//examplesite.org/docs]
72 --tmp-space [Writable path for staging the antora UI repo and build files, defaults to ./build]
73 --html-output [Path for the generated HTML files, defaults to ./output]
74 --antora-ui-repo [Antora-UI repository for the built UI, defaults to git://git.evergreen-ils.org/eg-antora.git]
75 --antora-ui-repo-branch [OPTIONAL: Antora-UI repository checkout branch, Defaults to "main"]
76 --antora-version [Target version of antora, defaults to 3.1.7]
82 # Make sure the user supplied ALL of the options
83 help() if(!$base_url || !$tmp_space || !$html_output || !$antoraui_git || !$antora_version);
85 # make sure the URL is "right"
86 $base_url = lc ($base_url);
87 $base_url =~ s/^[\s\t]*//g;
88 $base_url =~ s/[\s\t]*$//g;
89 if ( !($base_url =~ m/^https?:\/\/.+\..+$/))
91 print "Please specify a proper URL starting with http(s)\n";
96 # deal with destination folders
97 if (-d "$tmp_space/antora-ui") {
98 print "cleaning $tmp_space/antora-ui/\n";
99 rmtree("$tmp_space/antora-ui/");
102 if (-d "$html_output") {
103 print "cleaning $html_output/\n";
104 rmtree("$html_output/");
107 # make sure the temp folder is good
108 mkdir $tmp_space unless ( -d $tmp_space );
110 # make sure the output folder is good
111 mkdir $html_output unless ( -d $html_output );
113 die "Both " . $tmp_space . " and " . $html_output . " must be writable!" unless ( -w $tmp_space && -w $html_output );
116 exec_system_cmd("git clone $antoraui_git $tmp_space/antora-ui");
118 exec_system_cmd("cd $tmp_space/antora-ui && git checkout $antoraui_git_branch");
120 exec_system_cmd("cd $tmp_space/antora-ui && npm install gulp-cli");
122 exec_system_cmd("cd $tmp_space/antora-ui && npm install");
124 exec_system_cmd("cd $tmp_space/antora-ui && npx gulp build && npx gulp pack");
127 copy('site.yml', 'site-working.yml');
129 # Deal with root URL Antora configuration
130 rewrite_yml($base_url,"site/url","site-working.yml");
131 rewrite_yml("$html_output","output/dir","site-working.yml");
132 rewrite_yml("$tmp_space/antora-ui/build/ui-bundle.zip","ui/bundle/url","site-working.yml");
134 # clean up before installing Antora - it was observed during the
135 # upgrade from 2.3 to 3.1.7 that a package.json node_modules
136 # from 2.3 could cause the older version of the CLI to be
137 # used instead of the new one
138 if (-d 'node_modules') {
139 rmtree('node_modules');
141 unlink('package.json');
142 unlink('package-lock.json');
145 exec_system_cmd('npm install antora@' . $antora_version . ' @antora/lunr-extension@^1.0.0-alpha.8');
147 # Now, finally, let's build the site
148 local $ENV{NODE_PATH} = `npm root`;
149 exec_system_cmd('npx antora site-working.yml');
151 print "Success: your site files are available at " . $html_output . " and can be moved into place for access at " . $base_url . "\n";
155 my $replacement = shift;
156 my $yml_path = shift;
158 my $contents = replace_yml($replacement,$yml_path,$file);
159 $contents =~ s/[\n\t]*$//g;
160 write_file($file, $contents) if ($contents =~ m/$replacement/);
166 my $contents = shift;
169 open(OUTPUT, '> '.$file) or $ret=0;
170 binmode(OUTPUT, ":utf8");
171 print OUTPUT "$contents\n";
178 my $replacement = shift;
179 my $yml_path = shift;
181 my @path = split(/\//,$yml_path);
182 my @lines = @{read_file($file)};
187 my $line = shift @lines;
190 my $preceed_space = $depth * 2;
191 my $exp = '\s{'.$preceed_space.'}';
192 $exp = '[^\s#]' if $preceed_space == 0;
193 # print "testing $exp\n";
194 if($line =~ m/^$exp.*/)
196 if($line =~ m/^\s*@path[0].*/)
201 # print "replacing '$line'\n";
203 $line =~ s/^(.*?$t[^\s]*).*$/\1 $replacement/g;
204 # print "now: '$line'\n";
210 $line =~ s/[\n\t]*$//g;
220 print "executing $cmd\n";
222 or die "system @args failed: $?";
231 #print "Attempting open\n";
234 my $worked = open (inputfile, '< '. $file);
237 print "******************Failed to read file*************\n";
239 binmode(inputfile, ":utf8");
240 while (!(open (inputfile, '< '. $file)) && $trys<100)
242 print "Trying again attempt $trys\n";
248 #print "Finally worked... now reading\n";
249 @lines = <inputfile>;
254 print "Attempted $trys times. COULD NOT READ FILE: $file\n";
260 print "File does not exist: $file\n";