Skip to content

Commit 429c54b

Browse files
committed
feat: prompt to install Yarn if not found before generating monorepo
1 parent 97d6a4a commit 429c54b

File tree

1 file changed

+34
-4
lines changed

1 file changed

+34
-4
lines changed

.suite-cli/cli/cli.js

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
#!/usr/bin/env node
22

3+
const ora = require('ora')
34
const { Command } = require('commander');
45
const { createPromptModule } = require('inquirer');
5-
const figlet = require('figlet');
6+
const { execSync } = require('node:child_process')
67
const actionHandlers = require('./scripts')
78
const { logInfo } = require('./scripts/scripts.module');
89
const program = new Command()
@@ -78,7 +79,36 @@ program
7879
program
7980
.command('generate')
8081
.description('Generate a new monorepo resource')
81-
.action(() => {
82+
.action(async () => {
83+
try {
84+
// Check if Yarn is installed
85+
execSync('yarn --version', { stdio: 'ignore' });
86+
} catch (error) {
87+
const spinner = ora().fail('Yarn is not installed.');
88+
89+
const { installYarn } = await prompt([
90+
{
91+
type: 'confirm',
92+
name: 'installYarn',
93+
message: 'Would you like to install it now?',
94+
default: true
95+
}
96+
]);
97+
98+
if (installYarn) {
99+
try {
100+
spinner.start('Installing Yarn...');
101+
execSync('npm install -g yarn', { stdio: 'inherit' });
102+
spinner.succeed('Yarn installed successfully.');
103+
} catch (installError) {
104+
spinner.fail('Failed to install Yarn. Please install it manually and try again.');
105+
process.exit(1);
106+
}
107+
} else {
108+
spinner.fail('Yarn is required to proceed. Exiting.');
109+
process.exit(1);
110+
}
111+
}
82112
prompt([
83113
{
84114
type: 'list',
@@ -120,13 +150,13 @@ program
120150
message: 'Select license:',
121151
choices: ['ISC', 'MIT'],
122152
default: 'ISC'
123-
},{
153+
}, {
124154
type: 'input',
125155
name: 'service_name',
126156
message: 'Initial service:',
127157
default: 'microservice1'
128158
}
129-
159+
130160
])
131161
.then(answers => {
132162
// find out if this separater works on windows

0 commit comments

Comments
 (0)