fix: init script (#2458)

This commit is contained in:
Luca Casonato
2024-05-24 20:29:31 +02:00
committed by GitHub
parent 476b4c75a7
commit 584e5716c3
2 changed files with 15 additions and 16 deletions
+10 -11
View File
@@ -173,11 +173,11 @@ ENV DENO_DEPLOYMENT_ID=\${GIT_REVISION}
WORKDIR /app WORKDIR /app
COPY . . COPY . .
RUN deno cache main.tsx RUN deno cache main.ts
EXPOSE 8000 EXPOSE 8000
CMD ["run", "-A", "main.tsx"] CMD ["run", "-A", "main.ts"]
`; `;
await writeFile("Dockerfile", DOCKERFILE_TEXT); await writeFile("Dockerfile", DOCKERFILE_TEXT);
@@ -350,17 +350,16 @@ html {
// Skip this and be silent if there is a network issue. // Skip this and be silent if there is a network issue.
} }
const MAIN_TSX = `import { App, staticFiles, fsRoutes } from "@fresh/core"; const MAIN_TS = `import { App, staticFiles, fsRoutes } from "@fresh/core";
import { State } from "./utils.ts"; import { State } from "./utils.ts";
export const app = new App<State>() export const app = new App<State>();
.use(staticFiles()) app.use(staticFiles());
.get("/api/:joke", () => new Response("Hello World"))
.get("/greet/:name", (ctx) => { app.get("/api/:joke", () => new Response("Hello World"));
return ctx.render(<h1>Hello {ctx.params.name}</h1>);
});
await fsRoutes(app, { await fsRoutes(app, {
dir: "./",
loadIsland: (path) => import(\`./islands/\${path}\`), loadIsland: (path) => import(\`./islands/\${path}\`),
loadRoute: (path) => import(\`./routes/\${path}\`), loadRoute: (path) => import(\`./routes/\${path}\`),
}); });
@@ -369,7 +368,7 @@ if (import.meta.main) {
await app.listen(); await app.listen();
} }
`; `;
await writeFile("main.tsx", MAIN_TSX); await writeFile("main.ts", MAIN_TS);
const COMPONENTS_BUTTON_TSX = `import { ComponentChildren } from "preact"; const COMPONENTS_BUTTON_TSX = `import { ComponentChildren } from "preact";
@@ -469,7 +468,7 @@ export default function Counter(props: CounterProps) {
const DEV_TS = `#!/usr/bin/env -S deno run -A --watch=static/,routes/ const DEV_TS = `#!/usr/bin/env -S deno run -A --watch=static/,routes/
${useTailwind ? `import { tailwind } from "@fresh/plugin-tailwind";\n` : ""}; ${useTailwind ? `import { tailwind } from "@fresh/plugin-tailwind";\n` : ""};
import { Builder } from "@fresh/core/dev"; import { Builder } from "@fresh/core/dev";
import { app } from "./main.tsx"; import { app } from "./main.ts";
const builder = new Builder(); const builder = new Builder();
${useTailwind ? "tailwind(builder, app, {});\n" : "\n"} ${useTailwind ? "tailwind(builder, app, {});\n" : "\n"}
+5 -5
View File
@@ -66,7 +66,7 @@ Deno.test("init - create project dir", async () => {
const root = path.join(dir, "fresh-init"); const root = path.join(dir, "fresh-init");
await expectProjectFile(root, "deno.json"); await expectProjectFile(root, "deno.json");
await expectProjectFile(root, "main.tsx"); await expectProjectFile(root, "main.ts");
await expectProjectFile(root, "dev.ts"); await expectProjectFile(root, "dev.ts");
await expectProjectFile(root, ".gitignore"); await expectProjectFile(root, ".gitignore");
await expectProjectFile(root, "static/styles.css"); await expectProjectFile(root, "static/styles.css");
@@ -84,7 +84,7 @@ Deno.test("init - with tailwind", async () => {
const css = await readProjectFile(dir, "static/styles.css"); const css = await readProjectFile(dir, "static/styles.css");
expect(css).toMatch(/@tailwind/); expect(css).toMatch(/@tailwind/);
const main = await readProjectFile(dir, "main.tsx"); const main = await readProjectFile(dir, "main.ts");
const dev = await readProjectFile(dir, "dev.ts"); const dev = await readProjectFile(dir, "dev.ts");
expect(main).not.toMatch(/tailwind/); expect(main).not.toMatch(/tailwind/);
expect(dev).toMatch(/tailwind/); expect(dev).toMatch(/tailwind/);
@@ -111,7 +111,7 @@ Deno.test.ignore("init - can start dev server", async () => {
[InitStep.ProjectName]: ".", [InitStep.ProjectName]: ".",
}); });
await initProject(dir, [], {}, mock.tty); await initProject(dir, [], {}, mock.tty);
await expectProjectFile(dir, "main.tsx"); await expectProjectFile(dir, "main.ts");
await expectProjectFile(dir, "dev.ts"); await expectProjectFile(dir, "dev.ts");
await withChildProcessServer( await withChildProcessServer(
@@ -135,7 +135,7 @@ Deno.test.ignore("init - can start build project", async () => {
[InitStep.ProjectName]: ".", [InitStep.ProjectName]: ".",
}); });
await initProject(dir, [], {}, mock.tty); await initProject(dir, [], {}, mock.tty);
await expectProjectFile(dir, "main.tsx"); await expectProjectFile(dir, "main.ts");
await expectProjectFile(dir, "dev.ts"); await expectProjectFile(dir, "dev.ts");
// Build // Build
@@ -149,7 +149,7 @@ Deno.test.ignore("init - can start build project", async () => {
await withChildProcessServer( await withChildProcessServer(
dir, dir,
path.join(dir, "main.tsx"), path.join(dir, "main.ts"),
async (address) => { async (address) => {
console.log({ address }); console.log({ address });
await withBrowser(async (page) => { await withBrowser(async (page) => {