├── .DS_Store
├── .gitignore
├── LICENSE
├── README.md
├── dist
├── constants
│ ├── index.js
│ └── templates.js
├── index.js
└── utils
│ ├── index.js
│ ├── next.helpers.js
│ └── vite.helpers.js
├── package.json
├── pnpm-lock.yaml
├── src
├── constants
│ ├── index.ts
│ └── templates.ts
├── index.ts
└── utils
│ ├── index.ts
│ ├── next.helpers.ts
│ └── vite.helpers.ts
├── tsconfig.json
└── types.d.ts
/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Consensys/create-web3-template/99710eaf75893d452acceffc2f95f10bb5475c86/.DS_Store
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | demo
3 | *.yaml
4 | dist
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright [yyyy] [name of copyright owner]
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Create Web3 Template CLI
2 |
3 | This is a CLI tool that scaffolds Next.js and React projects with a focus on Web3 development.
4 |
5 | ## Features
6 |
7 | - **Framework Options**: Choose between [Next.js](https://nextjs.org/) and [React with Vite](https://vitejs.dev/) for your frontend application.
8 | - **Blockchain Tooling**: Select either [Hardhat](https://hardhat.org/) or [Foundry](https://getfoundry.sh/) for smart contract development.
9 | - **Package Manager Choice**: Use your preferred package manager: **npm**, **yarn**, or **pnpm**.
10 | - **TypeScript Support**: Write strongly-typed code with built-in TypeScript support.
11 | - **Tailwind CSS**: Style your application with utility-first CSS.
12 | - **Viem and Wagmi**: Integrate with Ethereum using [Viem](https://viem.sh/) and [Wagmi](https://wagmi.sh/) libraries.
13 | - **Monorepo Setup**: Organize your frontend and smart contracts in a monorepo structure.
14 |
15 | ## Getting Started
16 |
17 | ### Installation
18 |
19 | To create a new project using the Web3 Template CLI, run one of the following commands:
20 |
21 | Using **pnpm**:
22 |
23 | ```bash
24 | pnpm create @consensys/create-web3-template [project-name]
25 | ```
26 |
27 | Using **npx**:
28 |
29 | ```bash
30 | npx @consensys/create-web3-template [project-name]
31 | ```
32 |
33 | ### Interactive Setup
34 |
35 | After running the command, the CLI will guide you through the setup process with the following prompts:
36 |
37 | 1. **Project Name**: Specify a name for your project if not provided in the command.
38 | 2. **Framework Selection**: Choose between **Next.js** and **React (Vite)**.
39 | 3. **Blockchain Tooling**: Select **Hardhat** or **Foundry** for smart contract development.
40 | 4. **Package Manager**: Choose your preferred package manager: **npm**, **yarn**, or **pnpm**.
41 |
42 | ### Example
43 |
44 | ```bash
45 | npx @consensys/create-web3-template my-web3-project
46 | ```
47 |
48 | ## Project Structure
49 |
50 | The generated project will have the following structure:
51 |
52 | ```
53 | my-web3-project/
54 | ├── packages/
55 | │ ├── blockchain/ # Smart contracts and blockchain tooling
56 | │ └── site/ # Frontend application (Next.js or React)
57 | ├── pnpm-workspace.yaml (if using pnpm)
58 | ├── package.json
59 | └── .gitignore
60 | ```
61 |
62 | - **packages/blockchain**: Contains your smart contracts and related tooling.
63 | - **packages/site**: Contains your frontend application.
64 |
65 | ## Installing Dependencies
66 |
67 | Navigate to your project directory and install the dependencies:
68 |
69 | ```bash
70 | cd my-web3-project
71 |
72 | # If you chose pnpm
73 | pnpm install
74 |
75 | # If you chose npm
76 | npm install
77 |
78 | # If you chose yarn
79 | yarn install
80 | ```
81 |
82 | ## Running the Application
83 |
84 | ### Backend (Smart Contracts)
85 |
86 | Navigate to the `blockchain` package to work on your smart contracts.
87 |
88 | ```bash
89 | cd packages/blockchain
90 | ```
91 |
92 | - **Hardhat Users**: Refer to the [Hardhat documentation](https://hardhat.org/getting-started/) for commands to compile, test, and deploy your contracts.
93 | - **Foundry Users**: Refer to the [Foundry Book](https://book.getfoundry.sh/) for instructions on using Foundry.
94 |
95 | ### Frontend Application
96 |
97 | Navigate to the `site` package to run your frontend application.
98 |
99 | ```bash
100 | cd packages/site
101 |
102 | # Start the development server
103 | # Using pnpm
104 | pnpm run dev
105 |
106 | # Using npm
107 | npm run dev
108 |
109 | # Using yarn
110 | yarn dev
111 | ```
112 |
113 | The development server will start, and you can view your application in the browser.
114 |
115 | ## Wagmi Configuration
116 |
117 | The project includes a default **Wagmi** configuration for connecting to the Linea Testnet. You can find this configuration in the `wagmi.config.ts` file in your frontend application:
118 |
119 | ```
120 | import { http, createConfig } from "wagmi";
121 | import { lineaTestnet } from "wagmi/chains";
122 | import { metaMask } from "wagmi/connectors";
123 |
124 | export const config = createConfig({
125 | chains: [lineaTestnet],
126 | connectors: [metaMask()],
127 | transports: {
128 | [lineaTestnet.id]: http(),
129 | },
130 | });
131 | ```
132 |
133 | Feel free to modify this configuration to connect to different networks or use different connectors.
134 |
135 | ## Monorepo Management
136 |
137 | This project uses a monorepo structure to keep your frontend and backend code organized and in sync.
138 |
139 | - **Package Management**: If you selected **pnpm**, a `pnpm-workspace.yaml` file is included to manage the monorepo packages.
140 | - **Scripts**: Each package (`blockchain` and `site`) can have its own scripts. Navigate into each package directory to run and manage scripts specific to that package.
141 |
142 | ## Customization
143 |
144 | After project creation, you can customize the setup according to your needs:
145 |
146 | - **Add Dependencies**: Install additional npm packages as required.
147 | - **Modify Configurations**: Update Tailwind CSS, TypeScript, or other configurations.
148 | - **Update Smart Contracts**: Write and deploy your own smart contracts using Hardhat or Foundry.
149 |
150 | ## Contributing
151 |
152 | Contributions are welcome! If you have suggestions or find issues, please open an issue or submit a pull request.
153 |
154 | ## License
155 |
156 | This project is licensed under the MIT License.
157 |
158 | ---
159 |
--------------------------------------------------------------------------------
/dist/constants/index.js:
--------------------------------------------------------------------------------
1 | export var FRAMEWORK_CHOICES = [
2 | {
3 | name: "React (with Vite)",
4 | value: "react",
5 | },
6 | {
7 | name: "Next.js",
8 | value: "nextjs",
9 | },
10 | ];
11 | export var BLOCKCHAIN_TOOLING_CHOICES = [
12 | {
13 | name: "HardHat",
14 | value: "hardhat",
15 | },
16 | {
17 | name: "Foundry",
18 | value: "foundry",
19 | },
20 | {
21 | name: "None",
22 | value: "none",
23 | },
24 | ];
25 | export var PACAKGE_MANAGER_CHOICES = [
26 | {
27 | name: "Yarn",
28 | value: "yarn",
29 | },
30 | {
31 | name: "NPM",
32 | value: "npm",
33 | },
34 | {
35 | name: "pnpm",
36 | value: "pnpm",
37 | },
38 | ];
39 | export var NPM_COMMAND = function (projectName, path) {
40 | return path
41 | ? "cd ".concat(path, " && npm init vite@latest . -- --template react-ts")
42 | : "npm init vite@latest ".concat(projectName, " -- --template react-ts");
43 | };
44 | export var YARN_COMMAND = function (projectName, path) {
45 | return path
46 | ? "cd ".concat(path, " && yarn create vite . --template react-ts")
47 | : "yarn create vite ".concat(projectName, " --template react-ts");
48 | };
49 | export var PNPM_COMMAND = function (projectName, path) {
50 | return path
51 | ? "cd ".concat(path, " && pnpm create vite . --template react-ts")
52 | : "pnpm create vite ".concat(projectName, " --template react-ts");
53 | };
54 |
--------------------------------------------------------------------------------
/dist/constants/templates.js:
--------------------------------------------------------------------------------
1 | export var TEMPLATES = [
2 | {
3 | name: "Next Web3 Starter",
4 | id: "next-web3-starter",
5 | repo_url: "https://github.com/Consensys/next-web3-starter.git",
6 | packageName: "@consensys/web3-starter",
7 | },
8 | {
9 | name: "React Web3 Starter",
10 | id: "react-web3-starter",
11 | repo_url: "https://github.com/Consensys/react-web3-starter.git",
12 | packageName: "@consensys/react-web3-starter",
13 | },
14 | {
15 | name: "React/Vite and foundry starter",
16 | id: "foundry-starter",
17 | repo_url: "https://github.com/cxalem/foundry-template",
18 | packageName: "@consensys/foundry-template",
19 | },
20 | ];
21 |
--------------------------------------------------------------------------------
/dist/index.js:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3 | function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4 | return new (P || (P = Promise))(function (resolve, reject) {
5 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7 | function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8 | step((generator = generator.apply(thisArg, _arguments || [])).next());
9 | });
10 | };
11 | var __generator = (this && this.__generator) || function (thisArg, body) {
12 | var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13 | return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14 | function verb(n) { return function (v) { return step([n, v]); }; }
15 | function step(op) {
16 | if (f) throw new TypeError("Generator is already executing.");
17 | while (g && (g = 0, op[0] && (_ = 0)), _) try {
18 | if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19 | if (y = 0, t) op = [op[0] & 2, t.value];
20 | switch (op[0]) {
21 | case 0: case 1: t = op; break;
22 | case 4: _.label++; return { value: op[1], done: false };
23 | case 5: _.label++; y = op[1]; op = [0]; continue;
24 | case 7: op = _.ops.pop(); _.trys.pop(); continue;
25 | default:
26 | if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27 | if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28 | if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29 | if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30 | if (t[2]) _.ops.pop();
31 | _.trys.pop(); continue;
32 | }
33 | op = body.call(thisArg, _);
34 | } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35 | if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36 | }
37 | };
38 | import { Command } from "commander";
39 | import { createProject } from "./utils/index.js";
40 | function main() {
41 | return __awaiter(this, void 0, void 0, function () {
42 | var program;
43 | return __generator(this, function (_a) {
44 | program = new Command()
45 | .name("create-web3-template")
46 | .description("Web3 starter template CLI tool.")
47 | .arguments("[project-name]")
48 | .action(function (args) { return createProject(args); })
49 | .version("0.0.2");
50 | program.parse(process.argv);
51 | return [2 /*return*/];
52 | });
53 | });
54 | }
55 | main().catch(function (error) {
56 | console.error("An unexpected error occurred:", error);
57 | });
58 |
--------------------------------------------------------------------------------
/dist/utils/index.js:
--------------------------------------------------------------------------------
1 | var __assign = (this && this.__assign) || function () {
2 | __assign = Object.assign || function(t) {
3 | for (var s, i = 1, n = arguments.length; i < n; i++) {
4 | s = arguments[i];
5 | for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6 | t[p] = s[p];
7 | }
8 | return t;
9 | };
10 | return __assign.apply(this, arguments);
11 | };
12 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
13 | function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
14 | return new (P || (P = Promise))(function (resolve, reject) {
15 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
16 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
17 | function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
18 | step((generator = generator.apply(thisArg, _arguments || [])).next());
19 | });
20 | };
21 | var __generator = (this && this.__generator) || function (thisArg, body) {
22 | var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
23 | return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
24 | function verb(n) { return function (v) { return step([n, v]); }; }
25 | function step(op) {
26 | if (f) throw new TypeError("Generator is already executing.");
27 | while (g && (g = 0, op[0] && (_ = 0)), _) try {
28 | if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
29 | if (y = 0, t) op = [op[0] & 2, t.value];
30 | switch (op[0]) {
31 | case 0: case 1: t = op; break;
32 | case 4: _.label++; return { value: op[1], done: false };
33 | case 5: _.label++; y = op[1]; op = [0]; continue;
34 | case 7: op = _.ops.pop(); _.trys.pop(); continue;
35 | default:
36 | if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
37 | if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
38 | if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
39 | if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
40 | if (t[2]) _.ops.pop();
41 | _.trys.pop(); continue;
42 | }
43 | op = body.call(thisArg, _);
44 | } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
45 | if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
46 | }
47 | };
48 | import { exec } from "child_process";
49 | import { promises as fs } from "fs";
50 | import { BLOCKCHAIN_TOOLING_CHOICES, FRAMEWORK_CHOICES, PACAKGE_MANAGER_CHOICES, } from "../constants/index.js";
51 | import { createReactApp } from "./vite.helpers.js";
52 | import { createNextApp } from "./next.helpers.js";
53 | import path from "path";
54 | import util from "util";
55 | import inquirer from "inquirer";
56 | export var execAsync = util.promisify(exec);
57 | var promptForFramework = function () { return __awaiter(void 0, void 0, void 0, function () {
58 | var frameworkChoice, framework;
59 | return __generator(this, function (_a) {
60 | switch (_a.label) {
61 | case 0:
62 | frameworkChoice = FRAMEWORK_CHOICES.map(function (choice) { return choice.name; });
63 | return [4 /*yield*/, inquirer.prompt([
64 | {
65 | type: "list",
66 | name: "framework",
67 | message: "Please select the framework you want to use:",
68 | choices: frameworkChoice,
69 | },
70 | ])];
71 | case 1:
72 | framework = (_a.sent()).framework;
73 | console.log("Selected framework: ".concat(framework));
74 | return [2 /*return*/, framework];
75 | }
76 | });
77 | }); };
78 | var promptForTooling = function () { return __awaiter(void 0, void 0, void 0, function () {
79 | var toolingChoice, tooling;
80 | return __generator(this, function (_a) {
81 | switch (_a.label) {
82 | case 0:
83 | toolingChoice = BLOCKCHAIN_TOOLING_CHOICES.map(function (choice) { return choice.name; });
84 | return [4 /*yield*/, inquirer.prompt([
85 | {
86 | type: "list",
87 | name: "tooling",
88 | message: "Would you like to use HardHat or Foundry?",
89 | choices: toolingChoice,
90 | },
91 | ])];
92 | case 1:
93 | tooling = (_a.sent()).tooling;
94 | console.log("Selected tooling: ".concat(tooling));
95 | return [2 /*return*/, tooling];
96 | }
97 | });
98 | }); };
99 | var promptForPackageManager = function () { return __awaiter(void 0, void 0, void 0, function () {
100 | var packageManagerChoice, packageManager;
101 | return __generator(this, function (_a) {
102 | switch (_a.label) {
103 | case 0:
104 | packageManagerChoice = PACAKGE_MANAGER_CHOICES.map(function (choice) { return choice.name; });
105 | return [4 /*yield*/, inquirer.prompt([
106 | {
107 | type: "list",
108 | name: "packageManager",
109 | message: "Please select the package manager you want to use:",
110 | choices: packageManagerChoice,
111 | },
112 | ])];
113 | case 1:
114 | packageManager = (_a.sent()).packageManager;
115 | console.log("Selected package manager: ".concat(packageManager));
116 | return [2 /*return*/, packageManager];
117 | }
118 | });
119 | }); };
120 | var promptForProjectDetails = function (args) { return __awaiter(void 0, void 0, void 0, function () {
121 | var projectName;
122 | return __generator(this, function (_a) {
123 | switch (_a.label) {
124 | case 0:
125 | if (!!args) return [3 /*break*/, 2];
126 | return [4 /*yield*/, inquirer.prompt([
127 | {
128 | type: "input",
129 | name: "projectName",
130 | message: "Please specify a name for your project: ",
131 | validate: function (input) { return (input ? true : "Project name cannot be empty"); },
132 | },
133 | ])];
134 | case 1:
135 | projectName = (_a.sent()).projectName;
136 | console.log("Creating project with name:", projectName);
137 | return [2 /*return*/, projectName];
138 | case 2: return [2 /*return*/, args];
139 | }
140 | });
141 | }); };
142 | var promptForOptions = function (args) { return __awaiter(void 0, void 0, void 0, function () {
143 | var projectName, framework, tooling, packageManager, options;
144 | var _a, _b, _c;
145 | return __generator(this, function (_d) {
146 | switch (_d.label) {
147 | case 0: return [4 /*yield*/, promptForProjectDetails(args)];
148 | case 1:
149 | projectName = _d.sent();
150 | return [4 /*yield*/, promptForFramework()];
151 | case 2:
152 | framework = _d.sent();
153 | return [4 /*yield*/, promptForTooling()];
154 | case 3:
155 | tooling = _d.sent();
156 | return [4 /*yield*/, promptForPackageManager()];
157 | case 4:
158 | packageManager = _d.sent();
159 | options = {
160 | projectName: projectName,
161 | framework: (_a = FRAMEWORK_CHOICES.find(function (choice) { return choice.name === framework; })) === null || _a === void 0 ? void 0 : _a.value,
162 | blockchain_tooling: (_b = BLOCKCHAIN_TOOLING_CHOICES.find(function (choice) { return choice.name === tooling; })) === null || _b === void 0 ? void 0 : _b.value,
163 | packageManager: (_c = PACAKGE_MANAGER_CHOICES.find(function (choice) { return choice.name === packageManager; })) === null || _c === void 0 ? void 0 : _c.value,
164 | };
165 | return [2 /*return*/, options];
166 | }
167 | });
168 | }); };
169 | var initializeMonorepo = function (options) { return __awaiter(void 0, void 0, void 0, function () {
170 | var projectName, packageManager;
171 | return __generator(this, function (_a) {
172 | switch (_a.label) {
173 | case 0:
174 | projectName = options.projectName, packageManager = options.packageManager;
175 | console.log("Initializing monorepo...");
176 | if (!(packageManager === "pnpm")) return [3 /*break*/, 2];
177 | return [4 /*yield*/, fs.writeFile(path.join(projectName, "pnpm-workspace.yaml"), "packages:\n - 'packages/*'")];
178 | case 1:
179 | _a.sent();
180 | _a.label = 2;
181 | case 2: return [4 /*yield*/, fs.writeFile(path.join(projectName, ".gitignore"), "node_modules")];
182 | case 3:
183 | _a.sent();
184 | return [4 /*yield*/, execAsync("cd ".concat(projectName, " && npm init -y"))];
185 | case 4:
186 | _a.sent();
187 | return [4 /*yield*/, execAsync("cd ".concat(projectName, " && npm init -w ./packages/blockchain -y"))];
188 | case 5:
189 | _a.sent();
190 | return [4 /*yield*/, execAsync("cd ".concat(projectName, " && npm init -w ./packages/site -y"))];
191 | case 6:
192 | _a.sent();
193 | return [4 /*yield*/, fs.rm(path.join(projectName, "packages", "blockchain", "package.json"))];
194 | case 7:
195 | _a.sent();
196 | return [4 /*yield*/, fs.rm(path.join(projectName, "packages", "site", "package.json"))];
197 | case 8:
198 | _a.sent();
199 | return [4 /*yield*/, fs.rm(path.join(projectName, "node_modules"), { recursive: true })];
200 | case 9:
201 | _a.sent();
202 | return [2 /*return*/];
203 | }
204 | });
205 | }); };
206 | var createHardhatProject = function (options) { return __awaiter(void 0, void 0, void 0, function () {
207 | var projectName, framework;
208 | return __generator(this, function (_a) {
209 | switch (_a.label) {
210 | case 0:
211 | projectName = options.projectName, framework = options.framework;
212 | return [4 /*yield*/, fs.mkdir(projectName)];
213 | case 1:
214 | _a.sent();
215 | console.log("Creating a project with HardHat...");
216 | return [4 /*yield*/, initializeMonorepo(options)];
217 | case 2:
218 | _a.sent();
219 | return [4 /*yield*/, execAsync("git clone https://github.com/cxalem/hardhat-template.git ".concat(path.join(projectName, "packages", "blockchain")))];
220 | case 3:
221 | _a.sent();
222 | if (!(framework === "nextjs")) return [3 /*break*/, 5];
223 | return [4 /*yield*/, createNextApp(options, path.join(projectName, "packages", "site"))];
224 | case 4:
225 | _a.sent();
226 | return [3 /*break*/, 7];
227 | case 5: return [4 /*yield*/, createReactApp(options, path.join(projectName, "packages", "site"))];
228 | case 6:
229 | _a.sent();
230 | _a.label = 7;
231 | case 7: return [2 /*return*/];
232 | }
233 | });
234 | }); };
235 | var createFoundryProject = function (options) { return __awaiter(void 0, void 0, void 0, function () {
236 | var projectName, framework;
237 | return __generator(this, function (_a) {
238 | switch (_a.label) {
239 | case 0:
240 | projectName = options.projectName, framework = options.framework;
241 | return [4 /*yield*/, fs.mkdir(projectName)];
242 | case 1:
243 | _a.sent();
244 | console.log("Creating a project with Foundry...");
245 | return [4 /*yield*/, initializeMonorepo(options)];
246 | case 2:
247 | _a.sent();
248 | if (!(framework === "nextjs")) return [3 /*break*/, 4];
249 | return [4 /*yield*/, createNextApp(options, path.join(projectName, "packages", "site"))];
250 | case 3:
251 | _a.sent();
252 | return [3 /*break*/, 6];
253 | case 4: return [4 /*yield*/, createReactApp(options, path.join(projectName, "packages", "site"))];
254 | case 5:
255 | _a.sent();
256 | _a.label = 6;
257 | case 6: return [4 /*yield*/, execAsync("\n cd ".concat(projectName, "/packages/blockchain && forge init . --no-commit\n "))];
258 | case 7:
259 | _a.sent();
260 | return [2 /*return*/];
261 | }
262 | });
263 | }); };
264 | export var pathOrProjectName = function (projectName, projectPath) {
265 | return projectPath ? projectPath : projectName;
266 | };
267 | export var updatePackageJsonDependencies = function (dependencies, projectPath) { return __awaiter(void 0, void 0, void 0, function () {
268 | var packageJsonPath, packageJsonContent, packageJson, newPackageJsonContent;
269 | return __generator(this, function (_a) {
270 | switch (_a.label) {
271 | case 0:
272 | packageJsonPath = path.join(projectPath, "package.json");
273 | return [4 /*yield*/, fs.readFile(packageJsonPath, "utf-8")];
274 | case 1:
275 | packageJsonContent = _a.sent();
276 | packageJson = JSON.parse(packageJsonContent);
277 | packageJson.dependencies = __assign(__assign({}, packageJson.dependencies), dependencies);
278 | newPackageJsonContent = JSON.stringify(packageJson, null, 2);
279 | return [4 /*yield*/, fs.writeFile(packageJsonPath, newPackageJsonContent, "utf-8")];
280 | case 2:
281 | _a.sent();
282 | console.log("Dependencies added to package.json");
283 | return [2 /*return*/];
284 | }
285 | });
286 | }); };
287 | export var createWagmiConfigFile = function (projectPath) { return __awaiter(void 0, void 0, void 0, function () {
288 | return __generator(this, function (_a) {
289 | switch (_a.label) {
290 | case 0: return [4 /*yield*/, fs.writeFile(path.join(projectPath, "wagmi.config.ts"), "\nimport { http, createConfig } from \"wagmi\";\nimport { lineaTestnet } from \"wagmi/chains\";\nimport { metaMask } from \"wagmi/connectors\";\n\nexport const config = createConfig({\n chains: [lineaTestnet],\n connectors: [metaMask()],\n transports: {\n [lineaTestnet.id]: http(),\n },\n});\n")];
291 | case 1:
292 | _a.sent();
293 | return [2 /*return*/];
294 | }
295 | });
296 | }); };
297 | export var usePackageManager = function (packageManager) {
298 | switch (packageManager) {
299 | case "npm":
300 | return "--use-npm";
301 | case "yarn":
302 | return "--use-yarn";
303 | case "pnpm":
304 | return "--use-pnpm";
305 | default:
306 | return "--use-npm";
307 | }
308 | };
309 | export var createProject = function (args) { return __awaiter(void 0, void 0, void 0, function () {
310 | var options, _a;
311 | return __generator(this, function (_b) {
312 | switch (_b.label) {
313 | case 0: return [4 /*yield*/, promptForOptions(args)];
314 | case 1:
315 | options = _b.sent();
316 | if (options.blockchain_tooling === "hardhat") {
317 | createHardhatProject(options);
318 | return [2 /*return*/];
319 | }
320 | if (options.blockchain_tooling === "foundry") {
321 | createFoundryProject(options);
322 | return [2 /*return*/];
323 | }
324 | _a = options.framework;
325 | switch (_a) {
326 | case "nextjs": return [3 /*break*/, 2];
327 | case "react": return [3 /*break*/, 4];
328 | }
329 | return [3 /*break*/, 6];
330 | case 2: return [4 /*yield*/, createNextApp(options)];
331 | case 3:
332 | _b.sent();
333 | return [3 /*break*/, 7];
334 | case 4: return [4 /*yield*/, createReactApp(options)];
335 | case 5:
336 | _b.sent();
337 | return [3 /*break*/, 7];
338 | case 6: return [3 /*break*/, 7];
339 | case 7: return [2 /*return*/];
340 | }
341 | });
342 | }); };
343 |
--------------------------------------------------------------------------------
/dist/utils/next.helpers.js:
--------------------------------------------------------------------------------
1 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2 | function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3 | return new (P || (P = Promise))(function (resolve, reject) {
4 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6 | function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7 | step((generator = generator.apply(thisArg, _arguments || [])).next());
8 | });
9 | };
10 | var __generator = (this && this.__generator) || function (thisArg, body) {
11 | var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
12 | return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13 | function verb(n) { return function (v) { return step([n, v]); }; }
14 | function step(op) {
15 | if (f) throw new TypeError("Generator is already executing.");
16 | while (g && (g = 0, op[0] && (_ = 0)), _) try {
17 | if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18 | if (y = 0, t) op = [op[0] & 2, t.value];
19 | switch (op[0]) {
20 | case 0: case 1: t = op; break;
21 | case 4: _.label++; return { value: op[1], done: false };
22 | case 5: _.label++; y = op[1]; op = [0]; continue;
23 | case 7: op = _.ops.pop(); _.trys.pop(); continue;
24 | default:
25 | if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26 | if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27 | if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28 | if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29 | if (t[2]) _.ops.pop();
30 | _.trys.pop(); continue;
31 | }
32 | op = body.call(thisArg, _);
33 | } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34 | if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35 | }
36 | };
37 | import path from "path";
38 | import { promises as fs } from "fs";
39 | import { createWagmiConfigFile, execAsync, pathOrProjectName, updatePackageJsonDependencies, usePackageManager, } from "./index.js";
40 | export var createNextApp = function (options, projectPath) { return __awaiter(void 0, void 0, void 0, function () {
41 | var projectName, packageManager, command, error_1;
42 | return __generator(this, function (_a) {
43 | switch (_a.label) {
44 | case 0:
45 | console.log("Creating Next.js project...");
46 | _a.label = 1;
47 | case 1:
48 | _a.trys.push([1, 8, , 9]);
49 | projectName = options.projectName, packageManager = options.packageManager;
50 | command = "npx create-next-app ".concat(pathOrProjectName(projectName, projectPath), " --ts --tailwind --eslint --app --src-dir --skip-install --import-alias \"@/*\" ").concat(usePackageManager(packageManager), " --turbopack");
51 | return [4 /*yield*/, execAsync(command)];
52 | case 2:
53 | _a.sent();
54 | return [4 /*yield*/, updatePackageJsonDependencies({
55 | "@consensys/connect-button": "^1.0.3",
56 | "@tanstack/react-query": "^5.51.23",
57 | viem: "2.x",
58 | wagmi: "^2.12.5",
59 | }, pathOrProjectName(projectName, projectPath))];
60 | case 3:
61 | _a.sent();
62 | return [4 /*yield*/, updateLayoutFile(pathOrProjectName(projectName, projectPath))];
63 | case 4:
64 | _a.sent();
65 | return [4 /*yield*/, createProvider(pathOrProjectName(projectName, projectPath))];
66 | case 5:
67 | _a.sent();
68 | return [4 /*yield*/, createWagmiConfigFile(projectPath ? "".concat(projectPath, "/src") : "".concat(projectName, "/src"))];
69 | case 6:
70 | _a.sent();
71 | return [4 /*yield*/, updatePageFile(pathOrProjectName(projectName, projectPath))];
72 | case 7:
73 | _a.sent();
74 | console.log("Next.js project created successfully!");
75 | return [3 /*break*/, 9];
76 | case 8:
77 | error_1 = _a.sent();
78 | console.error("An unexpected error occurred:", error_1);
79 | return [3 /*break*/, 9];
80 | case 9: return [2 /*return*/];
81 | }
82 | });
83 | }); };
84 | var updateLayoutFile = function (projectPath) { return __awaiter(void 0, void 0, void 0, function () {
85 | var layoutFilePath;
86 | return __generator(this, function (_a) {
87 | switch (_a.label) {
88 | case 0:
89 | layoutFilePath = path.join(projectPath, "src", "app", "layout.tsx");
90 | return [4 /*yield*/, fs.writeFile(layoutFilePath, "\n \"use client\";\n\n import { Inter } from \"next/font/google\";\n import \"./globals.css\";\n import Provider from \"@/providers/WagmiProvider\";\n \n const inter = Inter({ subsets: [\"latin\"] });\n \n export default function RootLayout({\n children,\n }: Readonly<{\n children: React.ReactNode;\n }>) {\n return (\n \n \n {children}\n \n \n );\n }\n \n")];
91 | case 1:
92 | _a.sent();
93 | return [2 /*return*/];
94 | }
95 | });
96 | }); };
97 | var createProvider = function (projectPath) { return __awaiter(void 0, void 0, void 0, function () {
98 | var providerFilePath;
99 | return __generator(this, function (_a) {
100 | switch (_a.label) {
101 | case 0: return [4 /*yield*/, fs.mkdir(path.join(projectPath, "src", "providers"))];
102 | case 1:
103 | _a.sent();
104 | providerFilePath = path.join(projectPath, "src", "providers", "WagmiProvider.tsx");
105 | return [4 /*yield*/, fs.writeFile(providerFilePath, "\n\"use client\";\n\nimport { WagmiProvider } from \"wagmi\";\nimport { config } from \"@/wagmi.config\";\nimport { QueryClient, QueryClientProvider } from \"@tanstack/react-query\";\nimport { createPublicClient, http } from \"viem\";\nimport { linea } from \"viem/chains\";\n\nexport const client = createPublicClient({\n chain: linea,\n transport: http(),\n});\n\ninterface WagmiProviderProps {\n children: React.ReactNode;\n}\n\nconst Provider: React.FC = ({ children }) => {\n const queryClient = new QueryClient();\n\n return (\n \n {children}\n \n );\n};\n\nexport default Provider;\n ")];
106 | case 2:
107 | _a.sent();
108 | return [2 /*return*/];
109 | }
110 | });
111 | }); };
112 | var updatePageFile = function (projectPath) { return __awaiter(void 0, void 0, void 0, function () {
113 | var pageFilePath;
114 | return __generator(this, function (_a) {
115 | switch (_a.label) {
116 | case 0:
117 | pageFilePath = path.join(projectPath, "src", "app", "page.tsx");
118 | return [4 /*yield*/, fs.writeFile(pageFilePath, "\n\"use client\";\n\nimport { ConnectButton } from \"@consensys/connect-button\";\nimport { client } from \"@/providers/WagmiProvider\";\nimport { Suspense, useEffect, useState } from \"react\";\nimport { useAccount } from \"wagmi\";\n\nexport default function Home() {\n const { isConnected, address } = useAccount();\n const [blockNumber, setBlockNumber] = useState(null);\n\n useEffect(() => {\n client.getBlockNumber().then((block) => {\n setBlockNumber(block);\n });\n }, []);\n\n return (\n \n Loading...}>\n