Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: bolt cli to work as standalone npm package #893

Open
wants to merge 16 commits into
base: main
Choose a base branch
from

Conversation

thecodacus
Copy link
Collaborator

@thecodacus thecodacus commented Dec 24, 2024

Add CLI Support for Global Installation

Overview

This PR adds CLI support to the Bolt package, enabling users to install and run Bolt globally via npm. This change significantly improves the user experience by allowing users to run Bolt directly as a command line tool, eliminating the need to clone the repository and manage potentially unstable development versions.

Key Changes

1. CLI Implementation

  • Added new bin/bolt.js script for CLI functionality
  • Configured package.json for global npm installation
  • Implemented command-line argument parsing for port, help, and version flags
  • Added user-friendly banner and help messages

2. Package Configuration

  • Updated package.json with bin configuration for CLI support
  • Added necessary files array to specify published package contents
  • Changed package name to "bolt-diy" for npm registry
  • Maintained version numbering and package configuration

Technical Details

CLI Implementation

Key technical implementation details:

  • Uses Node.js spawn to manage the development server process
  • Implements clean process management with proper signal handling
  • Provides version detection from package.json
  • Supports custom port configuration

Simple usage example:

// Command line usage
bolt              // Start with default settings
bolt --port 3000  // Start on custom port
bolt --help       // Show help message
bolt --version    // Display version info

// Core CLI implementation
const options = {
  port: 5173,
  help: false,
  version: false
};

// Parse arguments
for (let i = 0; i < args.length; i++) {
  const arg = args[i];
  switch (arg) {
    case '--port':
    case '-p':
      options.port = parseInt(args[i + 1]);
      i++;
      break;
    // ... other argument handling
  }
}

System Changes

  • Added new execution path through CLI entry point
  • Modified package distribution configuration
  • Updated development server startup process
  • Maintained backwards compatibility with existing scripts

Testing

  • Verified CLI installation and execution
  • Tested all command line arguments
  • Validated process management and cleanup
  • Confirmed compatibility with existing npm scripts
  • Tested error handling for invalid arguments

Migration Impact

  • No breaking changes for existing users
  • New installation method available via npm global install
  • Repository-based installation continues to work as before
  • All existing npm scripts remain functional

Future Improvements

  • Add support for additional CLI configuration options
  • Implement environment-specific configurations
  • Add auto-update checking functionality
  • Consider adding configuration file support

Example Usage

Installation

# Install globally using npm
npm install -g bolt.diy

# Install globally using pnpm
pnpm add -g bolt.diy

# Install globally using yarn
yarn global add bolt.diy

Basic Usage

# Start Bolt with default settings (port 5173)
bolt.diy

# Start Bolt on a specific port
bolt.diy --port 3000
bolt.diy -p 3000

# View help and available commands
bolt.diy --help
bolt.diy -h

# Check current version
bolt.diy --version
bolt.diy -v

Example Output

★═══════════════════════════════════════★
          B O L T . D I Y
         ⚡️  Welcome  ⚡️
★═══════════════════════════════════════★
📍 Current Version Tag: v0.0.3
📍 Starting on port: 5173
  Please wait until the URL appears here
★═══════════════════════════════════════★

@thecodacus thecodacus marked this pull request as ready for review January 6, 2025 14:46
Copy link
Collaborator

@coleam00 coleam00 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thecodacus Absolutely fantastic work with this! Your attention to detail is super impressive, especially with everything in bin/bolt.js. Nice work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants