9 releases
new 0.2.3 | Mar 31, 2025 |
---|---|
0.2.2 | Mar 31, 2025 |
0.1.9 | Mar 28, 2025 |
#269 in Filesystem
727 downloads per month
21KB
350 lines
Index
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
{
"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
#[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:
# Cargo.toml
[dependencies]
validate_directory_structure = "0.2.3"
use validate_directory_structure::ValidateDirTree;
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
Dependencies
~0.6–1.5MB
~33K SLoC