Skip to content

Commit 0945cb3

Browse files
authored
Merge pull request #474 from Inxton/473-styling-should-be-confined-into-a-single-depenency
Styling should be confined into a single depenency
2 parents 44c9e86 + e4cf7f5 commit 0945cb3

File tree

16 files changed

+1197
-3093
lines changed

16 files changed

+1197
-3093
lines changed

Directory.Packages.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
<!-- Framework-Agnostic Packages -->
1717
<ItemGroup>
18-
<PackageVersion Include="Inxton.Operon" Version="0.2.0-alpha.94" />
18+
<PackageVersion Include="Inxton.Operon" Version="0.3.0-alpha.99" />
1919
<PackageVersion Include="Cake.DocFx" Version="1.0.0" />
2020
<PackageVersion Include="Octokit" Version="13.0.1" />
2121
<PackageVersion Include="Octokit.Extensions" Version="1.0.7" />

cake/BuildContext.cs

Lines changed: 100 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,6 @@
55
// https://github.com/inxton/axsharp/blob/dev/LICENSE
66
// Third party licenses: https://github.com/inxton/axsharp/blob/master/notices.md
77

8-
using System;
9-
using System.Collections.Generic;
10-
using System.IO;
11-
using System.IO.Compression;
12-
using System.Linq;
138
using Build.FilteredSolution;
149
using Cake.Common.IO;
1510
using Cake.Common.Tools.DotNet;
@@ -22,9 +17,15 @@
2217
using Cake.Core.Diagnostics;
2318
using Cake.Core.IO;
2419
using Cake.Frosting;
20+
using Polly;
21+
using System;
22+
using System.Collections.Generic;
2523
using System.Formats.Tar;
24+
using System.IO;
2625
using System.IO.Compression;
27-
using Polly;
26+
using System.IO.Compression;
27+
using System.Linq;
28+
using System.Runtime.InteropServices;
2829
using static NuGet.Packaging.PackagingConstants;
2930
using Path = System.IO.Path;
3031

@@ -189,7 +190,99 @@ public void PushNugetPackages(string artifactDirectory)
189190
public string ApaxSignKey { get; set; } = System.Environment.GetEnvironmentVariable("APAX_KEY");
190191
public string GitHubUser { get; set; } = System.Environment.GetEnvironmentVariable("GH_USER");
191192
public string GitHubToken { get; set; } = System.Environment.GetEnvironmentVariable("GH_TOKEN");
192-
193+
194+
internal void ProvisionNodeJs()
195+
{
196+
// Check if node is available
197+
var nodeCommand = RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? "node" : "node.exe";
198+
var npmCommand = RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? "npm" : "npm.cmd";
199+
200+
try
201+
{
202+
var nodeProcess = ProcessRunner.Start(nodeCommand, new ProcessSettings()
203+
{
204+
Arguments = "--version",
205+
RedirectStandardOutput = true,
206+
RedirectStandardError = true,
207+
Silent = true
208+
});
209+
210+
nodeProcess.WaitForExit();
211+
212+
if (nodeProcess.GetExitCode() == 0)
213+
{
214+
var version = string.Join("", nodeProcess.GetStandardOutput());
215+
Log.Information($"Node.js is already installed: {version.Trim()}");
216+
return;
217+
}
218+
}
219+
catch (Exception ex)
220+
{
221+
Log.Warning($"Node.js not found or failed to execute: {ex.Message}");
222+
}
223+
224+
// Node.js is not available, provision it
225+
Log.Information("Node.js not found. Provisioning Node.js...");
226+
227+
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
228+
{
229+
// Use winget to install Node.js on Windows
230+
Log.Information("Attempting to install Node.js using winget...");
231+
var wingetProcess = ProcessRunner.Start("winget", new ProcessSettings()
232+
{
233+
Arguments = "install OpenJS.NodeJS.LTS --accept-source-agreements --accept-package-agreements",
234+
RedirectStandardOutput = false,
235+
RedirectStandardError = false,
236+
Silent = false
237+
});
238+
239+
wingetProcess.WaitForExit();
240+
241+
if (wingetProcess.GetExitCode() != 0)
242+
{
243+
Log.Warning("winget installation failed. Trying Chocolatey...");
244+
245+
// Fallback to Chocolatey
246+
var chocoProcess = ProcessRunner.Start("choco", new ProcessSettings()
247+
{
248+
Arguments = "install nodejs-lts -y",
249+
RedirectStandardOutput = false,
250+
RedirectStandardError = false,
251+
Silent = false
252+
});
253+
254+
chocoProcess.WaitForExit();
255+
256+
if (chocoProcess.GetExitCode() != 0)
257+
{
258+
throw new Exception("Failed to provision Node.js. Please install Node.js manually from https://nodejs.org/");
259+
}
260+
}
261+
}
262+
else
263+
{
264+
// Linux - use package manager or nvm
265+
Log.Information("Attempting to install Node.js on Linux...");
266+
267+
// Try using apt (Debian/Ubuntu)
268+
var aptProcess = ProcessRunner.Start("bash", new ProcessSettings()
269+
{
270+
Arguments = "-c \"curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash - && sudo apt-get install -y nodejs\"",
271+
RedirectStandardOutput = false,
272+
RedirectStandardError = false,
273+
Silent = false
274+
});
275+
276+
aptProcess.WaitForExit();
277+
278+
if (aptProcess.GetExitCode() != 0)
279+
{
280+
throw new Exception("Failed to provision Node.js on Linux. Please install Node.js manually.");
281+
}
282+
}
283+
284+
Log.Information("Node.js provisioning completed.");
285+
}
193286

194287

195288
public IEnumerable<(string ax, string approject, string solution)> GetTemplateProjects()

cake/Program.cs

Lines changed: 86 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,7 @@
66
// https://github.com/inxton/axsharp/blob/dev/LICENSE
77
// Third party licenses: https://github.com/inxton/axsharp/blob/master/notices.md
88

9-
using System;
10-
using System.Collections.Generic;
11-
using System.Diagnostics.Contracts;
12-
using System.IO;
13-
using System.IO.Compression;
14-
using System.IO.Packaging;
15-
using System.Linq;
16-
using System.Management.Automation;
17-
using System.Net;
18-
using System.Text;
19-
using System.Threading.Tasks;
9+
using AXSharp.nuget.update;
2010
using Build.FilteredSolution;
2111
using Cake.Common;
2212
using Cake.Common.IO;
@@ -31,15 +21,26 @@
3121
using Cake.Powershell;
3222
using CliWrap;
3323
using CommandLine;
34-
using AXSharp.nuget.update;
3524
using Microsoft.Extensions.DependencyInjection;
3625
using NuGet.Packaging;
3726
using Octokit;
3827
using Polly;
28+
using System;
29+
using System.Collections.Generic;
30+
using System.Diagnostics;
31+
using System.Diagnostics.Contracts;
32+
using System.IO;
33+
using System.IO.Compression;
34+
using System.IO.Packaging;
35+
using System.Linq;
36+
using System.Management.Automation;
37+
using System.Net;
38+
using System.Text;
39+
using System.Threading.Tasks;
40+
using static NuGet.Packaging.PackagingConstants;
3941
using Credentials = Octokit.Credentials;
4042
using Path = System.IO.Path;
4143
using ProductHeaderValue = Octokit.ProductHeaderValue;
42-
using static NuGet.Packaging.PackagingConstants;
4344

4445

4546
public static class Program
@@ -85,6 +86,7 @@ public override void Run(BuildContext context)
8586
});
8687

8788
ProvisionProjectWideTools(context);
89+
context.ProvisionNodeJs();
8890
}
8991

9092
private static void ProvisionProjectWideTools(BuildContext context)
@@ -119,7 +121,7 @@ private static void ProvisionProjectWideTools(BuildContext context)
119121
public sealed class BuildTask : FrostingTask<BuildContext>
120122
{
121123
public override void Run(BuildContext context)
122-
{
124+
{
123125
context.DotNetBuild(Path.Combine(context.ScrDir, "AXSharp.compiler\\src\\ixc\\AXSharp.ixc.csproj"), context.DotNetBuildSettings);
124126

125127
var axprojects = new List<string>()
@@ -142,9 +144,79 @@ public override void Run(BuildContext context)
142144
context.DotNetRun(Path.Combine(context.ScrDir, "AXSharp.compiler\\src\\ixc\\AXSharp.ixc.csproj"), context.DotNetRunSettings);
143145
}
144146

147+
context.DotNetRestore(Path.Combine(context.ScrDir, "AXSharp.sln"));
148+
BuildTailwindCss(context);
145149
context.DotNetBuild(Path.Combine(context.ScrDir, "AXSharp.sln"), context.DotNetBuildSettings);
146150

147151
}
152+
153+
private void BuildTailwindCss(BuildContext context)
154+
{
155+
var stylingFolder = System.IO.Path.Combine(context.RootDir, "AXSharp.blazor", "src", "AXSharp.Presentation.Blazor.Controls");
156+
var nodeModulesFolder = System.IO.Path.Combine(stylingFolder, "node_modules");
157+
158+
context.Log.Information($"Building Tailwind CSS in folder: {stylingFolder}");
159+
160+
// Check if node_modules exists, if not install packages
161+
if (!Directory.Exists(nodeModulesFolder))
162+
{
163+
context.Log.Information("node_modules not found. Installing npm packages...");
164+
var npmInstall = new Process
165+
{
166+
StartInfo = new ProcessStartInfo
167+
{
168+
FileName = "cmd.exe",
169+
Arguments = "/c npm install",
170+
WorkingDirectory = stylingFolder,
171+
UseShellExecute = false,
172+
RedirectStandardOutput = true,
173+
RedirectStandardError = true,
174+
CreateNoWindow = true
175+
}
176+
};
177+
npmInstall.OutputDataReceived += (sender, e) => { if (e.Data != null) Console.WriteLine(e.Data); };
178+
npmInstall.ErrorDataReceived += (sender, e) => { if (e.Data != null) Console.Error.WriteLine(e.Data); };
179+
npmInstall.Start();
180+
npmInstall.BeginOutputReadLine();
181+
npmInstall.BeginErrorReadLine();
182+
npmInstall.WaitForExit();
183+
184+
if (npmInstall.ExitCode != 0)
185+
{
186+
throw new Exception($"npm install failed with exit code {npmInstall.ExitCode}");
187+
}
188+
}
189+
190+
// Run the tailwind build using npx
191+
context.Log.Information("Running Tailwind build...");
192+
var npxBuild = new Process
193+
{
194+
StartInfo = new ProcessStartInfo
195+
{
196+
FileName = "cmd.exe",
197+
Arguments = "/c npx @tailwindcss/cli -i ./wwwroot/css/tailwind.css -o ./wwwroot/css/momentum.css --minify",
198+
WorkingDirectory = stylingFolder,
199+
UseShellExecute = false,
200+
RedirectStandardOutput = true,
201+
RedirectStandardError = true,
202+
CreateNoWindow = true
203+
}
204+
};
205+
npxBuild.OutputDataReceived += (sender, e) => { if (e.Data != null) Console.WriteLine(e.Data); };
206+
npxBuild.ErrorDataReceived += (sender, e) => { if (e.Data != null) Console.Error.WriteLine(e.Data); };
207+
npxBuild.Start();
208+
npxBuild.BeginOutputReadLine();
209+
npxBuild.BeginErrorReadLine();
210+
npxBuild.WaitForExit();
211+
212+
if (npxBuild.ExitCode != 0)
213+
{
214+
throw new Exception($"Tailwind CSS build failed with exit code {npxBuild.ExitCode}");
215+
}
216+
217+
context.Log.Information("Tailwind CSS build completed.");
218+
}
219+
148220
}
149221

150222
[TaskName("Test")]

src/AXSharp.blazor/src/AXSharp.Presentation.Blazor.Controls/AXSharp.Presentation.Blazor.Controls.csproj

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434

3535
<ItemGroup>
3636
<Compile Remove="RenderableContentControl\**" />
37-
<Compile Remove="wwwroot\**" />
3837
</ItemGroup>
3938

4039
<ItemGroup>
@@ -68,16 +67,5 @@
6867
<ItemGroup>
6968
<!-- <ProjectReference Include="..\..\..\..\..\operon\src\Operon\Operon.csproj" /> -->
7069
<ProjectReference Include="..\AXSharp.Presentation.Blazor\AXSharp.Presentation.Blazor.csproj" />
71-
</ItemGroup>
72-
73-
<ItemGroup>
74-
<None Include="Layouts\**\*.*" Pack="true" PackagePath="contentFiles\Layouts\%(RecursiveDir)%(Filename)%(Extension)" CopyToOutputDirectory="PreserveNewest" />
75-
<None Include="Templates\**\*.*" Pack="true" PackagePath="contentFiles\Templates\%(RecursiveDir)%(Filename)%(Extension)" CopyToOutputDirectory="PreserveNewest" />
76-
<None Include="build\AXSharp.Presentation.Blazor.Controls.targets" Pack="true" PackagePath="build\AXSharp.Presentation.Blazor.Controls.targets" CopyToOutputDirectory="PreserveNewest" />
77-
</ItemGroup>
78-
79-
<PropertyGroup>
80-
<DefaultItemExcludes>$(DefaultItemExcludes);temp\**\*</DefaultItemExcludes>
81-
</PropertyGroup>
82-
70+
</ItemGroup>
8371
</Project>

0 commit comments

Comments
 (0)