|
1 | 1 | #!/usr/bin/env node |
2 | 2 |
|
| 3 | +const ora = require('ora') |
3 | 4 | const { Command } = require('commander'); |
4 | 5 | const { createPromptModule } = require('inquirer'); |
5 | | -const figlet = require('figlet'); |
| 6 | +const { execSync } = require('node:child_process') |
6 | 7 | const actionHandlers = require('./scripts') |
7 | 8 | const { logInfo } = require('./scripts/scripts.module'); |
8 | 9 | const program = new Command() |
@@ -78,7 +79,36 @@ program |
78 | 79 | program |
79 | 80 | .command('generate') |
80 | 81 | .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 | + } |
82 | 112 | prompt([ |
83 | 113 | { |
84 | 114 | type: 'list', |
@@ -120,13 +150,13 @@ program |
120 | 150 | message: 'Select license:', |
121 | 151 | choices: ['ISC', 'MIT'], |
122 | 152 | default: 'ISC' |
123 | | - },{ |
| 153 | + }, { |
124 | 154 | type: 'input', |
125 | 155 | name: 'service_name', |
126 | 156 | message: 'Initial service:', |
127 | 157 | default: 'microservice1' |
128 | 158 | } |
129 | | - |
| 159 | + |
130 | 160 | ]) |
131 | 161 | .then(answers => { |
132 | 162 | // find out if this separater works on windows |
|
0 commit comments