CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-tarojs--cli

Command-line interface tool for Taro, a cross-platform framework that enables developers to build apps for Mini Programs, Web, and mobile platforms

Pending
Overview
Eval results
Files

cli.mddocs/

Command-Line Interface

Main CLI class that handles command parsing, environment setup, and command execution for all Taro operations.

Capabilities

CLI Class

Main command-line interface handler that processes arguments and executes Taro commands.

/**
 * Main CLI class for handling Taro command-line operations
 */
class CLI {
  appPath: string;
  
  /**
   * Initialize CLI with optional application path
   * @param appPath - Optional path to the application directory, defaults to process.cwd()
   */
  constructor(appPath?: string);
  
  /**
   * Execute CLI with command-line arguments
   * @returns Promise that resolves when command execution completes
   */
  run(): Promise<void>;
  
  /**
   * Parse command-line arguments and route to appropriate handlers
   * @returns Promise that resolves when argument parsing completes
   */
  parseArgs(): Promise<void>;
}

Usage Examples:

import { CLI } from "@tarojs/cli";

// Basic CLI usage
const cli = new CLI();
await cli.run();

// CLI with custom app path
const cli = new CLI('/path/to/my-app');
await cli.run();

// Direct argument parsing
const cli = new CLI();
await cli.parseArgs();

Command-Line Options

The CLI supports numerous command-line options for different operations:

interface CLIOptions {
  // Global options
  version?: boolean;
  help?: boolean;
  'disable-global-config'?: boolean;
  
  // Build options
  type?: string;         // Platform type (weapp, h5, etc.)
  watch?: boolean;       // Enable watch mode
  env?: string;          // Environment (development, production)
  mode?: string;         // Build mode
  port?: number;         // Development server port
  
  // React Native specific
  'reset-cache'?: boolean;
  'public-path'?: string;
  'bundle-output'?: string;
  'sourcemap-output'?: string;
  'sourcemap-use-absolute-path'?: boolean;
  'sourcemap-sources-root'?: string;
  'assets-dest'?: string;
  
  // Project creation options
  name?: string;
  description?: string;
  typescript?: boolean;
  framework?: FrameworkType;
  compiler?: CompilerTypes;
  npm?: NpmType;
  'template-source'?: string;
  template?: string;
  css?: CSSType;
  clone?: boolean;
  autoInstall?: boolean;
  
  // Build feature flags
  build?: boolean;
  check?: boolean;
  'inject-global-style'?: boolean;
  'new-blended'?: boolean;
  blended?: boolean;
  qr?: boolean;
}

Available Commands

The CLI provides the following built-in commands:

type TaroCommand = 
  | 'init'           // Initialize new project
  | 'build'          // Build project for target platform
  | 'create'         // Create page/component
  | 'config'         // Manage configuration
  | 'global-config'  // Manage global configuration
  | 'doctor'         // Run project diagnostics
  | 'info'           // Display environment information
  | 'update'         // Update Taro packages
  | 'inspect'        // Inspect webpack configuration
  | 'help';          // Display help information

Command Usage Examples:

# Project initialization
taro init my-project --framework react --typescript

# Building for different platforms
taro build --type weapp --env production
taro build --type h5 --watch --port 3000

# Creating new pages
taro create --name HomePage --typescript

# Project diagnostics
taro doctor

# Configuration management
taro config set registry https://registry.npm.taobao.org
taro global-config

# Environment information
taro info

# Package updates
taro update

Environment Variables

The CLI recognizes and sets several environment variables:

interface TaroEnvironment {
  NODE_ENV?: 'development' | 'production' | 'test';
  TARO_ENV?: string;        // Target platform
  TARO_APP_ID?: string;     // Application ID for mini programs
}

Platform Detection

The CLI automatically detects and configures platform-specific settings:

type SupportedPlatform = 
  | 'weapp'          // WeChat Mini Program
  | 'ascf'           // Ascend Platform
  | 'alipay'         // Alipay Mini Program
  | 'swan'           // Baidu Smart Program
  | 'tt'             // ByteDance Mini Program
  | 'qq'             // QQ Mini Program
  | 'jd'             // JD Mini Program
  | 'h5'             // HTML5 Web
  | 'rn'             // React Native
  | 'harmony-hybrid' // Harmony Hybrid
  | 'plugin';        // Mini Program Plugin

Error Handling

The CLI provides comprehensive error handling and user feedback:

interface CLIError {
  code: string;
  message: string;
  details?: any;
}

// Common error scenarios
type CLIErrorType = 
  | 'INVALID_COMMAND'
  | 'MISSING_CONFIG'
  | 'BUILD_FAILED'
  | 'TEMPLATE_NOT_FOUND'
  | 'PLATFORM_NOT_SUPPORTED'
  | 'VERSION_MISMATCH';

Install with Tessl CLI

npx tessl i tessl/npm-tarojs--cli

docs

cli.md

configuration.md

diagnostics.md

index.md

page-creation.md

plugin-development.md

project-creation.md

utilities.md

tile.json