From 2ef2179ce07b66efc358214d593d6a0c35555850 Mon Sep 17 00:00:00 2001 From: Rinat Date: Wed, 27 Mar 2024 00:43:26 +0100 Subject: [PATCH 1/3] feat: templated quickstart --- templates/base/README.md.template.mjs | 101 +++++++++++++----- .../extensions/foundry/README.md.args.mjs | 47 +------- .../extensions/hardhat/README.md.args.mjs | 47 +------- templates/utils.js | 15 +-- 4 files changed, 96 insertions(+), 114 deletions(-) diff --git a/templates/base/README.md.template.mjs b/templates/base/README.md.template.mjs index 8e5eb60c3..1ced6039c 100644 --- a/templates/base/README.md.template.mjs +++ b/templates/base/README.md.template.mjs @@ -1,6 +1,68 @@ import { withDefaults } from "../utils.js"; -const contents = ({ solidityFrameWork, quickStart }) => +const getQuickStart = ({ + solidityFramework, + networkConfigPath, + contractsPath, + scriptsPath, + testCommand, +}) => `## Quickstart + +To get started with Scaffold-ETH 2, follow the steps below: + +1. Install dependencies if it was skipped in CLI: + +\`\`\` +cd my-dapp-example +yarn install +\`\`\` + +${ + Boolean(solidityFramework[0]) + ? `2. Run a local network in the first terminal: + +\`\`\` +yarn chain +\`\`\` + +This command starts a local Ethereum network using ${solidityFramework[0]}. The network runs on your local machine and can be used for testing and development. You can customize the network configuration in ${networkConfigPath[0]}. + +3. On a second terminal, deploy the test contract: + +\`\`\` +yarn deploy +\`\`\` + +This command deploys a test smart contract to the local network. The contract is located in ${contractsPath[0]} and can be modified to suit your needs. The \`yarn deploy\` command uses the deploy script located in ${scriptsPath[0]} to deploy the contract to the network. You can also customize the deploy script. + +4. On a third terminal, start your NextJS app:` + : "2. Start your NextJS app:" +} + +\`\`\` +yarn start +\`\`\` + +Visit your app on: \`http://localhost:3000\`. You can interact with your smart contract using the \`Debug Contracts\` page. You can tweak the app config in \`packages/nextjs/scaffold.config.ts\`. +${ + Boolean(solidityFramework[0]) + ? ` +Run smart contract test with ${testCommand[0]} + +- Edit your smart contract \`YourContract.sol\` in ${contractsPath[0]} +- Edit your frontend homepage at \`packages/nextjs/app/page.tsx\`. For guidance on [routing](https://nextjs.org/docs/app/building-your-application/routing/defining-routes) and configuring [pages/layouts](https://nextjs.org/docs/app/building-your-application/routing/pages-and-layouts) checkout the Next.js documentation. +- Edit your deployment scripts in ${scriptsPath[0]} +` + : "" +}`; + +const contents = ({ + solidityFramework, + networkConfigPath, + contractsPath, + scriptsPath, + testCommand, +}) => `# ๐Ÿ— Scaffold-ETH 2

@@ -11,10 +73,10 @@ const contents = ({ solidityFrameWork, quickStart }) => ๐Ÿงช An open-source, up-to-date toolkit for building decentralized applications (dapps) on the Ethereum blockchain. It's designed to make it easier for developers to create and deploy smart contracts and build user interfaces that interact with those contracts. โš™๏ธ Built using NextJS, RainbowKit, ${ - Boolean(solidityFrameWork[0]) ? solidityFrameWork[0] + ", " : "" + Boolean(solidityFramework[0]) ? solidityFramework[0] + ", " : "" }Wagmi, Viem, and Typescript. ${ - Boolean(solidityFrameWork[0]) + Boolean(solidityFramework[0]) ? "\n- โœ… **Contract Hot Reload**: Your frontend auto-adapts to your smart contract as you edit it." : "" } @@ -33,8 +95,13 @@ Before you begin, you need to install the following tools: - Yarn ([v1](https://classic.yarnpkg.com/en/docs/install/) or [v2+](https://yarnpkg.com/getting-started/install)) - [Git](https://git-scm.com/downloads) -${quickStart[0]} - +${getQuickStart({ + solidityFramework, + networkConfigPath, + contractsPath, + scriptsPath, + testCommand, +})} ## Documentation Visit our [docs](https://docs.scaffoldeth.io) to learn how to start building with Scaffold-ETH 2. @@ -48,23 +115,9 @@ We welcome contributions to Scaffold-ETH 2! Please see [CONTRIBUTING.MD](https://github.com/scaffold-eth/scaffold-eth-2/blob/main/CONTRIBUTING.md) for more information and guidelines for contributing to Scaffold-ETH 2.`; export default withDefaults(contents, { - solidityFrameWork: "", - quickStart: `## Quickstart - -To get started with Scaffold-ETH 2, follow the steps below: - -1. Install dependencies if it was skipped in CLI: - -\`\`\` -cd my-dapp-example -yarn install -\`\`\` - -2. Start your NextJS app: - -\`\`\` -yarn start -\`\`\` - -Visit your app on: \`http://localhost:3000\`. You can interact with your smart contract using the \`Debug Contracts\` page. You can tweak the app config in \`packages/nextjs/scaffold.config.ts\`.`, + solidityFramework: "", + networkConfigPath: "", + contractsPath: "", + scriptsPath: "", + testCommand: "", }); diff --git a/templates/extensions/foundry/README.md.args.mjs b/templates/extensions/foundry/README.md.args.mjs index 4379af638..750d91ae8 100644 --- a/templates/extensions/foundry/README.md.args.mjs +++ b/templates/extensions/foundry/README.md.args.mjs @@ -1,42 +1,5 @@ -export const quickStart = `## Quickstart - -To get started with Scaffold-ETH 2, follow the steps below: - -1. Install dependencies if it was skipped in CLI: - -\`\`\` -cd my-dapp-example -yarn install -\`\`\` - -2. Run a local network in the first terminal: - -\`\`\` -yarn chain -\`\`\` - -This command starts a local Ethereum network using Foundry. The network runs on your local machine and can be used for testing and development. You can customize the network configuration in \`packages/foundry/foundry.toml\`. - -3. On a second terminal, deploy the test contract: - -\`\`\` -yarn deploy -\`\`\` - -This command deploys a test smart contract to the local network. The contract is located in \`packages/foundry/contracts\` and can be modified to suit your needs. The \`yarn deploy\` command uses the deploy script located in \`packages/foundry/script\` to deploy the contract to the network. You can also customize the deploy script. - -4. On a third terminal, start your NextJS app: - -\`\`\` -yarn start -\`\`\` - -Visit your app on: \`http://localhost:3000\`. You can interact with your smart contract using the \`Debug Contracts\` page. You can tweak the app config in \`packages/nextjs/scaffold.config.ts\`. - -Run smart contract test with \`yarn foundry:test\` - -- Edit your smart contract \`YourContract.sol\` in \`packages/foundry/contracts\` -- Edit your frontend homepage at \`packages/nextjs/app/page.tsx\`. For guidance on [routing](https://nextjs.org/docs/app/building-your-application/routing/defining-routes) and configuring [pages/layouts](https://nextjs.org/docs/app/building-your-application/routing/pages-and-layouts) checkout the Next.js documentation. -- Edit your deployment scripts in \`packages/foundry/script\``; - -export const solidityFrameWork = "Foundry"; +export const solidityFramework = "Foundry"; +export const networkConfigPath = `\`packages/foundry/foundry.toml\``; +export const contractsPath = `\`packages/foundry/contracts\``; +export const scriptsPath = `\`packages/foundry/script\``; +export const testCommand = `\`yarn foundry:test\``; diff --git a/templates/extensions/hardhat/README.md.args.mjs b/templates/extensions/hardhat/README.md.args.mjs index 06da83b51..a390c43e4 100644 --- a/templates/extensions/hardhat/README.md.args.mjs +++ b/templates/extensions/hardhat/README.md.args.mjs @@ -1,42 +1,5 @@ -export const quickStart = `## Quickstart - -To get started with Scaffold-ETH 2, follow the steps below: - -1. Install dependencies if it was skipped in CLI: - -\`\`\` -cd my-dapp-example -yarn install -\`\`\` - -2. Run a local network in the first terminal: - -\`\`\` -yarn chain -\`\`\` - -This command starts a local Ethereum network using Hardhat. The network runs on your local machine and can be used for testing and development. You can customize the network configuration in \`packages/hardhat/hardhat.config.ts\`. - -3. On a second terminal, deploy the test contract: - -\`\`\` -yarn deploy -\`\`\` - -This command deploys a test smart contract to the local network. The contract is located in \`packages/hardhat/contracts\` and can be modified to suit your needs. The \`yarn deploy\` command uses the deploy script located in \`packages/hardhat/deploy\` to deploy the contract to the network. You can also customize the deploy script. - -4. On a third terminal, start your NextJS app: - -\`\`\` -yarn start -\`\`\` - -Visit your app on: \`http://localhost:3000\`. You can interact with your smart contract using the \`Debug Contracts\` page. You can tweak the app config in \`packages/nextjs/scaffold.config.ts\`. - -Run smart contract test with \`yarn hardhat:test\` - -- Edit your smart contract \`YourContract.sol\` in \`packages/hardhat/contracts\` -- Edit your frontend homepage at \`packages/nextjs/app/page.tsx\`. For guidance on [routing](https://nextjs.org/docs/app/building-your-application/routing/defining-routes) and configuring [pages/layouts](https://nextjs.org/docs/app/building-your-application/routing/pages-and-layouts) checkout the Next.js documentation. -- Edit your deployment scripts in \`packages/hardhat/deploy\``; - -export const solidityFrameWork = "Hardhat"; +export const solidityFramework = "Hardhat"; +export const networkConfigPath = `\`packages/hardhat/hardhat.config.ts\``; +export const contractsPath = `\`packages/hardhat/contracts\``; +export const scriptsPath = `\`packages/hardhat/deploy\``; +export const testCommand = `\`yarn hardhat:test\``; diff --git a/templates/utils.js b/templates/utils.js index 26de24a9c..b6a3cbd45 100644 --- a/templates/utils.js +++ b/templates/utils.js @@ -2,21 +2,24 @@ export const withDefaults = (template, expectedArgsDefaults, debug = false) => (receivedArgs) => { const argsWithDefault = Object.fromEntries( - Object.entries(expectedArgsDefaults) - .map(([argName, argDefault]) => [argName, receivedArgs[argName] ?? [argDefault]]) + Object.entries(expectedArgsDefaults).map(([argName, argDefault]) => [ + argName, + receivedArgs[argName] ?? [argDefault], + ]) ); if (debug) { console.log(argsWithDefault, expectedArgsDefaults, receivedArgs); } - const expectedArgsNames = Object.keys(expectedArgsDefaults) + const expectedArgsNames = Object.keys(expectedArgsDefaults); + Object.keys(receivedArgs).forEach((receivedArgName) => { if (!expectedArgsNames.includes(receivedArgName)) { throw new Error( - `Templated received unexpected argument \`${receivedArgName}\`. Expecting only ${ - expectedArgsNames.map(name => `\`${name}\``).join(", ") - }` + `Template received unexpected argument \`${receivedArgName}\`. Expecting only ${expectedArgsNames + .map((name) => `\`${name}\``) + .join(", ")}` ); } }); From 9dfd6503b9c378c7196e9a8feaa99fb5c22dc844 Mon Sep 17 00:00:00 2001 From: Shiv Bhonde Date: Thu, 28 Mar 2024 21:01:20 +0530 Subject: [PATCH 2/3] revert changes to template/utils.js file --- templates/utils.js | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/templates/utils.js b/templates/utils.js index b6a3cbd45..6339f0be2 100644 --- a/templates/utils.js +++ b/templates/utils.js @@ -2,27 +2,24 @@ export const withDefaults = (template, expectedArgsDefaults, debug = false) => (receivedArgs) => { const argsWithDefault = Object.fromEntries( - Object.entries(expectedArgsDefaults).map(([argName, argDefault]) => [ - argName, - receivedArgs[argName] ?? [argDefault], - ]) + Object.entries(expectedArgsDefaults) + .map(([argName, argDefault]) => [argName, receivedArgs[argName] ?? [argDefault]]) ); if (debug) { console.log(argsWithDefault, expectedArgsDefaults, receivedArgs); } - const expectedArgsNames = Object.keys(expectedArgsDefaults); - + const expectedArgsNames = Object.keys(expectedArgsDefaults) Object.keys(receivedArgs).forEach((receivedArgName) => { if (!expectedArgsNames.includes(receivedArgName)) { throw new Error( - `Template received unexpected argument \`${receivedArgName}\`. Expecting only ${expectedArgsNames - .map((name) => `\`${name}\``) - .join(", ")}` + `Templated received unexpected argument \`${receivedArgName}\`. Expecting only ${ + expectedArgsNames.map(name => `\`${name}\``).join(", ") + }` ); } }); return template(argsWithDefault); - }; + }; \ No newline at end of file From 790a954bddca4ccad0b9b4351f58d7e0a83b1dbe Mon Sep 17 00:00:00 2001 From: Shiv Bhonde Date: Thu, 28 Mar 2024 21:02:21 +0530 Subject: [PATCH 3/3] add extra line in templates/utils.js --- templates/utils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/utils.js b/templates/utils.js index 6339f0be2..26de24a9c 100644 --- a/templates/utils.js +++ b/templates/utils.js @@ -22,4 +22,4 @@ export const withDefaults = }); return template(argsWithDefault); - }; \ No newline at end of file + };