diff --git a/.changeset/soft-shrimps-pull.md b/.changeset/soft-shrimps-pull.md new file mode 100644 index 000000000..43521e9f8 --- /dev/null +++ b/.changeset/soft-shrimps-pull.md @@ -0,0 +1,5 @@ +--- +"create-eth": patch +--- + +templates: added template for tsconfig.json file diff --git a/templates/base/packages/nextjs/public/manifest.json b/templates/base/packages/nextjs/public/manifest.json deleted file mode 100644 index bb1c96df9..000000000 --- a/templates/base/packages/nextjs/public/manifest.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Scaffold-ETH 2 DApp", - "description": "A DApp built with Scaffold-ETH", - "iconPath": "logo.svg" -} diff --git a/templates/base/packages/nextjs/public/manifest.json.template.mjs b/templates/base/packages/nextjs/public/manifest.json.template.mjs new file mode 100644 index 000000000..29c0849aa --- /dev/null +++ b/templates/base/packages/nextjs/public/manifest.json.template.mjs @@ -0,0 +1,15 @@ +import { stringify, withDefaults } from '../../../../utils.js' + +const contents = ({ name, description, iconPath, extraContent }) => stringify({ + name: name[0], + description: description[0], + ...(iconPath[0] && { iconPath: iconPath[0] }), // Only include iconPath if it's provided + ...extraContent[0] +}) + +export default withDefaults(contents, { + name: "Scaffold-ETH 2 DApp", + description: "A DApp built with Scaffold-ETH", + iconPath: "logo.svg", + extraContent: [] +}) \ No newline at end of file diff --git a/templates/base/packages/nextjs/tsconfig.json b/templates/base/packages/nextjs/tsconfig.json.template.mjs similarity index 54% rename from templates/base/packages/nextjs/tsconfig.json rename to templates/base/packages/nextjs/tsconfig.json.template.mjs index 69290112d..633090b0a 100644 --- a/templates/base/packages/nextjs/tsconfig.json +++ b/templates/base/packages/nextjs/tsconfig.json.template.mjs @@ -1,4 +1,6 @@ -{ +import { stringify, withDefaults } from '../../../utils.js' + +const contents = ({ extraPlugins, extraCompilerOptions }) => `${stringify({ "compilerOptions": { "target": "es2020", "lib": ["dom", "dom.iterable", "esnext"], @@ -20,9 +22,23 @@ "plugins": [ { "name": "next" - } - ] + }, + ...extraPlugins[0] + ], + ...extraCompilerOptions[0] }, - "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"], - "exclude": ["node_modules"] -} + "include": [ + "next-env.d.ts", + "**/*.ts", + "**/*.tsx", + ".next/types/**/*.ts" + ], + "exclude": [ + "node_modules" + ] +})}` + +export default withDefaults(contents, { + extraPlugins: [], + extraCompilerOptions: {} +}) diff --git a/templates/base/packages/nextjs/utils/scaffold-eth/getMetadata.ts b/templates/base/packages/nextjs/utils/scaffold-eth/getMetadata.ts.template.mjs similarity index 54% rename from templates/base/packages/nextjs/utils/scaffold-eth/getMetadata.ts rename to templates/base/packages/nextjs/utils/scaffold-eth/getMetadata.ts.template.mjs index ad531aea6..6212e0b55 100644 --- a/templates/base/packages/nextjs/utils/scaffold-eth/getMetadata.ts +++ b/templates/base/packages/nextjs/utils/scaffold-eth/getMetadata.ts.template.mjs @@ -1,9 +1,12 @@ +import { stringify, withDefaults } from '../../../../../utils.js' + +const contents = ({ titleTemplate, extraIcons, extraMetadata }) => ` import type { Metadata } from "next"; const baseUrl = process.env.VERCEL_PROJECT_PRODUCTION_URL - ? `https://${process.env.VERCEL_PROJECT_PRODUCTION_URL}` - : `http://localhost:${process.env.PORT || 3000}`; -const titleTemplate = "%s | Scaffold-ETH 2"; + ? \`https://\${process.env.VERCEL_PROJECT_PRODUCTION_URL}\` + : \`http://localhost:\${process.env.PORT || 3000}\`; +const titleTemplate = "${titleTemplate[0] || '%s | Scaffold-ETH 2'}"; export const getMetadata = ({ title, @@ -14,7 +17,7 @@ export const getMetadata = ({ description: string; imageRelativePath?: string; }): Metadata => { - const imageUrl = `${baseUrl}${imageRelativePath}`; + const imageUrl = \`\${baseUrl}\${imageRelativePath}\`; return { metadataBase: new URL(baseUrl), @@ -45,6 +48,15 @@ export const getMetadata = ({ }, icons: { icon: [{ url: "/favicon.png", sizes: "32x32", type: "image/png" }], + ${extraIcons[0] ? Object.entries(extraIcons[0]).map(([key, value]) => `${key}: ${JSON.stringify(value)}`).join(',\n ') : ''} }, + ${extraMetadata[0] ? Object.entries(extraMetadata[0]).map(([key, value]) => `${key}: ${JSON.stringify(value)}`).join(',\n ') : ''} }; }; +` + +export default withDefaults(contents, { + titleTemplate: '', + extraIcons: {}, + extraMetadata: {} +})