|
| 1 | +#!/usr/bin/env -S dotnet fsi |
| 2 | + |
| 3 | +open System |
| 4 | +open System.IO |
| 5 | + |
| 6 | +#r "nuget: Fsdk, Version=0.6.0--date20230214-0422.git-1ea6f62" |
| 7 | + |
| 8 | +open Fsdk |
| 9 | + |
| 10 | +#load "../src/FileConventions/Helpers.fs" |
| 11 | + |
| 12 | +let version = "4.7.997-prerelease" |
| 13 | + |
| 14 | +let args = Fsdk.Misc.FsxOnlyArguments() |
| 15 | + |
| 16 | +match args with |
| 17 | +| [] -> () |
| 18 | +| _ -> |
| 19 | + failwithf |
| 20 | + "Too many arguments (this script doesn't receive any arguments): %A" |
| 21 | + args |
| 22 | + |
| 23 | +let rootDir = Path.Combine(__SOURCE_DIRECTORY__, "..") |> DirectoryInfo |
| 24 | +let currentDir = Directory.GetCurrentDirectory() |> DirectoryInfo |
| 25 | + |
| 26 | +let targetDir, _ = Helpers.PreferLessDeeplyNestedDir currentDir rootDir |
| 27 | + |
| 28 | +let formattingConfigFileName = ".editorconfig" |
| 29 | + |
| 30 | +let formattingDefaultConfigFile = |
| 31 | + Path.Combine(rootDir.FullName, formattingConfigFileName) |> FileInfo |
| 32 | + |
| 33 | +let formattingConfigFileInTargetDir = |
| 34 | + Path.Combine(targetDir.FullName, formattingConfigFileName) |> FileInfo |
| 35 | + |
| 36 | +if formattingDefaultConfigFile.Exists |
| 37 | + && not formattingConfigFileInTargetDir.Exists then |
| 38 | + formattingDefaultConfigFile.CopyTo( |
| 39 | + formattingConfigFileInTargetDir.FullName, |
| 40 | + false |
| 41 | + ) |
| 42 | + |> ignore<FileInfo> |
| 43 | + |
| 44 | +let formattingConfigFileInCurrentDir = |
| 45 | + Path.Combine(currentDir.FullName, formattingConfigFileName) |> FileInfo |
| 46 | + |
| 47 | +if formattingDefaultConfigFile.Exists |
| 48 | + && not formattingConfigFileInCurrentDir.Exists then |
| 49 | + formattingDefaultConfigFile.CopyTo( |
| 50 | + formattingConfigFileInCurrentDir.FullName, |
| 51 | + false |
| 52 | + ) |
| 53 | + |> ignore<FileInfo> |
| 54 | + |
| 55 | +Fsdk |
| 56 | + .Process |
| 57 | + .Execute( |
| 58 | + { |
| 59 | + Command = "dotnet" |
| 60 | + Arguments = sprintf "new tool-manifest --force" |
| 61 | + }, |
| 62 | + Fsdk.Process.Echo.All |
| 63 | + ) |
| 64 | + .UnwrapDefault() |
| 65 | +|> ignore<string> |
| 66 | + |
| 67 | +Fsdk |
| 68 | + .Process |
| 69 | + .Execute( |
| 70 | + { |
| 71 | + Command = "dotnet" |
| 72 | + Arguments = |
| 73 | + sprintf "tool install fantomless-tool --version %s" version |
| 74 | + }, |
| 75 | + Fsdk.Process.Echo.All |
| 76 | + ) |
| 77 | + .UnwrapDefault() |
| 78 | +|> ignore<string> |
| 79 | + |
| 80 | +Fsdk |
| 81 | + .Process |
| 82 | + .Execute( |
| 83 | + { |
| 84 | + Command = "dotnet" |
| 85 | + Arguments = sprintf "fantomless --recurse %s" targetDir.FullName |
| 86 | + }, |
| 87 | + Fsdk.Process.Echo.All |
| 88 | + ) |
| 89 | + .UnwrapDefault() |
| 90 | +|> ignore<string> |
| 91 | + |
| 92 | +// If this is run in a GitHub Actions environment, check for changes |
| 93 | +if not String.IsNullOrWhitespace(Environment.GetEnvironmentVariable "GITHUB_EVENT_PATH") then |
| 94 | + Fsdk |
| 95 | + .Process |
| 96 | + .Execute( |
| 97 | + { |
| 98 | + Command = "git" |
| 99 | + Arguments = "diff --exit-code" |
| 100 | + }, |
| 101 | + Fsdk.Process.Echo.All |
| 102 | + ) |
| 103 | + .UnwrapDefault() |
| 104 | + |> ignore<string> |
0 commit comments