-
Notifications
You must be signed in to change notification settings - Fork 3
/
build.fsx
147 lines (119 loc) · 4.23 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
147
//
// FAKE script adapter for FSI
//
// Adapter details from here:
// https://github.com/fsharp/FAKE/issues/2517
//
// Use this adapter template if you're suffering from this:
// Error: Package manager key 'paket' was not registered
// Explanation here:
// https://stackoverflow.com/questions/66665009/fix-for-package-manager-key-paket-was-not-registered-in-build-fsx
//
// Usage:
// % dotnet fsi build.fsx
// % dotnet fsi build.fsx --target <target>
#r "nuget: System.Reactive" // Prevent "Could not load file or assembly ..." error when using adapter
#r "nuget: Fake.Core"
#r "nuget: Fake.Core.Target"
#load "node_modules/fable-publish-utils/PublishUtils.fs"
//open PublishUtils
open System
open System.IO
open Fake.Core
open PublishUtils
open Fake.Core.TargetOperators
// Boilerplate for adapter
System.Environment.GetCommandLineArgs()
|> Array.skip 2 // skip fsi.exe; build.fsx
|> Array.toList
|> Fake.Core.Context.FakeExecutionContext.Create false __SOURCE_FILE__
|> Fake.Core.Context.RuntimeContext.Fake
|> Fake.Core.Context.setExecutionContext
// ---------------------------------------------------
// -- Your targets and regular FAKE code goes below --
//open Fake.IO.Shell
open Fake.Core
//open Fake.DotNet
open Fake.IO
Target.initEnvironment ()
let sharedPath = Path.getFullName "./src/Shared"
let serverPath = Path.getFullName "./src/Server"
let deployDir = Path.getFullName "./deploy"
let sharedTestsPath = Path.getFullName "./tests/Shared"
let serverTestsPath = Path.getFullName "./tests/Server"
let npm args workingDir =
let npmPath =
match ProcessUtils.tryFindFileOnPath "npm" with
| Some path -> path
| None ->
"npm was not found in path. Please install it and make sure it's available from your path. " +
"See https://safe-stack.github.io/docs/quickstart/#install-pre-requisites for more info"
|> failwith
let arguments = args |> String.split ' ' |> Arguments.OfArgs
Command.RawCommand (npmPath, arguments)
|> CreateProcess.fromCommand
|> CreateProcess.withWorkingDirectory workingDir
|> CreateProcess.ensureExitCode
|> Proc.run
|> ignore
let dotnet cmd workingDir =
run ("dotnet " + cmd)
// let result = DotNet.exec (DotNet.Options.withWorkingDirectory workingDir) cmd ""
// if result.ExitCode <> 0 then failwithf "'dotnet %s' failed in %s" cmd workingDir
Target.create "Clean" (fun _ -> Shell.cleanDir deployDir)
Target.create "InstallClient" (fun _ -> npm "install" ".")
Target.create "Bundle" (fun _ ->
dotnet (sprintf "publish -c Release -o \"%s\"" deployDir) serverPath
npm "run build" "."
)
Target.create "BundleForGHPages" (fun _ ->
npm "run build-gh-pages" "."
)
Target.create "Run" (fun _ ->
dotnet "build" sharedPath
[ async { dotnet "watch run" serverPath }
async { npm "run start" "." } ]
|> Async.Parallel
|> Async.RunSynchronously
|> ignore
)
Target.create "RunTests" (fun _ ->
dotnet "build" sharedTestsPath
[ async { dotnet "watch run" serverTestsPath }
async { npm "run test:live" "." } ]
|> Async.Parallel
|> Async.RunSynchronously
|> ignore
)
Target.create "PublishApp" <| fun _ ->
npm "run publish" "."
let (</>) a b = Path.combine a b
let publish (projectPath : string) = fun _ ->
[ projectPath </> "bin"
projectPath </> "obj" ] |> Shell.cleanDirs
dotnet "restore --no-cache" projectPath
dotnet "pack -c Release" projectPath
let nugetKey =
match Environment.environVarOrNone "NUGET_KEY" with
| Some nugetKey -> nugetKey
| None -> failwith "The Nuget API key must be set in a NUGET_KEY environmental variable"
let nupkg =
System.IO.Directory.GetFiles(projectPath </> "bin" </> "Release")
|> Seq.head
|> System.IO.Path.GetFullPath
let pushCmd = sprintf "nuget push %s -s nuget.org -k %s" nupkg nugetKey
System.Console.WriteLine(pushCmd)
dotnet pushCmd projectPath
Target.create "PublishPkg" (publish ("src" </> "Fable.React.DrawingCanvas"))
open Fake.Core.TargetOperators
"Clean"
==> "InstallClient"
==> "Run"
"Clean"
==> "InstallClient"
==> "RunTests"
"Clean"
==> "InstallClient"
==> "BundleForGHPages"
==> "PublishApp"
Target.runOrDefaultWithArguments "Bundle"