-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathbuild.fsx
110 lines (89 loc) · 3.58 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
#r "paket: groupref build //"
#load "./.fake/build.fsx/intellisense.fsx"
#if !NETCOREAPP
#r "System.IO.Compression.FileSystem.dll"
#endif
open Fake.Core
open Fake.Core.TargetOperators
open Fake.IO
open Fake.IO.FileSystemOperators
open Fake.DotNet
open Fake.JavaScript
open System
open System.IO
let project = "src/FsSnip.Website"
let publishDirectory = "artifacts"
// FAKE 5 does not apply cli args to environment before module initialization, delay
// override syntax: dotnet fake run build.fsx -e foo=bar -e foo=bar -t target
let config () = DotNet.BuildConfiguration.fromEnvironVarOrDefault "configuration" DotNet.BuildConfiguration.Release
let runtime () = Environment.environVarOrNone "runtime"
System.Environment.CurrentDirectory <- __SOURCE_DIRECTORY__
//// -------------------------------------------------------------------------------------
//// Minifying JS for better performance
//// This is using built in NPMHelper and other things are getting done by node js
//// -------------------------------------------------------------------------------------
Target.create "minify" (fun _ ->
Trace.trace "Node js web compilation thing"
// Use nuget tools if windows, require already installed otherwise
//let npmPath = Path.GetFullPath "packages/jstools/Npm.js/tools"
//let nodePath = Path.GetFullPath "packages/jstools/Node.js"
//if Environment.isWindows then
// [ npmPath ; nodePath ; Environment.environVar "PATH" ]
// |> String.concat ";"
// |> Environment.setEnvironVar "PATH"
//let getNpmFilePath (p : Npm.NpmParams) =
// if Environment.isWindows then Path.Combine(npmPath, "npm.cmd") else p.NpmFilePath
Npm.install (fun p -> p) //{ p with NpmFilePath = getNpmFilePath p })
Npm.exec "run-script build" (fun p -> p) //{ p with NpmFilePath = getNpmFilePath p })
)
Target.create "clean" (fun _ ->
Shell.cleanDirs [publishDirectory]
)
let dataDumpLocation = System.Uri "https://github.com/fssnippets/fssnip-data/archive/master.zip"
Target.create "download-data-dump" (fun _ ->
Directory.delete "data"
let tmpfile = Path.ChangeExtension(Path.GetTempFileName(), ".zip")
use client = new System.Net.WebClient()
client.DownloadFile(dataDumpLocation, tmpfile)
System.IO.Compression.ZipFile.ExtractToDirectory(tmpfile, ".")
Directory.Move("fssnip-data-master", "data")
)
Target.create "run" (fun _ ->
let environment = Map.ofList [("LOG_LEVEL", "Info"); ("DISABLE_RECAPTCHA", "true")]
DotNet.exec (fun p ->
{ p with WorkingDirectory = project ; Environment = environment }) "run" (sprintf "-c %O" (config()))
|> ignore
)
Target.create "publish" (fun _ ->
DotNet.publish (fun p ->
{ p with
Configuration = config ()
Runtime = runtime ()
OutputPath = Some publishDirectory
}) project
)
let newName prefix f =
Seq.initInfinite (sprintf "%s_%d" prefix) |> Seq.skipWhile (f >> not) |> Seq.head
Target.create "deploy" (fun _ ->
let wwwroot = "wwwroot"
Shell.mkdir wwwroot
Shell.cleanDir wwwroot
Shell.mkdir (wwwroot </> "templates")
Shell.mkdir (wwwroot </> "web")
printfn "copying binaries into wwwroot"
Shell.copyRecursive publishDirectory wwwroot false |> ignore
printfn "copying templates into wwwroot/templates"
Shell.copyRecursive "templates" (wwwroot </> "templates") false |> ignore
printfn "copying web into wwwroot/web"
Shell.copyRecursive "web" (wwwroot </> "web") false |> ignore
)
Target.create "root" ignore
"root"
==> "minify"
=?> ("download-data-dump", not (File.Exists "data/index.json"))
==> "run"
"clean"
==> "minify"
==> "publish"
==> "deploy"
Target.runOrDefaultWithArguments "deploy"