Repository navigation
Expand file tree
/
Copy pathamsite.fsx
More file actions
130 lines (105 loc) · 4.64 KB
/
Copy pathamsite.fsx
File metadata and controls
130 lines (105 loc) · 4.64 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
open System.Diagnostics
open System
open System.IO
open System.Runtime.InteropServices
let (/) a b = Path.Combine(a, b)
let log msg =
printfn $"Log: {msg}"
let generatorP = "src"
let outputP = ".output" / "final"
let contentP = "content"
let dirExists path =
try
Directory.Exists(path)
with
| :? Exception as e ->
log $"Issue accessing {path}"
raise e
let dirDelete path =
try
// What `uninit` deletes are git clones, and git marks the files under
// .git/objects/pack read-only. Directory.Delete refuses a read-only file on
// Windows, so the attribute has to come off first -- otherwise uninit fails with
// UnauthorizedAccessException on a pack .idx, which is what it did.
for file in Directory.EnumerateFiles(path, "*", SearchOption.AllDirectories) do
File.SetAttributes(file, FileAttributes.Normal)
Directory.Delete(path, true)
with
| :? Exception as e ->
log $"Issue deleting {path}"
raise e
let runProgram name activeDir args =
let startInfo = ProcessStartInfo()
startInfo.FileName <- name
startInfo.Arguments <- args
startInfo.WorkingDirectory <- activeDir
startInfo.UseShellExecute <- false
use proc = new Process()
proc.StartInfo <- startInfo
if proc.Start() |> not then
raise (Exception $"Failure to start process {name}. Report this bug, please.")
proc.WaitForExit()
if proc.ExitCode <> 0 then
raise (Exception $"Error of command {name}. Exit code: {proc.ExitCode}.")
let git = runProgram "git"
let dotnet = runProgram "dotnet"
let cliArgs = Environment.GetCommandLineArgs() |> List.ofArray
let init () =
if dirExists("." / generatorP / "AngouriMath") then
log "Skipping AngouriMath cloning..."
else
git ("." / generatorP) "clone https://github.com/asc-community/AngouriMath AngouriMath"
// The library moved up a folder in asc-community/AngouriMath@f0db3eef (2026-01-03), so
// this was `Sources/AngouriMath/AngouriMath` and had stopped existing. Keep it in step
// with the path NaiveStaticGenerator reads AngouriMath.xml from.
dotnet ("." / generatorP / "AngouriMath" / "Sources" / "AngouriMath") "publish -c release -o publish-output --framework netstandard2.0"
if dirExists("." / generatorP / "Yadg.NET") then
log "Skipping Yadg.NET cloning..."
else
git ("." / generatorP) "clone -c core.autocrlf=false https://github.com/WhiteBlackGoose/Yadg.NET Yadg.NET"
// Yadg.NET has not changed since 2022 and this repository cannot push to it, so the
// site carries its fixes in Yadg.NET.patch, at the commit the patch was written against.
// The clone keeps LF line endings on Windows too, as the patch has them.
git ("." / generatorP / "Yadg.NET") "checkout --quiet a79a053df06a2a87d4fc6fac84dd5e81cecc11f6"
git ("." / generatorP / "Yadg.NET") "apply ../Yadg.NET.patch"
if dirExists("." / generatorP / contentP / "_wiki") then
log "Skipping wiki cloning..."
else
git ("." / generatorP / contentP) "clone https://github.com/asc-community/AngouriMath.wiki.git _wiki"
let uninit () =
if dirExists("." / generatorP / "AngouriMath") |> not then
log "Skipping deleting AngouriMath..."
else
dirDelete("." / generatorP / "AngouriMath")
if dirExists("." / generatorP / "Yadg.NET") |> not then
log "Skipping deleting Yadg.NET..."
else
dirDelete("." / generatorP / "Yadg.NET")
if dirExists("." / generatorP / contentP / "_wiki") |> not then
log "Skipping deleting wiki..."
else
dirDelete("." / generatorP / contentP / "_wiki")
let build () =
dotnet (generatorP / "NaiveStaticGenerator") "run"
let run () =
if RuntimeInformation.IsOSPlatform(OSPlatform.Windows) then
runProgram "start" "." ("." / outputP / "index.html")
else if RuntimeInformation.IsOSPlatform(OSPlatform.OSX) then
runProgram "open" "." ("." / outputP / "index.html")
else if RuntimeInformation.IsOSPlatform(OSPlatform.Linux) then
runProgram "xdg-open" "." ("." / outputP / "index.html")
// All of .output, not only final: the generator copies every page in .output/pre into final,
// so a page an older build wrote to pre -- one for a member the library has since removed --
// came back after a clean, with whatever broken links it had.
let clean () =
dirDelete ("." / ".output")
match cliArgs with
| [ _; _; "init" ] -> init ()
| [ _; _; "uninit" ] -> uninit ()
| [ _; _; "build" ] -> build ()
| [ _; _; "run" ] ->
build ()
run ()
| [ _; _; "clean" ] -> clean ()
| _ ->
log $"Unrecognized arguments: {cliArgs}"