Last active
December 19, 2016 20:00
-
-
Save Kimserey/3083b127710181e4d4a7 to your computer and use it in GitHub Desktop.
FAKE script to compile WebSharper JS for specific folder. Files are loaded in order based on fsproj. Ex: `Build.cmd instance=test` will compile to JS all the fs files in \config\test\.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
cls | |
..\packages\FAKE\tools\FAKE.exe BuildJS.fsx %* |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#I @"..\packages\FAKE\tools\" | |
#r "FakeLib.dll" | |
open System | |
open System.IO | |
open System.Diagnostics | |
open System.Text.RegularExpressions | |
open Fake | |
open Fake.FscHelper | |
open Fake.ProcessHelper | |
module Config = | |
let srcDir = __SOURCE_DIRECTORY__ | |
let instance = getBuildParam "instance" | |
let appName = getBuildParamOrDefault "name" "app" | |
let outputDir = getBuildParamOrDefault "out" (srcDir @@ "webroot" @@ "content") | |
let configDir = srcDir @@ "configs" @@ instance | |
let compiledWebSharperDllPath = srcDir @@ "bin" @@ "ws.dll" | |
let webSharperLibraryPaths = | |
let dllPath path = List.map ((@@) path >> sprintf "%s.dll") | |
([ "WebSharper.Collections" | |
"WebSharper.Control" | |
"WebSharper.Core" | |
"WebSharper.Core.JavaScript" | |
"WebSharper.InterfaceGenerator" | |
"WebSharper.JavaScript" | |
"WebSharper.JQuery" | |
"WebSharper.Main" | |
"WebSharper.Sitelets" | |
"WebSharper.Web" ] |> dllPath @"..\packages\WebSharper\lib\net40") | |
@ | |
([ "WebSharper.UI.Next" | |
"WebSharper.UI.Next.Templating" ] |> dllPath @"..\packages\WebSharper.UI.Next\lib\net40") | |
@ | |
([ "WebSharper.UI.Next.Piglets" ] |> dllPath @"..\packages\WebSharper.UI.Next.Piglets\lib\net40") | |
Target "Compile" (fun _ -> | |
if String.IsNullOrWhiteSpace Config.instance then | |
failwith "An instance name must be provided. Build.cmd instance=[instance name]" | |
let files = | |
let filePattern prefix = | |
sprintf """<Compile Include="(%s[\w.-]*\.fs+)" />""" prefix | |
let getFiles projContent pattern = | |
let matches = Regex.Matches(projContent, pattern) | |
seq { for m in matches -> m.Groups.[1].Value } | |
Directory.GetFiles Config.srcDir | |
|> Seq.filter (fun file -> (FileInfo file).Extension = ".fsproj") | |
|> Seq.collect (fun file -> | |
let content = File.ReadAllText file | |
[ yield! getFiles content (filePattern String.Empty) | |
yield! getFiles content (filePattern (sprintf @"configs\\%s\\" Config.instance)) ]) | |
|> Seq.toList | |
files | |
|> Fsc (fun p -> { p with Output = Config.compiledWebSharperDllPath | |
FscTarget = Library | |
References = Config.webSharperLibraryPaths }) | |
) | |
Target "CompileWithWebSharper" (fun _ -> | |
if not <| directExec (fun info -> | |
info.FileName <- @"..\packages\WebSharper\tools\net40\WebSharper.exe" | |
info.Arguments <- sprintf "%s %s %s" | |
(Config.webSharperLibraryPaths |> List.map ((+) "-r ") |> String.concat " ") | |
Config.compiledWebSharperDllPath | |
Config.compiledWebSharperDllPath) then | |
failwith "Failed to compile with websharper" | |
else () | |
) | |
Target "BundleWithWebSharper" (fun _ -> | |
if not <| directExec (fun info -> | |
info.FileName <- @"..\packages\WebSharper\tools\net40\WebSharper.exe" | |
info.Arguments <- sprintf "bundle %s -name %s -out %s %s" | |
(Config.webSharperLibraryPaths |> String.concat " ") | |
Config.appName | |
Config.outputDir | |
Config.compiledWebSharperDllPath) then | |
failwith "Failed to bundle with websharper" | |
else () | |
) | |
"Compile" | |
==> "CompileWithWebSharper" | |
==> "BundleWithWebSharper" | |
RunTargetOrDefault "BundleWithWebSharper" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment