-
Notifications
You must be signed in to change notification settings - Fork 1
/
amsite.fsx
113 lines (88 loc) · 3.23 KB
/
amsite.fsx
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
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
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"
dotnet ("." / generatorP / "AngouriMath" / "Sources" / "AngouriMath" / "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 https://github.com/WhiteBlackGoose/Yadg.NET Yadg.NET"
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")
let clean () =
dirDelete ("." / outputP)
match cliArgs with
| [ _; _; "init" ] -> init ()
| [ _; _; "uninit" ] -> uninit ()
| [ _; _; "build" ] -> build ()
| [ _; _; "run" ] ->
build ()
run ()
| [ _; _; "clean" ] -> clean ()
| _ ->
log $"Unrecognized arguments: {cliArgs}"