@@ -9,9 +9,9 @@ import { existsSync } from "fs";
9
9
import { mkdir } from "./helpers/mkdir.js" ;
10
10
import { cleanUpFiles } from "./helpers/cleanUpFiles.js" ;
11
11
import { cloneRepo } from "./helpers/cloneRepo.js" ;
12
- import { selfDestroy , setRoot } from "./helpers/selfDestroy.js"
12
+ import { selfDestroy , setRoot } from "./helpers/selfDestroy.js" ;
13
13
import chalk from "chalk" ;
14
-
14
+ import { createEnv } from "./helpers/createEnv.js"
15
15
console . log ( `MMMMMMMMMMMMMMMMMK:..:KMMMMMMMMMMMMMMMMM
16
16
MMMMMMMMMMMMMMMWO, ,OWMMMMMMMMMMMMMMM
17
17
MMMMMMMMMMMMMMWk' 'kWMMMMMMMMMMMMMM
@@ -28,10 +28,10 @@ MMWO, .cXMXkxxxxxxxxxxxxxxxxxkKWMM
28
28
MWx' .oNW0;. 'xWM
29
29
Nd. .xNWk' .dN
30
30
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" ) ;
35
35
let projectPath = "" ;
36
36
37
37
const program = new Commander . Command ( "create-web3-dapp" )
@@ -45,111 +45,117 @@ const program = new Commander.Command("create-web3-dapp")
45
45
. parse ( process . argv ) ;
46
46
47
47
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
152
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 :
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
+ }
153
159
}
154
160
155
161
run ( ) ;
0 commit comments