-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalchemy-cli.js
executable file
·49 lines (42 loc) · 1.96 KB
/
alchemy-cli.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
#!/usr/bin/env node
const { Command } = require('commander');
const chalk = require('chalk');
const execSync = require('child_process').execSync;
const path = require('path');
const program = new Command();
// Define the 'init' command to scaffold a new Ethereum project using create-eth
program
.command('init <project-name>')
.description('Initialize a new Ethereum project using create-eth')
.action((projectName) => {
console.log(chalk.green(`Initializing new Ethereum project: ${projectName}...`));
// Step 1: Ensure `create-eth` dependencies are installed
try {
console.log(chalk.blue('Running yarn install for create-eth...'));
execSync('yarn install', { cwd: path.resolve(__dirname, 'node_modules/create-eth'), stdio: 'inherit' });
} catch (error) {
console.error(chalk.red('Error during yarn install:'));
console.error(chalk.red(error.message));
return;
}
// Step 2: Run `yarn build:dev` to build the project
try {
console.log(chalk.blue('Running yarn build:dev for create-eth...'));
execSync('yarn build:dev', { cwd: path.resolve(__dirname, 'node_modules/create-eth'), stdio: 'inherit' });
} catch (error) {
console.error(chalk.red('Error during yarn build:dev:'));
console.error(chalk.red(error.message));
return;
}
// Step 3: Scaffold the new project using `npx create-eth`
try {
console.log(chalk.blue('Running npx create-eth to create the new project...'));
execSync(`npx create-eth ${projectName}`, { stdio: 'inherit' });
console.log(chalk.green(`Project "${projectName}" created successfully!`));
} catch (error) {
console.error(chalk.red(`Error creating project "${projectName}":`));
console.error(chalk.red(error.message));
}
});
// Parse the CLI arguments
program.parse(process.argv);