# ant-design/antd-tools architecture

> Architecture diagram of the GitHub repository ant-design/antd-tools, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-03). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ant-design/antd-tools
- Repository: https://github.com/ant-design/antd-tools

## Overview

##### Main Components
- CLI Interface: This is the entry point for the tool commands. Look mainly at the files under src/cli (especially src/cli/index.ts) as well as the main entry file src/index.ts.
- Configuration Generators: There are several “get configuration” modules such as:
- getBabelCommonConfig.ts
- getTSCommonConfig.ts
- getWebpackConfig.ts
These indicate that the project dynamically creates or supplies configurations for Babel, TypeScript, and Webpack.
- Build and Task Automation: The project contains a gulpfile (src/gulpfile.ts) and scripts in the “script” directory (lint-prettier.js and prettier.js), suggesting its involvement in automation of tasks.
- Testing Preprocessors: Under src/jest, there are several preprocessor modules (codePreprocessor.ts, demoPreprocessor.ts, imagePreprocessor.ts, rewriteSource.ts) that prepare code for Jest testing.
- Linting and API Tools: There is a lint directory (src/lint/checkDiff.ts) and modules such as sortApiTable.ts and apiCollection.ts – these are geared towards maintaining codebase quality and organizing API details.
- Utility Functions: The utils folder (with CleanUpStatsPlugin.ts and projectHelper.ts) provides additional functions to support the core features.
- Build Scripts & CLI Commands: In addition to the CLI folder, there are several one-off scripts (such as src/replaceLib.ts) that may be invoked by the commands listed in the README.

##### Relationships and Interactions
- The main “CLI interface” acts as the driver where command-line arguments determine which sub-component or task to execute.
- When a command is received (for instance “run compile”), the CLI module will trigger:
- Configuration Generators to create/modify build configurations.
- Gulp and other build scripts to process files.
- Lint and API utility tools to check or reorganize code.
- The testing pipeline uses modules under src/jest to preprocess code before actual Jest testing runs.
- The “utils” directory is used across various modules to encapsulate common logic, such as cleaning up stats or assisting with project structure information.

##### Architectural Patterns or Design Principles
- Modular Design: Each functionality is separated into its own module (e.g., individual preprocessor files, config generators, commands). This improves maintainability and allows for individual testing.
- Command Pattern: The CLI commands act as separate units where each “run XYZ” command addresses specific tasks such as building or cleaning the project.
- Configuration-as-Code: The use of dynamic configuration generators (for Babel, TS, Webpack) emphasizes the principle of keeping build configurations in code, which can be programmatically altered or extended.

##### Relevant Technologies, Frameworks, and Libraries
- Node.js: The project is a Node-based CLI tool.
- TypeScript: Many source files are written in TypeScript (e.g., .ts files throughout src), ensuring type safety.
- Babel, TypeScript, Webpack: Clearly used as underlying technology for building or transpiling the project.
- Gulp: Used for task automation, as seen in the gulpfile.
- Jest: The testing framework is supported with custom preprocessors.
- ESLint, Prettier: Code quality tools are configured (files like .eslintrc, .prettierrc, etc.).

## Diagram (Mermaid)

```mermaid
flowchart TD
    UserCmd["User Command Input"]:::user
    UserCmd --> CLI_INDEX

    subgraph "CLI Interface"
        CLI_INDEX["CLI Entry Point (index.ts)"]:::cli
        CLI_CLI["CLI Command Handler (cli/index.ts)"]:::cli
        CLI_INDEX --> CLI_CLI
    end

    %% CLI triggers configuration generation
    CLI_CLI --> BABEL
    CLI_CLI --> TS
    CLI_CLI --> WEBPACK

    subgraph "Configuration Generators"
        BABEL["Babel Config Generator (getBabelCommonConfig.ts)"]:::config
        TS["TS Config Generator (getTSCommonConfig.ts)"]:::config
        WEBPACK["Webpack Config Generator (getWebpackConfig.ts)"]:::config
    end

    %% Config generators feed into build automation
    BABEL --> GULP
    TS --> GULP
    WEBPACK --> GULP

    subgraph "Build & Task Automation"
        GULP["Gulp Task Runner (gulpfile.ts)"]:::build
        LINT_PRET["Lint & Prettier (lint-prettier.js)"]:::build
        PRET["Prettier Script (prettier.js)"]:::build
        ANTDTOOLS["CLI Command (antd-tools.js)"]:::build
    end

    %% Build automation triggers testing and linting/API checks
    GULP --> CODE_PRE
    GULP --> DEMO_PRE
    GULP --> IMAGE_PRE
    GULP --> REWRITE
    GULP --> LINT_CHECK
    GULP --> SORT_API
    GULP --> API_COL

    subgraph "Testing Preprocessors"
        CODE_PRE["Code Preprocessor (codePreprocessor.ts)"]:::test
        DEMO_PRE["Demo Preprocessor (demoPreprocessor.ts)"]:::test
        IMAGE_PRE["Image Preprocessor (imagePreprocessor.ts)"]:::test
        REWRITE["Source Rewriter (rewriteSource.ts)"]:::test
    end

    subgraph "Linting & API Tools"
        LINT_CHECK["Lint Check (checkDiff.ts)"]:::lint
        SORT_API["API Sorting (sortApiTable.ts)"]:::lint
        API_COL["API Collection (apiCollection.ts)"]:::lint
    end

    subgraph "Utility Functions"
        CLEANUP["Stats Cleanup Utility (CleanUpStatsPlugin.ts)"]:::util
        PROJ_HELP["Project Helper Utility (projectHelper.ts)"]:::util
    end

    %% Utility functions support various modules (dashed connections)
    CLEANUP --- GULP
    PROJ_HELP --- GULP
    CLEANUP --- BABEL
    PROJ_HELP --- TS

    subgraph "Build Scripts & CLI Commands"
        REPLACE_LIB["Replace Library Script (replaceLib.ts)"]:::script
    end

    %% Build automation command triggers build scripts
    ANTDTOOLS --> REPLACE_LIB

    %% Class Definitions for styling
    classDef cli fill:#cce5ff,stroke:#007bff,stroke-width:2px;
    classDef config fill:#d1e7dd,stroke:#0f5132,stroke-width:2px;
    classDef build fill:#fff3cd,stroke:#856404,stroke-width:2px;
    classDef test fill:#f8d7da,stroke:#842029,stroke-width:2px;
    classDef lint fill:#d1c4e9,stroke:#5e2e8c,stroke-width:2px;
    classDef util fill:#e2e3e5,stroke:#41464b,stroke-width:2px;
    classDef script fill:#fefefe,stroke:#6c757d,stroke-width:2px;
    classDef user fill:#cfe2ff,stroke:#084298,stroke-width:2px;

    %% Click Events
    click CLI_INDEX "https://github.com/ant-design/antd-tools/blob/master/src/index.ts"
    click CLI_CLI "https://github.com/ant-design/antd-tools/blob/master/src/cli/index.ts"
    click BABEL "https://github.com/ant-design/antd-tools/blob/master/src/getBabelCommonConfig.ts"
    click TS "https://github.com/ant-design/antd-tools/blob/master/src/getTSCommonConfig.ts"
    click WEBPACK "https://github.com/ant-design/antd-tools/blob/master/src/getWebpackConfig.ts"
    click GULP "https://github.com/ant-design/antd-tools/blob/master/src/gulpfile.ts"
    click LINT_PRET "https://github.com/ant-design/antd-tools/blob/master/script/lint-prettier.js"
    click PRET "https://github.com/ant-design/antd-tools/blob/master/script/prettier.js"
    click ANTDTOOLS "https://github.com/ant-design/antd-tools/blob/master/bin/antd-tools.js"
    click CODE_PRE "https://github.com/ant-design/antd-tools/blob/master/src/jest/codePreprocessor.ts"
    click DEMO_PRE "https://github.com/ant-design/antd-tools/blob/master/src/jest/demoPreprocessor.ts"
    click IMAGE_PRE "https://github.com/ant-design/antd-tools/blob/master/src/jest/imagePreprocessor.ts"
    click REWRITE "https://github.com/ant-design/antd-tools/blob/master/src/jest/rewriteSource.ts"
    click LINT_CHECK "https://github.com/ant-design/antd-tools/blob/master/src/lint/checkDiff.ts"
    click SORT_API "https://github.com/ant-design/antd-tools/blob/master/src/sortApiTable.ts"
    click API_COL "https://github.com/ant-design/antd-tools/blob/master/src/apiCollection.ts"
    click CLEANUP "https://github.com/ant-design/antd-tools/blob/master/src/utils/CleanUpStatsPlugin.ts"
    click PROJ_HELP "https://github.com/ant-design/antd-tools/blob/master/src/utils/projectHelper.ts"
    click REPLACE_LIB "https://github.com/ant-design/antd-tools/blob/master/src/replaceLib.ts"
```
