Skip to content

Commit bdbebe9

Browse files
committed
ADD: new 0.3.0 with rules and maid.json support
1 parent 74395f7 commit bdbebe9

File tree

6 files changed

+1063
-64
lines changed

6 files changed

+1063
-64
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
All notable changes to this project will be documented in this file.
44

5+
## [0.3.0] - 2024-10-07
6+
7+
- Breaking: removed support for '.maidignore' files, now use 'maid.json' instead.
8+
- Added support for reading 'maid.json' file.
9+
- Added support for rules in 'maid.json' file.
10+
- Updated README.md with new usage instructions.
11+
512
## [0.2.1] - 2024-10-07
613

714
- Enhanced markdown output with better formatting for filenames.

README.md

Lines changed: 87 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
# MAID - `M`arkdown `AI` `D`oc creator
22

3-
`maid` is a Python script that aggregates content from directories and files into a single Markdown file. It supports various options for logging, blacklisting files, and reading local `.maidignore` files.
3+
`maid` is a Python script that aggregates content from directories and files into a single Markdown file.
4+
It is very powerful and flexible, with support for:
5+
6+
- blacklisting files and directories
7+
- filtering text files using special `rules` (see below)
8+
- logging
9+
10+
Configuration can be keept in a `maid.json` file in the root directory of the project and even modified in subdirectories using a `maid.json` file that is only applied to that directory and its subdirectories.
411

512
## Usage
613

@@ -13,7 +20,7 @@
1320
- `-o`, `--output`: Specify the output Markdown file (default: `_content.md` in the current directory).
1421
- `--log`: Enable logging to stdout.
1522
- `--blacklist`: Glob patterns for files or directories to skip (matched against filename only). This option can be used multiple times.
16-
- `--blacklist-file`: File containing blacklist glob patterns.
23+
- `--maid-file`: File containing `maid` configuration (default: `maid.json` in the current directory).
1724
- `--version`: Display the version.
1825

1926
### Arguments
@@ -46,53 +53,112 @@ To skip certain files or directories:
4653
./maid.py -o output.md --blacklist "*.log" --blacklist "__pycache__" src
4754
```
4855

49-
### Using a Blacklist File
56+
### Using a Maid configuration File
5057

5158
To use a blacklist file:
5259

5360
```bash
54-
./maid.py -o output.md --blacklist-file blacklist.txt src
61+
./maid.py -o output.md --maid-file maid-special.json src
5562
```
5663

57-
### Reading Global and Local .maidignore Files
64+
### Reading Global and Local maid.json Files
5865

59-
Every directory scanned by `maid` will be checked for a `.maidignore` file. If found, the patterns in the file will be used to skip files or directories.
66+
Every directory scanned by `maid` will be checked for a `maid.json` file. If found, the patterns and rules in the file will be used to skip files or directories.
6067
Patterns are added to the current blacklist, so they can be combined with other blacklist patterns.
6168

62-
At startup, `maid` will look for a global `.maidignore` file in the following locations:
69+
At startup, `maid` will look for a global `maid.json` file in the following locations:
6370

71+
- current directory.
6472
- Home directory.
6573
- `.maid` directory in the home directory.
6674
- `.local/share/maid` directory in the home directory.
6775
- `.config/maid` directory in the home directory.
6876

6977
### Blacklist Patterns
7078

71-
Blacklist patterns can be specified directly via the `--blacklist` option or through a file using the `--blacklist-file` option. Patterns are matched against filenames only.
79+
Blacklist patterns can be specified directly via the `--blacklist` option or through a file using the `patterns` section in `--maid-file` option. Patterns are matched against filenames only.
7280

73-
### Example Blacklist File
81+
### Example `maid.json` File
7482

75-
```bash
76-
*.log
77-
__pycache__
78-
.DS_Store
83+
```json
84+
{
85+
"patterns": ["*.log", "__pycache__", ".DS_Store"],
86+
"rules": []
87+
}
7988
```
8089

81-
## Logging
90+
## Rules definition
8291

83-
If the `--log` option is enabled, `maid` will log its actions to stdout, including which files are being processed and which are being skipped due to blacklist patterns.
92+
Rules are a powerful way to filter text files. They are defined in the `rules` section of the `maid.json` file and are applied to text files only.
93+
94+
A rule is some special text manipulation that can be applied to a range of lines in a text file.
95+
The range is defined by a start pattern (the `start` key in the `rule` definition).
96+
At the moment, the only supported end of the range is the rule inside the `delete` key.
8497

85-
### Local `.maidignore` Files
98+
Let's see an example of a rule that deletes all lines in a Godot `.tscn` file
8699

87-
If the `--local-maidignore` option is enabled, `maid` will look for a `.maidignore` file in each directory it scans. The `.maidignore` file should contain glob patterns, one per line, for files or directories to skip.
100+
Original godot `.tscn` file section:
88101

89-
### Example `.maidignore` File
102+
```ini
103+
[gd_scene load_steps=98 format=3 uid="uid://clmi4pv7vlgn1"]
104+
105+
[ext_resource type="Script" path="res://player/player_graphics.gd" id="1_ayi7m"]
106+
[ext_resource type="Texture2D" uid="uid://dhq5k7y6mo74e" path="res://player/assets/spritesheet.png" id="2_bmcav"]
107+
108+
[sub_resource type="AtlasTexture" id="AtlasTexture_nbjsh"]
109+
atlas = ExtResource("2_bmcav")
110+
region = Rect2(48, 128, 48, 64)
111+
112+
[sub_resource type="AtlasTexture" id="AtlasTexture_ktvfe"]
113+
atlas = ExtResource("2_bmcav")
114+
region = Rect2(48, 128, 48, 64)
115+
116+
[node name="torso" type="AnimatedSprite2D" parent="."]
117+
position = Vector2(1, -30)
118+
sprite_frames = SubResource("SpriteFrames_w0qkt")
119+
animation = &"run"
120+
frame_progress = 0.410062
121+
```
90122

91-
```text
92-
*.tmp
93-
*.bak
123+
Suppose you want to remove all sub resources of type `AtlasTexture`, you can write a rule similar to this:
124+
125+
```json
126+
"rules": [
127+
{
128+
"pattern": "*.tscn",
129+
"name": "subres AtlasTexture",
130+
"start": ".sub_resource.*type=.AtlasTexture",
131+
"delete": "::empty::",
132+
"keep_start": false
133+
}
134+
]
94135
```
95136

137+
This rule will delete all lines, starting from the line containing the `sub_resource` declaration with `type="AtlasTexture"` until the first empty line in the file.
138+
139+
### Rule definition
140+
141+
A rule is defined by a dictionary with the following keys:
142+
143+
- `pattern`: A glob pattern to match the file name.
144+
- `name`: A name for the rule.
145+
- `start`: A Regular Expression pattern to match the start of the range.
146+
- `delete`: A Regular Expression pattern to match the end of the range or the special values:
147+
- `::empty::`: The first empty line after the start of the range.
148+
- `::line::`: the same line as the start of the range.
149+
- `keep_start`: A boolean value to keep the start line matched in the output.
150+
151+
Rules are applied only if the pattern matches the file name and they are applied in the order they are defined in the `rules` section.
152+
153+
## Logging
154+
155+
If the `--log` option is enabled, `maid` will log its actions to stdout, including which files are being processed and which are being skipped due to blacklist patterns.
156+
157+
### Local `maid.json` Files
158+
159+
`maid` will look for a `maid.json` file in each directory it scans. The `maid.json` file should contain glob patterns in the `patterns` section and text manipultation rules in the `rules` section.
160+
Patterns and rules in local `maid.json` files are only applied to the directory and its subdirectories.
161+
96162
## License
97163

98164
This project is licensed under the MIT License. See the LICENSE file for details.

0 commit comments

Comments
 (0)