Skip to content

Commit 55d5bc5

Browse files
Merge pull request paritytech#33 from paritytech/yuri/hardhat-pnpm
Hardhat template + removing pnpm
2 parents d3fd613 + 800dd7e commit 55d5bc5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+42316
-11439
lines changed

README.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,21 @@ Create Polkadot DApp in one command:
66
npx create-polkadot-dapp@latest
77
```
88

9-
(the templates use `pnpm` as a package manager, so maybe do `npm install -g pnpm` first)
10-
119
## Templates
1210

1311
* [react-papi-tailwind](https://github.com/paritytech/create-polkadot-dapp/tree/master/templates/react-papi-tailwind):<br/>
1412
React front-end app with [PAPI](papi.how) [ReactiveDOT](https://reactivedot.dev) + [dotconnect](https://dotconnect.dev/) for chain and wallet interactions.<br/>
1513
[Tailwind CSS](https://tailwindcss.com) + [Tailwind UI](https://tailwindui.com/). <br/>
1614
[Vite](https://vite.dev/) for dev tooling.
17-
* [react-solidity](https://github.com/paritytech/create-polkadot-dapp/tree/master/templates/react-solidity) a monorepo for smart contracts for AssetHub and a React, [Tailwind CSS](https://tailwindcss.com) and [ethers](https://docs.ethers.org/v6/)
15+
* [react-solidity-hardhat](https://github.com/paritytech/create-polkadot-dapp/tree/master/templates/react-solidity-hardhat) modern smart contract + react app template, with:
16+
* [OpenZeppelin](https://docs.openzeppelin.com/contracts/5.x/) smart contract library.
17+
* [hardhat](https://hardhat.org/) smart contract development tooling.
18+
* [wagmi](https://wagmi.sh/) for smart contract interaction.
19+
* [Tailwind CSS](https://tailwindcss.com) + [Tailwind UI](https://tailwindui.com/).
20+
* [Vite](https://vite.dev/) for dev tooling.
21+
* [react-solidity](https://github.com/paritytech/create-polkadot-dapp/tree/master/templates/react-solidity) (deprecated) a monorepo for smart contracts for AssetHub and a React, [Tailwind CSS](https://tailwindcss.com) and [ethers](https://docs.ethers.org/v6/)
1822

1923
## Planned templates
20-
* react-tailwind-solidity: a unified setup for developing Solidity smart contracts on Asset Hub
2124
* papi-nodejs: pure server-side application with polkadot-api
2225

2326
## Development

src/bin/main.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#!/usr/bin/env node
22
import { ExitPromptError } from "@inquirer/core";
33
import { inquireDappData } from "#src/util/dappData";
4-
import { ensurePnpm } from "#src/util/ensurePnpm";
54
import { spawnTemplate } from "#src/util/spawnTemplate";
65

76
/* This is somewhat a hack to automatically include
@@ -13,8 +12,6 @@ import * as pkg from "../../package.json";
1312
(async () => {
1413
console.log(`${pkg.name} ${pkg.version}`);
1514

16-
await ensurePnpm();
17-
1815
const dappData = await inquireDappData();
1916

2017
await spawnTemplate(dappData);

src/templateConfigs/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
import reactPapiTailwind from "./react-papi-tailwind";
22
import reactSolidity from "./react-solidity";
3+
import reactSolidityHardhat from "./react-solidity-hardhat";
34

45
export type TemplateConfig = {
56
setupPapi: boolean;
67
backSyncPatterns: RegExp[];
78
instructions: string;
9+
npmRoots: string[];
810
};
911

1012
export const configs: Record<string, TemplateConfig> = {
1113
"react-papi-tailwind": reactPapiTailwind,
1214
"react-solidity": reactSolidity,
15+
"react-solidity-hardhat": reactSolidityHardhat,
1316
};
1417

1518
export type TemplateNames = keyof typeof configs;

src/templateConfigs/react-papi-tailwind.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ import { colors as c } from "#src/util/log";
44
const config: TemplateConfig = {
55
setupPapi: true,
66
backSyncPatterns: [/^src.*/],
7+
npmRoots: ["/"],
78
instructions: `
89
${c.secondary("Start app:")}
9-
${c.code("pnpm dev")}`,
10+
${c.code("npm run dev")}`,
1011
};
1112

1213
export default config;
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { TemplateConfig } from "#src/templateConfigs/index";
2+
import { colors as c } from "#src/util/log";
3+
4+
const config: TemplateConfig = {
5+
setupPapi: false,
6+
npmRoots: ["contracts", "frontend"],
7+
backSyncPatterns: [
8+
/^contracts$/,
9+
/^contracts\/contracts.*/,
10+
/^contracts\/ignition$/,
11+
/^contracts\/ignition.*/,
12+
/^contracts\/test.*/,
13+
/^contracts\/package\.json/,
14+
/^contracts\/package-lock\.json/,
15+
/^contracts\/tsconfig\.json/,
16+
/^contracts\/hardhat.config.ts/,
17+
/^frontend$/,
18+
/^frontend\/src.*/,
19+
/^frontend\/package\.json/,
20+
/^frontend\/package-lock\.json/,
21+
/^README.md$/,
22+
],
23+
instructions: `
24+
${c.primary("Develop smart contracts:")}
25+
${c.primary("1. ")}${c.secondary("set up hardhat environment (see README.md): ")}
26+
${c.primary("2. ")}${c.secondary("edit contracts in ")}${c.code("contracts/contracts")}
27+
${c.primary("3. ")}${c.secondary("edit ignition module in ")}${c.code("contracts/igniton/modules")}
28+
${c.primary("4. ")}${c.secondary("deploy the contract with ")}${c.code("npx hardhat ignition deploy")}
29+
30+
${c.primary("Use the contract in the frontend app:")}
31+
${c.primary("1. ")}${c.secondary("go to ")}${c.code("frontend")}${c.secondary(" directory ")}
32+
${c.primary("2. ")}${c.secondary("generate the types with ")}${c.code("npm run generate")}
33+
${c.primary("3. ")}${c.secondary("start frontend app: ")}${c.code("npm run dev")}
34+
35+
${c.secondary("See ")}${c.primary("README.md")}${c.secondary(" for more info")}
36+
`,
37+
};
38+
39+
export default config;

src/templateConfigs/react-solidity.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { colors as c } from "#src/util/log";
33

44
const config: TemplateConfig = {
55
setupPapi: false,
6+
npmRoots: ["contracts", "frontend"],
67
backSyncPatterns: [
78
/^contracts$/,
89
/^contracts\/.+.sol/,
@@ -13,7 +14,7 @@ const config: TemplateConfig = {
1314
/^frontend\/src.*/,
1415
/^frontend\/package\.json/,
1516
/^package\.json/,
16-
/^pnpm-lock\.yaml/,
17+
/^package-lock\.json/,
1718
],
1819
instructions: `
1920
${c.primary("For Remix environment:")}

src/util/ensurePnpm.ts

Lines changed: 0 additions & 31 deletions
This file was deleted.

src/util/spawnTemplate.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export async function spawnTemplate(dappData: DappData): Promise<void> {
1212

1313
await copyTemplate(dappData, targetDir, templatesDir);
1414
await updateFiles(dappData, targetDir);
15-
await installDeps(targetDir);
15+
await installDeps(targetDir, dappData);
1616
if (dappData.config.setupPapi) {
1717
await setupPapi(targetDir);
1818
}
@@ -46,18 +46,22 @@ async function copyTemplate(dappData: DappData, targetDir: string, templatesDir:
4646
async function updateFiles(dappData: DappData, targetDir: string): Promise<void> {
4747
console.log(c.primary("Updating template files..."));
4848

49-
const pkgJsonPath = path.join(targetDir, "package.json");
50-
const pkgJsonContent = JSON.parse(await fs.readFile(pkgJsonPath, "utf8")) as PackageJson;
49+
for (const root of dappData.config.npmRoots) {
50+
const pkgJsonPath = path.join(targetDir, root, "package.json");
51+
const pkgJsonContent = JSON.parse(await fs.readFile(pkgJsonPath, "utf8")) as PackageJson;
5152

52-
pkgJsonContent.name = dappData.name;
53+
pkgJsonContent.name = dappData.name;
5354

54-
await fs.writeFile(pkgJsonPath, JSON.stringify(pkgJsonContent, null, 2));
55+
await fs.writeFile(pkgJsonPath, JSON.stringify(pkgJsonContent, null, 2));
56+
}
5557
}
5658

57-
async function installDeps(targetDir: string): Promise<void> {
59+
async function installDeps(targetDir: string, dappData: DappData): Promise<void> {
5860
console.log(c.primary("Installing dependencies..."));
5961

60-
await spawnAndWait("pnpm", ["install"], { cwd: targetDir });
62+
for (const root of dappData.config.npmRoots) {
63+
await spawnAndWait("npm", ["install"], { cwd: path.join(targetDir, root) });
64+
}
6165
}
6266

6367
async function setupPapi(targetDir: string): Promise<void> {

0 commit comments

Comments
 (0)