diff --git a/build.fsx b/build.fsx index 991b5242..e44811e8 100644 --- a/build.fsx +++ b/build.fsx @@ -4,6 +4,7 @@ #r @"packages/build/FAKE/tools/FakeLib.dll" #load "tools/fakexunithelper.fsx" // helper for xunit 1 is gone, work around by having our own copy for now +#load "tools/fakeiisexpress.fsx" // helper for iisexpress is not ready, work around by having our own copy for now open System open System.IO @@ -191,6 +192,11 @@ Target.create "GenerateDocs" (fun _ -> Fake.FSIHelper.executeFSIWithArgs "docs/tools" "generate.fsx" ["--define:RELEASE"] [] |> ignore ) +Target.create "ServeDocs" (fun _ -> + Fakeiisexpress.HostStaticWebsite id (__SOURCE_DIRECTORY__ @@ @"docs\output\") |> ignore + Fakeiisexpress.OpenUrlInBrowser "http://localhost:8080" +) + Target.create "ReleaseDocs" (fun _ -> Repository.clone "" (gitHome + "/" + gitName + ".git") "temp/gh-pages" Branches.checkoutBranch "temp/gh-pages" "gh-pages" diff --git a/docs/content/whatsnew.fsx b/docs/content/whatsnew.fsx index 338069a9..62314d18 100644 --- a/docs/content/whatsnew.fsx +++ b/docs/content/whatsnew.fsx @@ -36,7 +36,7 @@ and accessing to built-in objects like stored procedures, functoins and tables. Connectivity information (connection string and/or config file name) is defined in one place and doesn't have be carried around like in SqlCommandProvider case. -```CreateCommand``` optionally accepts connection, transaction and command timeout parameters. +`CreateCommand` optionally accepts connection, transaction and command timeout parameters. Any of these parameters can be ommited. *) @@ -62,8 +62,8 @@ do Access to command and record types ------------------------------------- -```CreateMethod``` combines command type definition and constructor invocation. -Compare it with usage of ```SqlCommandProvider``` where generated command type aliased explicitly. +`CreateMethod` combines command type definition and constructor invocation. +Compare it with usage of `SqlCommandProvider` where generated command type aliased explicitly. *) let cmd1 = DB.CreateCommand<"SELECT name, create_date FROM sys.databases">(connectionString) diff --git a/docs/tools/generate.fsx b/docs/tools/generate.fsx index fce6a090..50c485d9 100644 --- a/docs/tools/generate.fsx +++ b/docs/tools/generate.fsx @@ -14,26 +14,20 @@ let info = "project-github", githubLink "project-nuget", "http://www.nuget.org/packages/FSharp.Data.SqlClient" ] -#I "../../packages/FSharp.Formatting.2.4.1/lib/net40" -#I "../../packages/RazorEngine.3.3.0/lib/net40" -#I "../../packages/FSharp.Compiler.Service.0.0.36/lib/net40" -#r "../../packages/Microsoft.AspNet.Razor.2.0.30506.0/lib/net40/System.Web.Razor.dll" -#r "../../packages/FAKE/tools/FakeLib.dll" -#r "RazorEngine.dll" -#r "FSharp.Literate.dll" -#r "FSharp.CodeFormat.dll" -#r "FSharp.MetadataFormat.dll" +#load "../../.paket/load/net46/Build/FSharp.Formatting.fsx" +#load "../../.paket/load/net46/Build/FAKE.Lib.fsx" + open Fake open System.IO -open Fake.FileHelper +open Fake.IO.FileSystemOperators open FSharp.Literate open FSharp.MetadataFormat -#if RELEASE -let root = website -#else -let root = "file://" + (__SOURCE_DIRECTORY__ @@ "../output") -#endif +// see https://github.com/fsharp/FAKE/issues/1579#issuecomment-306580820 +let execContext = Fake.Core.Context.FakeExecutionContext.Create false (Path.Combine(__SOURCE_DIRECTORY__, __SOURCE_FILE__)) [] +Fake.Core.Context.setExecutionContext (Fake.Core.Context.RuntimeContext.Fake execContext) + +let root = "." // Paths with template/source/output locations let bin = __SOURCE_DIRECTORY__ @@ "../../bin" @@ -41,7 +35,7 @@ let content = __SOURCE_DIRECTORY__ @@ "../content" let output = __SOURCE_DIRECTORY__ @@ "../output" let files = __SOURCE_DIRECTORY__ @@ "../files" let templates = __SOURCE_DIRECTORY__ @@ "templates" -let formatting = __SOURCE_DIRECTORY__ @@ "../../packages/FSharp.Formatting.2.4.1/" +let formatting = __SOURCE_DIRECTORY__ @@ "../../packages/Build/FSharp.Formatting/" let docTemplate = formatting @@ "templates/docpage.cshtml" // Where to look for *.csproj templates (in this order) @@ -51,14 +45,14 @@ let layoutRoots = // Copy static files and CSS + JS from F# Formatting let copyFiles () = - CopyRecursive files output true |> Log "Copying file: " - ensureDirectory (output @@ "content") - CopyRecursive (formatting @@ "styles") (output @@ "content") true - |> Log "Copying styles and scripts: " + Fake.IO.Shell.copyRecursive files output true |> Fake.Core.Trace.logItems "Copying file: " + Fake.IO.Directory.ensure (output @@ "content") + Fake.IO.Shell.copyRecursive (formatting @@ "styles") (output @@ "content") true + |> Fake.Core.Trace.logItems "Copying styles and scripts: " // Build API reference from XML comments let buildReference () = - CleanDir (output @@ "reference") + Fake.IO.Shell.cleanDir (output @@ "reference") for lib in referenceBinaries do MetadataFormat.Generate ( bin @@ lib, output @@ "reference", layoutRoots, diff --git a/paket.dependencies b/paket.dependencies index 4855423c..22def0da 100644 --- a/paket.dependencies +++ b/paket.dependencies @@ -14,8 +14,14 @@ group Build framework: >= net40 redirects: force + nuget FAKE = 5.0.0-rc014.167 + nuget Fake.Lib = 5.0.0-rc014.167 + + nuget FSharp.Formatting = 2.4.1 + nuget FSharp.Compiler.Service = 0.0.36 + nuget RazorEngine = 3.3.0 + nuget NuGet.CommandLine - nuget FAKE = 5.0.0-rc014.167 group Test source https://www.nuget.org/api/v2/ diff --git a/paket.lock b/paket.lock index bfea17c4..cfc5b285 100644 --- a/paket.lock +++ b/paket.lock @@ -103,7 +103,16 @@ RESTRICTION: >= net40 NUGET remote: https://www.nuget.org/api/v2 FAKE (5.0.0-rc014.167) + FAKE.Lib (5.0.0-rc014.167) + FSharp.Compiler.Service (0.0.36) + FSharp.Formatting (2.4.1) + FSharp.Compiler.Service (>= 0.0.32) + Microsoft.AspNet.Razor (>= 2.0.30506) + RazorEngine (>= 3.3) + Microsoft.AspNet.Razor (3.2.6) NuGet.CommandLine (4.6.2) + RazorEngine (3.3) + Microsoft.AspNet.Razor (>= 2.0.30506) GROUP Samples REDIRECTS: FORCE diff --git a/tools/fakeiisexpress.fsx b/tools/fakeiisexpress.fsx new file mode 100644 index 00000000..43a8fd15 --- /dev/null +++ b/tools/fakeiisexpress.fsx @@ -0,0 +1,107 @@ +// https://github.com/fsharp/FAKE/blob/e1378887c41c37d425e134f83424424b76781228/src/legacy/Fake.IIS/IISExpress.fs +// added HostStaticWebsite +#r "System.Xml.Linq" +open Fake +/// Contains tasks to host webprojects in IIS Express. +//[] +//module Fake.IISExpress + +open System.Diagnostics +open System +open System.IO +open System.Xml.Linq + +/// Options for using IISExpress +[] +type IISExpressOptions = + { ToolPath : string } + +/// IISExpress default parameters - tries to locate the iisexpress.exe +[] +let IISExpressDefaults = + { ToolPath = + let root = + if Environment.Is64BitOperatingSystem then + Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86) + else Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) + + Path.Combine(root, "IIS Express", "iisexpress.exe") } + +/// Create a IISExpress config file from a given template +[] +let createConfigFile (name, siteId : int, templateFileName, path, hostName, port : int) = + let xname s = XName.Get(s) + let uniqueConfigFile = Path.Combine(Path.GetTempPath(), "iisexpress-" + Guid.NewGuid().ToString() + ".config") + use template = File.OpenRead(templateFileName) + let xml = XDocument.Load(template) + let sitesElement = xml.Root.Element(xname "system.applicationHost").Element(xname "sites") + let appElement = + XElement + (xname "site", XAttribute(xname "name", name), XAttribute(xname "id", siteId.ToString()), + XAttribute(xname "serverAutoStart", "true"), + + XElement + (xname "application", XAttribute(xname "path", "/"), + + XElement + (xname "virtualDirectory", XAttribute(xname "path", "/"), XAttribute(xname "physicalPath", DirectoryInfo(path).FullName))), + + XElement + (xname "bindings", + + XElement + (xname "binding", XAttribute(xname "protocol", "http"), + XAttribute(xname "bindingInformation", "*:" + port.ToString() + ":" + hostName)), + + XElement + (xname "binding", XAttribute(xname "protocol", "http"), + XAttribute(xname "bindingInformation", "*:" + port.ToString() + ":*")))) + sitesElement.Add(appElement) + xml.Save(uniqueConfigFile) + uniqueConfigFile + +/// This task starts the given site in IISExpress with the given ConfigFile. +/// ## Parameters +/// +/// - `setParams` - Function used to overwrite the default parameters. +/// - `configFileName` - The file name of the IISExpress configfile. +/// - `siteId` - The id (in the config file) of the website to run. +/// +/// ## Sample +/// +/// HostWebsite (fun p -> { p with ToolPath = "iisexpress.exe" }) "configfile.config" 1 +[] +let HostWebsite setParams configFileName siteId = + let parameters = setParams IISExpressDefaults + + use __ = traceStartTaskUsing "StartWebSite" configFileName + let args = sprintf "/config:\"%s\" /siteid:%d" configFileName siteId + tracefn "Starting WebSite with %s %s" parameters.ToolPath args + + let proc = + ProcessStartInfo(FileName = parameters.ToolPath, Arguments = args, UseShellExecute = false) + |> Process.Start + + proc + +let HostStaticWebsite setParams folder = + // https://blogs.msdn.microsoft.com/rido/2015/09/30/serving-static-content-with-iisexpress/ + let parameters = setParams IISExpressDefaults + + use __ = traceStartTaskUsing "StartWebSite" folder + let args = sprintf @"/path:""%s\""" folder + tracefn "Starting WebSite with %s %s" parameters.ToolPath args + + let proc = + ProcessStartInfo(FileName = parameters.ToolPath, Arguments = args, UseShellExecute = false) + |> Process.Start + + proc + +/// Opens the given url in the browser +[] +let OpenUrlInBrowser url = Process.Start(url:string) |> ignore + +/// Opens the given website in the browser +[] +let OpenWebsiteInBrowser hostName port = sprintf "http://%s:%d/" hostName port |> OpenUrlInBrowser \ No newline at end of file