-
-
Notifications
You must be signed in to change notification settings - Fork 124
Add SvelteKit support to fedify init
#971
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
Changes from all commits
baffa32
5031f57
e346470
6eeb562
5c8b4e3
ff7cbf5
e4b2836
b3c5541
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| - Added [SvelteKit] option to `fedify init` command. This option allows users | ||
| to initialize a new Fedify project with SvelteKit integration. | ||
| [[#892], [#971] by Jang Hanarae] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| links: | ||
| '#971': https://github.com/fedify-dev/fedify/pull/971 | ||
| --- | ||
| - Supported [SvelteKit] as a web framework option in | ||
| `fedify init`. [[#892], [#971] by Jang Hanarae] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| import { fedifyHook } from "@fedify/sveltekit"; | ||
| import { sequence } from "@sveltejs/kit/hooks"; | ||
| import federation from "$lib/federation"; | ||
|
|
||
| export const handle = sequence( | ||
| fedifyHook(federation), | ||
| ); | ||
|
Comment on lines
+1
to
+7
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -euo pipefail
# Inspect the SvelteKit server entry.
rg -n -C 3 'logging|federation|fedifyHook' \
packages/init/src/templates/sveltekit/hooks.server.ts.tpl
# Locate and inspect the template that generates src/lib/federation.ts.
fd -t f -g 'federation.ts.tpl' packages/init/src/templates -x \
rg -n -C 3 'logging|federation' {}Repository: fedify-dev/fedify Length of output: 892 🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "== target template =="
cat -n packages/init/src/templates/sveltekit/hooks.server.ts.tpl
echo
echo "== federation template(s) =="
fd -t f -g 'federation.ts.tpl' packages/init/src/templates -x sh -c 'printf "\n--- %s ---\n" "$1"; cat -n "$1"' sh {}
echo
echo "== generate hook and logging references =="
rg -n -C 4 'logging|src/lib/logging|hooks\.server|federation\.ts.tpl' packages/init/src
echo
echo "== static init flow snippets =="
fd -t f 'sveltekit\.ts|hooks\.server\.ts\.tpl|federation\.ts\.tpl' packages/init/src -x sh -c 'echo "--- $1 linecount ---"; wc -l "$1"' sh {}Repository: fedify-dev/fedify Length of output: 30074 Load LogTape in the SvelteKit server entry. The generated 🤖 Prompt for AI Agents |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| import { PACKAGE_MANAGER } from "../const.ts"; | ||
| import deps from "../json/deps.json" with { type: "json" }; | ||
| import { PACKAGE_VERSION, readTemplate } from "../lib.ts"; | ||
| import type { PackageManager, WebFrameworkDescription } from "../types.ts"; | ||
| import { defaultDenoDependencies, defaultDevDependencies } from "./const.ts"; | ||
| import { getInstruction, nodeBunDevToolTasks, pmToRt } from "./utils.ts"; | ||
|
|
||
| const sveltekitDescription: WebFrameworkDescription = { | ||
| label: "SvelteKit", | ||
| packageManagers: PACKAGE_MANAGER, | ||
| defaultPort: 5173, | ||
| init: async ({ packageManager: pm, testMode }) => ({ | ||
| command: Array.from(getInitCommand(pm)), | ||
| dependencies: { | ||
| "@fedify/sveltekit": PACKAGE_VERSION, | ||
| ...(pm === "deno" ? defaultDenoDependencies : {}), | ||
| }, | ||
| devDependencies: { | ||
| ...defaultDevDependencies, | ||
| "typescript": deps["npm:typescript"], | ||
| "@types/node": deps["npm:@types/node@25"], | ||
| ...(pmToRt(pm) === "deno" | ||
| ? {} | ||
| : { "@dotenvx/dotenvx": deps["npm:@dotenvx/dotenvx"] }), | ||
| }, | ||
| federationFile: "src/lib/federation.ts", | ||
| loggingFile: "src/lib/logging.ts", | ||
| env: testMode ? { HOST: "127.0.0.1" } : {} as Record<string, string>, | ||
| files: { | ||
| "src/hooks.server.ts": await readTemplate("sveltekit/hooks.server.ts"), | ||
| }, | ||
| tasks: pmToRt(pm) === "deno" ? {} : { ...TASKS }, | ||
| instruction: getInstruction(pm, 5173), | ||
| }), | ||
| }; | ||
|
|
||
| export default sveltekitDescription; | ||
|
|
||
| /** | ||
| * Returns the shell command array to scaffold a new SvelteKit project | ||
| * in the current directory using the given package manager. | ||
| */ | ||
| function* getInitCommand(pm: PackageManager) { | ||
| yield* getSvelteKitInitCommand(pm); | ||
| yield* [ | ||
| ".", | ||
| "--template", | ||
| "minimal", | ||
| "--types", | ||
| "ts", | ||
| "--no-add-ons", | ||
| "--no-dir-check", | ||
| "--no-download-check", | ||
| "--install", | ||
| pm, | ||
| ]; | ||
| } | ||
|
|
||
| const getSvelteKitInitCommand = (pm: PackageManager): string[] => | ||
| pm === "bun" | ||
| ? ["bunx", "sv", "create"] | ||
| : pm === "deno" | ||
| ? ["deno", "run", "-A", "npm:sv", "create"] | ||
| : pm === "npm" | ||
| ? ["npx", "sv", "create"] | ||
| : [pm, "dlx", "sv", "create"]; | ||
|
|
||
| const TASKS = { | ||
| "dev": "dotenvx run -- vite dev", | ||
| "build": "dotenvx run -- vite build", | ||
| "preview": "dotenvx run -- vite preview", | ||
| ...nodeBunDevToolTasks, | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Point the SvelteKit reference to the SvelteKit documentation.
The current reference opens the generic Svelte homepage. Use the SvelteKit documentation URL already used in
CHANGES.md.Proposed fix
🤖 Prompt for AI Agents