Skip to content

Commit 1b7197d

Browse files
committed
require parameters to be specified by user
1 parent b459db9 commit 1b7197d

File tree

1 file changed

+68
-21
lines changed
  • src/app/(docs)/docs/installation/framework-guides

1 file changed

+68
-21
lines changed

src/app/(docs)/docs/installation/framework-guides/dotnet.tsx

+68-21
Original file line numberDiff line numberDiff line change
@@ -71,26 +71,59 @@ export let steps: Step[] = [
7171
name: "Tailwind.targets",
7272
lang: "xml",
7373
code: `<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
74+
<!-- This file exposes the following parameters -->
75+
<!-- TailwindVersion: The version of the Tailwind Standalone CLI to download. -->
76+
<!-- TailwindDownloadPath: The path to where to download the Tailwind Standalone CLI. This property is optional, and defaults to %LOCALAPPDATA% on Windows, and $XDG_CACHE_HOME on Linux and MacOS. -->
77+
<!-- TailwindInputStyleSheetPath: The path to the input stylesheet. -->
78+
<!-- TailwindOutputStyleSheetPath: The path to the output stylesheet. -->
79+
<!-- TailwindOptimizeOutputStyleSheet: Whether to optimize the output stylesheet. This property is optional, and defaults to false. -->
80+
<!-- TailwindMinifyOutputStyleSheet: Whether to minify the output stylesheet. This property is optional, and defaults to false when Configuration is Debug, and true when Configuration is Release. -->
81+
<!-- TailwindDownloadUrl: The URL to the Tailwind Standalone CLI. This property is optional, and defaults to downloading the specified version from GitHub. -->
82+
83+
<!-- To override these properties, create a PropertyGroup in the csproj file -->
84+
<!-- For example: -->
85+
<!-- <PropertyGroup> -->
86+
<!-- <TailwindVersion>v4.0.14</TailwindVersion> -->
87+
<!-- <TailwindInputStyleSheetPath>Styles/main.css</TailwindVersion> -->
88+
<!-- <TailwindOutputStyleSheetPath>wwwroot/main.css</TailwindVersion> -->
89+
<!-- </PropertyGroup -->
90+
7491
<PropertyGroup>
75-
<!-- Specify which version of Tailwind to download -->
76-
<TailwindVersion>v4.0.14</TailwindVersion>
92+
<TailwindOptimizeOutputStyleSheet Condition="'$(TailwindOptimizeOutputStyleSheet)' == ''">false</TailwindOptimizeOutputStyleSheet>
7793
78-
<!-- Provide the path to the input & output stylesheets -->
79-
<InputStyleSheetPath>Styles/main.css</InputStyleSheetPath>
80-
<OutputStyleSheetPath>wwwroot/main.build.css</OutputStyleSheetPath>
94+
<TailwindMinifyOutputStyleSheet Condition="$(TailwindMinifyOutputStyleSheet) == '' And '$(Configuration)' == 'Debug'">false</TailwindMinifyOutputStyleSheet>
95+
<TailwindMinifyOutputStyleSheet Condition="$(TailwindMinifyOutputStyleSheet) == '' And '$(Configuration)' == 'Release'">true</TailwindMinifyOutputStyleSheet>
8196
82-
<!-- Provide the path to where Tailwind should be downloaded to -->
97+
<!-- The path to where Tailwind should be downloaded to -->
8398
<!-- This should be a path that is writable by the current user, as well as one that is accessible in CI/CD pipelines -->
84-
<!-- On Linux and MacOS, use $XDG_CACHE_HOME or $HOME/.cache ($HOME/.cache/Tailwind/<TailwindVersion>) -->
85-
<TailwindDownloadPath Condition="$([System.OperatingSystem]::IsLinux()) Or $([System.OperatingSystem]::IsMacOS())">$([System.IO.Path]::Combine($([MSBuild]::ValueOrDefault($([System.Environment]::GetEnvironmentVariable('XDG_CONFIG_HOME')), $([System.IO.Path]::Combine($([System.Environment]::GetEnvironmentVariable('HOME')), '.cache')))), 'Tailwind'))</TailwindDownloadPath>
99+
<!-- By default, this is set to the local app data folder on Windows, and $XDG_CACHE_HOME on Linux and MacOS -->
100+
101+
<!-- On Linux and MacOS, use $XDG_CACHE_HOME or $HOME/.cache -->
102+
<TailwindDownloadPath Condition="'$(TailwindDownloadPath)' == '' And ($([System.OperatingSystem]::IsLinux()) Or $([System.OperatingSystem]::IsMacOS()))">$([MSBuild]::ValueOrDefault($([System.Environment]::GetEnvironmentVariable('XDG_CONFIG_HOME')), $([System.IO.Path]::Combine($([System.Environment]::GetEnvironmentVariable('HOME')), '.cache'))))</TailwindDownloadPath>
86103
87-
<!-- On Windows, use local app data (%LOCALAPPDATA%\\Tailwind\\<TailwindVersion>) -->
88-
<TailwindDownloadPath Condition="$([System.OperatingSystem]::IsWindows())">$([System.IO.Path]::Combine($([System.Environment]::GetFolderPath($([System.Environment]::SpecialFolder.LocalApplicationData))), 'Tailwind'))</TailwindDownloadPath>
104+
<!-- On Windows, use local app data (%LOCALAPPDATA%) -->
105+
<TailwindDownloadPath Condition="'$(TailwindDownloadPath)' == '' And $([System.OperatingSystem]::IsWindows())">$([System.Environment]::GetFolderPath($([System.Environment]::SpecialFolder.LocalApplicationData)))</TailwindDownloadPath>
89106
</PropertyGroup>
90107
108+
<!-- Validate the parameters before download or building -->
109+
<Target Name="ValidateParameters" BeforeTargets="DownloadTailwind; Tailwind">
110+
<!-- Ensure the version is specified -->
111+
<Error Condition="'$(TailwindVersion)' == ''" Text="Tailwind version not specified. Please specify the version. For example: &lt;PropertyGroup&gt;&lt;TailwindVersion&gt;v4.0.14&lt;/TailwindVersion&gt;&lt;/PropertyGroup&gt;"/>
112+
113+
<!-- Ensure the input stylesheet path is specified & the file exists -->
114+
<Error Condition="'$(TailwindInputStyleSheetPath)' == ''" Text="Tailwind input stylesheet not specified. Please specify the path to the input stylesheet in the csproj file. For example: &lt;PropertyGroup&gt;&lt;TailwindInputStyleSheetPath&gt;Styles/main.css&lt;/TailwindInputStyleSheetPath&gt;&lt;/PropertyGroup&gt;"/>
115+
<Error Condition="!Exists('$(TailwindInputStyleSheetPath)')" Text="Tailwind input stylesheet '$(TailwindInputStyleSheetPath)' does not exist. Please specify a path to a stylesheet. For example: &lt;PropertyGroup&gt;&lt;TailwindInputStyleSheetPath&gt;Styles/main.css&lt;/TailwindInputStyleSheetPath&gt;&lt;/PropertyGroup&gt;"/>
116+
117+
<!-- Ensure the output stylesheet path is specified -->
118+
<Error Condition="'$(TailwindOutputStyleSheetPath)' == ''" Text="Tailwind output stylesheet not specified. Please specify the path to the output stylesheet in the csproj file. For example: &lt;PropertyGroup&gt;&lt;TailwindOutputStyleSheetPath&gt;Styles/main.css&lt;/TailwindOutputStyleSheetPath>&lt;/PropertyGroup&gt;"/>
119+
120+
<!-- Ensure the download path is specified -->
121+
<Error Condition="'$(TailwindDownloadPath)' == ''" Text="Tailwind download path not specified. Please specify the download path in the csproj file. For example: &lt;PropertyGroup&gt;&lt;TailwindDownloadPath&gt;/tmp&lt;/TailwindDownloadPath&gt;&lt;/PropertyGroup&gt;"/>
122+
</Target>
123+
91124
<!-- This line supports hot reload by instructing dotnet watch to be aware of modifications to the input stylesheet -->
92-
<ItemGroup>
93-
<Watch Include="$(InputStyleSheetPath)"/>
125+
<ItemGroup Condition="Exists('$(TailwindInputStyleSheetPath)')">
126+
<Watch Include="$(TailwindInputStyleSheetPath)"/>
94127
</ItemGroup>
95128
96129
<Target Name="DownloadTailwind">
@@ -104,31 +137,39 @@ export let steps: Step[] = [
104137
105138
<TailwindReleaseName Condition="$([System.OperatingSystem]::IsWindows()) And $([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture) == X64">tailwindcss-windows-x64.exe</TailwindReleaseName>
106139
<TailwindReleaseName Condition="$([System.OperatingSystem]::IsWindows()) And $([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture) == Arm64">tailwindcss-windows-arm64.exe</TailwindReleaseName>
140+
141+
<TailwindDownloadUrl Condition="'$(TailwindDownloadUrl)' == '' And $(TailwindVersion) != 'latest'">https://github.com/tailwindlabs/tailwindcss/releases/download/$(TailwindVersion)/$(TailwindReleaseName)</TailwindDownloadUrl>
142+
<TailwindDownloadUrl Condition="'$(TailwindDownloadUrl)' == '' And $(TailwindVersion) == 'latest'">https://github.com/tailwindlabs/tailwindcss/releases/latest/download/$(TailwindReleaseName)</TailwindDownloadUrl>
107143
</PropertyGroup>
108144
109145
<!-- Download the file -->
110-
<DownloadFile DestinationFolder="$([System.IO.Path]::Combine('$(TailwindDownloadPath)', '$(TailwindVersion)'))"
146+
<DownloadFile DestinationFolder="$([System.IO.Path]::Combine('$(TailwindDownloadPath)', 'Tailwind', '$(TailwindVersion)'))"
111147
DestinationFileName="$(TailwindReleaseName)"
112-
SourceUrl="https://github.com/tailwindlabs/tailwindcss/releases/download/$(TailwindVersion)/$(TailwindReleaseName)"
148+
SourceUrl="$(TailwindDownloadUrl)"
113149
SkipUnchangedFiles="true"
114150
Retries="3">
115151
<Output TaskParameter="DownloadedFile" PropertyName="TailwindCliPath"/>
116152
</DownloadFile>
117153
118154
<!-- On unix systems, make the file executable -->
119-
<Exec Condition="$([System.OperatingSystem]::IsLinux()) Or $([System.OperatingSystem]::IsMacOS())" Command="chmod +x '$(TailwindCliPath)'"/>
155+
<Exec Condition="Exists('$(TailwindCliPath)') And ($([System.OperatingSystem]::IsLinux()) Or $([System.OperatingSystem]::IsMacOS()))" Command="chmod +x '$(TailwindCliPath)'"/>
120156
</Target>
121157
122158
<!-- When building the project, run the Tailwind CLI -->
123159
<!-- This target can also be executed manually. For example, with dotnet watch: \`dotnet watch msbuild /t:Tailwind\` -->
124160
<!-- In order to use hot reload, run both \`dotnet watch run\` and \`dotnet watch msbuild /t:Tailwind\` -->
125161
<Target Name="Tailwind" DependsOnTargets="DownloadTailwind" BeforeTargets="Build">
126162
<PropertyGroup>
127-
<TailwindBuildCommand>'$(TailwindCliPath)' -i '$(InputStyleSheetPath)' -o '$(OutputStyleSheetPath)'</TailwindBuildCommand>
163+
<TailwindBuildCommand>'$(TailwindCliPath)' -i '$(TailwindInputStyleSheetPath)' -o '$(TailwindOutputStyleSheetPath)' --cwd '$(ProjectDir)'</TailwindBuildCommand>
164+
165+
<!-- Add optimize flag if specified -->
166+
<TailwindBuildCommand Condition="'$(TailwindOptimizeOutputStyleSheet)' == 'true'">$(TailwindBuildCommand) --optimize</TailwindBuildCommand>
167+
168+
<!-- Add minify flag if specified -->
169+
<TailwindBuildCommand Condition="'$(TailwindMinifyOutputStyleSheet)' == 'true'">$(TailwindBuildCommand) --minify</TailwindBuildCommand>
128170
</PropertyGroup>
129171
130-
<Exec Command="$(TailwindBuildCommand)" Condition="'$(Configuration)' == 'Debug'"/>
131-
<Exec Command="$(TailwindBuildCommand) --minify" Condition="'$(Configuration)' == 'Release'"/>
172+
<Exec Command="$(TailwindBuildCommand)"/>
132173
</Target>
133174
</Project>`
134175
}
@@ -137,13 +178,19 @@ export let steps: Step[] = [
137178
title: 'Configure your csproj',
138179
body: (
139180
<p>
140-
Open the <code>my-app.csproj</code> file and import the <code>Tailwind.targets</code> file.
181+
Specify the version and input & output stylesheets, and import the <code>Tailwind.targets</code> file.
141182
</p>
142183
),
143184
code: {
144185
name: 'my-app.csproj',
145186
lang: 'xml',
146-
code: `<Import Project="Tailwind.targets" />`,
187+
code: `<PropertyGroup>
188+
<TailwindVersion>latest</TailwindVersion>
189+
<TailwindInputStyleSheetPath>Styles/main.css</TailwindInputStyleSheetPath>
190+
<TailwindOutputStyleSheetPath>wwwroot/main.build.css</TailwindOutputStyleSheetPath>
191+
</PropertyGroup>
192+
193+
<Import Project="Tailwind.targets" />`,
147194
},
148195
},
149196

@@ -159,7 +206,7 @@ export let steps: Step[] = [
159206
name: 'Components/App.razor',
160207
lang: 'html',
161208
code: html`
162-
<link rel="stylesheet" href="/main.build.css"/>
209+
<link rel="stylesheet" href="@Assets["main.build.css"]"/>
163210
`,
164211
},
165212
},

0 commit comments

Comments
 (0)