or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

cli.mdconfiguration.mddiagnostics.mdindex.mdpage-creation.mdplugin-development.mdproject-creation.mdutilities.md
tile.json

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

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/@tarojs/cli@4.1.x

To install, run

npx @tessl/cli install tessl/npm-tarojs--cli@4.1.0

index.mddocs/

Taro CLI

Taro CLI is the command-line interface tool for Taro, an open-source cross-platform framework that enables developers to build applications for Mini Programs, Web, and mobile platforms. The CLI provides comprehensive commands for project creation, development, building, and deployment across multiple platforms including WeChat Mini Programs, Baidu Smart Program, Alipay Mini Program, and more.

Package Information

  • Package Name: @tarojs/cli
  • Package Type: npm
  • Language: TypeScript
  • Installation: npm install -g @tarojs/cli

Core Imports

import { CLI, Creator, Project, defineConfig, doctor, getRootPath } from "@tarojs/cli";

For CommonJS:

const { CLI, Creator, Project, defineConfig, doctor, getRootPath } = require("@tarojs/cli");

Basic Usage

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

// Initialize and run CLI
const cli = new CLI();
cli.run();

// Or use in custom Node.js scripts
import { Project, defineConfig } from "@tarojs/cli";

// Define Taro configuration
const config = defineConfig({
  projectName: 'my-app',
  framework: 'react',
  compiler: 'webpack5',
  // ... other config
});

Command Line Usage:

# Initialize new project
taro init my-project

# Build for specific platform
taro build --type weapp

# Start development server
taro build --type h5 --watch

# Create new page
taro create

# Run project diagnostics
taro doctor

Architecture

Taro CLI is built around several key components:

  • CLI Engine: Main command processor handling argument parsing and command routing
  • Service Kernel: Plugin system for extensible command and platform support
  • Creation System: Project, page, and plugin scaffolding with template management
  • Build System: Multi-platform compilation with framework and compiler abstraction
  • Configuration System: Type-safe configuration with environment-specific overrides
  • Diagnostic System: Project health checks and recommendations

Capabilities

Command-Line Interface

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

class CLI {
  constructor(appPath?: string);
  run(): Promise<void>;
  parseArgs(): Promise<void>;
}

Command-Line Interface

Project Creation

Comprehensive project scaffolding system with support for multiple frameworks, templates, and customization options.

class Project extends Creator {
  constructor(options: IProjectConf);
  init(): Promise<void>;
  create(): Promise<void>;
}

interface IProjectConf {
  projectName: string;
  projectDir: string;
  npm: NpmType;
  templateSource: string;
  framework: FrameworkType;
  typescript?: boolean;
  css: CSSType;
  template: string;
  description?: string;
  autoInstall?: boolean;
}

Project Creation

Page and Component Creation

Utilities for creating pages and components within existing Taro projects, with automatic configuration updates.

interface IPageConf {
  projectDir: string;
  projectName: string;
  pageName: string;
  framework: FrameworkType;
  css: CSSType;
  typescript?: boolean;
  pageDir?: string;
  subPkg?: string;
}

function modifyPagesOrSubPackages(
  configPath: string,
  pagePath: string,
  subPackage?: string
): ConfigModificationState;

Page Creation

Plugin Development

Plugin creation and management system for extending Taro functionality with custom build processes and platform support.

class Plugin extends Creator {
  constructor(options: IPluginConf);
  create(): Promise<void>;
  getCliVersion(): string;
}

interface IPluginConf {
  pluginName: string;
  type: string;
  description?: string;
  projectDir: string;
  projectName: string;
  template: string;
  version: string;
}

Plugin Development

Configuration Management

Type-safe configuration system with environment-specific overrides and webpack merge capabilities.

function defineConfig<T extends CompilerTypes = CompilerWebpackTypes>(
  config: UserConfigExport<T>
): UserConfigExport<T>;

interface ConfigEnv {
  command: string;
  mode: string;
}

type UserConfigFn<T extends CompilerTypes = CompilerWebpackTypes> = (
  merge: WebpackMerge,
  env: ConfigEnv
) => IProjectConfig<T> | Promise<IProjectConfig<T>>;

type UserConfigExport<T extends CompilerTypes = CompilerWebpackTypes> = 
  | IProjectConfig<T> 
  | Promise<IProjectConfig<T>> 
  | UserConfigFn<T>;

Configuration

Project Diagnostics

Comprehensive project health checking system that validates environment, configuration, packages, and provides recommendations.

const doctor: {
  validators: Array<(args?: any) => Promise<void> | void>;
};

Diagnostics

Utility Functions

Core utility functions for path resolution, package management, file operations, and development helpers.

function getRootPath(): string;
function getPkgVersion(): string;
function getAllFilesInFolder(folder: string, filter?: string[]): Promise<string[]>;
function getTemplateSourceType(url: string): TemplateSourceType;
function printPkgVersion(): void;

Utilities

Types

type FrameworkType = 'react' | 'vue3' | 'preact' | 'solid';
type CompilerTypes = 'webpack5' | 'vite' | 'esbuild';
type CSSType = 'sass' | 'stylus' | 'less' | 'none';
type NpmType = 'npm' | 'yarn' | 'pnpm' | 'cnpm';
type TemplateSourceType = 'git' | 'url';

interface FileStat {
  name: string;
  isDirectory: boolean;
  isFile: boolean;
}

enum ConfigModificationState {
  Success = 'SUCCESS',
  Fail = 'FAIL'
}

type WebpackMerge = (...configs: Array<object | null | undefined>) => object;

Supported Platforms

  • weapp: WeChat Mini Program
  • 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