How mori-yang/create-mori works
Main Components
a. CLI Entry Point – The tool’s execution starts at the entry point (index.ts) where command-line arguments (e.g., which template to generate) are parsed. This component handles invoking the appropriate functions based on user inputs.
b. Core Engine/Template Generator – The “common” folder contains modules like constant.ts, create-template.ts, and utils.ts that likely implement the core logic for processing and performing global replacements in files. This is the heart of the template creation logic.
c. Template Repository – The “templates” directory is extensive and structured into subfolders (such as eslint-plugin, npm-package, and various Vite-React combinations). Each subfolder contains the template’s own configuration files (like package.json, tsconfig.json, build.config.ts, etc.), source files, and additional assets. This repository represents the vault of predefined project layouts that the generator can scaffold.
d. Configuration and Metadata – Files such as package.json, eslint.config.mjs, and supported-templates.ts provide metadata about the project, configuration for linting and building, and a mapping of the templates that are supported. These are essential for ensuring that both the CLI and the generator engine behave correctly according to the chosen template type.
Relationships and Interactions
• The CLI component accepts user commands and, based on the selected template (via parameters like “-t” or aliases such as “ve” for vscode-extension), directs the flow to the core engine.
• The core engine then loads the corresponding template from the Template Repository. It leverages utility functions in the “common” folder to adjust template-specific details (like performing global text replacement for placeholders such as [name] and [repo]).
• The Template Repository is organized by template type, so it can be viewed as a collection of “blueprints” that the engine instantiates.
• Configuration files ensure that linting, build behavior, and project-specific settings are consistently applied across the generated projects.
Architectural Patterns and Principles
• Modularity: The project cleanly separates concerns by isolating the CLI, core engine, and template definitions in different parts of the directory structure.
• Template-based Scaffolding: The engine is built around a template mechanism where templates are stored as standalone project directories, enabling easy expansion and maintenance.
• Reusability: Shared logic in the “common” directory demonstrates DRY principles for tasks like text replacement and template building.
Detailed Component Breakdown
• CLI Entry (index.ts): Initiates the application; receives user input and passes template parameters.
• Core Logic (common directory): Contains shared functionality such as templating logic, global text replacement for placeholders, and utility functions.
• Templates (templates directory): Represents multiple supported project templates (e.g., for ESLint plugins, packages, and various React template variants). Emphasize how each sub-template itself can have its internal structure (src, assets, config files) that reflects a mini-application architecture.
• Auxiliary Configuration: Files like package.json and ESLint configuration ensure that both the CLI tool itself and the generated projects adhere to proper standards.