or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

index.md
tile.json

tessl/npm-grunt-cli

The grunt command line interface that provides the global grunt command for running locally installed Grunt tasks

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/grunt-cli@1.5.x

To install, run

npx @tessl/cli install tessl/npm-grunt-cli@1.5.0

index.mddocs/

grunt-cli

grunt-cli is the command line interface for Grunt, a JavaScript task runner. It provides the global grunt command that locates and loads locally installed Grunt instances in projects, enabling developers to run Grunt tasks from anywhere in their system while maintaining project-specific Grunt versions.

Package Information

  • Package Name: grunt-cli
  • Package Type: npm
  • Language: JavaScript (Node.js)
  • Installation: npm install -g grunt-cli

Core Imports

grunt-cli is designed as a global CLI tool, not as a library to import. It provides the grunt command globally after installation.

Basic Usage

# Install grunt-cli globally
npm install -g grunt-cli

# Run grunt tasks in a project directory
grunt
grunt build
grunt test

# Display version
grunt --version

# Show help
grunt --help

# Enable shell auto-completion
eval "$(grunt --completion=bash)"  # For Bash
eval "$(grunt --completion=zsh)"   # For Zsh

Architecture

grunt-cli follows a delegation pattern where the global CLI finds and executes locally installed Grunt instances:

  • Global Installation: The CLI is installed globally but doesn't contain task logic
  • Local Delegation: Finds and executes locally installed Grunt in each project
  • Module Resolution: Uses Liftup library to locate Grunt installations
  • Extension Support: Supports various JavaScript file formats through interpret library
  • V8 Flag Handling: Properly forwards Node.js V8 flags to the local Grunt process

Capabilities

Command Line Interface

The primary interface for executing Grunt tasks and managing the CLI.

// Command line usage patterns
grunt [tasks...] [options...]

// Available command line options:
--help              // Display help information
--version           // Show grunt-cli version
--base <path>       // Base directory for resolving paths
--gruntfile <path>  // Path to Gruntfile
--require <module>  // Module(s) to require before loading Gruntfile
--preload <module>  // Preload modules
--verbose           // Enable verbose mode
--completion <shell> // Output shell completion script (bash/zsh)

Shell Auto-completion

Shell tab completion functionality for Bash and Zsh shells.

# Enable bash completion
eval "$(grunt --completion=bash)"

# Enable zsh completion  
eval "$(grunt --completion=zsh)"

Usage Example:

# Add to ~/.bashrc for persistent bash completion
echo 'eval "$(grunt --completion=bash)"' >> ~/.bashrc

# Add to ~/.zshrc for persistent zsh completion
echo 'eval "$(grunt --completion=zsh)"' >> ~/.zshrc

The completion system provides:

  • Task name completion based on available tasks in current project
  • Command-line option completion
  • Automatic detection of Gruntfile presence
  • Dynamic completion based on locally installed Grunt version

Internal Modules

The CLI includes internal modules for completion and information display (not intended for external use):

// lib/completion.js
exports.print = function(name: string): void;

// lib/info.js  
exports.version = function(): void;
exports.fatal = function(msg: string, code: number): void;
exports.help = function(): void;
exports.helpHeader = function(): void;
exports.helpFooter = function(): void;

Error Handling

grunt-cli provides helpful error messages for common issues:

  • No local Grunt found: Displays installation guidance when no local Grunt is detected
  • Invalid options: Shows help information for unrecognized command-line options
  • Missing Gruntfile: Indicates when no Gruntfile is found in the project
  • Completion errors: Graceful fallback when shell completion files are missing

Dependencies

grunt-cli integrates several key dependencies:

  • liftup: Locates and loads local Grunt installations
  • v8flags: Handles V8 engine flags appropriately
  • interpret: Supports various JavaScript file extensions (JS, CoffeeScript, etc.)
  • nopt: Parses command-line options
  • grunt-known-options: Defines valid Grunt command-line options

Installation Patterns

# Global installation (recommended)
npm install -g grunt-cli

# Local installation (for npm scripts)
npm install grunt-cli --save-dev

# Usage in package.json scripts
{
  "scripts": {
    "build": "grunt build",
    "test": "grunt test"
  }
}

Best Practices

  1. Install globally: Use npm install -g grunt-cli for the global command
  2. Local Grunt: Always install Grunt locally in each project (npm install grunt --save-dev)
  3. Version management: The CLI delegates to project-specific Grunt versions automatically
  4. Shell completion: Enable completion for improved developer experience
  5. CI/CD: Use local installation in automated environments for consistency