|
1 | 1 | # MAID - `M`arkdown `AI` `D`oc creator |
2 | 2 |
|
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. |
4 | 11 |
|
5 | 12 | ## Usage |
6 | 13 |
|
|
13 | 20 | - `-o`, `--output`: Specify the output Markdown file (default: `_content.md` in the current directory). |
14 | 21 | - `--log`: Enable logging to stdout. |
15 | 22 | - `--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). |
17 | 24 | - `--version`: Display the version. |
18 | 25 |
|
19 | 26 | ### Arguments |
@@ -46,53 +53,112 @@ To skip certain files or directories: |
46 | 53 | ./maid.py -o output.md --blacklist "*.log" --blacklist "__pycache__" src |
47 | 54 | ``` |
48 | 55 |
|
49 | | -### Using a Blacklist File |
| 56 | +### Using a Maid configuration File |
50 | 57 |
|
51 | 58 | To use a blacklist file: |
52 | 59 |
|
53 | 60 | ```bash |
54 | | -./maid.py -o output.md --blacklist-file blacklist.txt src |
| 61 | +./maid.py -o output.md --maid-file maid-special.json src |
55 | 62 | ``` |
56 | 63 |
|
57 | | -### Reading Global and Local .maidignore Files |
| 64 | +### Reading Global and Local maid.json Files |
58 | 65 |
|
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. |
60 | 67 | Patterns are added to the current blacklist, so they can be combined with other blacklist patterns. |
61 | 68 |
|
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: |
63 | 70 |
|
| 71 | +- current directory. |
64 | 72 | - Home directory. |
65 | 73 | - `.maid` directory in the home directory. |
66 | 74 | - `.local/share/maid` directory in the home directory. |
67 | 75 | - `.config/maid` directory in the home directory. |
68 | 76 |
|
69 | 77 | ### Blacklist Patterns |
70 | 78 |
|
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. |
72 | 80 |
|
73 | | -### Example Blacklist File |
| 81 | +### Example `maid.json` File |
74 | 82 |
|
75 | | -```bash |
76 | | -*.log |
77 | | -__pycache__ |
78 | | -.DS_Store |
| 83 | +```json |
| 84 | +{ |
| 85 | + "patterns": ["*.log", "__pycache__", ".DS_Store"], |
| 86 | + "rules": [] |
| 87 | +} |
79 | 88 | ``` |
80 | 89 |
|
81 | | -## Logging |
| 90 | +## Rules definition |
82 | 91 |
|
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. |
84 | 97 |
|
85 | | -### Local `.maidignore` Files |
| 98 | +Let's see an example of a rule that deletes all lines in a Godot `.tscn` file |
86 | 99 |
|
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: |
88 | 101 |
|
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 | +``` |
90 | 122 |
|
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 | +] |
94 | 135 | ``` |
95 | 136 |
|
| 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 | + |
96 | 162 | ## License |
97 | 163 |
|
98 | 164 | This project is licensed under the MIT License. See the LICENSE file for details. |
|
0 commit comments