-
Notifications
You must be signed in to change notification settings - Fork 382
Rewrite generate-errors
and improve learn/errors
#1089
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
Merged
alice-i-cecile
merged 40 commits into
bevyengine:main
from
TrialDragon:make_error_pages_valid
Mar 18, 2024
Merged
Changes from all commits
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
e5eb1e3
Purge old error generator
TrialDragon 9aa88e2
Add get error pages
TrialDragon 2e1f860
Add errors section and introduction
TrialDragon efd34db
Add error code pages
TrialDragon c4a59ea
Make error page title not duplicate
TrialDragon b7514e7
Change learn errors link card URL
TrialDragon d277b6c
Update .gitignore to include folder used by tests
TrialDragon 8744329
Modify tests to reflect usage better
TrialDragon 6cbcd9f
Update Cargo
TrialDragon f085ca0
Add clean up to tests
TrialDragon e2d935f
Add new error page generator CLI
TrialDragon d7f4d25
Update generate errors script to use new CLI
TrialDragon 14f7c95
Remove unnecessary template
TrialDragon c261c0e
Update base layout to include errors page stuff
TrialDragon e6efe3a
Add README.md
TrialDragon 58d7d19
Update variable names to make semantic sense
TrialDragon 4c25c53
Fix typo
TrialDragon 8ee871d
Satisfy the formatter / linter
TrialDragon b38323c
Correct an old part in the docs
TrialDragon b6d162a
Fix outputted to output
TrialDragon a173e00
Improve comments
TrialDragon 319a910
Clarify a word
TrialDragon 6cf6227
Correct directory name referenced in README.md
TrialDragon 28efcde
Use `fs::read_to_string`
TrialDragon 10371d1
Clarify error
TrialDragon 78242b3
Fix annotation ordering
TrialDragon c50a4a9
Format code to be readable
TrialDragon bf9d8df
Update generate-errors/src/lib.rs
TrialDragon 99a2153
Update generate-errors/src/lib.rs
TrialDragon 21caba3
Clarify RegEx statement purpose
TrialDragon 557ea7d
Update generate-errors to use Rust 2021
TrialDragon 9f92445
Simplify returning anyhow error
TrialDragon 0732512
Update generate-errors to 0.2.0
TrialDragon 932b0cb
Add bail import
TrialDragon 43db94c
Decouple tests so they can be run parallel
TrialDragon da991c5
Improve entry unwrapping comment
TrialDragon 2b78532
Add title logic comment
TrialDragon 1868115
Explain some RegEx logic
TrialDragon f5a22a2
Make some page content const
TrialDragon cd1c5e4
Update .gitgnore
alice-i-cecile File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 |
---|---|---|
@@ -1,2 +1,5 @@ | ||
# Bevy repository | ||
bevy/ | ||
# Fake content folder for tests | ||
section_content/ | ||
pages_content/ |
This file contains hidden or 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 |
---|---|---|
@@ -1,17 +1,17 @@ | ||
[package] | ||
name = "generate-errors" | ||
version = "0.1.0" | ||
version = "0.2.0" | ||
authors = [ | ||
"Bevy Contributors <[email protected]>", | ||
"Carter Anderson <[email protected]>", | ||
] | ||
license = "MIT" | ||
edition = "2018" | ||
|
||
[dependencies] | ||
serde = { version = "1", features = [ "derive" ] } | ||
toml = "0.5" | ||
regex = "1.5" | ||
edition = "2021" | ||
|
||
[lints] | ||
workspace = true | ||
|
||
[dependencies] | ||
anyhow = "1.0.80" | ||
clap = { version = "4.5.2", features = ["derive"] } | ||
regex = "1.10.3" |
This file contains hidden or 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 @@ | ||
# Generate Errors | ||
|
||
This website utility tool takes the documentation of Bevy-unique error codes from the Bevy engine repo and makes them valid Zola pages. | ||
|
||
For most uses run the bash script from any directory: | ||
`./generate-errors/generate-errors.sh` | ||
or | ||
`./generate-errors.sh` | ||
|
||
## Niche Advice | ||
|
||
Almost certainly all use cases will be covered by the bash script above, but if you, for whatever reason, need to use the tool straight from cargo then you can run it like: | ||
`cargo run -- --errors-path <ERRORS_PATH> --output-path <OUTPUT_PATH>` | ||
Where `errors-path` is the directory containing the original error files in the Bevy repo. `output-path` is the folder that the errors section folder is output. | ||
|
||
You can also see the help page for the tool via: | ||
`cargo run -- -h` or `cargo run -- --help` |
This file contains hidden or 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 hidden or 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 |
---|---|---|
@@ -1,113 +1,34 @@ | ||
use generate_errors::{parse_errors, ErrorCode, FrontMatterErrorCode, Section}; | ||
use serde::Serialize; | ||
use std::fs::File; | ||
use std::io::Write; | ||
use std::path::Path; | ||
use std::{fs, io}; | ||
|
||
fn main() -> io::Result<()> { | ||
let errors_dir = std::env::args() | ||
.nth(1) | ||
.expect("First argument should specify the errors directory"); | ||
let content_dir = std::env::args() | ||
.nth(2) | ||
.expect("Second argument should specify the content directory"); | ||
let _ = fs::create_dir(content_dir.clone()); | ||
let errors_root_section = parse_errors(&errors_dir)?; | ||
|
||
errors_root_section.write(Path::new(&content_dir), Path::new(""), 0) | ||
} | ||
|
||
trait FrontMatterWriter { | ||
fn write(&self, root_path: &Path, current_path: &Path, weight: usize) -> io::Result<()>; | ||
} | ||
|
||
#[derive(Serialize)] | ||
struct FrontMatterSection { | ||
title: String, | ||
sort_by: String, | ||
template: Option<String>, | ||
weight: usize, | ||
extra: FrontMatterSectionExtra, | ||
} | ||
|
||
#[derive(Serialize)] | ||
struct FrontMatterSectionExtra { | ||
header_message: Option<String>, | ||
sort_order_reversed: bool, | ||
} | ||
|
||
impl From<&Section> for FrontMatterSection { | ||
fn from(section: &Section) -> Self { | ||
FrontMatterSection { | ||
title: section.name.clone(), | ||
sort_by: "weight".to_string(), | ||
template: section.template.clone(), | ||
weight: section.order.unwrap_or(0), | ||
extra: section.into(), | ||
} | ||
} | ||
} | ||
|
||
impl From<&Section> for FrontMatterSectionExtra { | ||
fn from(section: &Section) -> Self { | ||
FrontMatterSectionExtra { | ||
header_message: section.header.clone(), | ||
sort_order_reversed: section.sort_order_reversed, | ||
} | ||
} | ||
} | ||
|
||
impl FrontMatterWriter for Section { | ||
fn write(&self, root_path: &Path, current_path: &Path, weight: usize) -> io::Result<()> { | ||
let section_path = current_path.join(self.name.to_ascii_lowercase()); | ||
let path = root_path.join(§ion_path); | ||
fs::create_dir(path.clone())?; | ||
|
||
let mut frontmatter = FrontMatterSection::from(self); | ||
if self.order.is_none() { | ||
frontmatter.weight = weight; | ||
} | ||
|
||
let mut file = File::create(path.join("_index.md"))?; | ||
file.write_all( | ||
format!( | ||
r#"+++ | ||
{} | ||
+++ | ||
"#, | ||
toml::to_string(&frontmatter).unwrap(), | ||
) | ||
.as_bytes(), | ||
)?; | ||
|
||
for (i, content) in self.content.iter().enumerate() { | ||
content.write(root_path, §ion_path, i)?; | ||
} | ||
Ok(()) | ||
} | ||
} | ||
|
||
impl FrontMatterWriter for ErrorCode { | ||
fn write(&self, root_path: &Path, current_path: &Path, weight: usize) -> io::Result<()> { | ||
let path = root_path.join(current_path); | ||
|
||
let mut frontmatter = FrontMatterErrorCode::from(self); | ||
frontmatter.weight = weight; | ||
|
||
let mut file = File::create(path.join(format!("{}.md", self.code)))?; | ||
file.write_all( | ||
format!( | ||
r#"+++ | ||
{} | ||
+++ | ||
{}"#, | ||
toml::to_string(&frontmatter).unwrap(), | ||
self.content | ||
) | ||
.as_bytes(), | ||
)?; | ||
|
||
Ok(()) | ||
} | ||
use generate_errors::*; | ||
use std::path::PathBuf; | ||
|
||
use clap::Parser; | ||
|
||
/// Generate error reference pages from Bevy engine | ||
/// for use on the Bevy website. | ||
#[derive(Parser, Debug)] | ||
#[command(version, about, long_about = None)] | ||
struct Args { | ||
/// Path to the directory containing the | ||
/// error files stored in the | ||
/// local Bevy GitHub repo. | ||
#[arg(long)] | ||
errors_path: PathBuf, | ||
/// Path to the folder which the | ||
/// errors section should be generated in. | ||
#[arg(long)] | ||
output_path: PathBuf, | ||
} | ||
|
||
fn main() -> anyhow::Result<()> { | ||
let args = Args::parse(); | ||
|
||
println!("Writing section index & introduction . . ."); | ||
write_section(&args.output_path)?; | ||
println!("Getting error page contents . . ."); | ||
let error_page_content = get_error_pages(&args.errors_path)?; | ||
println!("Writing error pages content to output path . . ."); | ||
write_pages(&args.output_path, error_page_content)?; | ||
|
||
println!("All good!"); | ||
Ok(()) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.