-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocs.pl
More file actions
executable file
·58 lines (54 loc) · 2.16 KB
/
docs.pl
File metadata and controls
executable file
·58 lines (54 loc) · 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/perl
use v5.12;
use strict;
use warnings;
use Cwd;
for (shift) {
if (!defined) {
print "No command given, use $0 help for help.\n";
} elsif ($_ eq "help") {
print "$0 help\n\n";
print "help Show this help\n";
print "build Publish the documentation.\n";
print "serve [wiki] Serve one of the wikis locally\n";
} elsif ($_ eq "build") {
system('git branch -D gh-pages');
opendir(my $DIR, 'wiki') || die "Failed to open wiki dir: $!";
while (my $wiki = readdir $DIR) {
next unless rindex $wiki, '.', 0;
print "Building wiki $wiki\n";
mkdocs($wiki, 'mike', 'deploy', '-u', '-b', 'gh-pages', '--ignore', '-m', "$wiki wiki", "$wiki");
}
closedir($DIR);
mkdocs('libx', 'mike', 'set-default', '-b', 'gh-pages', '--ignore', '-m', 'Default redirect', 'libx')
} elsif ($_ eq "serve") {
die 'serve requires an argument' unless $#ARGV + 1;
mkdocs(shift, 'mkdocs', 'serve');
} else {
die "Unknown command: $_\n";
}
}
sub mkdocs {
my $wiki = shift;
system('rm -rf build') && die "Failed to delete build directory: $!";
system('mkdir build') && die "Failed to create build directory: $!";
system('cp -ra theme build/') && die "Failed to copy theme: $!";
system("cp -ra wiki/$wiki/* build/") && die "Failed to copy wiki: $!";
open(my $FILEOUT, '>', 'build/mkdocs.yml') || die "Failed to open mkdocs.yml: $!";
open(my $FILEIN, '<', "wiki/$wiki/mkdocs.yml") || die "Failed to read wiki meta for $wiki: $!";
{ local $/; print $FILEOUT (<$FILEIN>); }
close($FILEIN);
print $FILEOUT "\n\nedit_uri: https://github.com/ModdingX/WikiX/edit/master/wiki/$wiki/docs\n\n";
open($FILEIN, '<', 'mkdocs.yml') || die "Failed to read main wiki meta: $!";
{ local $/; print $FILEOUT (<$FILEIN>); }
close($FILEIN);
close($FILEOUT);
my $cwd = cwd();
my $PATH = $ENV{PATH};
$ENV{PATH} = "$cwd/venv/bin:" . $ENV{PATH};
chdir('build');
my $code = system(@_);
$ENV{PATH} = $PATH;
chdir($cwd);
die "mkdocs failed with exit code $code" unless $code == 0;
}