From 2783fe32f427ffa19abde15fb6bfcfd62dc32feb Mon Sep 17 00:00:00 2001 From: port dev <108868128+portdeveloper@users.noreply.github.com> Date: Sat, 26 Oct 2024 03:04:40 +0300 Subject: [PATCH 1/8] Add template for tsconfig.json --- .changeset/soft-shrimps-pull.md | 5 +++ templates/base/packages/nextjs/tsconfig.json | 28 ------------ .../nextjs/tsconfig.json.template.mjs | 45 +++++++++++++++++++ 3 files changed, 50 insertions(+), 28 deletions(-) create mode 100644 .changeset/soft-shrimps-pull.md delete mode 100644 templates/base/packages/nextjs/tsconfig.json create mode 100644 templates/base/packages/nextjs/tsconfig.json.template.mjs 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/tsconfig.json b/templates/base/packages/nextjs/tsconfig.json deleted file mode 100644 index 69290112d..000000000 --- a/templates/base/packages/nextjs/tsconfig.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "compilerOptions": { - "target": "es2020", - "lib": ["dom", "dom.iterable", "esnext"], - "allowJs": true, - "skipLibCheck": true, - "strict": true, - "forceConsistentCasingInFileNames": true, - "noEmit": true, - "esModuleInterop": true, - "module": "esnext", - "moduleResolution": "Bundler", - "resolveJsonModule": true, - "isolatedModules": true, - "jsx": "preserve", - "incremental": true, - "paths": { - "~~/*": ["./*"] - }, - "plugins": [ - { - "name": "next" - } - ] - }, - "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"], - "exclude": ["node_modules"] -} diff --git a/templates/base/packages/nextjs/tsconfig.json.template.mjs b/templates/base/packages/nextjs/tsconfig.json.template.mjs new file mode 100644 index 000000000..ac8fb1bee --- /dev/null +++ b/templates/base/packages/nextjs/tsconfig.json.template.mjs @@ -0,0 +1,45 @@ +import { withDefaults } from '../../../utils.js' + +const contents = ({ extraPaths, extraPlugins, extraCompilerOptions, extraInclude, extraExclude }) => `{ + "compilerOptions": { + "target": "es2020", + "lib": ["dom", "dom.iterable", "esnext"], + "allowJs": true, + "skipLibCheck": true, + "strict": true, + "forceConsistentCasingInFileNames": true, + "noEmit": true, + "esModuleInterop": true, + "module": "esnext", + "moduleResolution": "Bundler", + "resolveJsonModule": true, + "isolatedModules": true, + "jsx": "preserve", + "incremental": true, + "paths": { + "~~/*": ["./*"]${extraPaths[0] ? `,${extraPaths[0]}` : ''} + }, + "plugins": [ + { + "name": "next" + }${extraPlugins[0] ? `,${extraPlugins[0]}` : ''} + ]${extraCompilerOptions[0] ? `,${extraCompilerOptions[0]}` : ''} + }, + "include": [ + "next-env.d.ts", + "**/*.ts", + "**/*.tsx", + ".next/types/**/*.ts"${extraInclude[0] ? `,${extraInclude[0]}` : ''} + ], + "exclude": [ + "node_modules"${extraExclude[0] ? `,${extraExclude[0]}` : ''} + ] +}` + +export default withDefaults(contents, { + extraPaths: '', + extraPlugins: '', + extraCompilerOptions: '', + extraInclude: '', + extraExclude: '' +}) From 7df1a2cf6499a5ef15da8815fa189c19387c1060 Mon Sep 17 00:00:00 2001 From: port dev <108868128+portdeveloper@users.noreply.github.com> Date: Sun, 27 Oct 2024 23:34:35 +0300 Subject: [PATCH 2/8] Remove unnecessary params --- .../base/packages/nextjs/tsconfig.json.template.mjs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/templates/base/packages/nextjs/tsconfig.json.template.mjs b/templates/base/packages/nextjs/tsconfig.json.template.mjs index ac8fb1bee..836dd5704 100644 --- a/templates/base/packages/nextjs/tsconfig.json.template.mjs +++ b/templates/base/packages/nextjs/tsconfig.json.template.mjs @@ -1,6 +1,6 @@ import { withDefaults } from '../../../utils.js' -const contents = ({ extraPaths, extraPlugins, extraCompilerOptions, extraInclude, extraExclude }) => `{ +const contents = ({ extraPlugins, extraCompilerOptions }) => `{ "compilerOptions": { "target": "es2020", "lib": ["dom", "dom.iterable", "esnext"], @@ -17,7 +17,7 @@ const contents = ({ extraPaths, extraPlugins, extraCompilerOptions, extraInclude "jsx": "preserve", "incremental": true, "paths": { - "~~/*": ["./*"]${extraPaths[0] ? `,${extraPaths[0]}` : ''} + "~~/*": ["./*"] }, "plugins": [ { @@ -29,17 +29,14 @@ const contents = ({ extraPaths, extraPlugins, extraCompilerOptions, extraInclude "next-env.d.ts", "**/*.ts", "**/*.tsx", - ".next/types/**/*.ts"${extraInclude[0] ? `,${extraInclude[0]}` : ''} + ".next/types/**/*.ts" ], "exclude": [ - "node_modules"${extraExclude[0] ? `,${extraExclude[0]}` : ''} + "node_modules" ] }` export default withDefaults(contents, { - extraPaths: '', extraPlugins: '', - extraCompilerOptions: '', - extraInclude: '', - extraExclude: '' + extraCompilerOptions: '' }) From a5c129083b2186b37ecb9168eaf8be4368e15f9a Mon Sep 17 00:00:00 2001 From: port dev <108868128+portdeveloper@users.noreply.github.com> Date: Mon, 28 Oct 2024 18:59:36 +0300 Subject: [PATCH 3/8] Update the template file to use stringify func --- .../packages/nextjs/tsconfig.json.template.mjs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/templates/base/packages/nextjs/tsconfig.json.template.mjs b/templates/base/packages/nextjs/tsconfig.json.template.mjs index 836dd5704..16b7d28b2 100644 --- a/templates/base/packages/nextjs/tsconfig.json.template.mjs +++ b/templates/base/packages/nextjs/tsconfig.json.template.mjs @@ -1,6 +1,6 @@ -import { withDefaults } from '../../../utils.js' +import { stringify, withDefaults } from '../../../utils.js' -const contents = ({ extraPlugins, extraCompilerOptions }) => `{ +const contents = ({ extraPlugins, extraCompilerOptions }) => `${stringify({ "compilerOptions": { "target": "es2020", "lib": ["dom", "dom.iterable", "esnext"], @@ -22,8 +22,10 @@ const contents = ({ extraPlugins, extraCompilerOptions }) => `{ "plugins": [ { "name": "next" - }${extraPlugins[0] ? `,${extraPlugins[0]}` : ''} - ]${extraCompilerOptions[0] ? `,${extraCompilerOptions[0]}` : ''} + }, + ...extraPlugins[0] + ], + ...extraCompilerOptions[0] }, "include": [ "next-env.d.ts", @@ -34,9 +36,9 @@ const contents = ({ extraPlugins, extraCompilerOptions }) => `{ "exclude": [ "node_modules" ] -}` +})}` export default withDefaults(contents, { - extraPlugins: '', - extraCompilerOptions: '' + extraPlugins: [''], + extraCompilerOptions: [''] }) From f158bb8cb68cde724d63cd5180da309c3af66742 Mon Sep 17 00:00:00 2001 From: port dev <108868128+portdeveloper@users.noreply.github.com> Date: Mon, 28 Oct 2024 19:31:58 +0300 Subject: [PATCH 4/8] Modify template to work with non-existing args --- templates/base/packages/nextjs/tsconfig.json.template.mjs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/templates/base/packages/nextjs/tsconfig.json.template.mjs b/templates/base/packages/nextjs/tsconfig.json.template.mjs index 16b7d28b2..829fe8606 100644 --- a/templates/base/packages/nextjs/tsconfig.json.template.mjs +++ b/templates/base/packages/nextjs/tsconfig.json.template.mjs @@ -23,9 +23,9 @@ const contents = ({ extraPlugins, extraCompilerOptions }) => `${stringify({ { "name": "next" }, - ...extraPlugins[0] + ...(extraPlugins?.[0] || []) ], - ...extraCompilerOptions[0] + ...(extraCompilerOptions?.[0] || {}) }, "include": [ "next-env.d.ts", @@ -39,6 +39,6 @@ const contents = ({ extraPlugins, extraCompilerOptions }) => `${stringify({ })}` export default withDefaults(contents, { - extraPlugins: [''], - extraCompilerOptions: [''] + extraPlugins: null, + extraCompilerOptions: null }) From 14ddaf47787cf2ce4ceea8db2cfded88b4b16144 Mon Sep 17 00:00:00 2001 From: port dev <108868128+portdeveloper@users.noreply.github.com> Date: Mon, 28 Oct 2024 22:28:26 +0300 Subject: [PATCH 5/8] Fix bad practices --- templates/base/packages/nextjs/tsconfig.json.template.mjs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/templates/base/packages/nextjs/tsconfig.json.template.mjs b/templates/base/packages/nextjs/tsconfig.json.template.mjs index 829fe8606..633090b0a 100644 --- a/templates/base/packages/nextjs/tsconfig.json.template.mjs +++ b/templates/base/packages/nextjs/tsconfig.json.template.mjs @@ -23,9 +23,9 @@ const contents = ({ extraPlugins, extraCompilerOptions }) => `${stringify({ { "name": "next" }, - ...(extraPlugins?.[0] || []) + ...extraPlugins[0] ], - ...(extraCompilerOptions?.[0] || {}) + ...extraCompilerOptions[0] }, "include": [ "next-env.d.ts", @@ -39,6 +39,6 @@ const contents = ({ extraPlugins, extraCompilerOptions }) => `${stringify({ })}` export default withDefaults(contents, { - extraPlugins: null, - extraCompilerOptions: null + extraPlugins: [], + extraCompilerOptions: {} }) From ec2d35833a29a596f9808876f7614ebf6a2d4f15 Mon Sep 17 00:00:00 2001 From: port dev <108868128+portdeveloper@users.noreply.github.com> Date: Tue, 29 Oct 2024 17:37:55 +0300 Subject: [PATCH 6/8] Delete unnecessary files --- my-tsconfig-test | 1 - pwa | 1 - 2 files changed, 2 deletions(-) delete mode 160000 my-tsconfig-test delete mode 160000 pwa diff --git a/my-tsconfig-test b/my-tsconfig-test deleted file mode 160000 index 8bb8e77a0..000000000 --- a/my-tsconfig-test +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 8bb8e77a087822f725fcc75ceb66ff264452bfb7 diff --git a/pwa b/pwa deleted file mode 160000 index 9c7cbcd46..000000000 --- a/pwa +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 9c7cbcd4698c6aa544e31bc787af364ba87e8f16 From e8d62275822a014e2e856e5ebe2f37088f35f5fe Mon Sep 17 00:00:00 2001 From: port dev <108868128+portdeveloper@users.noreply.github.com> Date: Fri, 1 Nov 2024 20:44:16 +0300 Subject: [PATCH 7/8] Add manifest.json template --- .../base/packages/nextjs/public/manifest.json | 5 ----- .../nextjs/public/manifest.json.template.mjs | 15 +++++++++++++++ 2 files changed, 15 insertions(+), 5 deletions(-) delete mode 100644 templates/base/packages/nextjs/public/manifest.json create mode 100644 templates/base/packages/nextjs/public/manifest.json.template.mjs 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 From 08165994c884941c5592c92a36546f5c7d40a655 Mon Sep 17 00:00:00 2001 From: port dev <108868128+portdeveloper@users.noreply.github.com> Date: Fri, 1 Nov 2024 23:43:03 +0300 Subject: [PATCH 8/8] Add getmetadata template... in a weird way... --- ...etadata.ts => getMetadata.ts.template.mjs} | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) rename templates/base/packages/nextjs/utils/scaffold-eth/{getMetadata.ts => getMetadata.ts.template.mjs} (54%) 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: {} +})