|
| 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 | + "server/federation.ts": await readTemplate("nuxt/server/federation.ts"), |
| 26 | + "server/logging.ts": await readTemplate("nuxt/server/logging.ts"), |
| 27 | + "server/middleware/federation.ts": await readTemplate( |
| 28 | + "nuxt/server/middleware/federation.ts", |
| 29 | + ), |
| 30 | + ...(pm !== "deno" && { |
| 31 | + "eslint.config.ts": await readTemplate("defaults/eslint.config.ts"), |
| 32 | + }), |
| 33 | + }, |
| 34 | + tasks: pm !== "deno" |
| 35 | + ? { "lint": "eslint ." } |
| 36 | + : {} as Record<string, string>, |
| 37 | + instruction: getInstruction(pm, 3000), |
| 38 | + }), |
| 39 | +}; |
| 40 | + |
| 41 | +export default nuxtDescription; |
| 42 | + |
| 43 | +function* getInitCommand(pm: PackageManager) { |
| 44 | + yield* getNuxtInitCommand(pm); |
| 45 | + yield "init"; |
| 46 | + yield "."; |
| 47 | + yield "--template"; |
| 48 | + yield "minimal"; |
| 49 | + yield "--no-install"; |
| 50 | + yield "--force"; |
| 51 | + yield "--packageManager"; |
| 52 | + yield pm; |
| 53 | + yield "--no-gitInit"; |
| 54 | + yield "--no-modules"; |
| 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 | + "h3": deps["npm:h3"], |
| 75 | + "nuxt": deps["npm:nuxt"], |
| 76 | + } |
| 77 | + : { |
| 78 | + ...defaultDenoDependencies, |
| 79 | + "@fedify/nuxt": PACKAGE_VERSION, |
| 80 | + "npm:@nuxt/kit": deps["npm:@nuxt/kit"], |
| 81 | + "npm:h3": deps["npm:h3"], |
| 82 | + "npm:nuxt": deps["npm:nuxt"], |
| 83 | + }; |
0 commit comments