|
| 1 | +import { PACKAGE_MANAGER } from "../const.ts"; |
| 2 | +import deps from "../json/deps.json" with { type: "json" }; |
| 3 | +import { PACKAGE_VERSION, readTemplate } from "../lib.ts"; |
| 4 | +import type { PackageManager, WebFrameworkDescription } from "../types.ts"; |
| 5 | +import { defaultDenoDependencies, defaultDevDependencies } from "./const.ts"; |
| 6 | +import { getInstruction } from "./utils.ts"; |
| 7 | + |
| 8 | +const nuxtDescription: WebFrameworkDescription = { |
| 9 | + label: "Nuxt", |
| 10 | + packageManagers: PACKAGE_MANAGER, |
| 11 | + defaultPort: 3000, |
| 12 | + init: async ({ packageManager: pm, testMode }) => ({ |
| 13 | + command: Array.from(getInitCommand(pm)), |
| 14 | + dependencies: getDeps(pm), |
| 15 | + devDependencies: { |
| 16 | + ...defaultDevDependencies, |
| 17 | + "typescript": deps["npm:typescript"], |
| 18 | + "@types/node": deps["npm:@types/node@25"], |
| 19 | + }, |
| 20 | + federationFile: "server/federation.ts", |
| 21 | + loggingFile: "server/logging.ts", |
| 22 | + env: testMode ? { HOST: "127.0.0.1" } : {} as Record<string, string>, |
| 23 | + files: { |
| 24 | + "nuxt.config.ts": await readTemplate("nuxt/nuxt.config.ts"), |
| 25 | + ...(pm !== "deno" && { |
| 26 | + "eslint.config.ts": await readTemplate("defaults/eslint.config.ts"), |
| 27 | + }), |
| 28 | + }, |
| 29 | + tasks: pm !== "deno" |
| 30 | + ? { "lint": "eslint ." } |
| 31 | + : {} as Record<string, string>, |
| 32 | + instruction: getInstruction(pm, 3000), |
| 33 | + }), |
| 34 | +}; |
| 35 | + |
| 36 | +export default nuxtDescription; |
| 37 | + |
| 38 | +function* getInitCommand(pm: PackageManager) { |
| 39 | + yield* getNuxtInitCommand(pm); |
| 40 | + yield* [ |
| 41 | + "init", |
| 42 | + ".", |
| 43 | + "--template", |
| 44 | + "minimal", |
| 45 | + "--no-install", |
| 46 | + "--force", |
| 47 | + "--packageManager", |
| 48 | + pm, |
| 49 | + "--no-gitInit", |
| 50 | + "--no-modules", |
| 51 | + "&&", |
| 52 | + "rm", |
| 53 | + "nuxt.config.ts", |
| 54 | + ]; |
| 55 | +} |
| 56 | + |
| 57 | +/** |
| 58 | + * Returns the shell command array to scaffold a new Nuxt project |
| 59 | + * in the current directory using the given package manager. |
| 60 | + */ |
| 61 | +const getNuxtInitCommand = (pm: PackageManager): string[] => |
| 62 | + pm === "bun" |
| 63 | + ? ["bunx", "nuxi"] |
| 64 | + : pm === "deno" |
| 65 | + ? ["deno", "-A", "npm:nuxi@latest"] |
| 66 | + : pm === "npm" |
| 67 | + ? ["npx", "nuxi"] |
| 68 | + : [pm, "dlx", "nuxi"]; |
| 69 | + |
| 70 | +const getDeps = (pm: PackageManager): Record<string, string> => |
| 71 | + pm !== "deno" |
| 72 | + ? { |
| 73 | + "@fedify/nuxt": PACKAGE_VERSION, |
| 74 | + } |
| 75 | + : { |
| 76 | + ...defaultDenoDependencies, |
| 77 | + "@fedify/nuxt": PACKAGE_VERSION, |
| 78 | + }; |
0 commit comments