|
1 | 1 | using Nuke.Common; |
2 | 2 | using Nuke.Common.IO; |
3 | | -using Nuke.Common.ProjectModel; |
4 | 3 | using Nuke.Common.Tooling; |
5 | | -using Nuke.Common.Tools.DotNet; |
6 | | -using Nuke.Common.Tools.MSBuild; |
7 | 4 | using ReactiveUI.Web; |
8 | 5 | using System; |
9 | | -using System.IO; |
10 | | -using System.Linq; |
11 | | -using static Nuke.Common.Tools.DotNet.DotNetTasks; |
12 | 6 |
|
13 | 7 | class Build : NukeBuild |
14 | 8 | { |
15 | | - /// Support plugins are available for: |
16 | | - /// - JetBrains ReSharper https://nuke.build/resharper |
17 | | - /// - JetBrains Rider https://nuke.build/rider |
18 | | - /// - Microsoft VisualStudio https://nuke.build/visualstudio |
19 | | - /// - Microsoft VSCode https://nuke.build/vscode |
20 | | - |
21 | | - public static int Main() => Execute<Build>(x => x.Compile); |
22 | | - |
23 | | - [Parameter("Configuration to build - Default is 'Debug' (local) or 'Release' (server)")] |
24 | | - readonly Configuration Configuration = IsLocalBuild ? Configuration.Debug : Configuration.Release; |
25 | | - |
26 | | - private static readonly string reactiveui = nameof(reactiveui); |
27 | | - private static readonly string akavache = nameof(akavache); |
28 | | - private static readonly string fusillade = nameof(fusillade); |
29 | | - private static readonly string punchclock = nameof(punchclock); |
30 | | - private static readonly string splat = nameof(splat); |
31 | | - private static readonly string DynamicData = nameof(DynamicData); |
32 | | - private static readonly string reactivemarbles = nameof(reactivemarbles); |
33 | | - private static readonly string extensions = nameof(extensions); |
34 | | - private static readonly string[] RxUIProjects = [reactiveui, akavache, fusillade, punchclock, splat, "ReactiveUI.Validation", "ReactiveUI.Avalonia", extensions, "Maui.Plugins.Popup"]; |
35 | | - |
36 | | - private AbsolutePath RxUIAPIDirectory => RootDirectory / reactiveui / "api" / reactiveui; |
37 | | - private AbsolutePath RxMAPIDirectory => RootDirectory / reactiveui / "api" / reactivemarbles; |
| 9 | + public static int Main() => Execute<Build>(x => x.BuildWebsite); |
38 | 10 |
|
| 11 | + private AbsolutePath ApiLibDirectory => RootDirectory / "reactiveui" / "api" / "lib"; |
| 12 | + private AbsolutePath ApiRefsDirectory => RootDirectory / "reactiveui" / "api" / "refs"; |
| 13 | + private AbsolutePath ApiCacheDirectory => RootDirectory / "reactiveui" / "api" / "cache"; |
39 | 14 |
|
40 | 15 | Target Clean => _ => _ |
41 | | - .Before(Restore) |
| 16 | + .Before(FetchPackages) |
42 | 17 | .Executes(() => |
43 | 18 | { |
44 | | - RxUIAPIDirectory.DeleteDirectory(); |
45 | | - RxMAPIDirectory.DeleteDirectory(); |
| 19 | + ApiLibDirectory.DeleteDirectory(); |
| 20 | + ApiRefsDirectory.DeleteDirectory(); |
46 | 21 | // Install docfx |
47 | 22 | ProcessTasks.StartShell("dotnet tool update -g docfx").AssertZeroExitCode(); |
48 | 23 | }); |
49 | 24 |
|
50 | | - Target Restore => _ => _ |
| 25 | + Target FetchPackages => _ => _ |
51 | 26 | .DependsOn(Clean) |
52 | 27 | .Executes(() => |
53 | 28 | { |
54 | | - // Restore ReactiveUI Projects |
55 | | - RxUIAPIDirectory.GetSources(RootDirectory, reactiveui, RxUIProjects); |
56 | | - |
57 | | - // Restore Reactive Marbles Projects |
58 | | - RxMAPIDirectory.GetSources(RootDirectory, reactivemarbles, DynamicData); |
| 29 | + NuGetFetcher.FetchPackages(RootDirectory); |
59 | 30 | }); |
60 | 31 |
|
61 | | - Target Compile => _ => _ |
62 | | - .DependsOn(Restore) |
| 32 | + Target BuildWebsite => _ => _ |
| 33 | + .DependsOn(FetchPackages) |
| 34 | + .Produces(RootDirectory / "reactiveui" / "_site") |
63 | 35 | .Executes(() => |
64 | 36 | { |
65 | | - foreach (var project in RxUIProjects) |
66 | | - { |
67 | | - try |
68 | | - { |
69 | | - var dirRx = RxUIAPIDirectory / "external" / project / $"{project}-main" / "src"; |
70 | | - File.Copy(RootDirectory / "global.json", dirRx / "global.json", true); |
71 | | - var solutionFile = dirRx / $"{project}.sln"; |
72 | | - |
73 | | - // Find any .sln or .slnx file as a fallback |
74 | | - var solutionFileSearch = Directory.EnumerateFiles(dirRx, "*.sln*").FirstOrDefault(); |
75 | | - if (File.Exists(solutionFile) == false) |
76 | | - { |
77 | | - solutionFile += "x"; |
78 | | - if (File.Exists(solutionFile) == false) |
79 | | - { |
80 | | - if (File.Exists(solutionFileSearch)) |
81 | | - { |
82 | | - solutionFile = solutionFileSearch; |
83 | | - } |
84 | | - else |
85 | | - { |
86 | | - SourceFetcher.LogRepositoryError(reactiveui, project, $"Solution file not found: {dirRx / $"{project}.sln(x)"}"); |
87 | | - continue; |
88 | | - } |
89 | | - } |
90 | | - } |
91 | | - |
92 | | - SourceFetcher.LogInfo($"Restoring {solutionFile}..."); |
93 | | - DotNetRestore(s => s.SetProjectFile(solutionFile)); |
94 | | - SourceFetcher.LogInfo($"Building {solutionFile}..."); |
95 | | - DotNetBuild(s => s |
96 | | - .SetProjectFile(solutionFile) |
97 | | - .SetConfiguration(Configuration) |
98 | | - .EnableNoRestore()); |
99 | | - SourceFetcher.LogInfo($"{project} build complete"); |
100 | | - } |
101 | | - catch (Exception ex) |
102 | | - { |
103 | | - SourceFetcher.LogRepositoryError(reactiveui, project, ex.ToString()); |
104 | | - } |
105 | | - } |
106 | | - |
107 | 37 | try |
108 | 38 | { |
109 | | - var dirDd = RxMAPIDirectory / "external" / DynamicData / $"{DynamicData}-main" / "src"; |
110 | | - File.Copy(RootDirectory / "global.json", dirDd / "global.json", true); |
111 | | - var solutionFile = dirDd / $"{DynamicData}.sln"; |
112 | | - if (File.Exists(solutionFile) == false) |
113 | | - { |
114 | | - solutionFile += "x"; |
115 | | - if (File.Exists(solutionFile) == false) |
116 | | - { |
117 | | - SourceFetcher.LogRepositoryError(reactivemarbles, DynamicData, $"Solution file not found: {dirDd / $"{DynamicData}.sln(x)"}"); |
118 | | - return; |
119 | | - } |
120 | | - } |
121 | | - |
122 | | - SourceFetcher.LogInfo($"Building {solutionFile}..."); |
123 | | - MSBuildTasks.MSBuild(s => s |
124 | | - .SetProjectFile(solutionFile) |
125 | | - .SetConfiguration(Configuration) |
126 | | - .SetRestore(true)); |
127 | | - SourceFetcher.LogInfo($"{DynamicData} build complete"); |
| 39 | + NuGetFetcher.PatchDocfxJson(RootDirectory); |
| 40 | + ProcessTasks.StartShell("docfx reactiveui/docfx.json").AssertZeroExitCode(); |
| 41 | + NuGetFetcher.LogInfo("Web Site build complete"); |
128 | 42 | } |
129 | 43 | catch (Exception ex) |
130 | 44 | { |
131 | | - SourceFetcher.LogRepositoryError(reactivemarbles, DynamicData, ex.ToString()); |
| 45 | + NuGetFetcher.LogError(ex.ToString()); |
132 | 46 | } |
133 | 47 | }); |
134 | 48 |
|
135 | | - Target BuildWebsite => _ => _ |
136 | | - .Produces(RootDirectory / reactiveui / "_site") |
137 | | - .Executes(() => |
138 | | - { |
139 | | - try |
140 | | - { |
141 | | - ProcessTasks.StartShell("docfx reactiveui/docfx.json").AssertZeroExitCode(); |
142 | | - SourceFetcher.LogInfo("Web Site build complete"); |
143 | | - } |
144 | | - catch (Exception ex) |
| 49 | + [Parameter("Port for the preview server (default: 8080)")] |
| 50 | + readonly int Port = 8080; |
| 51 | + |
| 52 | + Target Serve => _ => _ |
| 53 | + .DependsOn(BuildWebsite) |
| 54 | + .Executes(() => |
145 | 55 | { |
146 | | - SourceFetcher.LogError(ex.ToString()); |
147 | | - } |
148 | | - }); |
| 56 | + NuGetFetcher.LogInfo($"Serving website at http://localhost:{Port}"); |
| 57 | + ProcessTasks.StartShell($"docfx serve reactiveui/_site -p {Port}").AssertZeroExitCode(); |
| 58 | + }); |
149 | 59 | } |
0 commit comments