Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C3 add hono experimental template #6827

Merged
merged 1 commit into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/green-fishes-rest.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"create-cloudflare": patch
---

fix: add missing hono with assets experimental template
2 changes: 2 additions & 0 deletions packages/create-cloudflare/src/templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import gatsbyTemplateExperimental from "templates-experimental/gatsby/c3";
import assetsOnlyTemplateExperimental from "templates-experimental/hello-world-assets-only/c3";
import helloWorldWithDurableObjectAssetsTemplateExperimental from "templates-experimental/hello-world-durable-object-with-assets/c3";
import helloWorldWithAssetsTemplateExperimental from "templates-experimental/hello-world-with-assets/c3";
import honoTemplateExperimental from "templates-experimental/hono/c3";
import nuxtTemplateExperimental from "templates-experimental/nuxt/c3";
import qwikTemplateExperimental from "templates-experimental/qwik/c3";
import remixTemplateExperimental from "templates-experimental/remix/c3";
Expand Down Expand Up @@ -165,6 +166,7 @@ export function getFrameworkMap({ experimental = false }): TemplateMap {
astro: astroTemplateExperimental,
docusaurus: docusaurusTemplateExperimental,
gatsby: gatsbyTemplateExperimental,
hono: honoTemplateExperimental,
nuxt: nuxtTemplateExperimental,
qwik: qwikTemplateExperimental,
remix: remixTemplateExperimental,
Expand Down
43 changes: 43 additions & 0 deletions packages/create-cloudflare/templates-experimental/hono/c3.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { logRaw } from "@cloudflare/cli";
import { runFrameworkGenerator } from "frameworks/index";
import { detectPackageManager } from "helpers/packageManagers";
import type { TemplateConfig } from "../../src/templates";
import type { C3Context } from "types";

const generate = async (ctx: C3Context) => {
const { name: pm } = detectPackageManager();

await runFrameworkGenerator(ctx, [
ctx.project.name,
"--template",
"cloudflare-workers",
"--install",
"--pm",
pm,
]);

logRaw(""); // newline
};

const config: TemplateConfig = {
configVersion: 1,
id: "hono",
frameworkCli: "create-hono",
displayName: "Hono",
copyFiles: {
path: "./templates",
},
platform: "workers",
path: "templates-experimental/hono",
generate,
transformPackageJson: async () => ({
scripts: {
dev: "wrangler dev",
deploy: "wrangler deploy --minify",
"cf-typegen": "wrangler types --env-interface CloudflareBindings",
},
}),
devScript: "dev",
deployScript: "deploy",
};
export default config;
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Hello, World!</title>
</head>
<body>
<h1 id="heading"></h1>
<script>
fetch('/message')
.then((resp) => resp.text())
.then((text) => {
const h1 = document.getElementById('heading');
h1.textContent = text;
});
</script>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Hono } from "hono";

const app = new Hono<{ Bindings: CloudflareBindings }>();

app.get("/message", (c) => {
return c.text("Hello Hono!");
});

export default app;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Generated by Wrangler
// After adding bindings to `wrangler.toml`, regenerate this interface via `npm run cf-typegen`
interface CloudflareBindings {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#:schema node_modules/wrangler/config-schema.json
name = "<TBD>"
main = "src/index.ts"
compatibility_date = "<TBD>"
assets = { directory = "./public", binding = "ASSETS" }
Loading