# Index
- [English](https://gitlab.com/public-sources1/validate_directory_structure/-/blob/main/readme.md)
- [EspaΓ±ol](https://gitlab.com/public-sources1/validate_directory_structure/-/blob/main/docs/readme_es.md)
# Directory Structure Validator
A tool to validate directory structures against a JSON schema. Checks for
required **folders** and **files** according to the specified configuration.
### Features
- Validates nested folder structures
- Checks for required/optional files
- Supports file extensions validation
- Detailed error reporting
### Example JSON structure
```JSON
{
"name": "TEST",
"description": "Structure of folders, folders required and files required",
"folders": [
{
"required": true,
"names": ["forest", "trees field"],
"files": [
{
"required": true,
"names": ["mountain", "hill"]
}
],
"folders": [
{
"names": ["sub_forest", "sub forest"],
"required": true,
"files": [
{
"names": ["file_sub_forest", "sub forest"],
"required": true
},
{
"names": ["file_optinal"],
"required": false
}
]
}
]
},
{
"required": false,
"names": ["rivers"],
"files": [
{
"required": true,
"names": ["aaaa", "bbbbb"]
}
]
}
]
}
```
## Significant typing
```rust
#[derive(Debug, Serialize)]
pub enum ItemType {
File,
Folder,
}
#[derive(Debug, Serialize)]
pub enum AlertType {
Warning, // --> Works only for property "required" false in JSON
MissingItem,
ExtraItem,
ErrorReadingFile,
}
#[derive(Debug, Serialize)]
pub struct AlertFileStructure {
pub path: String,
pub item_type: ItemType,
pub alert_type: AlertType,
}
```
### Usage:
```rust
let validate_structure = ValidateDirTree {
required_extensions: vec!["html", "css", "js"], // extensions of files mandatory
valid_extensions: vec!["ts", "tsx"], // These extensions aren't mandatory on folder
};
let results = validate_structure.validate_structure("/your/folder/path", YOUR_JSON_STRUCTUEE);
println!("these are the results: {:?}", results);
```
### Directory tree on my my_project_example
```
/ my_project_example
βββ trees field πΉ
β βββ mountain.html πΉ
β βββ mountain.js πΉ
β βββ mountain.css πΉ
β βββ main.js π· // no defined on JSON structure
β βββ sub_forest πΉ
β βββ file_optinal.html πΉ
β βββ file_optinal.js πΉ
β βββ file_optinal.css πΉ
β βββ file_optinal.lock π· // no defined on JSON structure
β βββ file_optinal.ts πΉ
βββ ocean π· // no defined on JSON structure
βββ pacific.html π· // only show message in parent folder
βββ pacific.js π· // only show message in parent folder
```
### Sample Output `Vec<AlertFileStructure>`
List of errors
- Error - > File "/trees field/main.js" is a **ExtraFile** because wasn't
defined on JSON
- Error - > File "/trees field/sub_forest/file_sub_forest.js" is a
**MissingFile** because was defined on JSON
- Error - > File "/trees field/sub_forest/file_sub_forest.css" is a
**MissingFile** because was defined on JSON
- Error - > File "/trees field/sub_forest/file_sub_forest.html" is a
**MissingFile** because was defined on JSON
- Error - > File "/trees field/sub_forest/file_optinal.lock" is a **ExtraFile**
because wasn's defined on JSON
- Warning - > Folder "/rivers" because it isn't mandatory however is a
**ExtraFile**
- Error - > Folder "/ocean" is a **ExtraFile** because that folder wasn't
defined on JSON