From 8ed721d029f800644a7802a7d801679377445789 Mon Sep 17 00:00:00 2001 From: Brian Madison Date: Sun, 26 Oct 2025 23:42:56 -0500 Subject: [PATCH] npx with version selector --- README.md | 12 ++++ package.json | 5 +- tools/bmad-npx-wrapper.js | 126 ++++++++++++++++++++++++++++++++++++++ tools/cli/bmad-cli.js | 2 - 4 files changed, 141 insertions(+), 4 deletions(-) create mode 100755 tools/bmad-npx-wrapper.js diff --git a/README.md b/README.md index c4559a12..84dc0e91 100644 --- a/README.md +++ b/README.md @@ -151,6 +151,18 @@ Install BMad to your project using npx: npx bmad-method install ``` +> **Version Selection:** When running `npx bmad-method install`, you'll be prompted to choose: +> +> - **Stable (v4.x)** - Production-ready version +> - **Beta (v6.0.0-beta)** - Latest features with early access +> +> To install a specific version directly (skip prompt): +> +> ```bash +> npx bmad-method@4 install # Stable v4.x +> npx bmad-method@6.0.0-beta.0 install # Beta v6 +> ``` + The interactive installer will guide you through: 1. **Project location** - Where to install BMad diff --git a/package.json b/package.json index 11150546..dcdc93e9 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "$schema": "https://json.schemastore.org/package.json", "name": "bmad-method", - "version": "6.0.0-alpha.0", + "version": "6.0.0-beta.0", "description": "Breakthrough Method of Agile AI-driven Development", "keywords": [ "agile", @@ -20,7 +20,8 @@ "author": "Brian (BMad) Madison", "main": "tools/cli/bmad-cli.js", "bin": { - "bmad": "tools/cli/bmad-cli.js" + "bmad": "tools/bmad-npx-wrapper.js", + "bmad-method": "tools/bmad-npx-wrapper.js" }, "scripts": { "bmad:install": "node tools/cli/bmad-cli.js install", diff --git a/tools/bmad-npx-wrapper.js b/tools/bmad-npx-wrapper.js new file mode 100755 index 00000000..0cf6ff95 --- /dev/null +++ b/tools/bmad-npx-wrapper.js @@ -0,0 +1,126 @@ +#!/usr/bin/env node + +/** + * BMad Method CLI - Direct execution wrapper for npx + * This file ensures proper execution when run via npx from GitHub or npm registry + * Supports version selection between stable (v4) and beta (v6) + */ + +const { execSync } = require('node:child_process'); +const path = require('node:path'); +const fs = require('node:fs'); + +// Check if we're running in an npx temporary directory +const isNpxExecution = __dirname.includes('_npx') || __dirname.includes('.npm'); + +async function promptVersionSelection() { + const inquirer = require('inquirer'); + const chalk = require('chalk'); + + console.log( + chalk.bold.cyan(` +██████╗ ███╗ ███╗ █████╗ ██████╗ ███╗ ███╗███████╗████████╗██╗ ██╗ ██████╗ ██████╗ +██╔══██╗████╗ ████║██╔══██╗██╔══██╗ ████╗ ████║██╔════╝╚══██╔══╝██║ ██║██╔═══██╗██╔══██╗ +██████╔╝██╔████╔██║███████║██║ ██║█████╗██╔████╔██║█████╗ ██║ ███████║██║ ██║██║ ██║ +██╔══██╗██║╚██╔╝██║██╔══██║██║ ██║╚════╝██║╚██╔╝██║██╔══╝ ██║ ██╔══██║██║ ██║██║ ██║ +██████╔╝██║ ╚═╝ ██║██║ ██║██████╔╝ ██║ ╚═╝ ██║███████╗ ██║ ██║ ██║╚██████╔╝██████╔╝ +╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚═════╝ ╚═╝ ╚═╝╚══════╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═════╝ + `), + ); + + console.log(chalk.bold.magenta('🚀 Universal AI Agent Framework for Any Domain\n')); + + const answers = await inquirer.prompt([ + { + type: 'list', + name: 'version', + message: 'Which version would you like to install?', + choices: [ + { + name: chalk.green('Stable (v4.x) - Production Ready'), + value: 'stable', + short: 'Stable v4.x', + }, + { + name: chalk.yellow('Beta (v6.0.0-beta) - Latest Features (Early Access)'), + value: 'beta', + short: 'Beta v6.0.0-beta', + }, + ], + default: 'stable', + }, + ]); + + return answers.version; +} + +async function installStableVersion(args) { + const chalk = require('chalk'); + + console.log(chalk.cyan('\n📦 Installing BMad Method v4 (Stable)...\n')); + + // Use npx to install the stable version from npm registry + // The @4 tag will fetch the latest v4.x.x version + const npxCommand = `npx bmad-method@4 ${args.join(' ')}`; + + try { + execSync(npxCommand, { + stdio: 'inherit', + cwd: process.cwd(), + }); + } catch (error) { + console.error(chalk.red('Failed to install stable version')); + process.exit(error.status || 1); + } +} + +async function installBetaVersion(args) { + const chalk = require('chalk'); + + console.log(chalk.yellow('\n📦 Installing BMad Method v6 Beta (Early Access)...\n')); + + // Use the v6 installer from the current installation + const bmadCliPath = path.join(__dirname, 'cli', 'bmad-cli.js'); + + if (!fs.existsSync(bmadCliPath)) { + console.error(chalk.red('Error: Could not find bmad-cli.js at'), bmadCliPath); + console.error(chalk.dim('Current directory:'), __dirname); + process.exit(1); + } + + try { + execSync(`node "${bmadCliPath}" ${args.join(' ')}`, { + stdio: 'inherit', + cwd: path.dirname(__dirname), + }); + } catch (error) { + process.exit(error.status || 1); + } +} + +async function main() { + const args = process.argv.slice(2); + + // Check if user wants to skip version prompt + const skipPrompt = args.includes('--skip-version-prompt'); + const filteredArgs = args.filter((arg) => arg !== '--skip-version-prompt'); + + if (isNpxExecution && !skipPrompt) { + // Running via npx - prompt for version selection unless skipped + const selectedVersion = await promptVersionSelection(); + + if (selectedVersion === 'stable') { + await installStableVersion(filteredArgs); + } else { + await installBetaVersion(filteredArgs); + } + } else { + // Local execution or skipped prompt - use the v6 installer directly + require('./cli/bmad-cli.js'); + } +} + +main().catch((error) => { + console.error('Unexpected error:', error); + process.exit(1); +}); diff --git a/tools/cli/bmad-cli.js b/tools/cli/bmad-cli.js index 41d01fcd..53134524 100755 --- a/tools/cli/bmad-cli.js +++ b/tools/cli/bmad-cli.js @@ -1,5 +1,3 @@ -#!/usr/bin/env node - const { program } = require('commander'); const path = require('node:path'); const fs = require('node:fs');