Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace FAKE with Fun.Build. #576

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
"commands": [
"paket"
]
},
"fantomas": {
"version": "6.2.3",
"commands": [
"fantomas"
]
}
}
}
}
149 changes: 88 additions & 61 deletions Content/default/Build.fs
Original file line number Diff line number Diff line change
@@ -1,78 +1,105 @@
open Fake.Core
open Fake.IO
open Farmer
open Farmer.Builders
open Fun.Build
open Fun.Result
open System.IO
open type System.IO.Path

open Helpers

initializeContext ()

let sharedPath = Path.getFullName "src/Shared"
let serverPath = Path.getFullName "src/Server"
let clientPath = Path.getFullName "src/Client"
let deployPath = Path.getFullName "deploy"
let sharedTestsPath = Path.getFullName "tests/Shared"
let serverTestsPath = Path.getFullName "tests/Server"
let clientTestsPath = Path.getFullName "tests/Client"

Target.create "Clean" (fun _ ->
Shell.cleanDir deployPath
run dotnet [ "fable"; "clean"; "--yes" ] clientPath // Delete *.fs.js files created by Fable
)

Target.create "InstallClient" (fun _ -> run npm [ "install" ] ".")

Target.create "Bundle" (fun _ ->
[
"server", dotnet [ "publish"; "-c"; "Release"; "-o"; deployPath ] serverPath
"client", dotnet [ "fable"; "-o"; "output"; "-s"; "--run"; "npx"; "vite"; "build" ] clientPath
]
|> runParallel)

Target.create "Azure" (fun _ ->
let web = webApp {
name "SAFE-App"
operating_system OS.Linux
runtime_stack (DotNet "8.0")
zip_deploy "deploy"
[<EntryPoint>]
let main _ =
let serverPath = GetFullPath "src/Server"
let clientPath = GetFullPath "src/Client"

pipeline "Test" {
description "Runs all tests"

stage "Build Shared Tests Component" { run $"""dotnet build {GetFullPath "tests/Shared"}""" }

stage "Run Tests" {
paralle

stage "Server Tests" { run $"""dotnet watch run --project {GetFullPath "tests/Server"}""" }

stage "Client Tests" {
run $"""dotnet fable watch -o output -s --cwd {GetFullPath "tests/Client"} --run npx vite"""
}
}

runIfOnlySpecified // custom pipeline - dotnet run -- -p Test
}

let deployment = arm {
location Location.WestEurope
add_resource web
pipeline "Format" {
description "Formats all code using Fantomas"
stage "format" { run "dotnet fantomas ." }
runIfOnlySpecified // custom pipeline - dotnet run -- -p Format
}

deployment |> Deploy.execute "SAFE-App" Deploy.NoParameters |> ignore)
pipeline "Bundle" {
description "Builds and packages the app for production"

Target.create "Run" (fun _ ->
run dotnet [ "build" ] sharedPath
stage "Build" {
paralle

[
"server", dotnet [ "watch"; "run" ] serverPath
"client", dotnet [ "fable"; "watch"; "-o"; "output"; "-s"; "--run"; "npx"; "vite" ] clientPath
]
|> runParallel)
stage "Server" {
run (fun ctx -> asyncResult {
let deployPath = GetFullPath "deploy"

Target.create "RunTests" (fun _ ->
run dotnet [ "build" ] sharedTestsPath
if Directory.Exists deployPath then
Directory.Delete(deployPath, true)

[
"server", dotnet [ "watch"; "run" ] serverTestsPath
"client", dotnet [ "fable"; "watch"; "-o"; "output"; "-s"; "--run"; "npx"; "vite" ] clientTestsPath
]
|> runParallel)
do! ctx.RunCommand $"dotnet publish -c Release {serverPath} -o {deployPath}"
})
}

Target.create "Format" (fun _ -> run dotnet [ "fantomas"; "." ] ".")
stage "Client" {
run "npm install"
run $"dotnet fable clean --cwd {clientPath} --yes"
run $"dotnet fable -o output -s --cwd {clientPath} --run npx vite build"
}
}

open Fake.Core.TargetOperators
runIfOnlySpecified // custom pipeline - dotnet run -- -p Bundle
}

let dependencies = [
"Clean" ==> "InstallClient" ==> "Bundle" ==> "Azure"
pipeline "Azure" {
description "Deploy to Azure"

"Clean" ==> "InstallClient" ==> "Run"
stage "Farmer deploy" {
run (fun _ ->
let web = webApp {
name "SAFE-App"
operating_system Linux
runtime_stack (DotNet "8.0")
zip_deploy "deploy"
}

"InstallClient" ==> "RunTests"
]
let deployment = arm {
location Location.WestEurope
add_resource web
}

[<EntryPoint>]
let main args = runOrDefault args
deployment |> Deploy.execute "SAFE-App" Deploy.NoParameters |> ignore)
}

runIfOnlySpecified // custom pipeline - dotnet run -- -p Azure
}

pipeline "Run" {
description "Runs the SAFE Stack application in watch mode"

stage "Run" {
paralle

stage "Server" { run $"dotnet watch run --project {serverPath}" }

stage "Client" {
run "npm install"
run $"dotnet fable watch -o output -s --cwd {clientPath} --run npx vite"
}
}

runIfOnlySpecified false // default pipeline - dotnet run
}

tryPrintPipelineCommandHelp ()
0
19 changes: 9 additions & 10 deletions Content/default/Build.fsproj
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>
<ItemGroup>
<Compile Include="Helpers.fs" />
<Compile Include="Build.fs" />
</ItemGroup>
<Import Project=".paket\Paket.Restore.targets" />
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>
<ItemGroup>
<Compile Include="Build.fs" />
</ItemGroup>
<Import Project=".paket\Paket.Restore.targets" />
</Project>
105 changes: 0 additions & 105 deletions Content/default/Helpers.fs

This file was deleted.

3 changes: 1 addition & 2 deletions Content/default/paket.dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,5 @@ nuget Fable.Mocha ~> 2
nuget Fable.Remoting.Client ~> 7
nuget Feliz ~> 2

nuget Fake.Core.Target ~> 5
nuget Fake.IO.FileSystem ~> 5
nuget Fun.Build ~> 1
nuget Farmer ~> 1
Loading