Skip to content

Commit 5bf1447

Browse files
committed
updates dependencies
1 parent 0c60bd9 commit 5bf1447

File tree

8 files changed

+218
-163
lines changed

8 files changed

+218
-163
lines changed

helpers/cloneRepo.js

+23-9
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ export const cloneRepo = (
1919
cliProgress.Presets.shades_classic
2020
);
2121
bar1.start(200, 0);
22-
console.log("\n")
22+
console.log("\n");
2323
execSync(
2424
`git clone --depth 1 ${"https://github.com/Eversmile12/create-web3-dapp"} .`
2525
);
2626

27-
2827
bar1.update(100);
2928

29+
console.log(chalk.yellow("Copying project files..."));
3030

3131
let template = path.join(
3232
process.cwd(),
@@ -38,24 +38,38 @@ export const cloneRepo = (
3838
fse.copySync(template, process.cwd());
3939

4040
bar1.update(200);
41+
console.log(chalk.green("Project files copied ✅"));
42+
4143
bar1.stop();
4244

4345
if (backendInfo.wantsBackend) {
44-
console.log("Copying backend files...");
46+
console.log(chalk.yellow(`Copying ${backendInfo.type} files...`));
4547
const bar2 = new cliProgress.SingleBar(
4648
{},
4749
cliProgress.Presets.shades_classic
4850
);
4951
bar2.start(100, 0);
50-
if (backendInfo.type == "hardhat") {
51-
52-
let hardhatTemplate = path.join(process.cwd(), "templates", "hardhat");
53-
fse.mkdirSync(path.join(process.cwd(), "backend"));
54-
fse.copySync(hardhatTemplate, path.join(process.cwd(), "backend"));
52+
bar2.update(50);
53+
54+
switch (backendInfo.type) {
55+
case "hardhat":
56+
let hardhatTemplate = path.join(
57+
process.cwd(),
58+
"templates",
59+
"hardhat"
60+
);
61+
fse.mkdirSync(path.join(process.cwd(), "backend"));
62+
fse.copySync(hardhatTemplate, path.join(process.cwd(), "backend"));
63+
break;
64+
case "foundry":
65+
break;
5566
}
67+
5668
bar2.update(100);
5769
bar2.stop();
58-
console.log("Finished copying backend files");
70+
console.log(
71+
chalk.green("Smart Contract Development Environment copied ✅")
72+
);
5973
}
6074
} catch (e) {
6175
selfDestroy(e);

helpers/createEnv.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import fs from "fs";
2+
3+
export const createEnv = (alchemyAPIKey) => {
4+
let env = {};
5+
6+
if (alchemyAPIKey) {
7+
env["NEXT_PUBLIC_ALCHEMY_API_KEY"] = "demo";
8+
}
9+
10+
if (Object.keys(env).length) {
11+
let writeStream = fs.createWriteStream(".env");
12+
for (const [key, value] of Object.entries(env)) {
13+
writeStream.write(`${key}=${value}`);
14+
}
15+
writeStream.end();
16+
}
17+
};

index.js

+116-110
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import { existsSync } from "fs";
99
import { mkdir } from "./helpers/mkdir.js";
1010
import { cleanUpFiles } from "./helpers/cleanUpFiles.js";
1111
import { cloneRepo } from "./helpers/cloneRepo.js";
12-
import {selfDestroy, setRoot} from "./helpers/selfDestroy.js"
12+
import { selfDestroy, setRoot } from "./helpers/selfDestroy.js";
1313
import chalk from "chalk";
14-
14+
import {createEnv} from "./helpers/createEnv.js"
1515
console.log(`MMMMMMMMMMMMMMMMMK:..:KMMMMMMMMMMMMMMMMM
1616
MMMMMMMMMMMMMMMWO, ,OWMMMMMMMMMMMMMMM
1717
MMMMMMMMMMMMMMWk' 'kWMMMMMMMMMMMMMM
@@ -28,10 +28,10 @@ MMWO, .cXMXkxxxxxxxxxxxxxxxxxkKWMM
2828
MWx' .oNW0;. 'xWM
2929
Nd. .xNWk' .dN
3030
l. 'kWNx. .l
31-
. .kWM0' .`)
32-
console.log("\n\n")
33-
console.log("🔵 Welcome to the create-web3-dapp wizard 🔵")
34-
console.log("\n")
31+
. .kWM0' .`);
32+
console.log("\n");
33+
console.log("🔵 Welcome to the create-web3-dapp wizard 🔵");
34+
console.log("\n");
3535
let projectPath = "";
3636

3737
const program = new Commander.Command("create-web3-dapp")
@@ -45,111 +45,117 @@ const program = new Commander.Command("create-web3-dapp")
4545
.parse(process.argv);
4646

4747
async function run() {
48-
try {
49-
if (typeof projectPath === "string") {
50-
projectPath = projectPath.trim();
51-
}
52-
53-
if (!projectPath) {
54-
projectPath = await prompts({
55-
type: "text",
56-
name: "projectPath",
57-
message: "Please add a project path",
58-
initial: "my-dapp",
59-
}).then((data) => data.projectPath);
60-
console.log(projectPath);
61-
}
62-
63-
if (!projectPath) {
64-
//exit non 0
65-
}
66-
67-
let resolvedProjectPath = path.resolve(projectPath);
68-
let dirExists = existsSync(resolvedProjectPath);
69-
setRoot(resolvedProjectPath)
70-
while (dirExists) {
71-
projectPath = await prompts({
72-
type: "text",
73-
name: "projectPath",
74-
message: "Please use a different project path",
75-
initial: "my-dapp",
76-
}).then((data) => data.projectPath);
77-
console.log(projectPath);
78-
resolvedProjectPath = path.resolve(projectPath);
79-
dirExists = existsSync(resolvedProjectPath);
80-
console.log(dirExists);
81-
}
82-
const projectName = path.basename(resolvedProjectPath);
83-
84-
const isEthereumProject = await prompts({
85-
type: "select",
86-
name: "virtualMachine",
87-
message: "For which VM are you building for?",
88-
choices: [
89-
{ title: "Ethereum", value: "ethereum" },
90-
{ title: "Solana", value: "solana" },
91-
],
92-
initial: 0,
93-
}).then((data) => data.virtualMachine == "ethereum" ? true : false);
94-
95-
const wantsTemplateFiles = await prompts({
96-
type: "toggle",
97-
name: "templateFiles",
98-
message: "Do you want to import the tutorial?",
99-
initial: true,
100-
active: "yes",
101-
inactive: "no",
102-
}).then((data) => (data.templateFiles));
103-
104-
105-
let backendInfo = {};
106-
107-
const wantsBackend = await prompts({
108-
type: "toggle",
109-
name: "backend",
110-
message: "Smart contract development environment?",
111-
initial: true,
112-
active: "yes",
113-
inactive: "no",
114-
}).then((data) => (data.backend));
115-
116-
backendInfo["wantsBackend"] = wantsBackend
117-
118-
119-
console.log(isEthereumProject)
120-
121-
if (isEthereumProject) {
122-
await prompts({
123-
type: "select",
124-
name: "ethereumBackend",
125-
message: "Choose one:",
126-
choices: [
127-
{ title: "Hardhat", value: "hardhat" },
128-
{ title: "Foundry", value: "foundry" },
129-
],
130-
initial: 0,
131-
}).then((data) => backendInfo["type"] = data.ethereumBackend );
132-
133-
}
134-
135-
console.log(backendInfo)
136-
137-
// console.log("wantsTemplate", wantsTemplateFiles);
138-
139-
mkdir(resolvedProjectPath);
140-
cloneRepo(resolvedProjectPath, isEthereumProject, wantsTemplateFiles, backendInfo);
141-
console.log(chalk.green("files copied ✅"))
142-
createPackageJson(
143-
isEthereumProject,
144-
projectName,
145-
backendInfo
146-
);
147-
cleanUpFiles();
148-
149-
console.log(chalk.green("Visit alchemy.com/docs for the complete tutorial"))
150-
} catch (e) {
151-
selfDestroy(e)
48+
try {
49+
if (typeof projectPath === "string") {
50+
projectPath = projectPath.trim();
51+
}
52+
53+
if (!projectPath) {
54+
projectPath = await prompts({
55+
type: "text",
56+
name: "projectPath",
57+
message: "Please, insert a project name",
58+
initial: "my-dapp",
59+
}).then((data) => data.projectPath);
60+
console.log(projectPath);
61+
}
62+
63+
if (!projectPath) {
64+
//exit non 0
15265
}
66+
67+
let resolvedProjectPath = path.resolve(projectPath);
68+
let dirExists = existsSync(resolvedProjectPath);
69+
setRoot(resolvedProjectPath);
70+
while (dirExists) {
71+
projectPath = await prompts({
72+
type: "text",
73+
name: "projectPath",
74+
message:
75+
"A directory with this name already exists, please use a different name",
76+
initial: "my-dapp",
77+
}).then((data) => data.projectPath);
78+
console.log(projectPath);
79+
resolvedProjectPath = path.resolve(projectPath);
80+
dirExists = existsSync(resolvedProjectPath);
81+
console.log(dirExists);
82+
}
83+
const projectName = path.basename(resolvedProjectPath);
84+
85+
const isEthereumProject = await prompts({
86+
type: "select",
87+
name: "virtualMachine",
88+
message: "For which VM are you building for?",
89+
choices: [
90+
{ title: "EVM", value: "ethereum" },
91+
{ title: "Solana", value: "solana" },
92+
],
93+
initial: 0,
94+
}).then((data) => (data.virtualMachine == "ethereum" ? true : false));
95+
96+
const wantsTemplateFiles = await prompts({
97+
type: "toggle",
98+
name: "templateFiles",
99+
message: "Do you want to import the template files?",
100+
initial: true,
101+
active: "yes",
102+
inactive: "no",
103+
}).then((data) => data.templateFiles);
104+
105+
let backendInfo = {};
106+
107+
const wantsBackend = await prompts({
108+
type: "toggle",
109+
name: "backend",
110+
message: "Do you want to import a Blockchain Development environment?",
111+
initial: true,
112+
active: "yes",
113+
inactive: "no",
114+
}).then((data) => data.backend);
115+
116+
backendInfo["wantsBackend"] = wantsBackend;
117+
118+
if (wantsBackend) {
119+
await prompts({
120+
type: "select",
121+
name: "ethereumBackend",
122+
message: "Choose a Blockchain development environment",
123+
choices: [
124+
{ title: "Hardhat", value: "hardhat" },
125+
{ title: "Foundry", value: "foundry" },
126+
],
127+
initial: 0,
128+
}).then((data) => (backendInfo["type"] = data.ethereumBackend));
129+
}
130+
131+
let alchemyAPIKey = await prompts({
132+
type: "text",
133+
name: "apiKey",
134+
message: "Insert your Alchemy API Key (if none, 'demo' will be used",
135+
initial: "demo",
136+
}).then((data) => data.apiKey);
137+
138+
console.log(alchemyAPIKey);
139+
140+
mkdir(resolvedProjectPath);
141+
cloneRepo(
142+
resolvedProjectPath,
143+
isEthereumProject,
144+
wantsTemplateFiles,
145+
backendInfo
146+
);
147+
148+
createPackageJson(isEthereumProject, projectName, backendInfo);
149+
150+
createEnv(alchemyAPIKey);
151+
cleanUpFiles();
152+
153+
console.log(
154+
chalk.green("Visit alchemy.com/docs for the complete tutorial")
155+
);
156+
} catch (e) {
157+
selfDestroy(e);
158+
}
153159
}
154160

155161
run();

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "create-web3-dapp",
3-
"version": "0.0.25",
3+
"version": "0.0.26",
44
"private": false,
55
"scripts": {
66
"test": "echo \"Error: no test specified\" && exit 1",

templates/ethereum/tutorial/pages/index.jsx

+4-3
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,14 @@ import { NFTGallery } from "./components/nftGallery";
77
import { TransactionsBox } from "./components/transactionsBox";
88
import { Panel } from "./components/panels";
99
import { Section } from "./layout/section";
10+
1011
export default function Home() {
1112
const { address, isConnected } = useAccount();
13+
/* WARNING:: the API key will be exposed on the browser - ideally you should get your key through server side rendering
14+
or get the data directly from your APIs */
1215

1316
const settings = {
14-
apiKey: "demo",
17+
apiKey: process.env.NEXT_PUBLIC_ALCHEMY_API_KEY,
1518
network: Network.ETH_MAINNET,
1619
};
1720

@@ -35,7 +38,6 @@ export default function Home() {
3538
</div>
3639
</header>
3740
<main className={styles.main}>
38-
3941
<Section>
4042
<Panel></Panel>
4143
</Section>
@@ -59,7 +61,6 @@ export default function Home() {
5961
</p>
6062
<TransactionsBox alchemy={alchemy} />
6163
</Section>
62-
6364
</main>
6465
</div>
6566
);

templates/ethereum/tutorial/pages/utils/walletSetup.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { publicProvider } from 'wagmi/providers/public'
1717
export const { chains, provider } = configureChains(
1818
[chain.mainnet, chain.polygon, chain.optimism, chain.arbitrum],
1919
[
20-
alchemyProvider({ alchemyId: "demo" }),
20+
alchemyProvider({ alchemyId: process.env.NEXT_PUBLIC_ALCHEMY_API_KEY }),
2121
publicProvider()
2222
]
2323
);

templates/ethereum/vanilla/pages/index.js

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ export default function Home() {
88
return (
99
<div>
1010
<header className={styles.header_container}>
11-
1211
<div className={styles.logo_container}>
1312
<Image
1413
src={"/logo.svg"}

0 commit comments

Comments
 (0)