-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBuild.fsx
146 lines (111 loc) · 3.96 KB
/
Build.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#r "nuget: FAKE, 5.16.0"
#r "nuget: Fake.Core.Target"
#r "nuget: Fake.DotNet.Cli, 6.0.0"
#r "nuget: Suave, 2.6.2"
#r "nuget: Fake.BuildServer.GitHubActions, 6.0.0"
#r "nuget: Argu, 6.2.4"
#r "nuget: FsHttp, 14.5.1"
open Fake.Core
open Fake.IO
open Fake.DotNet
open Fake.Core.TargetOperators
open Suave
open Suave.Filters
open Suave.Operators
open System.IO
open Argu
open FsHttp
open System.IO
type Arguments =
| Action of action: string
| Post of post: string
interface IArgParserTemplate with
member s.Usage =
match s with
| Action _ -> "Run or Deploy."
| Post _ -> "file name of single post to render"
let parser = ArgumentParser.Create<Arguments>()
let args = parser.Parse (fsi.CommandLineArgs |> Array.skip 1)
let action =
match args.TryGetResult Action with
| Some a -> a
| None -> failwith "non action passed in. Please pass --action Run or --action Deploy"
let singlePostRender =
match args.TryGetResult Post with
| Some p -> p
| None -> ""
let runDir =
match action with
| "Deploy" -> "./docs"
| "Run" -> "./local"
| _ -> "./local"
let downloadFile url outputPath =
async {
let! response =
http {
GET url
}
|> Request.sendAsync
let content = response.content.ReadAsStringAsync().Result
File.WriteAllText(outputPath, content)
printfn "File downloaded and saved to %s" outputPath
}
System.Environment.GetCommandLineArgs()
|> Array.skip 2 // 3 if run in interactive window.
|> Array.toList
|> Context.FakeExecutionContext.Create false "build.fsx"
|> Context.RuntimeContext.Fake
|> Context.setExecutionContext
Target.create "Clean" (fun _ ->
Shell.cleanDir runDir |> ignore
)
Target.create "BuildModel" (fun _ ->
Shell.cd "Model" |> ignore
DotNet.exec id "build" "./Model.fsproj" |> ignore
Shell.cd ".."
)
Target.create "Render" (fun _ ->
Shell.copyDir runDir "Server/images" (fun _ -> true) |> ignore
Shell.copyFile runDir "Server/styles.css" |> ignore
let arguments = sprintf "--project ./Server/Server.fsproj %s %s" runDir singlePostRender
DotNet.exec id "run" arguments |> ignore
)
Target.create "CompileJS" (fun _ ->
let outDir = sprintf "--outDir .%s" runDir
Shell.cd "Client"
DotNet.exec id "fable" outDir |> ignore
let gitIgnore = sprintf ".%s/.gitignore" outDir
Shell.rm gitIgnore
Shell.cd ".."
)
Target.create "Run" (fun _ ->
let app =
choose [
GET >=> path "/" >=> Files.file "local/index.html"
GET >=> Files.browseHome
RequestErrors.NOT_FOUND "Page not found."
]
let config =
{defaultConfig with homeFolder = Some (Path.GetFullPath "local") }
startWebServer config app
)
Target.create "Commit" (fun _ ->
let filePath = "./docs/CNAME"
let content = "harrymccarney.com"
// Write the content to the file
File.writeString false filePath content
Shell.Exec("git", "add .") |> ignore
Shell.Exec("git", "commit -a -m \"deploying to github pages\"") |> ignore
)
Target.create "CreateRobots" (fun _ ->
// Usage
let url = "https://raw.githubusercontent.com/ai-robots-txt/ai.robots.txt/main/robots.txt"
let outputPath = "./docs/robots.txt"
downloadFile url outputPath |> Async.RunSynchronously
)
Target.create "Deploy" (fun _ ->
Shell.Exec("git", "push") |> ignore
)
"Clean" ==> "BuildModel" ==> "Render" ==> "CompileJS" ==> "Run"
"Clean" ==> "BuildModel" ==> "Render" ==> "CompileJS" ==> "CreateRobots" ==>"Commit" ==> "Deploy"
Target.runOrDefaultWithArguments action