CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-umi

Enterprise-level, plugin-based React application framework with out-of-the-box functionality including routing, building, deployment, testing, and linting capabilities

Pending
Overview
Eval results
Files

cli-service.mddocs/

CLI and Service Management

Command-line interface and service management for running development servers, building applications, and executing framework commands.

Capabilities

CLI Runner

Main entry point for executing umi commands from the command line or programmatically.

/**
 * Main CLI runner that handles all umi commands
 * @param opts - Optional configuration for CLI execution
 * @returns Promise that resolves when command execution completes
 */
function run(opts?: IOpts): Promise<void>;

interface IOpts {
  presets?: string[]; // Additional presets to load
}

Usage Examples:

import { run } from "umi";

// Run CLI programmatically with default settings
await run();

// Run with custom presets
await run({
  presets: ["@umijs/preset-react", "./custom-preset"],
});

Command Line Usage:

# Development server
umi dev

# Production build
umi build

# Show version
umi -v
umi --version

# Show help
umi -h
umi --help

# Feature commands
umi setup
umi mfsu
umi deadcode

Service Class

Core service class that extends the base CoreService with umi-specific functionality and configuration.

/**
 * Main service class that manages application lifecycle, plugins, and configuration
 */
class Service extends CoreService {
  /**
   * Creates a new umi service instance
   * @param opts - Optional service configuration
   */
  constructor(opts?: ServiceOpts);

  /**
   * Enhanced run method with command preprocessing and error handling
   * @param opts - Command execution options
   * @returns Promise that resolves when command execution completes
   */
  run2(opts: RunOpts): Promise<any>;
}

interface ServiceOpts {
  cwd?: string; // Working directory
  defaultConfigFiles?: string[]; // Configuration file patterns
  frameworkName?: string; // Framework name override
  presets?: string[]; // Additional presets to load
  plugins?: string[]; // Additional plugins to load
}

interface RunOpts {
  name: string; // Command name to execute
  args?: any; // Command arguments
}

Usage Examples:

import { Service } from "umi";

// Create service with default configuration
const service = new Service();

// Run specific command
await service.run2({
  name: "build",
  args: { analyze: true },
});

// Create service with custom options
const customService = new Service({
  cwd: "/path/to/project",
  frameworkName: "my-framework",
  presets: ["./custom-preset"],
});

// Run development server
await customService.run2({
  name: "dev",
  args: { port: 3001 },
});

Development Server

Special handling for development server with support for forked processes and hot reloading.

/**
 * Development server runner with forked process support
 * Automatically called when running 'umi dev' command
 */
function dev(): void;

The development server provides:

  • Hot module replacement (HMR)
  • Live reloading
  • Mock API support
  • Plugin system integration
  • Forked process execution for performance

Service Configuration

Default Service Setup

The Service class automatically configures itself with:

// Environment setup
process.env.UMI_DIR = dirname(require.resolve('../../package'));

// Working directory resolution
const cwd = getCwd();

// Configuration file discovery
const defaultConfigFiles = [
  '.umirc.ts',
  '.umirc.js', 
  'config/config.ts',
  'config/config.js'
];

// Preset loading
const presets = [
  require.resolve('@umijs/preset-umi'),
  ...customPresets
];

// Plugin discovery
const plugins = [
  // Auto-discover plugin.ts or plugin.js in project root
  existsSync(join(cwd, 'plugin.ts')) && join(cwd, 'plugin.ts'),
  existsSync(join(cwd, 'plugin.js')) && join(cwd, 'plugin.js'),
].filter(Boolean);

Command Processing

Commands are processed with automatic handling for:

  • Version requests (-v, --version, v)
  • Help requests (-h, --help, or no command)
  • Environment variable setup based on command type
  • Error handling and graceful exit

Type Definitions

// CLI options interface
interface IOpts {
  presets?: string[];
}

// Service constructor options
interface ServiceOpts {
  cwd?: string;
  defaultConfigFiles?: string[];
  frameworkName?: string;
  presets?: string[];
  plugins?: string[];
  env?: string;
}

// Run command options
interface RunOpts {
  name: string;
  args?: any;
}

Install with Tessl CLI

npx tessl i tessl/npm-umi

docs

cli-service.md

configuration.md

index.md

plugin-system.md

testing.md

tile.json