From 65a6dad0b9c688e98829b473142ccc7b4231014b Mon Sep 17 00:00:00 2001 From: Drew Knab Date: Sat, 29 Aug 2020 23:53:08 -0400 Subject: [PATCH 1/2] Add LibGit2Sharp, add sub commands to fornax new add logic to handle alternate templates from git repos --- paket.dependencies | 1 + paket.lock | 25 ++++++------ src/Fornax/Fornax.fs | 79 +++++++++++++++++++++++++++++-------- src/Fornax/Fornax.fsproj | 6 +-- src/Fornax/paket.references | 3 +- 5 files changed, 80 insertions(+), 34 deletions(-) diff --git a/paket.dependencies b/paket.dependencies index 70f5d55..ebd0c57 100644 --- a/paket.dependencies +++ b/paket.dependencies @@ -10,6 +10,7 @@ nuget FSharp.Quotations.Evaluator nuget Argu nuget Suave +nuget LibGit2Sharp group Build source https://www.nuget.org/api/v2 diff --git a/paket.lock b/paket.lock index 725b121..091b40d 100644 --- a/paket.lock +++ b/paket.lock @@ -20,6 +20,9 @@ NUGET FSharp.Core (4.7.2) FSharp.Quotations.Evaluator (2.1) FSharp.Core (>= 4.3.1) - restriction: >= netstandard2.0 + LibGit2Sharp (0.26.2) + LibGit2Sharp.NativeBinaries (2.0.306) - restriction: || (>= net46) (>= netstandard2.0) + LibGit2Sharp.NativeBinaries (2.0.306) - restriction: || (>= net46) (>= netstandard2.0) Microsoft.NETCore.Platforms (3.1) - restriction: || (&& (< monoandroid) (< net45) (< netstandard1.2) (>= netstandard2.0) (< win8)) (&& (< monoandroid) (< net45) (< netstandard1.3) (>= netstandard2.0) (< win8) (< wpa81)) (&& (< monoandroid) (< net45) (< netstandard1.5) (>= netstandard2.0) (< win8) (< wpa81)) (&& (< monoandroid) (< net45) (>= netstandard2.0) (< win8) (< wpa81) (< xamarinios) (< xamarinmac)) (&& (>= net461) (>= netcoreapp2.1)) (>= netcoreapp2.0) (&& (>= netcoreapp2.1) (< netcoreapp3.0)) Microsoft.NETCore.Targets (3.1) - restriction: || (&& (< monoandroid) (< net45) (< netstandard1.2) (>= netstandard2.0) (< win8)) (&& (< monoandroid) (< net45) (< netstandard1.3) (>= netstandard2.0) (< win8) (< wpa81)) (&& (< monoandroid) (< net45) (< netstandard1.5) (>= netstandard2.0) (< win8) (< wpa81)) (&& (< monoandroid) (< net45) (>= netstandard2.0) (< win8) (< wpa81) (< xamarinios) (< xamarinmac)) Microsoft.Win32.SystemEvents (4.7) - restriction: >= netcoreapp3.0 @@ -29,9 +32,9 @@ NUGET FSharp.Core (>= 4.3.4) - restriction: || (>= net461) (>= netstandard2.0) System.Buffers (4.5.1) - restriction: || (>= net461) (>= netstandard2.0) System.Collections.Immutable (1.7) - restriction: || (>= net461) (>= netstandard2.0) - System.Memory (>= 4.5.3) - restriction: || (&& (< monoandroid) (< monotouch) (< net45) (>= netstandard1.3) (< netstandard2.0) (< win8) (< wpa81) (< xamarintvos) (< xamarinwatchos)) (&& (< net45) (< netcoreapp2.1) (>= netstandard2.0) (< xamarinios) (< xamarinmac)) (>= net46) (>= uap10.1) + System.Memory (>= 4.5.3) - restriction: || (&& (< monoandroid) (< monotouch) (< net45) (>= netstandard1.3) (< netstandard2.0) (< win8) (< wpa81) (< xamarintvos) (< xamarinwatchos)) (&& (< monoandroid) (< net45) (< netcoreapp2.1) (>= netstandard2.0) (< xamarinios) (< xamarinmac)) (>= net46) (>= uap10.1) System.Configuration.ConfigurationManager (4.7) - restriction: >= netstandard2.0 - System.Security.Cryptography.ProtectedData (>= 4.7) - restriction: && (< net461) (>= netstandard2.0) (< xamarinios) (< xamarinmac) + System.Security.Cryptography.ProtectedData (>= 4.7) - restriction: && (< monoandroid) (< net461) (>= netstandard2.0) (< xamarinios) (< xamarinmac) System.Security.Permissions (>= 4.7) - restriction: || (>= monoandroid) (>= monotouch) (>= net461) (>= netstandard2.0) (>= xamarintvos) (>= xamarinwatchos) System.Drawing.Common (4.7) - restriction: >= netcoreapp3.0 Microsoft.NETCore.Platforms (>= 3.1) - restriction: >= netcoreapp2.0 @@ -43,11 +46,11 @@ NUGET System.Text.Encoding (>= 4.3) - restriction: || (&& (< monoandroid) (< monotouch) (< net45) (>= netstandard1.5) (< win8) (< wpa81) (< xamarinios) (< xamarinmac) (< xamarintvos) (< xamarinwatchos)) (&& (< monoandroid) (< net45) (>= netstandard1.0) (< netstandard1.3) (< win8) (< wp8) (< wpa81)) (&& (< monoandroid) (< net45) (>= netstandard1.3) (< netstandard1.5) (< win8) (< wpa81)) System.Threading.Tasks (>= 4.3) - restriction: || (&& (< monoandroid) (< monotouch) (< net45) (>= netstandard1.5) (< win8) (< wpa81) (< xamarinios) (< xamarinmac) (< xamarintvos) (< xamarinwatchos)) (&& (< monoandroid) (< net45) (>= netstandard1.0) (< netstandard1.3) (< win8) (< wp8) (< wpa81)) (&& (< monoandroid) (< net45) (>= netstandard1.3) (< netstandard1.5) (< win8) (< wpa81)) System.Memory (4.5.4) - restriction: || (>= net461) (>= netstandard2.0) - System.Buffers (>= 4.5.1) - restriction: || (&& (>= monoandroid) (< netstandard2.0)) (&& (< monoandroid) (< net45) (>= netstandard1.1) (< netstandard2.0) (< win8) (< wpa81)) (&& (< monoandroid) (< netstandard1.1) (>= portable-net45+win8+wpa81) (< win8)) (>= monotouch) (&& (>= net45) (< netstandard2.0)) (&& (< net45) (< netcoreapp2.0) (>= netstandard2.0)) (>= net461) (&& (< netstandard1.1) (>= win8)) (&& (< netstandard2.0) (< uap10.1) (>= wpa81)) (>= xamarinios) (>= xamarinmac) (>= xamarintvos) (>= xamarinwatchos) - System.Numerics.Vectors (>= 4.4) - restriction: && (< net45) (< netcoreapp2.0) (>= netstandard2.0) (< xamarinios) (< xamarinmac) + System.Buffers (>= 4.5.1) - restriction: || (>= monoandroid) (>= monotouch) (&& (>= net45) (< netstandard2.0)) (&& (< net45) (< netcoreapp2.0) (>= netstandard2.0)) (&& (< net45) (>= netstandard1.1) (< netstandard2.0) (< win8) (< wpa81)) (>= net461) (&& (< netstandard1.1) (>= portable-net45+win8+wpa81) (< win8)) (&& (< netstandard1.1) (>= win8)) (&& (< netstandard2.0) (< uap10.1) (>= wpa81)) (>= xamarinios) (>= xamarinmac) (>= xamarintvos) (>= xamarinwatchos) + System.Numerics.Vectors (>= 4.4) - restriction: && (< monoandroid) (< net45) (< netcoreapp2.0) (>= netstandard2.0) (< xamarinios) (< xamarinmac) System.Numerics.Vectors (>= 4.5) - restriction: >= net461 - System.Runtime.CompilerServices.Unsafe (>= 4.5.3) - restriction: || (&& (>= monoandroid) (< netstandard2.0)) (&& (< monoandroid) (< net45) (>= netstandard1.1) (< netstandard2.0) (< win8) (< wpa81)) (&& (< monoandroid) (< netstandard1.1) (>= portable-net45+win8+wpa81) (< win8)) (>= monotouch) (&& (>= net45) (< netstandard2.0)) (&& (< net45) (< netcoreapp2.0) (>= netstandard2.0)) (>= net461) (&& (>= netcoreapp2.0) (< netcoreapp2.1)) (&& (< netstandard1.1) (>= win8)) (&& (< netstandard2.0) (>= wpa81)) (>= uap10.1) (>= xamarinios) (>= xamarinmac) (>= xamarintvos) (>= xamarinwatchos) - System.Numerics.Vectors (4.5) - restriction: || (&& (< net45) (< netcoreapp2.0) (>= netstandard2.0) (< xamarinios) (< xamarinmac)) (>= net461) + System.Runtime.CompilerServices.Unsafe (>= 4.5.3) - restriction: || (>= monoandroid) (>= monotouch) (&& (>= net45) (< netstandard2.0)) (&& (< net45) (< netcoreapp2.0) (>= netstandard2.0)) (&& (< net45) (>= netstandard1.1) (< netstandard2.0) (< win8) (< wpa81)) (>= net461) (&& (>= netcoreapp2.0) (< netcoreapp2.1)) (&& (< netstandard1.1) (>= portable-net45+win8+wpa81) (< win8)) (&& (< netstandard1.1) (>= win8)) (&& (< netstandard2.0) (>= wpa81)) (>= uap10.1) (>= xamarinios) (>= xamarinmac) (>= xamarintvos) (>= xamarinwatchos) + System.Numerics.Vectors (4.5) - restriction: || (&& (< monoandroid) (< net45) (< netcoreapp2.0) (>= netstandard2.0) (< xamarinios) (< xamarinmac)) (>= net461) System.Reflection (4.3) - restriction: && (< monoandroid) (< net461) (>= netstandard2.0) (< xamarinios) (< xamarinmac) Microsoft.NETCore.Platforms (>= 1.1) - restriction: || (&& (< monoandroid) (< monotouch) (< net45) (>= netstandard1.5) (< win8) (< wpa81) (< xamarinios) (< xamarinmac) (< xamarintvos) (< xamarinwatchos)) (&& (< monoandroid) (< net45) (>= netstandard1.0) (< netstandard1.3) (< win8) (< wp8) (< wpa81)) (&& (< monoandroid) (< net45) (>= netstandard1.3) (< netstandard1.5) (< win8) (< wpa81)) Microsoft.NETCore.Targets (>= 1.1) - restriction: || (&& (< monoandroid) (< monotouch) (< net45) (>= netstandard1.5) (< win8) (< wpa81) (< xamarinios) (< xamarinmac) (< xamarintvos) (< xamarinwatchos)) (&& (< monoandroid) (< net45) (>= netstandard1.0) (< netstandard1.3) (< win8) (< wp8) (< wpa81)) (&& (< monoandroid) (< net45) (>= netstandard1.3) (< netstandard1.5) (< win8) (< wpa81)) @@ -55,8 +58,8 @@ NUGET System.Reflection.Primitives (>= 4.3) - restriction: || (&& (< monoandroid) (< monotouch) (< net45) (>= netstandard1.5) (< win8) (< wpa81) (< xamarinios) (< xamarinmac) (< xamarintvos) (< xamarinwatchos)) (&& (< monoandroid) (< net45) (>= netstandard1.0) (< netstandard1.3) (< win8) (< wp8) (< wpa81)) (&& (< monoandroid) (< net45) (>= netstandard1.3) (< netstandard1.5) (< win8) (< wpa81)) System.Runtime (>= 4.3) - restriction: || (&& (< monoandroid) (< monotouch) (< net45) (>= netstandard1.5) (< win8) (< wpa81) (< xamarinios) (< xamarinmac) (< xamarintvos) (< xamarinwatchos)) (&& (< monoandroid) (< net45) (>= netstandard1.0) (< netstandard1.3) (< win8) (< wp8) (< wpa81)) (&& (< monoandroid) (< net45) (>= netstandard1.3) (< netstandard1.5) (< win8) (< wpa81)) System.Reflection.Emit (4.7) - restriction: && (< net461) (>= netstandard2.0) - System.Reflection.Emit.ILGeneration (>= 4.7) - restriction: || (&& (< monoandroid) (< monotouch) (< net45) (>= netstandard1.1) (< netstandard2.0) (< win8) (< wpa81) (< xamarintvos) (< xamarinwatchos)) (&& (< monoandroid) (< netstandard1.1) (>= portable-net45+win8+wpa81) (< win8)) (&& (< net45) (< netcoreapp2.0) (>= netstandard2.0) (< netstandard2.1) (< xamarinios) (< xamarinmac)) (&& (< netstandard1.1) (>= win8)) (&& (< netstandard2.0) (>= wpa81)) (>= uap10.1) - System.Reflection.Emit.ILGeneration (4.7) - restriction: || (&& (< monoandroid) (< netstandard1.1) (>= netstandard2.0) (< win8)) (&& (< net45) (< netcoreapp2.0) (>= netstandard2.0) (< netstandard2.1) (< xamarinios) (< xamarinmac)) (&& (< netstandard1.1) (>= netstandard2.0) (>= win8)) (&& (>= netstandard2.0) (>= uap10.1)) + System.Reflection.Emit.ILGeneration (>= 4.7) - restriction: || (&& (< monoandroid) (< monotouch) (< net45) (>= netstandard1.1) (< netstandard2.0) (< win8) (< wpa81) (< xamarintvos) (< xamarinwatchos)) (&& (< monoandroid) (< net45) (< netcoreapp2.0) (>= netstandard2.0) (< netstandard2.1) (< xamarinios) (< xamarinmac)) (&& (< monoandroid) (< netstandard1.1) (>= portable-net45+win8+wpa81) (< win8)) (&& (< netstandard1.1) (>= win8)) (&& (< netstandard2.0) (>= wpa81)) (>= uap10.1) + System.Reflection.Emit.ILGeneration (4.7) - restriction: || (&& (< monoandroid) (< net45) (< netcoreapp2.0) (>= netstandard2.0) (< netstandard2.1) (< xamarinios) (< xamarinmac)) (&& (< monoandroid) (< netstandard1.1) (>= netstandard2.0) (< win8)) (&& (< netstandard1.1) (>= netstandard2.0) (>= win8)) (&& (>= netstandard2.0) (>= uap10.1)) System.Reflection.Metadata (1.8) - restriction: || (>= net461) (>= netstandard2.0) System.Collections.Immutable (>= 1.7) - restriction: || (>= net45) (&& (< netcoreapp3.1) (>= netstandard2.0)) (&& (>= netstandard1.1) (< netstandard2.0) (< win8) (< wpa81)) (&& (< netstandard1.1) (>= portable-net45+win8+wpa81) (< win8)) (&& (< netstandard1.1) (>= win8)) (&& (< netstandard2.0) (>= wpa81)) System.Reflection.Primitives (4.3) - restriction: || (&& (< monoandroid) (< net45) (< netstandard1.3) (>= netstandard2.0) (< win8) (< wpa81)) (&& (< monoandroid) (< net45) (< netstandard1.5) (>= netstandard2.0) (< win8) (< wpa81)) (&& (< monoandroid) (< net45) (>= netstandard2.0) (< win8) (< wpa81) (< xamarinios) (< xamarinmac)) @@ -67,7 +70,7 @@ NUGET System.Runtime (4.3.1) - restriction: || (&& (< monoandroid) (< net45) (< netstandard1.3) (>= netstandard2.0) (< win8) (< wpa81)) (&& (< monoandroid) (< net45) (< netstandard1.5) (>= netstandard2.0) (< win8) (< wpa81)) (&& (< monoandroid) (< net45) (>= netstandard2.0) (< win8) (< wpa81) (< xamarinios) (< xamarinmac)) (&& (< monoandroid) (< net461) (>= netstandard2.0) (< xamarinios) (< xamarinmac)) Microsoft.NETCore.Platforms (>= 1.1.1) - restriction: || (&& (< monoandroid) (< monotouch) (< net45) (>= netstandard1.5) (< win8) (< wpa81) (< xamarinios) (< xamarinmac) (< xamarintvos) (< xamarinwatchos)) (&& (< monoandroid) (< net45) (>= netstandard1.0) (< netstandard1.2) (< win8) (< wp8)) (&& (< monoandroid) (< net45) (>= netstandard1.2) (< netstandard1.3) (< win8) (< wpa81)) (&& (< monoandroid) (< net45) (>= netstandard1.3) (< netstandard1.5) (< win8) (< wpa81)) Microsoft.NETCore.Targets (>= 1.1.3) - restriction: || (&& (< monoandroid) (< monotouch) (< net45) (>= netstandard1.5) (< win8) (< wpa81) (< xamarinios) (< xamarinmac) (< xamarintvos) (< xamarinwatchos)) (&& (< monoandroid) (< net45) (>= netstandard1.0) (< netstandard1.2) (< win8) (< wp8)) (&& (< monoandroid) (< net45) (>= netstandard1.2) (< netstandard1.3) (< win8) (< wpa81)) (&& (< monoandroid) (< net45) (>= netstandard1.3) (< netstandard1.5) (< win8) (< wpa81)) - System.Runtime.CompilerServices.Unsafe (4.7.1) - restriction: || (&& (< monoandroid) (< netstandard1.1) (>= netstandard2.0) (< win8)) (&& (>= monotouch) (>= netstandard2.0)) (&& (< net45) (< netcoreapp2.0) (>= netstandard2.0)) (>= net461) (&& (>= netcoreapp2.0) (< netcoreapp2.1)) (&& (< netstandard1.1) (>= netstandard2.0) (>= win8)) (&& (>= netstandard2.0) (>= uap10.1)) (&& (>= netstandard2.0) (>= xamarintvos)) (&& (>= netstandard2.0) (>= xamarinwatchos)) (>= xamarinios) (>= xamarinmac) + System.Runtime.CompilerServices.Unsafe (4.7.1) - restriction: || (&& (>= monoandroid) (>= netstandard2.0)) (&& (>= monotouch) (>= netstandard2.0)) (&& (< net45) (< netcoreapp2.0) (>= netstandard2.0)) (>= net461) (&& (>= netcoreapp2.0) (< netcoreapp2.1)) (&& (< netstandard1.1) (>= netstandard2.0) (>= win8)) (&& (< netstandard1.1) (>= netstandard2.0) (< win8)) (&& (>= netstandard2.0) (>= uap10.1)) (&& (>= netstandard2.0) (>= xamarintvos)) (&& (>= netstandard2.0) (>= xamarinwatchos)) (>= xamarinios) (>= xamarinmac) System.Runtime.Loader (4.3) - restriction: && (< net461) (>= netstandard2.0) System.IO (>= 4.3) - restriction: && (< monoandroid) (< monotouch) (< net462) (>= netstandard1.5) (< xamarinios) (< xamarinmac) (< xamarintvos) (< xamarinwatchos) System.Reflection (>= 4.3) - restriction: && (< monoandroid) (< monotouch) (< net462) (>= netstandard1.5) (< xamarinios) (< xamarinmac) (< xamarintvos) (< xamarinwatchos) @@ -75,8 +78,8 @@ NUGET System.Security.AccessControl (4.7) - restriction: >= netstandard2.0 Microsoft.NETCore.Platforms (>= 3.1) - restriction: >= netcoreapp2.0 System.Security.Principal.Windows (>= 4.7) - restriction: || (&& (>= net46) (< netstandard2.0)) (&& (< net46) (>= netstandard1.3) (< netstandard2.0) (< uap10.1)) (&& (< net46) (>= netstandard2.0)) (>= net461) (>= netcoreapp2.0) - System.Security.Cryptography.ProtectedData (4.7) - restriction: && (< net461) (>= netstandard2.0) (< xamarinios) (< xamarinmac) - System.Memory (>= 4.5.3) - restriction: && (< net46) (< netcoreapp2.1) (>= netstandard2.0) (< xamarinios) (< xamarinmac) + System.Security.Cryptography.ProtectedData (4.7) - restriction: && (< monoandroid) (< net461) (>= netstandard2.0) (< xamarinios) (< xamarinmac) + System.Memory (>= 4.5.3) - restriction: && (< monoandroid) (< net46) (< netcoreapp2.1) (>= netstandard2.0) (< xamarinios) (< xamarinmac) System.Security.Permissions (4.7) - restriction: >= netstandard2.0 System.Security.AccessControl (>= 4.7) - restriction: || (>= net461) (>= netstandard2.0) System.Windows.Extensions (>= 4.7) - restriction: >= netcoreapp3.0 diff --git a/src/Fornax/Fornax.fs b/src/Fornax/Fornax.fs index 303258c..462f76d 100644 --- a/src/Fornax/Fornax.fs +++ b/src/Fornax/Fornax.fs @@ -8,6 +8,7 @@ open Suave open Suave.Filters open Suave.Operators +open LibGit2Sharp open Suave.Sockets open Suave.Sockets.Control open Suave.WebSocket @@ -33,8 +34,18 @@ with match s with | Port _ -> "Specify a custom port (default: 8080)" +type [] NewOptions = + | [] Template of string + | [] Output of string +with + interface IArgParserTemplate with + member s.Usage = + match s with + | Template _ -> "Specify a template from an HTTPS git repo or local folder" + | Output _ -> "Specify an output folder" + type [] Arguments = - | New + | New of ParseResults | Build | Watch of ParseResults | Version @@ -43,7 +54,7 @@ with interface IArgParserTemplate with member s.Usage = match s with - | New -> "Create new web site" + | New _ -> "Create new web site" | Build -> "Build web site" | Watch _ -> "Start watch mode rebuilding " | Version -> "Print version" @@ -100,6 +111,44 @@ let getWebServerConfig port = | None -> defaultConfig +let getOutputDirectory (output : option) (cwd : string) = + match output with + | Some output -> + output + | None -> + cwd + +let deleteGit (gitDirectory : string) = + let test = Directory.Exists gitDirectory + + match test with + | true -> Directory.Delete(gitDirectory, true) + | false -> () + +let copyDirectories (input : string) (output : string) = + // Copy the folders from the template directory into the current folder. + Directory.GetDirectories(input, "*", SearchOption.AllDirectories) + |> Seq.iter (fun p -> Directory.CreateDirectory(p.Replace(input, output)) |> ignore) + + // Copy the files from the template directory into the current folder. + Directory.GetFiles(input, "*.*", SearchOption.AllDirectories) + |> Seq.iter (fun p -> File.Copy(p, p.Replace(input, output))) + +let handleTemplate (template : option) (outputDirectory : string) : unit = + match template with + | Some template -> + let uriTest, _ = Uri.TryCreate(template, UriKind.Absolute) + + match uriTest with + | true -> Repository.Clone(template, outputDirectory) |> ignore + Path.Combine(outputDirectory, ".git") |> deleteGit + | false -> copyDirectories template outputDirectory + Path.Combine(outputDirectory, ".git") |> deleteGit + | None -> + // The default path of the directory that holds the scaffolding for a new website. + let path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "blogTemplate") + copyDirectories path outputDirectory + let router basePath = choose [ path "/" >=> Redirection.redirect "/index.html" @@ -126,31 +175,27 @@ let main argv = let cwd = Directory.GetCurrentDirectory () match result with - | Some New -> - // The path of the directory that holds the scaffolding for a new website. - let newTemplateDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "blogTemplate") + | Some (New newOptions) -> + Console.WriteLine(newOptions) // The path of Fornax.Core.dll, which is located where the dotnet tool is installed. let corePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Fornax.Core.dll") - // Copy the folders from the template directory into the current folder. - Directory.GetDirectories(newTemplateDir, "*", SearchOption.AllDirectories) - |> Seq.iter (fun p -> Directory.CreateDirectory(p.Replace(newTemplateDir, cwd)) |> ignore) + // Parse output flag and create a folder in the cwd to copy files to + let outputDirectory = getOutputDirectory (newOptions.TryPostProcessResult(<@ Output @>, string)) cwd - // Copy the files from the template directory into the current folder. - Directory.GetFiles(newTemplateDir, "*.*", SearchOption.AllDirectories) - |> Seq.iter (fun p -> File.Copy(p, p.Replace(newTemplateDir, cwd))) + // Handle the template used to scaffold a new website + handleTemplate (newOptions.TryPostProcessResult(<@ Template @>, string)) (outputDirectory) - // Create the _bin directory in the current folder. It holds + // Create the _lib directory in the current folder. It holds // Fornax.Core.dll, which is used to provide Intellisense/autocomplete // in the .fsx files. - Directory.CreateDirectory(Path.Combine(cwd, "_lib")) |> ignore - - // Copy the Fornax.Core.dll into _bin - File.Copy(corePath, "./_lib/Fornax.Core.dll") + Directory.CreateDirectory(Path.Combine(outputDirectory, "_lib")) |> ignore + // Copy the Fornax.Core.dll into _lib + // Some/most times Fornax.Core.dll already exists + File.Copy(corePath, outputDirectory + "/_lib/Fornax.Core.dll", true) printfn "New project successfully created." - 0 | Some Build -> try diff --git a/src/Fornax/Fornax.fsproj b/src/Fornax/Fornax.fsproj index 1420c17..00ccc8a 100644 --- a/src/Fornax/Fornax.fsproj +++ b/src/Fornax/Fornax.fsproj @@ -12,11 +12,7 @@ - + diff --git a/src/Fornax/paket.references b/src/Fornax/paket.references index d378c19..dbbacf8 100644 --- a/src/Fornax/paket.references +++ b/src/Fornax/paket.references @@ -2,4 +2,5 @@ FSharp.Core Argu Suave FSharp.Compiler.Service -FSharp.Quotations.Evaluator \ No newline at end of file +FSharp.Quotations.Evaluator +LibGit2Sharp \ No newline at end of file From 79d421244057f7534fabc3465052199b19271c26 Mon Sep 17 00:00:00 2001 From: Drew Knab Date: Sun, 30 Aug 2020 10:57:33 -0400 Subject: [PATCH 2/2] Change after testing on Windows Directory.Delete throws exception on files with read-only attribute. --- src/Fornax/Fornax.fs | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/Fornax/Fornax.fs b/src/Fornax/Fornax.fs index 462f76d..d8eec03 100644 --- a/src/Fornax/Fornax.fs +++ b/src/Fornax/Fornax.fs @@ -118,11 +118,22 @@ let getOutputDirectory (output : option) (cwd : string) = | None -> cwd +// Recursively unset read-only attributes inside a folder +// Like, say, .git +let normalizeFiles directory = + Directory.GetFiles(directory, "*.*", SearchOption.AllDirectories) + |> Seq.iter (fun path -> File.SetAttributes(path, FileAttributes.Normal)) + + directory + +let deleteDirectory directory = + Directory.Delete(directory, true) + let deleteGit (gitDirectory : string) = let test = Directory.Exists gitDirectory match test with - | true -> Directory.Delete(gitDirectory, true) + | true -> gitDirectory |> normalizeFiles |> deleteDirectory | false -> () let copyDirectories (input : string) (output : string) = @@ -176,8 +187,6 @@ let main argv = match result with | Some (New newOptions) -> - Console.WriteLine(newOptions) - // The path of Fornax.Core.dll, which is located where the dotnet tool is installed. let corePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Fornax.Core.dll") @@ -190,7 +199,9 @@ let main argv = // Create the _lib directory in the current folder. It holds // Fornax.Core.dll, which is used to provide Intellisense/autocomplete // in the .fsx files. - Directory.CreateDirectory(Path.Combine(outputDirectory, "_lib")) |> ignore + Path.Combine(outputDirectory, "_lib") + |> Directory.CreateDirectory + |> ignore // Copy the Fornax.Core.dll into _lib // Some/most times Fornax.Core.dll already exists