Skip to content

Commit

Permalink
Use temp output directory in docstool watch mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Jimmy Byrd committed Dec 26, 2019
1 parent 088bfb1 commit 88582bb
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 14 deletions.
1 change: 0 additions & 1 deletion Content/Library/build.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ module DocsTool =
let watchCLI =
[
WatchArgs.ProjectGlob srcGlob
WatchArgs.DocsOutputDirectory docsDir
WatchArgs.DocsSourceDirectory docsSrcDir
WatchArgs.GitHubRepoUrl gitHubRepoUrl
WatchArgs.ProjectName gitRepoName
Expand Down
2 changes: 0 additions & 2 deletions Content/Library/docsTool/CLI.fs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ module CLIArgs =

type WatchArgs =
| ProjectGlob of string
| DocsOutputDirectory of string
| DocsSourceDirectory of string
| GitHubRepoUrl of string
| ProjectName of string
Expand All @@ -16,7 +15,6 @@ module CLIArgs =
member this.Usage =
match this with
| ProjectGlob _ -> "The glob for the dlls to generate API documentation."
| DocsOutputDirectory _ -> "The docs output directory."
| DocsSourceDirectory _ -> "The docs source directory."
| GitHubRepoUrl _ -> "The GitHub repository url."
| ProjectName _ -> "The project name."
Expand Down
30 changes: 27 additions & 3 deletions Content/Library/docsTool/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,25 @@
open System
open Fake.IO.FileSystemOperators
open Fake.IO
open Fake.Core

let dispose (d : #IDisposable) = d.Dispose()
type DisposableDirectory (directory : string) =
do
Trace.tracefn "Created disposable directory %s" directory
static member Create() =
let tempPath = IO.Path.Combine(IO.Path.GetTempPath(), Guid.NewGuid().ToString("n"))
IO.Directory.CreateDirectory tempPath |> ignore

new DisposableDirectory(tempPath)
member x.Directory = directory
member x.DirectoryInfo = IO.DirectoryInfo(directory)

interface IDisposable with
member x.Dispose() =
Trace.tracefn "Deleting directory %s" directory
IO.Directory.Delete(x.Directory,true)


let refreshWebpageEvent = new Event<string>()

Expand Down Expand Up @@ -506,12 +525,18 @@ open Fake.IO.Globbing.Operators
open DocsTool.CLIArgs
[<EntryPoint>]
let main argv =

use tempDocsOutDir = DisposableDirectory.Create()
use __ = AppDomain.CurrentDomain.ProcessExit.Subscribe(fun _ ->
dispose tempDocsOutDir
)
use __ = Console.CancelKeyPress.Subscribe(fun _ ->
dispose tempDocsOutDir
)
let defaultConfig = {
SiteBaseUrl = Uri(sprintf "http://%s:%d/" WebServer.hostname WebServer.port )
GitHubRepoUrl = Uri "https://github.com"
RepositoryRoot = IO.DirectoryInfo (__SOURCE_DIRECTORY__ @@ "..")
DocsOutputDirectory = IO.DirectoryInfo "docs"
DocsOutputDirectory = tempDocsOutDir.DirectoryInfo
DocsSourceDirectory = IO.DirectoryInfo "docsSrc"
ProjectName = ""
ProjectFilesGlob = !! ""
Expand Down Expand Up @@ -551,7 +576,6 @@ let main argv =
||> List.fold(fun state next ->
match next with
| WatchArgs.ProjectGlob glob -> {state with ProjectFilesGlob = !! glob}
| WatchArgs.DocsOutputDirectory outdir -> { state with DocsOutputDirectory = IO.DirectoryInfo outdir}
| WatchArgs.DocsSourceDirectory srcdir -> { state with DocsSourceDirectory = IO.DirectoryInfo srcdir}
| WatchArgs.GitHubRepoUrl url -> { state with GitHubRepoUrl = Uri url}
| WatchArgs.ProjectName repo -> { state with ProjectName = repo}
Expand Down
1 change: 0 additions & 1 deletion build.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ module DocsTool =
let watchCLI =
[
WatchArgs.ProjectGlob docsToolProj
WatchArgs.DocsOutputDirectory docsDir
WatchArgs.DocsSourceDirectory docsSrcDir
WatchArgs.GitHubRepoUrl gitHubRepoUrl
WatchArgs.ProjectName gitRepoName
Expand Down
2 changes: 0 additions & 2 deletions docsTool/CLI.fs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ module CLIArgs =

type WatchArgs =
| ProjectGlob of string
| DocsOutputDirectory of string
| DocsSourceDirectory of string
| GitHubRepoUrl of string
| ProjectName of string
Expand All @@ -16,7 +15,6 @@ module CLIArgs =
member this.Usage =
match this with
| ProjectGlob _ -> "The glob for the dlls to generate API documentation."
| DocsOutputDirectory _ -> "The docs output directory."
| DocsSourceDirectory _ -> "The docs source directory."
| GitHubRepoUrl _ -> "The GitHub repository url."
| ProjectName _ -> "The project name."
Expand Down
31 changes: 26 additions & 5 deletions docsTool/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,24 @@
open System
open Fake.IO.FileSystemOperators
open Fake.IO
open Fake.Core

let dispose (d : #IDisposable) = d.Dispose()
type DisposableDirectory (directory : string) =
do
Trace.tracefn "Created disposable directory %s" directory
static member Create() =
let tempPath = IO.Path.Combine(IO.Path.GetTempPath(), Guid.NewGuid().ToString("n"))
IO.Directory.CreateDirectory tempPath |> ignore

new DisposableDirectory(tempPath)
member x.Directory = directory
member x.DirectoryInfo = IO.DirectoryInfo(directory)

interface IDisposable with
member x.Dispose() =
Trace.tracefn "Deleting directory %s" directory
IO.Directory.Delete(x.Directory,true)

let refreshWebpageEvent = new Event<string>()

Expand Down Expand Up @@ -426,12 +444,18 @@ open Fake.IO.Globbing.Operators
open DocsTool.CLIArgs
[<EntryPoint>]
let main argv =

use tempDocsOutDir = DisposableDirectory.Create()
use __ = AppDomain.CurrentDomain.ProcessExit.Subscribe(fun _ ->
dispose tempDocsOutDir
)
use __ = Console.CancelKeyPress.Subscribe(fun _ ->
dispose tempDocsOutDir
)
let defaultConfig = {
SiteBaseUrl = Uri(sprintf "http://%s:%d/" WebServer.hostname WebServer.port )
GitHubRepoUrl = Uri "https://github.com"
RepositoryRoot = IO.DirectoryInfo (__SOURCE_DIRECTORY__ @@ "..")
DocsOutputDirectory = IO.DirectoryInfo "docs"
DocsOutputDirectory = tempDocsOutDir.DirectoryInfo
DocsSourceDirectory = IO.DirectoryInfo "docsSrc"
ProjectName = ""
ProjectFilesGlob = !! ""
Expand All @@ -446,8 +470,6 @@ let main argv =
else
name



let parser = ArgumentParser.Create<CLIArguments>(programName = programName, errorHandler = errorHandler)
let parsedArgs = parser.Parse argv
match parsedArgs.GetSubCommand() with
Expand All @@ -471,7 +493,6 @@ let main argv =
||> List.fold(fun state next ->
match next with
| WatchArgs.ProjectGlob glob -> {state with ProjectFilesGlob = !! glob}
| WatchArgs.DocsOutputDirectory outdir -> { state with DocsOutputDirectory = IO.DirectoryInfo outdir}
| WatchArgs.DocsSourceDirectory srcdir -> { state with DocsSourceDirectory = IO.DirectoryInfo srcdir}
| WatchArgs.GitHubRepoUrl url -> { state with GitHubRepoUrl = Uri url}
| WatchArgs.ProjectName repo -> { state with ProjectName = repo}
Expand Down

0 comments on commit 88582bb

Please sign in to comment.