This repository has been archived by the owner on Apr 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.fsx
50 lines (41 loc) · 2.04 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
open System.IO
open System.Net.Http
open System.Net.Http.Json
open System.Text.Json
open System
let outputDirectory = "_site"
let indexHtml = "index.html"
let getLatestPackageVersion package =
async {
use httpClient = new HttpClient()
let! document = httpClient.GetFromJsonAsync<JsonDocument>($"https://api-v2v3search-0.nuget.org/query?q={package}&skip=0&take=1&prerelease=false&semVerLevel=2.0.0") |> Async.AwaitTask
return (document.RootElement.GetProperty("data")[0]).GetProperty("version").GetString()
}
let getLatestFunckyVersion() = getLatestPackageVersion "Funcky"
let renderIndexHtml (template: string, packageVersion, year) =
template
.Replace("{{PackageVersion}}", packageVersion)
.Replace("{{Year}}", year.ToString())
let writeIndexHtml() =
let version = getLatestFunckyVersion() |> Async.RunSynchronously
let indexHtmlContents = renderIndexHtml(File.ReadAllText(indexHtml), version, DateTime.Today.Year)
File.WriteAllText(Path.Combine(outputDirectory, indexHtml), contents = indexHtmlContents)
let copyFileToOutput source =
let relativePath = Path.GetRelativePath(relativeTo = Environment.CurrentDirectory, path = source)
let target = Path.Combine(outputDirectory, relativePath)
Directory.CreateDirectory(Path.GetDirectoryName(target)) |> ignore
File.Copy(source, target, overwrite = true)
let isFileInOutputDirectory path =
let absoluteTargetPath = Path.GetFullPath(outputDirectory) + Path.DirectorySeparatorChar.ToString()
let absolutePath = Path.GetFullPath(path)
absolutePath.StartsWith(absoluteTargetPath)
let copyToOutput (pattern) =
Directory.GetFiles(Environment.CurrentDirectory, searchPattern = pattern, searchOption = SearchOption.AllDirectories)
|> Seq.where (fun p -> not (isFileInOutputDirectory p))
|> Seq.iter copyFileToOutput
Directory.CreateDirectory(outputDirectory)
writeIndexHtml()
copyToOutput("fonts/*.woff2")
copyToOutput("icons/*.svg")
copyToOutput("*.css")
copyToOutput("*.js")