feat: improve tailwind deployment flow (#2227)

By moving folks from `twind` over to the `tailwind` plugin we have
traded support questions about "how to get twind autocompletion
working?" with "my styles are not showing up in automatic mode". The
tailwind plugin has a hard requirement on having a build step. We have
documented this at various places and have a guide on how to set
everything up, but it's much better if we float those steps from Fresh
itself when we detect this.

With this PR we will prepare a `.github/workflows/deploy.yml` file
already where the user only needs to swap out the project name.

When Fresh is started in production mode, the tailwind plugin is active
and no snapshot files were loaded, then we print a helpful hint to the
console:

```sh
No pre-compiled tailwind styles found.

Did you forget to run "deno task build" prior to starting the production server?
```

When we are running inside Deno Deploy this PR goes one step further.
Since it is the first time many users might use Deno Deploy we'll also
show a simple page that shows how to finish the tailwind setup. I've
intentionally tried to not present this as a warning but rather as a
"finishing" step to avoid scaring users off. It's not the prettiest
page, but it's good enough for now.

<img width="892" alt="Screenshot 2024-01-09 at 23 41 27"
src="https://github.com/denoland/fresh/assets/1062408/9bf2a61b-5551-4d8e-bdf8-b498072f8e98">


Fixes https://github.com/denoland/fresh/issues/2223
This commit is contained in:
Marvin Hagemeister
2024-01-10 10:35:26 +01:00
committed by GitHub
parent 8d01051b5b
commit 912f3782a3
9 changed files with 253 additions and 8 deletions
+80
View File
@@ -0,0 +1,80 @@
import { AOT_GH_ACTION } from "../dev/imports.ts";
const LINK = "https://fresh.deno.dev/docs/concepts/ahead-of-time-builds";
export default function TailwindErrorPage() {
return (
<div class="frsh-error-page">
<div style="max-width: 48rem; padding: 2rem 1rem; margin: 0 auto; font-family: sans-serif">
<h1>Finish setting up Fresh</h1>
<p style="line-height: 1.6;margin-bottom: 1rem;">
The <b>tailwindcss</b>{" "}
plugin requires ahead of time builds to be set up for production
usage. To finish the setup, follow these steps:
</p>
<ol style="line-height: 1.6; margin-bottom: 1.5rem">
<li>
Go to your project in Deno Deploy and click the{" "}
<code>Settings</code> tab.
</li>
<li>
Set Git-Integration to <code>GitHub Action</code>.<br />
<i style="display: block; font-style: italic; color: gray;">
Unlink the repository first if it is already linked via{" "}
<code>Automatic</code> and re-link it again.
</i>
</li>
<li>
Add the file <code>.github/workflows/deploy.yml</code>{" "}
to your repository with the following contents:<br />
<span style="background: #f0f0f0;display: block; position: relative;">
<button
id="copy-gh-action"
style="position: absolute; top: .5rem; right: .5rem;z-index: 100"
>
copy code
</button>
<pre style="height: 200px; overflow: auto;padding: 1rem;"><code>{AOT_GH_ACTION}</code></pre>
</span>
</li>
<li>
Copy the project name under <code>Setting {">"} Project Name</code>
{" "}
and replace "example project" with your actual project name in{" "}
<code>.github/workflows/deploy.yml</code>.
</li>
<li>
Commit the file you created and merge it into the <code>main</code>
{" "}
branch. This will trigger a new deployment and finish the setup.
</li>
</ol>
<p>
See the detailed guide here: <a href={LINK}>{LINK}</a>.
</p>
</div>
<script
dangerouslySetInnerHTML={{
__html: `
const copyBtn = document.querySelector("#copy-gh-action");
if (copyBtn) {
let timeout;
const text = copyBtn.textContent;
copyBtn.addEventListener("click", async () => {
copyBtn.textContent = "copied!";
clearTimeout(timeout);
timeout = setTimeout(() => {
copyBtn.textContent = text
}, 2000);
const code = \`${AOT_GH_ACTION}\`;
await navigator.clipboard.writeText(code);
})
}
`,
}}
/>
</div>
);
}