Skip to content

Commit 46adc98

Browse files
committed
revamp wizard
1 parent 5bf1447 commit 46adc98

File tree

7 files changed

+176
-90
lines changed

7 files changed

+176
-90
lines changed

helpers/cloneRepo.js

+20-29
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ import path from "path";
44
import fse from "fs-extra";
55
import chalk from "chalk";
66
import cliProgress from "cli-progress";
7+
import { createEnv } from "./createEnv.js";
8+
import { setUpHardhat } from "./setupHardhat.js";
79

810
export const cloneRepo = (
911
projectPath,
10-
isEthereumProject,
11-
wantsTemplateFiles,
12-
backendInfo
12+
dappInfo
1313
) => {
1414
try {
1515
process.chdir(projectPath);
@@ -23,53 +23,44 @@ export const cloneRepo = (
2323
execSync(
2424
`git clone --depth 1 ${"https://github.com/Eversmile12/create-web3-dapp"} .`
2525
);
26-
26+
console.log("\n");
2727
bar1.update(100);
2828

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

31+
console.log("\n");
32+
33+
3134
let template = path.join(
3235
process.cwd(),
3336
"templates",
34-
isEthereumProject ? "ethereum" : "solana",
35-
wantsTemplateFiles ? "tutorial" : "vanilla"
37+
(dappInfo.chain == "ethereum" || dappInfo.chain == "polygon" || dappInfo.chain == "arbitrum"|| dappInfo.chain == "optimism") ? "ethereum" : "solana",
38+
dappInfo.wantsTemplateFiles ? "tutorial" : "vanilla"
3639
);
3740

41+
console.log("Template: ", template);
42+
console.log(dappInfo.chain)
43+
3844
fse.copySync(template, process.cwd());
3945

4046
bar1.update(200);
4147
console.log(chalk.green("Project files copied ✅"));
4248

4349
bar1.stop();
4450

45-
if (backendInfo.wantsBackend) {
46-
console.log(chalk.yellow(`Copying ${backendInfo.type} files...`));
47-
const bar2 = new cliProgress.SingleBar(
48-
{},
49-
cliProgress.Presets.shades_classic
50-
);
51-
bar2.start(100, 0);
52-
bar2.update(50);
53-
54-
switch (backendInfo.type) {
51+
if (dappInfo.wantsBackend) {
52+
switch (dappInfo.type) {
5553
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"));
54+
setUpHardhat(dappInfo)
6355
break;
56+
6457
case "foundry":
6558
break;
59+
case "Anchor":
60+
break;
6661
}
67-
68-
bar2.update(100);
69-
bar2.stop();
70-
console.log(
71-
chalk.green("Smart Contract Development Environment copied ✅")
72-
);
62+
63+
setUpHardhat(dappInfo)
7364
}
7465
} catch (e) {
7566
selfDestroy(e);

helpers/createEnv.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
import fs from "fs";
22

3-
export const createEnv = (alchemyAPIKey) => {
3+
export const createEnv = (keys, path) => {
44
let env = {};
55

6-
if (alchemyAPIKey) {
6+
if (keys.alchemyKey) {
77
env["NEXT_PUBLIC_ALCHEMY_API_KEY"] = "demo";
88
}
9-
109
if (Object.keys(env).length) {
11-
let writeStream = fs.createWriteStream(".env");
10+
let writeStream = fs.createWriteStream(path.join(path,".env"));
1211
for (const [key, value] of Object.entries(env)) {
13-
writeStream.write(`${key}=${value}`);
12+
writeStream.write(`NEXT_PUBLIC_${key.toUpperCase()}= ${value}`);
1413
}
1514
writeStream.end();
1615
}

helpers/createPackage.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { execSync } from "child_process";
33
import chalk from "chalk";
44
import cliProgress from "cli-progress";
55

6-
export const createPackageJson = async (isEthereumProject, projectName, backendInfo) => {
6+
export const createPackageJson = async ( projectName, {isEthereumProject, wantsBackend, type}) => {
77
try {
88
console.log(chalk.yellow("Generating package.json"));
99
const bar1 = new cliProgress.SingleBar(
@@ -47,9 +47,9 @@ export const createPackageJson = async (isEthereumProject, projectName, backendI
4747
packageJson["dependencies"]["@solana/web3.js"] = "^1.50.1";
4848
}
4949

50-
if (backendInfo.wantsBackend) {
50+
if (wantsBackend) {
5151

52-
switch (backendInfo.type) {
52+
switch (type) {
5353
case "hardhat":
5454
packageJson["devDependencies"]["@nomicfoundation/hardhat-toolbox"] = "^1.0.2";
5555
packageJson["devDependencies"]["hardhat"] = "^2.10.1";

helpers/selfDestroy.js

+11-4
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,19 @@ export const setRoot = (path) => {
77
}
88

99
export const selfDestroy = (e) => {
10-
console.log("CURRENT WORKING DIRECTORY::", process.cwd())
11-
console.log("ROOT::", root)
12-
console.log(e)
10+
// console.log("CURRENT WORKING DIRECTORY::", process.cwd())
11+
// console.log("ROOT::", root)
12+
1313
fs.rmSync(root, {
1414
recursive: true,
1515
force: true,
1616
});
1717
process.exit(1)
18-
}
18+
}
19+
20+
process.on('exit', selfDestroy.bind(null))
21+
process.on('SIGINT', selfDestroy.bind(null))
22+
process.on('SIGUSR1', selfDestroy.bind(null))
23+
process.on('SIGUSR2', selfDestroy.bind(null))
24+
process.on('uncaughtException', selfDestroy.bind(null))
25+

helpers/setupHardhat.js

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
export const setUpHardhat = (dappInfo) => {
2+
console.log(chalk.yellow(`Copying ${dappInfo.type} files...`));
3+
const bar2 = new cliProgress.SingleBar(
4+
{},
5+
cliProgress.Presets.shades_classic
6+
);
7+
bar2.start(100, 0);
8+
bar2.update(50);
9+
10+
switch (dappInfo.type) {
11+
case "hardhat":
12+
let hardhatTemplate = path.join(
13+
process.cwd(),
14+
"templates",
15+
"hardhat"
16+
);
17+
fse.mkdirSync(path.join(process.cwd(), "backend"));
18+
fse.copySync(hardhatTemplate, path.join(process.cwd(), "backend"));
19+
createEnv(dappInfo.APIKey, path.join(process.cwd(), "backend"))
20+
break;
21+
case "foundry":
22+
break;
23+
case "anchor":
24+
break;
25+
}
26+
27+
bar2.update(100);
28+
bar2.stop();
29+
console.log(
30+
chalk.green("Smart Contract Development Environment copied ✅")
31+
);
32+
33+
}

0 commit comments

Comments
 (0)