-
Notifications
You must be signed in to change notification settings - Fork 257
/
Copy pathindex.js
executable file
·67 lines (55 loc) · 1.45 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env node
import chalk from "chalk";
import inquirer from "inquirer";
import { Command } from "commander";
import { setupProjectDirectory } from "./src/utils/directory.js";
import { logo } from "./src/utils/ascii-art.js";
import {
projectNamePrompt,
chainPrompt,
VALID_CHAINS,
} from "./src/prompts/project-prompts.js";
import { printOutroMessage } from "./src/utils/outro.js";
console.log(chalk.blue(logo));
const program = new Command();
program
.option("-c, --chain <chain>", "specify the chain to use")
.parse(process.argv);
const options = program.opts();
async function main() {
// Validate chain if provided via command line
if (options.chain && !VALID_CHAINS.includes(options.chain)) {
console.error(
chalk.red(
`Error: Invalid chain "${
options.chain
}". Valid chains are: ${VALID_CHAINS.join(", ")}`
)
);
process.exit(1);
}
const nameAnswer = await inquirer.prompt([projectNamePrompt]);
const { projectName } = nameAnswer;
let chain = options.chain;
if (!chain) {
const chainAnswer = await inquirer.prompt([chainPrompt]);
chain = chainAnswer.chain;
}
const { projectDir } = await setupProjectDirectory(
projectName,
chain,
inquirer
);
console.log(
chalk.green(
`\nCreating a new web3 dapp in ${chalk.bold(
projectDir
)} using ${chalk.bold(chain)} chain...\n`
)
);
printOutroMessage(projectName);
}
main().catch((error) => {
console.error(chalk.red("Error:"), error);
process.exit(1);
});