https://github.com/alexdemure/fastgenerator
Code generator CLI tool
https://github.com/alexdemure/fastgenerator
code codegenerate codegenerator fastapi-boilerplate fastapi-crud fastapi-template generation generator
Last synced: about 2 months ago
JSON representation
Code generator CLI tool
- Host: GitHub
- URL: https://github.com/alexdemure/fastgenerator
- Owner: AlexDemure
- License: mit
- Created: 2025-03-17T14:53:12.000Z (2 months ago)
- Default Branch: production
- Last Pushed: 2025-04-02T11:16:06.000Z (about 2 months ago)
- Last Synced: 2025-04-02T12:25:37.022Z (about 2 months ago)
- Topics: code, codegenerate, codegenerator, fastapi-boilerplate, fastapi-crud, fastapi-template, generation, generator
- Language: Python
- Homepage:
- Size: 61.5 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
CLI utility for code generation based on a TOML configuration file.---
## Installation
```
pip install fastgenerator
```## Usage
Run the code generation process:
```sh
fastgenerator --file {config.toml} --context "{}"
```## Configuration File Guide
Fastgenerator uses a structured TOML configuration file to define the project structure, file contents, and commands to execute.
### General Structure
```
workdir = "myproject"folders = []
exclude = []
[[files]]
path = "{{name}}.py"
content = """
def hello():
print("Hello", {{name}})if __name__ == '__main__':
hello()
"""[[scripts]]
command = "isort {{workdir}}"
check = true
```### Sections Overview
| Section | Format | Description | | |
|---------------|---------------------------------|-------------------------------------------------------------------------|---|---|
| `workdir` | `""` | Uses the current directory | | |
| | `"myproject"` | Uses the current directory + `/myproject` | | |
| | `"/home/myproject"` | Uses an absolute path | | |
| `exclude` | `["src/static/__init__.py"]` | Uses a relative path to `workdir`. Excludes file creation. | | |
| `folders` | `["src/", "src/static"]` | Uses a relative path to `workdir`. Describes directories to be created. | | |
| `[[files]]` | | Defines file creation rules | | |
| | `mode = "a"` | File writing mode: `"a"` (append), `"w"` (overwrite) | | |
| | `path = "src/__init__.py"` | Relative to workdir, specifies file location. | | |
| | `""" ... """ / path / url` | Raw content, local file path, or URL for remote content. | | |
| `[[scripts]]` | | Defines commands to be executed after generation. | | |
| | `command = "isort {{workdir}}"` | Command to execute, supports dynamic variables. | | |
| | `check = True\False"` | If true, raises an error if the command fails, otherwise logs output. | | |## Using Dynamic Variables
Fastgenerator supports dynamic variables in both file paths, contents, and script commands.
```toml
[[files]]
path = "src/{{name}}.py"
content = """
def hello():
print("Hello, {{name}}!")if __name__ == '__main__':
hello()
"""
```## Automating Post-Generation Tasks
FastGenerator allows you to execute scripts after generating files. These scripts can perform tasks such as formatting, linting, or additional file modifications.
#### Example
```
[[scripts]]
command = "isort {{workdir}}"
check = true[[scripts]]
command = "ruff {{workdir}} --fix"
check = false
```- Commands support dynamic variables.
- If check = true, the execution will fail if the command returns a non-zero exit code.