-
Notifications
You must be signed in to change notification settings - Fork 1
/
combineIntoOneFile.fsx
122 lines (80 loc) · 3.61 KB
/
combineIntoOneFile.fsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
(*
This script combines several files into AutoGeneratedCode/AllScriptingFilesCombinedIntoOne_DontEditThisFile.fs before compiling.
the generated file gets deleted after compiling
this must be in fsproj file:
<!-- Combine all files of the rhinoscriptingsyntax into one: https://stackoverflow.com/a/44829863/969070 -->
<Target Name="GenerateSomeFiles" BeforeTargets="BeforeBuild">
<Exec Command="dotnet fsi combineIntoOneFile.fsx" />
<ItemGroup> <Compile Include="Src/AutoGeneratedCode/AllScriptingFilesCombinedIntoOne_DontEditThisFile.fs" /> </ItemGroup>
</Target>
<!-- Delete AutoGeneratedCode/AllScriptingFilesCombinedIntoOne_DontEditThisFile.fs when done-->
<Target Name="DeleteMergedFile" BeforeTargets="AfterBuild"> <Delete Files="Src/AutoGeneratedCode/AllScriptingFilesCombinedIntoOne_DontEditThisFile.fs" TreatErrorsAsWarnings="true" /> </Target>
*)
module CombineIntoOneFile =
open System
let splitMarker = "{@$%^&*()*&^%$@}"
let head = "Src/Scripting_Header.fs"
let files = [
"Src/Scripting_Coerce.fs"
"Src/Scripting_Layer.fs"
"Src/Scripting_Application.fs"
"Src/Scripting_Block.fs"
"Src/Scripting_Curve.fs"
"Src/Scripting_Dimension.fs"
"Src/Scripting_Document.fs"
"Src/Scripting_Geometry.fs"
"Src/Scripting_Grips.fs"
"Src/Scripting_Group.fs"
"Src/Scripting_Hatch.fs"
"Src/Scripting_Light.fs"
"Src/Scripting_Line.fs"
"Src/Scripting_Linetype.fs"
"Src/Scripting_Material.fs"
"Src/Scripting_Mesh.fs"
"Src/Scripting_Object.fs"
"Src/Scripting_Plane.fs"
"Src/Scripting_PointVector.fs"
"Src/Scripting_Selection.fs"
"Src/Scripting_Surface.fs"
"Src/Scripting_Toolbar.fs"
"Src/Scripting_Transformation.fs"
"Src/Scripting_UserData.fs"
"Src/Scripting_UserInterface.fs"
"Src/Scripting_Utility.fs"
"Src/Scripting_Views.fs"
]
let getLines(p:string) =
if IO.File.Exists p then
IO.File.ReadAllLines p
else
eprintfn "*!*!*!*!*!* ERROR in build script "
eprintfn "*!*!*!*!*!* File %s NOT found in CurrentDirectory: %s" p Environment.CurrentDirectory
eprintfn "*!*!*!*!*!* ERROR in build script "
[| |]
let afterMarker file (lns:string []) :seq<string> =
match lns |> Array.tryFindIndex( fun ln -> ln.Contains splitMarker) with
|Some i ->
//lns.[i+1 .. ] // |> Array.map (addNote file)
Seq.skip i lns
|None ->
eprintfn "*!*!*!*!*!* ERROR in build script "
eprintfn "*!*!*!*!*!* Split marker %s NOT found in %s !" splitMarker file
eprintfn "*!*!*!*!*!* ERROR in build script "
Seq.empty
let run() =
let lines = ResizeArray<string>()
// Start merging files:
lines.AddRange(getLines head)
printfn "--Pre Build Step:"
printf "--Combine all files of Src/Scripting_****.fs into one:"
for i, file in files |> Seq.indexed do
let n = file.Replace("Src/Scripting_", " ")
lines.AddRange(file|> getLines |> afterMarker file)
if i%7 =0 then
printf "\r\n -- %s" n
else
printf " %s" n
printfn ""
IO.File.WriteAllLines("Src/AutoGeneratedCode/AllScriptingFilesCombinedIntoOne_DontEditThisFile.fs", lines, Text.Encoding.UTF8)
printfn "--Done combining files into Src/AutoGeneratedCode/AllScriptingFilesCombinedIntoOne_DontEditThisFile.fs. compiling now .."
CombineIntoOneFile.run()