Skip to content

Commit

Permalink
fsxc: refactoring (DRY)
Browse files Browse the repository at this point in the history
Tiny DRY-respect improvement.
  • Loading branch information
knocte committed Sep 5, 2024
1 parent bc3acc4 commit 2b8bf4f
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions fsxc/Fsxc.fs
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,17 @@ let fsi = { CommandLineArgs = System.Environment.GetCommandLineArgs() }
: FileInfo =
let projectFile = GetAutoGenerationTargets origScript "fsproj"

let addFile relativeOrAbsoluteFilePath =
let fsProjFragment =
sprintf
"<ItemGroup><Compile Include=\"%s\" /></ItemGroup>"
relativeOrAbsoluteFilePath

File.AppendAllText(
projectFile.FullName,
fsProjFragment + Environment.NewLine
)

let rec iterate(lines: List<LineAction>) : unit =
match lines with
| head :: tail ->
Expand Down Expand Up @@ -741,16 +752,13 @@ let fsi = { CommandLineArgs = System.Environment.GetCommandLineArgs() }
+ Environment.NewLine
)
| PreProcessorAction.Load fileName ->
let fsProjFragment =
addFile(
sprintf
"<ItemGroup><Compile Include=\"..%c%s\" /></ItemGroup>"
"..%c%s"
Path.DirectorySeparatorChar
fileName

File.AppendAllText(
projectFile.FullName,
fsProjFragment + Environment.NewLine
)

| PreProcessorAction.Ref refName ->
let fsProjFragment =
if refName.ToLower().EndsWith(".dll") then
Expand Down Expand Up @@ -797,13 +805,9 @@ let fsi = { CommandLineArgs = System.Environment.GetCommandLineArgs() }

iterate contents

File.AppendAllText(
projectFile.FullName,
"<ItemGroup>
<Compile Include=\"{userScriptFileName}.fs\" />
</ItemGroup></Project>"
.Replace("{userScriptFileName}", origScript.Name)
)
addFile (sprintf "%s.fs" origScript.Name)

File.AppendAllText(projectFile.FullName, "</Project>")

projectFile
#endif
Expand Down

0 comments on commit 2b8bf4f

Please sign in to comment.