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 a0c2077
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions fsxc/Fsxc.fs
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,18 @@ let fsi = { CommandLineArgs = System.Environment.GetCommandLineArgs() }
: FileInfo =
let projectFile = GetAutoGenerationTargets origScript "fsproj"

let addFile fileName =
let fsProjFragment =
sprintf
"<ItemGroup><Compile Include=\"..%c%s\" /></ItemGroup>"
Path.DirectorySeparatorChar
fileName

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

let rec iterate(lines: List<LineAction>) : unit =
match lines with
| head :: tail ->
Expand Down Expand Up @@ -740,17 +752,8 @@ let fsi = { CommandLineArgs = System.Environment.GetCommandLineArgs() }
+ fsprojFragmentEnd
+ Environment.NewLine
)
| PreProcessorAction.Load fileName ->
let fsProjFragment =
sprintf
"<ItemGroup><Compile Include=\"..%c%s\" /></ItemGroup>"
Path.DirectorySeparatorChar
fileName
| PreProcessorAction.Load fileName -> addFile 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 +800,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 origScript.Name

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

projectFile
#endif
Expand Down

0 comments on commit a0c2077

Please sign in to comment.