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:
@@ -185,6 +185,7 @@ Deno.test({
|
||||
"/.vscode/settings.json",
|
||||
"/.vscode/extensions.json",
|
||||
"/.gitignore",
|
||||
"/.github/workflows/deploy.yml",
|
||||
];
|
||||
|
||||
await t.step("check generated files", async () => {
|
||||
|
||||
+62
-2
@@ -1,5 +1,12 @@
|
||||
import { runBuild, withFakeServe } from "./test_utils.ts";
|
||||
import { assert, assertStringIncludes } from "./deps.ts";
|
||||
import { fetchHtml, runBuild, withFakeServe, withFresh } from "./test_utils.ts";
|
||||
import {
|
||||
assert,
|
||||
assertStringIncludes,
|
||||
dirname,
|
||||
join,
|
||||
TextLineStream,
|
||||
} from "./deps.ts";
|
||||
import { assertEquals } from "$std/assert/assert_equals.ts";
|
||||
|
||||
Deno.test("TailwindCSS - dev mode", async () => {
|
||||
await withFakeServe("./tests/fixture_tailwind/dev.ts", async (server) => {
|
||||
@@ -62,3 +69,56 @@ Deno.test("TailwindCSS - middleware only css", async () => {
|
||||
{ loadConfig: true },
|
||||
);
|
||||
});
|
||||
|
||||
Deno.test("TailwindCSS - missing snapshot warning", async () => {
|
||||
const dir = dirname(import.meta.url);
|
||||
const out = await new Deno.Command(Deno.execPath(), {
|
||||
args: ["run", "-A", join(dir, "./fixture_tailwind/main.ts")],
|
||||
stdout: "piped",
|
||||
stderr: "piped",
|
||||
}).spawn();
|
||||
|
||||
const lines: ReadableStream<string> = out.stderr
|
||||
.pipeThrough(new TextDecoderStream())
|
||||
.pipeThrough(new TextLineStream());
|
||||
|
||||
let found = false;
|
||||
// @ts-ignore yes it does
|
||||
for await (const line of lines.values({ preventCancel: true })) {
|
||||
if (!found && line.includes("No pre-compiled tailwind styles found")) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
assert(found, "Tailwind compile warning was not logged");
|
||||
} finally {
|
||||
await out.stdout.cancel();
|
||||
out.kill("SIGTERM");
|
||||
await out.status;
|
||||
|
||||
// Drain the lines stream
|
||||
for await (const _ of lines) { /* noop */ }
|
||||
}
|
||||
});
|
||||
|
||||
Deno.test("TailwindCSS - missing snapshot on Deno Deploy", async () => {
|
||||
await withFresh(
|
||||
{
|
||||
name: "./tests/fixture_tailwind/main.ts",
|
||||
options: {
|
||||
env: {
|
||||
DENO_DEPLOYMENT_ID: "foo",
|
||||
},
|
||||
},
|
||||
},
|
||||
async (address) => {
|
||||
const doc = await fetchHtml(address);
|
||||
assertEquals(
|
||||
doc.querySelector("h1")?.textContent,
|
||||
"Finish setting up Fresh",
|
||||
);
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
+13
-2
@@ -218,11 +218,22 @@ export async function withFresh(
|
||||
}
|
||||
|
||||
export async function withPageName(
|
||||
name: string,
|
||||
name: string | { name: string; options: Omit<Deno.CommandOptions, "args"> },
|
||||
fn: (page: Page, address: string) => Promise<void>,
|
||||
) {
|
||||
let file: string;
|
||||
let options = {};
|
||||
|
||||
if (typeof name === "object") {
|
||||
file = name.name;
|
||||
options = name.options ?? {};
|
||||
} else {
|
||||
file = name;
|
||||
}
|
||||
|
||||
const { lines, serverProcess, address } = await startFreshServer({
|
||||
args: ["run", "-A", name],
|
||||
...options,
|
||||
args: ["run", "-A", file],
|
||||
});
|
||||
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user