chore: refactor installer to use modern JS patterns and improve code clarity
## CHANGES - Replace require with node:path import - Add block scoping to switch cases - Remove unused options parameter from update - Use optional chaining for ideConfig check - Replace forEach with for...of loops - Use template literals for string concatenation - Add early return to avoid else block - Update spell check dictionary entries
This commit is contained in:
parent
47794f301d
commit
17cb6d866c
|
|
@ -27,6 +27,7 @@
|
||||||
"Luxon",
|
"Luxon",
|
||||||
"MERN",
|
"MERN",
|
||||||
"mgmt",
|
"mgmt",
|
||||||
|
"nodir",
|
||||||
"Nuxt",
|
"Nuxt",
|
||||||
"overcommitting",
|
"overcommitting",
|
||||||
"pasteable",
|
"pasteable",
|
||||||
|
|
@ -58,6 +59,8 @@
|
||||||
"Turborepo",
|
"Turborepo",
|
||||||
"Underserved",
|
"Underserved",
|
||||||
"unredacted",
|
"unredacted",
|
||||||
|
"upgrader",
|
||||||
|
"upgraders",
|
||||||
"VARCHAR",
|
"VARCHAR",
|
||||||
"venv",
|
"venv",
|
||||||
"vercel",
|
"vercel",
|
||||||
|
|
|
||||||
|
|
@ -66,9 +66,9 @@ program
|
||||||
.description('Update existing BMAD installation')
|
.description('Update existing BMAD installation')
|
||||||
.option('--force', 'Force update, overwriting modified files')
|
.option('--force', 'Force update, overwriting modified files')
|
||||||
.option('--dry-run', 'Show what would be updated without making changes')
|
.option('--dry-run', 'Show what would be updated without making changes')
|
||||||
.action(async (options) => {
|
.action(async () => {
|
||||||
try {
|
try {
|
||||||
await installer.update(options);
|
await installer.update();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(chalk.red('Update failed:'), error.message);
|
console.error(chalk.red('Update failed:'), error.message);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
const path = require("path");
|
const path = require("node:path");
|
||||||
const chalk = require("chalk");
|
const chalk = require("chalk");
|
||||||
const ora = require("ora");
|
const ora = require("ora");
|
||||||
const inquirer = require("inquirer");
|
const inquirer = require("inquirer");
|
||||||
|
|
@ -257,11 +257,12 @@ class Installer {
|
||||||
]);
|
]);
|
||||||
|
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case "upgrade":
|
case "upgrade": {
|
||||||
console.log(chalk.cyan("\n📦 Starting v3 to v4 upgrade process..."));
|
console.log(chalk.cyan("\n📦 Starting v3 to v4 upgrade process..."));
|
||||||
const V3ToV4Upgrader = require("../../upgraders/v3-to-v4-upgrader");
|
const V3ToV4Upgrader = require("../../upgraders/v3-to-v4-upgrader");
|
||||||
const upgrader = new V3ToV4Upgrader();
|
const upgrader = new V3ToV4Upgrader();
|
||||||
return await upgrader.upgrade({ projectPath: installDir });
|
return await upgrader.upgrade({ projectPath: installDir });
|
||||||
|
}
|
||||||
case "alongside":
|
case "alongside":
|
||||||
return await this.performFreshInstall(config, installDir, spinner);
|
return await this.performFreshInstall(config, installDir, spinner);
|
||||||
case "cancel":
|
case "cancel":
|
||||||
|
|
@ -299,7 +300,7 @@ class Installer {
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case "force":
|
case "force":
|
||||||
return await this.performFreshInstall(config, installDir, spinner);
|
return await this.performFreshInstall(config, installDir, spinner);
|
||||||
case "different":
|
case "different": {
|
||||||
const { newDir } = await inquirer.prompt([
|
const { newDir } = await inquirer.prompt([
|
||||||
{
|
{
|
||||||
type: "input",
|
type: "input",
|
||||||
|
|
@ -310,6 +311,7 @@ class Installer {
|
||||||
]);
|
]);
|
||||||
config.directory = newDir;
|
config.directory = newDir;
|
||||||
return await this.install(config);
|
return await this.install(config);
|
||||||
|
}
|
||||||
case "cancel":
|
case "cancel":
|
||||||
console.log("Installation cancelled.");
|
console.log("Installation cancelled.");
|
||||||
return;
|
return;
|
||||||
|
|
@ -330,7 +332,9 @@ class Installer {
|
||||||
if (modifiedFiles.length > 0) {
|
if (modifiedFiles.length > 0) {
|
||||||
spinner.warn("Found modified files");
|
spinner.warn("Found modified files");
|
||||||
console.log(chalk.yellow("\nThe following files have been modified:"));
|
console.log(chalk.yellow("\nThe following files have been modified:"));
|
||||||
modifiedFiles.forEach((file) => console.log(` - ${file}`));
|
for (const file of modifiedFiles) {
|
||||||
|
console.log(` - ${file}`);
|
||||||
|
}
|
||||||
|
|
||||||
const { action } = await inquirer.prompt([
|
const { action } = await inquirer.prompt([
|
||||||
{
|
{
|
||||||
|
|
@ -395,9 +399,9 @@ class Installer {
|
||||||
|
|
||||||
if (config.ide) {
|
if (config.ide) {
|
||||||
const ideConfig = configLoader.getIdeConfiguration(config.ide);
|
const ideConfig = configLoader.getIdeConfiguration(config.ide);
|
||||||
if (ideConfig && ideConfig.instructions) {
|
if (ideConfig?.instructions) {
|
||||||
console.log(
|
console.log(
|
||||||
chalk.bold("To use BMAD agents in " + ideConfig.name + ":")
|
chalk.bold(`To use BMAD agents in ${ideConfig.name}:`)
|
||||||
);
|
);
|
||||||
console.log(ideConfig.instructions);
|
console.log(ideConfig.instructions);
|
||||||
}
|
}
|
||||||
|
|
@ -422,7 +426,7 @@ class Installer {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Legacy method for backward compatibility
|
// Legacy method for backward compatibility
|
||||||
async update(options) {
|
async update() {
|
||||||
console.log(chalk.yellow('The "update" command is deprecated.'));
|
console.log(chalk.yellow('The "update" command is deprecated.'));
|
||||||
console.log(
|
console.log(
|
||||||
'Please use "install" instead - it will detect and offer to update existing installations.'
|
'Please use "install" instead - it will detect and offer to update existing installations.'
|
||||||
|
|
@ -436,9 +440,8 @@ class Installer {
|
||||||
ide: null,
|
ide: null,
|
||||||
};
|
};
|
||||||
return await this.install(config);
|
return await this.install(config);
|
||||||
} else {
|
|
||||||
console.log(chalk.red("No BMAD installation found."));
|
|
||||||
}
|
}
|
||||||
|
console.log(chalk.red("No BMAD installation found."));
|
||||||
}
|
}
|
||||||
|
|
||||||
async listAgents() {
|
async listAgents() {
|
||||||
|
|
@ -446,9 +449,9 @@ class Installer {
|
||||||
|
|
||||||
console.log(chalk.bold("\nAvailable BMAD Agents:\n"));
|
console.log(chalk.bold("\nAvailable BMAD Agents:\n"));
|
||||||
|
|
||||||
agents.forEach((agent) => {
|
for (const agent of agents) {
|
||||||
console.log(chalk.cyan(` ${agent.id.padEnd(20)}`), agent.description);
|
console.log(chalk.cyan(` ${agent.id.padEnd(20)}`), agent.description);
|
||||||
});
|
}
|
||||||
|
|
||||||
console.log(
|
console.log(
|
||||||
chalk.dim("\nInstall with: npx bmad-method install --agent=<id>\n")
|
chalk.dim("\nInstall with: npx bmad-method install --agent=<id>\n")
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue