-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: adding support for new tools (#650)
* docs: how to add new tools * chore: automatically update CONTRIBUTING.md toc
- Loading branch information
Showing
8 changed files
with
142 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
# Contributing to mdsf | ||
|
||
Thank you for considering contributing to mdsf. It is greatly appreciated! ❤️ | ||
|
||
## Table of contents | ||
|
||
<!-- START_SECTION:toc --> | ||
|
||
- [Contributing to mdsf](#contributing-to-mdsf) | ||
- [Table of contents](#table-of-contents) | ||
- [Adding support for a new tool](#adding-support-for-a-new-tool) | ||
- [Tool metadata](#tool-metadata) | ||
|
||
<!-- END_SECTION:toc --> | ||
|
||
## Adding support for a new tool | ||
|
||
Adding support for new tools is extremely easy, and does not require any knowledge of Rust programming. | ||
|
||
To add support for a new tool start by creating a folder in [`tools`](tools/) with the name of the tool. | ||
|
||
Inside the folder you create a new file called `plugin.json`. | ||
|
||
The file must include _at least_ 2 keys, `binary`, which, as the key suggest, is the name of the binary, and `commands`, which is a nested map of all the commands for the tool. | ||
|
||
If we wanted to add support for mdsf (`mdsf format PATH_TO_FILE`) that would look like the following: | ||
|
||
```json | ||
// tools/mdsf/plugin.json | ||
{ | ||
"$schema": "../tool.schema.json", | ||
|
||
"binary": "mdsf", | ||
"commands": { | ||
"format": { | ||
"arguments": ["format", "$PATH"] | ||
} | ||
} | ||
} | ||
``` | ||
|
||
As seen in the example above we used the argument `$PATH`. That is a special keyword that is automatically replaced with the actual path to the file. | ||
|
||
If you wish to test the tool locally you can generate the code for the new tool by running `just codegen`. Otherwise the code will automatically be generated when the `plugin.json` files is committed. | ||
|
||
### Tool metadata | ||
|
||
`plugin.json` also supports some metadata keys that are used when generating the documentation for the tool. | ||
|
||
The metadata fields does **not** affect mdsf when it is ran. | ||
|
||
The current metadata keys are: | ||
|
||
| Key | Datatype | Description | | ||
| ------------- | ---------- | ---------------------------------------------------------- | | ||
| `description` | `string` | Description of what the tool does. | | ||
| `homepage` | `string` | Link to the repository/homepage/documentation of the tool. | | ||
| `categories` | `string[]` | The purpose of the tool (`formatter` or `linter`). | | ||
| `languages` | `string[]` | The languages/file types the tool supports. | | ||
|
||
```json | ||
// tools/mdsf/plugin.json | ||
{ | ||
"$schema": "../tool.schema.json", | ||
|
||
"binary": "mdsf", | ||
"commands": { | ||
"format": { | ||
"arguments": ["format", "$PATH"] | ||
} | ||
}, | ||
|
||
"description": "mdsf is a markdown codeblock formatter and linter", | ||
"homepage": "https://github.com/hougesen/mdsf", | ||
"languages": ["markdown"], | ||
"categories": ["linter", "formatter"] | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
use crate::markdown::{table_of_contents, update_markdown_section}; | ||
|
||
pub fn generate() -> anyhow::Result<()> { | ||
let path = std::path::PathBuf::from("./CONTRIBUTING.md"); | ||
|
||
let mut contents = std::fs::read_to_string(&path)?; | ||
|
||
{ | ||
let t = table_of_contents::generate(&path)?; | ||
|
||
contents = update_markdown_section(&contents, "toc", &t)?; | ||
|
||
std::fs::write(&path, contents)?; | ||
}; | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
pub mod table_of_contents; | ||
|
||
pub fn update_markdown_section( | ||
readme: &str, | ||
key: &str, | ||
value: &str, | ||
) -> Result<String, regex::Error> { | ||
let start = format!("<!-- START_SECTION:{key} -->"); | ||
let end = format!("<!-- END_SECTION:{key} -->"); | ||
|
||
let re = regex::RegexBuilder::new(format!(r"({start})[^{{}}]*?{end}").as_str()) | ||
.multi_line(true) | ||
.build()?; | ||
|
||
let first_value = format!("{start}{end}"); | ||
|
||
let updated = re.replace(readme, &first_value); | ||
|
||
let update = format!("{start}\n\n{value}\n\n{end}"); | ||
|
||
Ok(updated.replace(&first_value, &update)) | ||
} |
4 changes: 2 additions & 2 deletions
4
codegen/src/readme/table_of_contents.rs → codegen/src/markdown/table_of_contents.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters