├── .github └── workflows │ └── dotnet.yml ├── .gitignore ├── LICENSE ├── Tailwind ├── .config │ └── dotnet-tools.json ├── .idea │ └── .idea.Tailwind │ │ └── .idea │ │ ├── .gitignore │ │ ├── indexLayout.xml │ │ └── vcs.xml ├── App │ ├── DefaultTailwindCommand.cs │ ├── InitTailwindCommand.cs │ ├── ProjectService.cs │ ├── RemoveTailwindCommand.cs │ ├── RemoveTailwindSettings.cs │ ├── SdkHelper.cs │ ├── TailwindConfigurationService.cs │ ├── TailwindSettings.cs │ └── UpdateTailwindCommand.cs ├── Program.cs ├── Properties │ └── launchSettings.json ├── Tailwind.csproj ├── Tailwind.sln ├── Templates │ └── TailwindConfigTemplates.cs └── readme.md └── readme.md /.github/workflows/dotnet.yml: -------------------------------------------------------------------------------- 1 | # This workflow will build a .NET project 2 | # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net 3 | 4 | name: .NET 5 | 6 | on: 7 | push: 8 | branches: [ "main" ] 9 | pull_request: 10 | branches: [ "main" ] 11 | 12 | jobs: 13 | build: 14 | 15 | runs-on: ubuntu-latest 16 | 17 | steps: 18 | - uses: actions/checkout@v4 19 | - name: Setup .NET 20 | uses: actions/setup-dotnet@v4 21 | with: 22 | dotnet-version: 8.0.x 23 | - name: Restore dependencies 24 | run: dotnet restore Tailwind 25 | - name: Build 26 | run: dotnet build Tailwind --no-restore 27 | - name: Test 28 | run: dotnet test Tailwind --no-build --verbosity normal 29 | 30 | - name: Publish to NuGet 31 | if: ${{ github.ref == 'refs/heads/main' }} 32 | run: dotnet nuget push --skip-duplicate --api-key ${{secrets.TAILWIND_NUGET_KEY}} --source 'https://api.nuget.org/v3/index.json' ${{github.workspace}}/Tailwind/**/Tailwind.*.nupkg 33 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Mono auto generated files 17 | mono_crash.* 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | [Rr]eleases/ 24 | x64/ 25 | x86/ 26 | [Ww][Ii][Nn]32/ 27 | [Aa][Rr][Mm]/ 28 | [Aa][Rr][Mm]64/ 29 | bld/ 30 | [Bb]in/ 31 | [Oo]bj/ 32 | [Ll]og/ 33 | [Ll]ogs/ 34 | 35 | # Visual Studio 2015/2017 cache/options directory 36 | .vs/ 37 | # Uncomment if you have tasks that create the project's static files in wwwroot 38 | #wwwroot/ 39 | 40 | # Visual Studio 2017 auto generated files 41 | Generated\ Files/ 42 | 43 | # MSTest test Results 44 | [Tt]est[Rr]esult*/ 45 | [Bb]uild[Ll]og.* 46 | 47 | # NUnit 48 | *.VisualState.xml 49 | TestResult.xml 50 | nunit-*.xml 51 | 52 | # Build Results of an ATL Project 53 | [Dd]ebugPS/ 54 | [Rr]eleasePS/ 55 | dlldata.c 56 | 57 | # Benchmark Results 58 | BenchmarkDotNet.Artifacts/ 59 | 60 | # .NET Core 61 | project.lock.json 62 | project.fragment.lock.json 63 | artifacts/ 64 | 65 | # ASP.NET Scaffolding 66 | ScaffoldingReadMe.txt 67 | 68 | # StyleCop 69 | StyleCopReport.xml 70 | 71 | # Files built by Visual Studio 72 | *_i.c 73 | *_p.c 74 | *_h.h 75 | *.ilk 76 | *.meta 77 | *.obj 78 | *.iobj 79 | *.pch 80 | *.pdb 81 | *.ipdb 82 | *.pgc 83 | *.pgd 84 | *.rsp 85 | *.sbr 86 | *.tlb 87 | *.tli 88 | *.tlh 89 | *.tmp 90 | *.tmp_proj 91 | *_wpftmp.csproj 92 | *.log 93 | *.tlog 94 | *.vspscc 95 | *.vssscc 96 | .builds 97 | *.pidb 98 | *.svclog 99 | *.scc 100 | 101 | # Chutzpah Test files 102 | _Chutzpah* 103 | 104 | # Visual C++ cache files 105 | ipch/ 106 | *.aps 107 | *.ncb 108 | *.opendb 109 | *.opensdf 110 | *.sdf 111 | *.cachefile 112 | *.VC.db 113 | *.VC.VC.opendb 114 | 115 | # Visual Studio profiler 116 | *.psess 117 | *.vsp 118 | *.vspx 119 | *.sap 120 | 121 | # Visual Studio Trace Files 122 | *.e2e 123 | 124 | # TFS 2012 Local Workspace 125 | $tf/ 126 | 127 | # Guidance Automation Toolkit 128 | *.gpState 129 | 130 | # ReSharper is a .NET coding add-in 131 | _ReSharper*/ 132 | *.[Rr]e[Ss]harper 133 | *.DotSettings.user 134 | 135 | # TeamCity is a build add-in 136 | _TeamCity* 137 | 138 | # DotCover is a Code Coverage Tool 139 | *.dotCover 140 | 141 | # AxoCover is a Code Coverage Tool 142 | .axoCover/* 143 | !.axoCover/settings.json 144 | 145 | # Coverlet is a free, cross platform Code Coverage Tool 146 | coverage*.json 147 | coverage*.xml 148 | coverage*.info 149 | 150 | # Visual Studio code coverage results 151 | *.coverage 152 | *.coveragexml 153 | 154 | # NCrunch 155 | _NCrunch_* 156 | .*crunch*.local.xml 157 | nCrunchTemp_* 158 | 159 | # MightyMoose 160 | *.mm.* 161 | AutoTest.Net/ 162 | 163 | # Web workbench (sass) 164 | .sass-cache/ 165 | 166 | # Installshield output folder 167 | [Ee]xpress/ 168 | 169 | # DocProject is a documentation generator add-in 170 | DocProject/buildhelp/ 171 | DocProject/Help/*.HxT 172 | DocProject/Help/*.HxC 173 | DocProject/Help/*.hhc 174 | DocProject/Help/*.hhk 175 | DocProject/Help/*.hhp 176 | DocProject/Help/Html2 177 | DocProject/Help/html 178 | 179 | # Click-Once directory 180 | publish/ 181 | 182 | # Publish Web Output 183 | *.[Pp]ublish.xml 184 | *.azurePubxml 185 | # Note: Comment the next line if you want to checkin your web deploy settings, 186 | # but database connection strings (with potential passwords) will be unencrypted 187 | *.pubxml 188 | *.publishproj 189 | 190 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 191 | # checkin your Azure Web App publish settings, but sensitive information contained 192 | # in these scripts will be unencrypted 193 | PublishScripts/ 194 | 195 | # NuGet Packages 196 | *.nupkg 197 | # NuGet Symbol Packages 198 | *.snupkg 199 | # The packages folder can be ignored because of Package Restore 200 | **/[Pp]ackages/* 201 | # except build/, which is used as an MSBuild target. 202 | !**/[Pp]ackages/build/ 203 | # Uncomment if necessary however generally it will be regenerated when needed 204 | #!**/[Pp]ackages/repositories.config 205 | # NuGet v3's project.json files produces more ignorable files 206 | *.nuget.props 207 | *.nuget.targets 208 | 209 | # Microsoft Azure Build Output 210 | csx/ 211 | *.build.csdef 212 | 213 | # Microsoft Azure Emulator 214 | ecf/ 215 | rcf/ 216 | 217 | # Windows Store app package directories and files 218 | AppPackages/ 219 | BundleArtifacts/ 220 | Package.StoreAssociation.xml 221 | _pkginfo.txt 222 | *.appx 223 | *.appxbundle 224 | *.appxupload 225 | 226 | # Visual Studio cache files 227 | # files ending in .cache can be ignored 228 | *.[Cc]ache 229 | # but keep track of directories ending in .cache 230 | !?*.[Cc]ache/ 231 | 232 | # Others 233 | ClientBin/ 234 | ~$* 235 | *~ 236 | *.dbmdl 237 | *.dbproj.schemaview 238 | *.jfm 239 | *.pfx 240 | *.publishsettings 241 | orleans.codegen.cs 242 | 243 | # Including strong name files can present a security risk 244 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 245 | #*.snk 246 | 247 | # Since there are multiple workflows, uncomment next line to ignore bower_components 248 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 249 | #bower_components/ 250 | 251 | # RIA/Silverlight projects 252 | Generated_Code/ 253 | 254 | # Backup & report files from converting an old project file 255 | # to a newer Visual Studio version. Backup files are not needed, 256 | # because we have git ;-) 257 | _UpgradeReport_Files/ 258 | Backup*/ 259 | UpgradeLog*.XML 260 | UpgradeLog*.htm 261 | ServiceFabricBackup/ 262 | *.rptproj.bak 263 | 264 | # SQL Server files 265 | *.mdf 266 | *.ldf 267 | *.ndf 268 | 269 | # Business Intelligence projects 270 | *.rdl.data 271 | *.bim.layout 272 | *.bim_*.settings 273 | *.rptproj.rsuser 274 | *- [Bb]ackup.rdl 275 | *- [Bb]ackup ([0-9]).rdl 276 | *- [Bb]ackup ([0-9][0-9]).rdl 277 | 278 | # Microsoft Fakes 279 | FakesAssemblies/ 280 | 281 | # GhostDoc plugin setting file 282 | *.GhostDoc.xml 283 | 284 | # Node.js Tools for Visual Studio 285 | .ntvs_analysis.dat 286 | node_modules/ 287 | 288 | # Visual Studio 6 build log 289 | *.plg 290 | 291 | # Visual Studio 6 workspace options file 292 | *.opt 293 | 294 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 295 | *.vbw 296 | 297 | # Visual Studio 6 auto-generated project file (contains which files were open etc.) 298 | *.vbp 299 | 300 | # Visual Studio 6 workspace and project file (working project files containing files to include in project) 301 | *.dsw 302 | *.dsp 303 | 304 | # Visual Studio 6 technical files 305 | *.ncb 306 | *.aps 307 | 308 | # Visual Studio LightSwitch build output 309 | **/*.HTMLClient/GeneratedArtifacts 310 | **/*.DesktopClient/GeneratedArtifacts 311 | **/*.DesktopClient/ModelManifest.xml 312 | **/*.Server/GeneratedArtifacts 313 | **/*.Server/ModelManifest.xml 314 | _Pvt_Extensions 315 | 316 | # Paket dependency manager 317 | .paket/paket.exe 318 | paket-files/ 319 | 320 | # FAKE - F# Make 321 | .fake/ 322 | 323 | # CodeRush personal settings 324 | .cr/personal 325 | 326 | # Python Tools for Visual Studio (PTVS) 327 | __pycache__/ 328 | *.pyc 329 | 330 | # Cake - Uncomment if you are using it 331 | # tools/** 332 | # !tools/packages.config 333 | 334 | # Tabs Studio 335 | *.tss 336 | 337 | # Telerik's JustMock configuration file 338 | *.jmconfig 339 | 340 | # BizTalk build output 341 | *.btp.cs 342 | *.btm.cs 343 | *.odx.cs 344 | *.xsd.cs 345 | 346 | # OpenCover UI analysis results 347 | OpenCover/ 348 | 349 | # Azure Stream Analytics local run output 350 | ASALocalRun/ 351 | 352 | # MSBuild Binary and Structured Log 353 | *.binlog 354 | 355 | # NVidia Nsight GPU debugger configuration file 356 | *.nvuser 357 | 358 | # MFractors (Xamarin productivity tool) working folder 359 | .mfractor/ 360 | 361 | # Local History for Visual Studio 362 | .localhistory/ 363 | 364 | # Visual Studio History (VSHistory) files 365 | .vshistory/ 366 | 367 | # BeatPulse healthcheck temp database 368 | healthchecksdb 369 | 370 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 371 | MigrationBackup/ 372 | 373 | # Ionide (cross platform F# VS Code tools) working folder 374 | .ionide/ 375 | 376 | # Fody - auto-generated XML schema 377 | FodyWeavers.xsd 378 | 379 | # VS Code files for those working on multiple tools 380 | .vscode/* 381 | !.vscode/settings.json 382 | !.vscode/tasks.json 383 | !.vscode/launch.json 384 | !.vscode/extensions.json 385 | *.code-workspace 386 | 387 | # Local History for Visual Studio Code 388 | .history/ 389 | 390 | # Windows Installer files from build outputs 391 | *.cab 392 | *.msi 393 | *.msix 394 | *.msm 395 | *.msp 396 | 397 | # JetBrains Rider 398 | *.sln.iml 399 | 400 | .DS_Store -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Cody Mullins 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Tailwind/.config/dotnet-tools.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 1, 3 | "isRoot": true, 4 | "tools": { 5 | "tailwind": { 6 | "version": "0.1.0", 7 | "commands": [ 8 | "tailwind" 9 | ] 10 | } 11 | } 12 | } -------------------------------------------------------------------------------- /Tailwind/.idea/.idea.Tailwind/.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | # Rider ignored files 5 | /modules.xml 6 | /projectSettingsUpdater.xml 7 | /contentModel.xml 8 | /.idea.Tailwind.iml 9 | # Editor-based HTTP Client requests 10 | /httpRequests/ 11 | # Datasource local storage ignored files 12 | /dataSources/ 13 | /dataSources.local.xml 14 | # GitHub Copilot persisted chat sessions 15 | /copilot/chatSessions 16 | -------------------------------------------------------------------------------- /Tailwind/.idea/.idea.Tailwind/.idea/indexLayout.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Tailwind/.idea/.idea.Tailwind/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Tailwind/App/DefaultTailwindCommand.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using Spectre.Console; 3 | using Spectre.Console.Cli; 4 | 5 | namespace Tailwind.App; 6 | 7 | internal class DefaultTailwindCommand(IAnsiConsole console) : Command 8 | { 9 | public class DefaultSettings : CommandSettings 10 | { 11 | } 12 | 13 | public override int Execute(CommandContext context, DefaultSettings settings) 14 | { 15 | var versionString = Assembly.GetEntryAssembly()? 16 | .GetCustomAttribute()? 17 | .InformationalVersion 18 | .ToString(); 19 | 20 | console.MarkupLine($"dotnet-tailwind v{versionString}"); 21 | console.MarkupLine("-------------"); 22 | console.MarkupLine("\nUsage:"); 23 | console.MarkupLine(" dotnet tailwind init"); 24 | return 0; 25 | } 26 | } -------------------------------------------------------------------------------- /Tailwind/App/InitTailwindCommand.cs: -------------------------------------------------------------------------------- 1 | using Spectre.Console; 2 | using Spectre.Console.Cli; 3 | 4 | namespace Tailwind.App; 5 | 6 | internal class InitTailwindCommand(IAnsiConsole console) : AsyncCommand 7 | { 8 | public override async Task ExecuteAsync(CommandContext context, TailwindSettings settings) 9 | { 10 | AnsiConsole.MarkupLine("Initializing tailwind"); 11 | var tailwind = TailwindConfigurationService.Create(console, settings); 12 | await tailwind.CreateBaseCssIfNotExists(); 13 | await tailwind.CreateTailwindConfigIfNotExists(); 14 | await tailwind.AddBuildTasks(); 15 | //tailwind.AddTailwindTargets(settings.Version); 16 | return 0; 17 | } 18 | } 19 | 20 | -------------------------------------------------------------------------------- /Tailwind/App/ProjectService.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Build.Evaluation; 2 | using Spectre.Console; 3 | 4 | namespace Tailwind.App; 5 | 6 | internal class ProjectService(IAnsiConsole console) 7 | { 8 | public Project LoadProject(TailwindSettings settings, CancellationToken cancel) 9 | { 10 | var projectFile = SdkHelper.FindWebSdkProject(settings.Directory); 11 | if (projectFile == null) 12 | { 13 | throw new ApplicationException("No project files found"); 14 | } 15 | 16 | AnsiConsole.MarkupLineInterpolated($"Found a project file at {projectFile.Path}"); 17 | var collection = new ProjectCollection(); 18 | var project = collection.LoadProject(projectFile.Path); 19 | return project; 20 | } 21 | } -------------------------------------------------------------------------------- /Tailwind/App/RemoveTailwindCommand.cs: -------------------------------------------------------------------------------- 1 | using Spectre.Console; 2 | using Spectre.Console.Cli; 3 | 4 | namespace Tailwind.App; 5 | 6 | internal class RemoveTailwindCommand(IAnsiConsole console) : AsyncCommand 7 | { 8 | public override async Task ExecuteAsync(CommandContext context, RemoveTailwindSettings settings) 9 | { 10 | var tailwind = TailwindConfigurationService.Create(console, settings); 11 | var files = await tailwind.RemovePluginFiles(false); 12 | 13 | if (!files.Any()) 14 | { 15 | AnsiConsole.MarkupLine("Tailwind already uninstalled."); 16 | return 0; 17 | } 18 | 19 | var innerGrid = new Grid(); 20 | innerGrid.AddColumn(); 21 | foreach (var file in files) 22 | { 23 | innerGrid.AddRow(new TextPath(file)); 24 | } 25 | var panel = new Panel(new Padder(innerGrid, new Padding(1, 2))); 26 | panel.Header = new PanelHeader("Files will be removed:"); 27 | 28 | var grid = new Grid(); 29 | grid.AddColumn(); 30 | grid.AddRow(panel); 31 | console.Write(new Padder(grid, new Padding(0, 1))); 32 | 33 | if (settings.DryRun == true) 34 | { 35 | return 0; 36 | } 37 | 38 | if (AnsiConsole.Confirm("Delete these files?")) 39 | { 40 | await tailwind.RemovePluginFiles(true); 41 | } 42 | 43 | await tailwind.RemoveBuildTasks(); 44 | 45 | return 0; 46 | } 47 | } -------------------------------------------------------------------------------- /Tailwind/App/RemoveTailwindSettings.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel; 2 | using Spectre.Console.Cli; 3 | 4 | namespace Tailwind.App; 5 | 6 | public class RemoveTailwindSettings : TailwindSettings 7 | { 8 | 9 | [CommandOption("--dry-run")] 10 | [Description("Present the 'what-if' analysis")] 11 | public bool? DryRun { get; init; } 12 | } -------------------------------------------------------------------------------- /Tailwind/App/SdkHelper.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Build.Construction; 2 | using System.Xml.Linq; 3 | 4 | namespace Tailwind.App; 5 | 6 | public static class SdkHelper 7 | { 8 | const string WebSdk = "Microsoft.NET.Sdk.Web"; 9 | const string BlazorWasmSdk = "Microsoft.NET.Sdk.BlazorWebAssembly"; 10 | 11 | public static ProjectFile? FindWebSdkProject(string directory) 12 | { 13 | var projects = FindWebSdkProjects(directory).ToList(); 14 | 15 | // try to find web project first, then WASM if web not found 16 | var web = projects.SingleOrDefault(p => p.Type == ProjectType.Web) 17 | ?? projects.SingleOrDefault(p => p.Type == ProjectType.Wasm); 18 | 19 | return web; 20 | } 21 | 22 | private static IEnumerable FindWebSdkProjects(string directory) 23 | { 24 | var csprojFiles = Directory.GetFiles(directory, "*.csproj", SearchOption.AllDirectories); 25 | foreach (var file in csprojFiles) 26 | { 27 | var doc = XDocument.Load(file); 28 | var sdkAttribute = doc.Root?.Attribute("Sdk"); 29 | // TODO: find assembly name if it is set 30 | var assemblyName = GetAssemblyName(file); 31 | var dotnetVersion = GetDotnetVersion(file); 32 | 33 | // .NET 8.0 has this for the primary Web project 34 | if (sdkAttribute != null && 35 | sdkAttribute.Value.Equals(WebSdk, StringComparison.OrdinalIgnoreCase)) 36 | { 37 | yield return new ProjectFile(ProjectType.Web, file, assemblyName, dotnetVersion); 38 | } 39 | 40 | // .NET 8.0 has this for the .Client project. Older versions use this for standalone WASM projects. 41 | if (sdkAttribute != null && sdkAttribute.Value.Equals(BlazorWasmSdk, 42 | StringComparison.OrdinalIgnoreCase)) 43 | { 44 | yield return new ProjectFile(ProjectType.Wasm, file, assemblyName, dotnetVersion); 45 | } 46 | } 47 | } 48 | 49 | private static string GetDotnetVersion(string path) 50 | { 51 | var defaultVersion = "8.0"; 52 | var root = ProjectRootElement.Open(path); 53 | var groups = root.PropertyGroups; 54 | var ele = groups.FirstOrDefault(p => p.Children.Any(c => c.ElementName == "TargetFramework")); 55 | if (ele == null) 56 | { 57 | return defaultVersion; 58 | } 59 | 60 | var element = ele.Children.FirstOrDefault(p => p.ElementName == "TargetFramework"); 61 | var propertyElement = element as ProjectPropertyElement; 62 | return propertyElement?.Value?.Replace("net", "") ?? defaultVersion; 63 | } 64 | 65 | private static string GetAssemblyName(string path) 66 | { 67 | var defaultAssemblyName = Path.GetFileNameWithoutExtension(path); 68 | var root = ProjectRootElement.Open(path); 69 | var groups = root.PropertyGroups; 70 | var ele = groups.FirstOrDefault(p => p.Children.Any(c => c.ElementName == "AssemblyName")); 71 | if (ele == null) 72 | { 73 | return defaultAssemblyName; 74 | } 75 | 76 | var assemblyNameElement = ele.Children.FirstOrDefault(p => p.ElementName == "AssemblyName"); 77 | var assemblyName = assemblyNameElement as ProjectPropertyElement; 78 | return assemblyName?.Value ?? defaultAssemblyName; 79 | } 80 | 81 | public enum ProjectType 82 | { 83 | NotSet, 84 | Web, 85 | Wasm 86 | } 87 | 88 | public record ProjectFile(ProjectType Type, string Path, string AssemblyName, string DotnetVersion); 89 | } 90 | 91 | -------------------------------------------------------------------------------- /Tailwind/App/TailwindConfigurationService.cs: -------------------------------------------------------------------------------- 1 | using System.Text; 2 | using Microsoft.Build.Construction; 3 | using Microsoft.Build.Evaluation; 4 | using Spectre.Console; 5 | using Tailwind.Templates; 6 | 7 | namespace Tailwind.App; 8 | 9 | public class TailwindConfigurationService(IAnsiConsole console, Project project, TailwindSettings settings) 10 | { 11 | public static TailwindConfigurationService Create(IAnsiConsole console, TailwindSettings settings) 12 | { 13 | var cts = new CancellationTokenSource(); 14 | var projectService = new ProjectService(console); 15 | var project = projectService.LoadProject(settings, cts.Token); 16 | return new TailwindConfigurationService(console, project, settings); 17 | } 18 | 19 | private string GetInstallerUrl() 20 | { 21 | var installUrlRoot = $"https://github.com/tailwindlabs/tailwindcss/releases/download/v{settings.Version}"; 22 | return installUrlRoot; 23 | } 24 | 25 | public async Task CreateTailwindConfigIfNotExists() 26 | { 27 | var path = GetNormalizedPath("tailwind.config.js"); 28 | if (!File.Exists(path)) 29 | { 30 | console.MarkupLineInterpolated($"{path} not found, creating one for you..."); 31 | await CreateFile(path, TailwindConfigTemplates.Basic); 32 | } 33 | } 34 | 35 | public async Task CreateBaseCssIfNotExists() 36 | { 37 | var path = GetNormalizedPath("tailwind.css"); 38 | if (!File.Exists(path)) 39 | { 40 | console.MarkupLineInterpolated($"{path} not found, creating one for you..."); 41 | const string contents = "@tailwind base;\n@tailwind components;\n@tailwind utilities;"; 42 | await CreateFile(path, contents); 43 | } 44 | } 45 | 46 | /// 47 | /// Remove files added by this tool 48 | /// 49 | /// What-if analysis, no actions applied 50 | /// The files that were removed (or would be removed). 51 | public async Task> RemovePluginFiles(bool apply) 52 | { 53 | var files = await GetPluginFiles(); 54 | List filesToRemove = []; 55 | filesToRemove.AddRange(files.Where(File.Exists)); 56 | 57 | if (!apply) 58 | { 59 | return filesToRemove; 60 | } 61 | 62 | foreach (var file in filesToRemove) 63 | { 64 | File.Delete(file); 65 | AnsiConsole.MarkupLineInterpolated($"[bold maroon]Deleted file[/] {Path.GetFileName(file)}"); 66 | } 67 | 68 | return filesToRemove; 69 | } 70 | 71 | private Task> GetPluginFiles() 72 | { 73 | List files = 74 | [ 75 | GetNormalizedPath("tailwind.config.js"), 76 | GetNormalizedPath("tailwind.css"), 77 | GetNormalizedPath("tailwindcss.exe"), 78 | GetNormalizedPath("tailwindcss"), 79 | GetNormalizedPath("wwwroot/css/site.css") 80 | ]; 81 | 82 | return Task.FromResult(files); 83 | } 84 | 85 | private Task> GetBuildTasks() 86 | { 87 | var permissionTask = new BuildTask("Tailwind:Permission", "Making Tailwind CLI executable", TaskType.Exec, [ 88 | new("Command", "chmod +x $(TailwindExecutable)") 89 | ], 90 | Platforms: [new OsPlatform("Linux"), new OsPlatform("OSX"), new OsPlatform("OSX", "arm64")]); 91 | 92 | List baseInstallParameters = 93 | [ 94 | new("SkipUnchangedFiles", "true"), 95 | new("DestinationFolder", "$(MSBuildProjectDirectory)") 96 | ]; 97 | 98 | // todo: there has to be a better way to do this 99 | var installTaskWindows = new BuildTask( 100 | "Tailwind:Install", 101 | "Installing Tailwind CLI", 102 | TaskType.Download, 103 | [.. baseInstallParameters, new("SourceUrl", $"{GetInstallerUrl()}/tailwindcss-windows-x64.exe")], 104 | Platforms: [new OsPlatform("Windows")]); 105 | 106 | var installTaskLinux = installTaskWindows with 107 | { 108 | Name = "Tailwind:InstallLinux", 109 | Platforms = [new OsPlatform("Linux")], 110 | Parameters = [.. baseInstallParameters, new("SourceUrl", $"{GetInstallerUrl()}/tailwindcss-linux-x64")] 111 | }; 112 | 113 | var installTaskMac = installTaskWindows with 114 | { 115 | Name = "Tailwind:InstallMac", 116 | Platforms = [new OsPlatform("OSX")], 117 | Parameters = [.. baseInstallParameters, new("SourceUrl", $"{GetInstallerUrl()}/tailwindcss-macos-x64")] 118 | }; 119 | 120 | var installTaskMacArm = installTaskWindows with 121 | { 122 | Name = "Tailwind:InstallMacArm", 123 | Platforms = [new OsPlatform("OSX", "arm64")], 124 | Parameters = [.. baseInstallParameters, new("SourceUrl", $"{GetInstallerUrl()}/tailwindcss-macos-arm64")] 125 | }; 126 | 127 | var cssTask = new BuildTask( 128 | "Tailwind:Run", 129 | "Building CSS with Tailwind", 130 | TaskType.Exec, 131 | [new("Command", "$(TailwindExecutable) -i .\\tailwind.css -o .\\wwwroot\\css\\site.css")], 132 | DependsOnTask: permissionTask); 133 | 134 | return Task.FromResult>([installTaskWindows, installTaskLinux, installTaskMac, installTaskMacArm, permissionTask, cssTask]); 135 | } 136 | 137 | public async Task RemoveBuildTasks() 138 | { 139 | var tasks = await GetBuildTasks(); 140 | foreach (var target in tasks 141 | .Select(buildTask => project.Xml.Targets.FirstOrDefault(p => p.Name == buildTask.Name)) 142 | .OfType()) 143 | { 144 | target.RemoveAllChildren(); 145 | } 146 | 147 | project.Save(); 148 | } 149 | 150 | private string GetNormalizedPath(string path) 151 | { 152 | return Path.Combine(project.DirectoryPath, path); 153 | } 154 | 155 | private async Task CreateFile(string path, string contents) 156 | { 157 | await using var stream = File.Create(path); 158 | await stream.WriteAsync(Encoding.UTF8.GetBytes(contents)); 159 | await stream.FlushAsync(); 160 | } 161 | 162 | public async Task AddBuildTasks() 163 | { 164 | var tasks = await GetBuildTasks(); 165 | foreach (var buildTask in tasks) 166 | { 167 | var target = project.Xml.Targets.FirstOrDefault(p => p.Name == buildTask.Name); 168 | if (target == null) 169 | { 170 | target = project.Xml.AddTarget(buildTask.Name); 171 | } 172 | else 173 | { 174 | // reset the target so we can just call init over and over again 175 | target.RemoveAllChildren(); 176 | } 177 | 178 | target.AfterTargets = "AfterBuild"; 179 | if (buildTask.DependsOnTask != null) 180 | { 181 | target.DependsOnTargets = buildTask.DependsOnTask.Name; 182 | } 183 | 184 | var task = target.AddTask("Message"); 185 | task.SetParameter("Importance", "high"); 186 | task.SetParameter("Text", buildTask.Description); 187 | 188 | var taskType = buildTask.TaskType switch 189 | { 190 | TaskType.Download => "DownloadFile", 191 | TaskType.Exec => "Exec", 192 | TaskType.Message => "Message", 193 | _ => throw new ArgumentOutOfRangeException(nameof(buildTask.TaskType), buildTask.TaskType, null) 194 | }; 195 | 196 | var taskElement = target.AddTask(taskType); 197 | foreach (var parameter in buildTask.Parameters) 198 | { 199 | taskElement.SetParameter(parameter.Key, parameter.Value); 200 | } 201 | 202 | if (buildTask.Platforms != null && buildTask.Platforms.Any()) 203 | { 204 | var condition = $"($([MSBuild]::IsOSPlatform('{buildTask.Platforms.First().Name}')) AND '$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture)' == '{buildTask.Platforms.First().Arch.ToUpper()}')"; 205 | condition = buildTask.Platforms.Skip(1) 206 | .Aggregate(condition, (current, platform) => current + $" OR ($([MSBuild]::IsOSPlatform('{platform.Name}')) AND '$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture)' == '{platform.Arch.ToUpper()}')"); 207 | 208 | taskElement.Condition = condition; 209 | } 210 | 211 | if (buildTask.TaskType == TaskType.Download) 212 | { 213 | taskElement.AddOutputProperty("DownloadedFile", "TailwindExecutable"); 214 | } 215 | } 216 | 217 | project.Save(); 218 | } 219 | } 220 | 221 | public record BuildTask(string Name, string Description, TaskType TaskType, List Parameters, BuildTask? DependsOnTask = null, List? Platforms = null); 222 | public record OsPlatform(string Name, string Arch = "x64"); 223 | public enum TaskType 224 | { 225 | Message, 226 | Exec, 227 | Download 228 | } 229 | public record TargetParameter(string Key, string Value); -------------------------------------------------------------------------------- /Tailwind/App/TailwindSettings.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel; 2 | using Spectre.Console.Cli; 3 | 4 | namespace Tailwind.App; 5 | 6 | public class TailwindSettings : CommandSettings 7 | { 8 | [CommandOption("-v|--version")] 9 | [DefaultValue("3.4.1")] 10 | [Description("The version of Tailwind to install")] 11 | public required string Version { get; init; } 12 | 13 | [CommandOption("-o|--output")] 14 | [DefaultValue(@".\wwwroot\css\site.css")] 15 | [Description("The path to the output css file relative to the project file")] 16 | public required string Output { get; init; } 17 | 18 | [CommandOption("-d|--dir")] 19 | [DefaultValue(".")] 20 | [Description("The root directory for your code")] 21 | public required string Directory { get; init; } 22 | } -------------------------------------------------------------------------------- /Tailwind/App/UpdateTailwindCommand.cs: -------------------------------------------------------------------------------- 1 | using Spectre.Console; 2 | using Spectre.Console.Cli; 3 | 4 | namespace Tailwind.App; 5 | 6 | internal class UpdateTailwindCommand(IAnsiConsole console) : AsyncCommand 7 | { 8 | public override Task ExecuteAsync(CommandContext context, TailwindSettings settings) 9 | { 10 | throw new NotImplementedException(); 11 | } 12 | } -------------------------------------------------------------------------------- /Tailwind/Program.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Build.Locator; 2 | using Spectre.Console; 3 | using Spectre.Console.Cli; 4 | using Tailwind.App; 5 | 6 | // Register the build locator once outside any commands or logic 7 | // otherwise you may run into issues where this locator isn't registered 8 | RegisterBuildLocator(); 9 | 10 | var app = new CommandApp(); 11 | app.Configure(config => 12 | { 13 | config.SetApplicationName("dotnet tailwind"); 14 | config.AddCommand("init"); 15 | config.AddCommand("remove"); 16 | }); 17 | 18 | static void RegisterBuildLocator() 19 | { 20 | var queryOptions = new VisualStudioInstanceQueryOptions { DiscoveryTypes = DiscoveryType.DotNetSdk }; 21 | var instances = MSBuildLocator.QueryVisualStudioInstances(queryOptions).ToList(); 22 | 23 | VisualStudioInstance instance; 24 | switch (instances.Count) 25 | { 26 | case 1: 27 | instance = instances.First(); 28 | AnsiConsole.MarkupLine("Using .NET SDK version {0}", instance.Version); 29 | break; 30 | case > 1: 31 | instance = instances.OrderByDescending(p => p.Version).First(); 32 | AnsiConsole.MarkupLine("Multiple .NET SDK versions found, using {0}", instance.Version); 33 | break; 34 | case <= 0: 35 | throw new ApplicationException("No .NET SDK was found"); 36 | } 37 | 38 | MSBuildLocator.RegisterInstance(instance); 39 | } 40 | 41 | return await app.RunAsync(args); -------------------------------------------------------------------------------- /Tailwind/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "profiles": { 3 | "Tailwind": { 4 | "commandName": "Project", 5 | "commandLineArgs": "init -d G:\\repos\\pureblazor\\components" 6 | } 7 | } 8 | } -------------------------------------------------------------------------------- /Tailwind/Tailwind.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | Exe 4 | net7.0;net8.0 5 | enable 6 | Nullable 7 | enable 8 | false 9 | true 10 | true 11 | latest 12 | tailwind 13 | True 14 | ./nupkg 15 | 0.8.0 16 | Added remove command, changed init pattern, mac ARM 17 | Cody Mullins 18 | readme.md 19 | https://github.com/codymullins/dotnet-tailwind 20 | https://github.com/codymullins/dotnet-tailwind 21 | 22 | tailwind blazor 23 | MIT 24 | Automatically add Tailwind to your Blazor application 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /Tailwind/Tailwind.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.8.34004.107 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tailwind", "Tailwind.csproj", "{5B1CC072-8447-40D1-B7FB-C215342B5763}" 7 | EndProject 8 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{A18FA3B7-666F-44E3-B927-3CBB25FA3D73}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|Any CPU = Debug|Any CPU 13 | Release|Any CPU = Release|Any CPU 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {5B1CC072-8447-40D1-B7FB-C215342B5763}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 17 | {5B1CC072-8447-40D1-B7FB-C215342B5763}.Debug|Any CPU.Build.0 = Debug|Any CPU 18 | {5B1CC072-8447-40D1-B7FB-C215342B5763}.Release|Any CPU.ActiveCfg = Release|Any CPU 19 | {5B1CC072-8447-40D1-B7FB-C215342B5763}.Release|Any CPU.Build.0 = Release|Any CPU 20 | EndGlobalSection 21 | GlobalSection(SolutionProperties) = preSolution 22 | HideSolutionNode = FALSE 23 | EndGlobalSection 24 | GlobalSection(ExtensibilityGlobals) = postSolution 25 | SolutionGuid = {785B3ABF-E4D2-4832-A9FB-8B640232FF39} 26 | EndGlobalSection 27 | EndGlobal 28 | -------------------------------------------------------------------------------- /Tailwind/Templates/TailwindConfigTemplates.cs: -------------------------------------------------------------------------------- 1 | namespace Tailwind.Templates; 2 | 3 | public static class TailwindConfigTemplates 4 | { 5 | public const string Basic = """ 6 | /** @type {import('tailwindcss').Config} */ 7 | module.exports = { 8 | content: ["*.razor", "./Pages/**/*.{html,js,cshtml,razor}", "./Shared/**/*.{html,js,cshtml,razor}"], 9 | plugins: [], 10 | } 11 | """; 12 | 13 | public const string Batteries = """ 14 | /** @type {import('tailwindcss').Config} */ 15 | const defaultTheme = require('tailwindcss/defaultTheme') 16 | 17 | module.exports = { 18 | content: ["*.razor", "./Pages/**/*.{html,js,cshtml,razor}", "./Shared/**/*.{html,js,cshtml,razor}"], 19 | theme: { 20 | extend: { 21 | fontFamily: { 22 | sans: ['Inter var', ...defaultTheme.fontFamily.sans], 23 | }, 24 | }, 25 | }, 26 | plugins: [ 27 | require('@tailwindcss/forms'), 28 | require('@tailwindcss/typography'), 29 | ], 30 | } 31 | """; 32 | } -------------------------------------------------------------------------------- /Tailwind/readme.md: -------------------------------------------------------------------------------- 1 | # dotnet-tailwind 2 | 3 | Really basic tool to bootstrap Tailwind in .NET Blazor projects. 4 | 5 | Run `dotnet tailwind init` to automatically create the necessary build targets and files for a basic Tailwind integration. 6 | 7 | ## Installation 8 | 9 | ```sh 10 | cd 11 | dotnet new tool-manifest 12 | dotnet tool install tailwind 13 | ``` 14 | 15 | ## Initializing Tailwind 16 | 17 | ```sh 18 | cd .\path\to\project 19 | dotnet tailwind init 20 | ``` 21 | 22 | **Add to your `App.razor` in the ``:** 23 | 24 | ```html 25 | 26 | ``` 27 | 28 | Anytime you build the solution, `wwwroot/css/site.css` will now be regenerated. 29 | 30 | ## Updating Tailwind 31 | 32 | ```sh 33 | dotnet tailwind update 34 | ``` 35 | 36 | ## Support 37 | 38 | We support the below versions. The tool may work with versions outside this range, but we're not actively testing them. Your mileage may vary. 39 | 40 | | .NET 6 | .NET 7 | .NET 8 | .NET 9 | 41 | | -- | -- | -- | -- | 42 | | ❌ | ✅ | ✅ | | 43 | 44 | ## Sponsors 45 | 46 | Sponsored by [PureBlazor](https://pureblazor.com) 47 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # dotnet-tailwind 2 | 3 | Really basic tool to bootstrap Tailwind in .NET Blazor projects. 4 | 5 | Run `dotnet tailwind init` to automatically create the necessary build targets and files for a basic Tailwind integration. 6 | 7 | ## Installation 8 | 9 | ```sh 10 | cd 11 | dotnet new tool-manifest 12 | dotnet tool install tailwind 13 | ``` 14 | 15 | ## Initializing Tailwind 16 | 17 | ```sh 18 | cd .\path\to\project 19 | dotnet tailwind init 20 | ``` 21 | 22 | **Add to your `App.razor` in the ``:** 23 | 24 | ```html 25 | 26 | ``` 27 | 28 | Anytime you build the solution, `wwwroot/css/site.css` will now be regenerated. 29 | 30 | ## Updating Tailwind 31 | 32 | ```sh 33 | dotnet tailwind update 34 | ``` 35 | 36 | ## Support 37 | 38 | We support the below versions. The tool may work with versions outside this range, but we're not actively testing them. Your mileage may vary. 39 | 40 | | .NET 6 | .NET 7 | .NET 8 | .NET 9 | 41 | | -- | -- | -- | -- | 42 | | ❌ | ✅ | ✅ | | 43 | 44 | ## Sponsors 45 | 46 | Sponsored by [PureBlazor](https://pureblazor.com) 47 | --------------------------------------------------------------------------------