Skip to content

Commit

Permalink
Updated to latest version of SAFE template
Browse files Browse the repository at this point in the history
  • Loading branch information
bruinbrown committed Jan 14, 2019
1 parent 7a1b63c commit e2fa501
Show file tree
Hide file tree
Showing 19 changed files with 4,194 additions and 3,363 deletions.
8 changes: 8 additions & 0 deletions .editorconfig
@@ -0,0 +1,8 @@
root = true

[*]
indent_style = space
indent_size = 4
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = false
40 changes: 0 additions & 40 deletions SAFE-Dojo.sln

This file was deleted.

184 changes: 109 additions & 75 deletions build.fsx
@@ -1,75 +1,109 @@
#r @"packages/build/FAKE/tools/FakeLib.dll"

open System

open Fake

let serverPath = "./src/Server" |> FullName
let clientPath = "./src/Client" |> FullName
let deployDir = "./deploy" |> FullName

let platformTool tool winTool =
let tool = if isUnix then tool else winTool
tool
|> ProcessHelper.tryFindFileOnPath
|> function Some t -> t | _ -> failwithf "%s not found" tool

let nodeTool = platformTool "node" "node.exe"

type JsPackageManager =
| NPM
| YARN
member this.Tool =
match this with
| NPM -> platformTool "npm" "npm.cmd"
| YARN -> platformTool "yarn" "yarn.cmd"
member this.ArgsInstall =
match this with
| NPM -> "install"
| YARN -> "install --frozen-lockfile"

let jsPackageManager =
match getBuildParam "jsPackageManager" with
| "npm" -> NPM
| "yarn" | _ -> YARN

let mutable dotnetCli = "dotnet"

let run cmd args workingDir =
let result =
ExecProcess (fun info ->
info.FileName <- cmd
info.WorkingDirectory <- workingDir
info.Arguments <- args) TimeSpan.MaxValue
if result <> 0 then failwithf "'%s %s' failed" cmd args

Target "Clean" (fun _ ->
CleanDirs [deployDir]
)

Target "InstallClient" (fun _ ->
printfn "Node version:"
run nodeTool "--version" __SOURCE_DIRECTORY__
run jsPackageManager.Tool jsPackageManager.ArgsInstall __SOURCE_DIRECTORY__
run dotnetCli "restore" clientPath
)

Target "Run" (fun () ->
let server = async { run dotnetCli "watch run" serverPath }
let client = async { run dotnetCli "fable webpack-dev-server" clientPath }
let browser = async {
Threading.Thread.Sleep 5000
Diagnostics.Process.Start "http://localhost:8080" |> ignore
}

[ server; client; browser]
|> Async.Parallel
|> Async.RunSynchronously
|> ignore
)

"Clean"
==> "InstallClient"
==> "Run"

RunTargetOrDefault "Run"
#r "paket: groupref build //"
#load "./.fake/build.fsx/intellisense.fsx"

#if !FAKE
#r "netstandard"
#r "Facades/netstandard" // https://github.com/ionide/ionide-vscode-fsharp/issues/839#issuecomment-396296095
#endif

open System

open Fake.Core
open Fake.DotNet
open Fake.IO

let serverPath = Path.getFullName "./src/Server"
let clientPath = Path.getFullName "./src/Client"
let deployDir = Path.getFullName "./deploy"

let platformTool tool winTool =
let tool = if Environment.isUnix then tool else winTool
match ProcessUtils.tryFindFileOnPath tool with
| Some t -> t
| _ ->
let errorMsg =
tool + " 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 errorMsg

let nodeTool = platformTool "node" "node.exe"
let yarnTool = platformTool "yarn" "yarn.cmd"

let runTool cmd args workingDir =
let arguments = args |> String.split ' ' |> Arguments.OfArgs
Command.RawCommand (cmd, arguments)
|> CreateProcess.fromCommand
|> CreateProcess.withWorkingDirectory workingDir
|> CreateProcess.ensureExitCode
|> Proc.run
|> ignore

let runDotNet cmd workingDir =
let result =
DotNet.exec (DotNet.Options.withWorkingDirectory workingDir) cmd ""
if result.ExitCode <> 0 then failwithf "'dotnet %s' failed in %s" cmd workingDir

let openBrowser url =
//https://github.com/dotnet/corefx/issues/10361
Command.ShellCommand url
|> CreateProcess.fromCommand
|> CreateProcess.ensureExitCodeWithMessage "opening browser failed"
|> Proc.run
|> ignore

Target.create "Clean" (fun _ ->
Shell.cleanDirs [deployDir]
)

Target.create "InstallClient" (fun _ ->
printfn "Node version:"
runTool nodeTool "--version" __SOURCE_DIRECTORY__
printfn "Yarn version:"
runTool yarnTool "--version" __SOURCE_DIRECTORY__
runTool yarnTool "install --frozen-lockfile" __SOURCE_DIRECTORY__
runDotNet "restore" clientPath
)

Target.create "Build" (fun _ ->
runDotNet "build" serverPath
runDotNet "fable webpack-cli -- --config src/Client/webpack.config.js -p" clientPath
)
Target.create "Run" (fun _ ->
let server = async {
runDotNet "watch run" serverPath
}
let client = async {
runDotNet "fable webpack-dev-server -- --config src/Client/webpack.config.js" clientPath
}
let browser = async {
do! Async.Sleep 5000
openBrowser "http://localhost:8080"
}

let vsCodeSession = Environment.hasEnvironVar "vsCodeSession"
let safeClientOnly = Environment.hasEnvironVar "safeClientOnly"

let tasks =
[ if not safeClientOnly then yield server
yield client
if not vsCodeSession then yield browser ]

tasks
|> Async.Parallel
|> Async.RunSynchronously
|> ignore
)


open Fake.Core.TargetOperators

"Clean"
==> "InstallClient"
==> "Build"

"Clean"
==> "InstallClient"
==> "Run"

Target.runOrDefaultWithArguments "Build"
52 changes: 21 additions & 31 deletions package.json
@@ -1,33 +1,23 @@
{
"private": true,
"dependencies": {
"babel-polyfill": "6.26.0",
"babel-runtime": "6.26.0",
"react": "16.0.0",
"react-bootstrap": "0.31.3",
"react-dom": "16.0.0",
"recharts": "^1.0.0-beta.10",
"remotedev": "0.2.7"
},
"devDependencies": {
"babel-core": "6.26.0",
"babel-loader": "7.1.2",
"babel-plugin-transform-runtime": "6.23.0",
"babel-preset-env": "1.6.0",
"concurrently": "3.5.0",
"fable-loader": "1.1.3",
"fable-utils": "1.0.6",
"webpack": "3.7.1",
"webpack-dev-server": "2.9.1"
},
"scripts": {
"prebuildServer": "dotnet restore src/Server/Server.fsproj",
"buildServer": "dotnet build src/Server/Server.fsproj",
"prebuildServerTest": "dotnet restore test/ServerTests/ServerTests.fsproj",
"buildServerTest": "dotnet build test/ServerTests/ServerTests.fsproj",
"restoreClient": "cd src/Client && yarn install",
"restoreNetClient": "dotnet restore src/Client/Client.fsproj",
"prestartClient": "concurrently \"npm run restoreClient\" \"npm run restoreNetClient\" ",
"startClient": "cd src/Client && dotnet fable webpack-dev-server"
}
"private": true,
"devDependencies": {
"@babel/core": "^7.0.0",
"@babel/plugin-transform-runtime": "^7.0.0",
"@babel/polyfill": "^7.0.0",
"@babel/preset-env": "^7.0.0",
"@babel/runtime": "^7.0.0",
"babel-loader": "^8.0.0",
"fable-loader": "^2.0.0",
"react": "16.5.2",
"react-dom": "16.5.2",
"remotedev": "0.2.7",
"terser-webpack-plugin": "^1.1.0",
"webpack": "^4.20.2",
"webpack-cli": "^3.1.2",
"webpack-dev-server": "^3.1.9",
"whatwg-fetch": "^3.0.0"
},
"dependencies": {
"recharts": "^1.4.2"
}
}
62 changes: 38 additions & 24 deletions paket.dependencies
@@ -1,24 +1,38 @@
group Server
source https://api.nuget.org/v3/index.json
storage: none

nuget Saturn
nuget Fable.JsonConverter
nuget FSharp.Data 3.0.0-beta

group Client
source https://api.nuget.org/v3/index.json
storage: none

nuget Fable.Elmish.Debugger
nuget Fable.Elmish.React
nuget Fable.Elmish.HMR
nuget Fable.Recharts
nuget Fulma 1.0.0-beta-007

clitool dotnet-fable

group Build
source https://api.nuget.org/v3/index.json

nuget FAKE
group Server
source https://api.nuget.org/v3/index.json
framework: netcoreapp2.1
storage: none

nuget FSharp.Core
nuget Saturn
nuget Thoth.Json.Giraffe
nuget FSharp.Data

group Client
source https://api.nuget.org/v3/index.json
framework: netstandard2.0
storage: none

nuget Fable.Core ~> 2
nuget Fable.Elmish ~> 2
nuget Fable.Elmish.Debugger ~> 2
nuget Fable.Elmish.React ~> 2
nuget Fable.Elmish.HMR ~> 2
nuget Fable.React ~> 4
nuget Fulma ~> 1
nuget Fable.Recharts
nuget Fable.FontAwesome
nuget Fable.FontAwesome.Free

clitool dotnet-fable ~> 2

group Build
source https://api.nuget.org/v3/index.json
framework: netstandard2.0
storage: none

nuget FSharp.Core 4.3.4 // https://github.com/fsharp/FAKE/issues/2001
nuget Fake.Core.Target
nuget Fake.DotNet.Cli
nuget Fake.IO.FileSystem

0 comments on commit e2fa501

Please sign in to comment.