Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: codegen tooling from config files #493

Merged
merged 14 commits into from
Oct 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ jobs:
# we specify bash to get pipefail; it guards against the `curl` command
# failing. otherwise `sh` won't catch that `curl` returned non-0
shell: bash
run: "curl --proto '=https' --tlsv1.2 -LsSf /~https://github.com/axodotdev/cargo-dist/releases/download/v0.22.1/cargo-dist-installer.sh | sh"
run: "curl --proto '=https' --tlsv1.2 -LsSf /~https://github.com/axodotdev/cargo-dist/releases/download/v0.23.0/cargo-dist-installer.sh | sh"
- name: Cache cargo-dist
uses: actions/upload-artifact@v4
with:
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ Generated by [`auto-changelog`](/~https://github.com/CookPete/auto-changelog).
#### [Unreleased](/~https://github.com/hougesen/mdsf/compare/v0.2.7...HEAD)

- feat: support multiple input paths [`#491`](/~https://github.com/hougesen/mdsf/pull/491)
- feat: finally port remaining tools to new config [`b11e51f`](/~https://github.com/hougesen/mdsf/commit/b11e51f3df48bde1378ec3b96ca97f7147f648ef)
- feat: reimplement a lot of tools [`b035b78`](/~https://github.com/hougesen/mdsf/commit/b035b7818813fe02525baa3d28da45ae8e657cac)
- feat: reimplement a lot more tools [`bbfe647`](/~https://github.com/hougesen/mdsf/commit/bbfe647bd68f1b2a1b84ccc5b1090752c9c8d3e2)

#### [v0.2.7](/~https://github.com/hougesen/mdsf/compare/v0.2.6...v0.2.7)

Expand Down
17 changes: 17 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 0 additions & 25 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,31 +51,6 @@ threadpool = "1.8.1"
toml = { version = "0.8.19" }
which = "6.0.3"

# Config for 'cargo dist'
[workspace.metadata.dist]
# The preferred cargo-dist version to use in CI (Cargo.toml SemVer syntax)
cargo-dist-version = "0.22.1"
# CI backends to support
ci = "github"
# The installers to generate for each app
installers = ["shell", "powershell", "npm", "homebrew", "msi"]
# A GitHub repo to push Homebrew formulas to
tap = "hougesen/homebrew-tap"
# Target platforms to build apps for (Rust target-triple syntax)
targets = ["aarch64-apple-darwin", "x86_64-apple-darwin", "x86_64-unknown-linux-gnu", "x86_64-pc-windows-msvc"]
# The archive format to use for windows builds (defaults .zip)
windows-archive = ".tar.gz"
# The archive format to use for non-windows builds (defaults .tar.xz)
unix-archive = ".tar.gz"
# Path that installers should place binaries in
install-path = "CARGO_HOME"
# Publish jobs to run in CI
publish-jobs = ["homebrew", "npm"]
# Whether to install an updater program
install-updater = false
# The npm package should have this name
npm-package = "mdsf-cli"

# The profile that 'cargo dist' will build with
[profile.dist]
inherits = "release"
Expand Down
389 changes: 197 additions & 192 deletions README.md

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
comment: false
coverage:
status:
project:
default:
informational: true
patch:
default:
informational: true
2 changes: 2 additions & 0 deletions codegen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ publish = false

[dependencies]
anyhow = { workspace = true }
convert_case = "0.6.0"
ignore.workspace = true
mdsf = { workspace = true }
regex = { workspace = true }
reqwest = { workspace = true }
Expand Down
3 changes: 3 additions & 0 deletions codegen/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@
mod language_to_filetype;
mod readme_tooling;
mod schema;
mod tools;

fn main() -> Result<()> {
tools::generate()?;

Check warning on line 11 in codegen/src/main.rs

View check run for this annotation

Codecov / codecov/patch

codegen/src/main.rs#L11

Added line #L11 was not covered by tests

schema::generate()?;

language_to_filetype::generate()?;
Expand Down
21 changes: 14 additions & 7 deletions codegen/src/readme_tooling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@
}

fn create_table(schema: Vec<Tool>) -> String {
let formatter_heading = "Formatter";
let formatter_heading = "Name";

Check warning on line 41 in codegen/src/readme_tooling.rs

View check run for this annotation

Codecov / codecov/patch

codegen/src/readme_tooling.rs#L41

Added line #L41 was not covered by tests
let mut formatter_width = formatter_heading.len();

let description_heading = "Description";
let description_heading = "Command";

Check warning on line 44 in codegen/src/readme_tooling.rs

View check run for this annotation

Codecov / codecov/patch

codegen/src/readme_tooling.rs#L44

Added line #L44 was not covered by tests
let mut description_width = description_heading.len();

let mut tools = std::collections::HashMap::<String, String>::new();
Expand All @@ -51,11 +51,18 @@

formatter_width = formatter_width.max(formatter.len());

let description = format!("[{}]({})", tool.description.trim(), tool.description.trim());
let description = tool.description.trim().to_string();

Check warning on line 54 in codegen/src/readme_tooling.rs

View check run for this annotation

Codecov / codecov/patch

codegen/src/readme_tooling.rs#L54

Added line #L54 was not covered by tests

description_width = description_width.max(description.len());

tools.insert(formatter.to_owned(), description);
tools.insert(
format!("`{formatter}`"),
if formatter == "juliaformatter.jl" {
description.replace("{$PATH_STRING}", "$PATH_STRING")

Check warning on line 61 in codegen/src/readme_tooling.rs

View check run for this annotation

Codecov / codecov/patch

codegen/src/readme_tooling.rs#L58-L61

Added lines #L58 - L61 were not covered by tests
} else {
description.replace("$PATH", "PATH")

Check warning on line 63 in codegen/src/readme_tooling.rs

View check run for this annotation

Codecov / codecov/patch

codegen/src/readme_tooling.rs#L63

Added line #L63 was not covered by tests
},
);
}

let tool_count = tools.len();
Expand Down Expand Up @@ -110,7 +117,7 @@

lines.insert(
0,
format!("`mdsf` currently supports {tool_count} tools. Feel free to open an issue/pull-request if your favorite tool is missing! 😃\n"),
format!("`mdsf` currently supports {tool_count} commands. Feel free to open an issue/pull-request if your favorite tool is missing! 😃\n"),

Check warning on line 120 in codegen/src/readme_tooling.rs

View check run for this annotation

Codecov / codecov/patch

codegen/src/readme_tooling.rs#L120

Added line #L120 was not covered by tests
);

lines.join("\n")
Expand All @@ -122,7 +129,7 @@
let update = format!("<!-- START_SECTION:{key} -->\n\n{value}\n\n<!-- END_SECTION:{key} -->");

let re = RegexBuilder::new(
format!(r"(<!-- START_SECTION:{key} -->)[^{{}}]*<!-- END_SECTION:{key} -->",).as_str(),
format!(r"(<!-- START_SECTION:{key} -->)[^{{}}]*?<!-- END_SECTION:{key} -->").as_str(),

Check warning on line 132 in codegen/src/readme_tooling.rs

View check run for this annotation

Codecov / codecov/patch

codegen/src/readme_tooling.rs#L132

Added line #L132 was not covered by tests
)
.multi_line(true)
.build()?;
Expand All @@ -143,7 +150,7 @@

let table = create_table(schema.definitions.tooling.one_of);

update_readme("supported-tools", &table)?;
update_readme("supported-tools", &table).unwrap();

Check warning on line 153 in codegen/src/readme_tooling.rs

View check run for this annotation

Codecov / codecov/patch

codegen/src/readme_tooling.rs#L153

Added line #L153 was not covered by tests

Ok(())
}
17 changes: 14 additions & 3 deletions codegen/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use anyhow::{Ok, Result};
use mdsf::config::MdsfConfig;

use crate::cargo::get_package_version;
use crate::{cargo::get_package_version, tools::Tool};

pub fn generate() -> Result<()> {
println!("generate schema");
Expand All @@ -14,9 +14,20 @@

std::fs::create_dir_all(&p)?;

let schema = serde_json::to_string_pretty(&schemars::schema_for!(MdsfConfig))?;
{
let schema = serde_json::to_string_pretty(&schemars::schema_for!(MdsfConfig))?;

Check warning on line 18 in codegen/src/schema.rs

View check run for this annotation

Codecov / codecov/patch

codegen/src/schema.rs#L18

Added line #L18 was not covered by tests

std::fs::write(p.join("mdsf.schema.json"), schema)?;
std::fs::write(p.join("mdsf.schema.json"), schema)?;

Check warning on line 20 in codegen/src/schema.rs

View check run for this annotation

Codecov / codecov/patch

codegen/src/schema.rs#L20

Added line #L20 was not covered by tests
};

{
let schema = serde_json::to_string_pretty(&schemars::schema_for!(Tool))?;

Check warning on line 24 in codegen/src/schema.rs

View check run for this annotation

Codecov / codecov/patch

codegen/src/schema.rs#L24

Added line #L24 was not covered by tests

std::fs::write(
std::path::PathBuf::from("tools").join("tool.schema.json"),
schema,
)?;

Check warning on line 29 in codegen/src/schema.rs

View check run for this annotation

Codecov / codecov/patch

codegen/src/schema.rs#L26-L29

Added lines #L26 - L29 were not covered by tests
};

Ok(())
}
Loading
Loading