33import chalk from "chalk" ;
44import inquirer from "inquirer" ;
55import { Command } from "commander" ;
6- import {
7- setupProjectDirectory ,
8- isInsideScaffoldAlchemyProject ,
9- updateProjectConfig ,
10- } from "./src/utils/directory.js" ;
6+ import { setupProjectDirectory } from "./src/utils/setup-project.js" ;
7+ import { setupChain } from "./src/utils/setup-chain.js" ;
118import { logo } from "./src/utils/ascii-art.js" ;
12- import {
13- projectNamePrompt ,
14- chainPrompt ,
15- VALID_CHAINS ,
16- } from "./src/prompts/project-prompts.js" ;
9+ import { projectNamePrompt } from "./src/prompts/project-prompts.js" ;
1710import { printOutroMessage } from "./src/utils/outro.js" ;
1811import { checkNodeVersion } from "./src/utils/version-check.js" ;
1912
@@ -25,70 +18,20 @@ program
2518
2619const options = program . opts ( ) ;
2720
28- async function getChain ( ) {
29- let chain = getChainOption ( ) ;
30- if ( ! chain ) {
31- const chainAnswer = await inquirer . prompt ( [ chainPrompt ] ) ;
32- chain = chainAnswer . chain ;
33- }
34- return chain ;
35- }
36-
37- function getChainOption ( ) {
38- if ( options . chain && ! VALID_CHAINS . includes ( options . chain ) ) {
39- console . error (
40- chalk . red (
41- `Error: Invalid chain "${
42- options . chain
43- } ". Valid chains are: ${ VALID_CHAINS . join ( ", " ) } `
44- )
45- ) ;
46- process . exit ( 1 ) ;
47- }
48-
49- return options . chain ;
50- }
51-
52- async function handleExistingProject ( ) {
53- const chain = await getChain ( ) ;
54- console . log (
55- chalk . green (
56- `\nUpdating chain configuration to ${ chalk . bold ( chain ) } ...\n`
57- )
58- ) ;
59- updateProjectConfig ( chain ) ;
60- console . log ( chalk . green ( "Chain configuration updated successfully!" ) ) ;
61- }
62-
6321async function handleNewProject ( ) {
6422 console . log ( chalk . blue ( logo ) ) ;
6523
6624 const { projectName } = await inquirer . prompt ( [ projectNamePrompt ] ) ;
6725
68- const chain = await getChain ( ) ;
26+ const { projectDir } = await setupProjectDirectory ( projectName , inquirer ) ;
27+
28+ await setupChain ( projectDir , options ) ;
6929
70- const { projectDir } = await setupProjectDirectory (
71- projectName ,
72- chain ,
73- inquirer
74- ) ;
75- console . log (
76- chalk . green (
77- `\nCreating a new web3 dapp in ${ chalk . bold (
78- projectDir
79- ) } using ${ chalk . bold ( chain ) } chain...\n`
80- )
81- ) ;
8230 await printOutroMessage ( projectName ) ;
8331}
8432
8533async function main ( ) {
86- if ( isInsideScaffoldAlchemyProject ( ) ) {
87- await handleExistingProject ( ) ;
88- } else {
89- await handleNewProject ( ) ;
90- }
91-
34+ await handleNewProject ( ) ;
9235 checkNodeVersion ( ) ;
9336}
9437
0 commit comments