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

Improve README of generated model #1365

Merged
merged 5 commits into from
Nov 17, 2022
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 15 additions & 47 deletions Cargo.lock

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

13 changes: 1 addition & 12 deletions crates/fj-app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,6 @@ license.workspace = true
keywords.workspace = true
categories.workspace = true

[build-dependencies.ignore]
version = "0.4.18"
default-features = false

[build-dependencies.tar]
version = "0.4.35"
default-features = false

[dependencies]
anyhow = "1.0.66"
fj.workspace = true
Expand All @@ -29,6 +21,7 @@ fj-math.workspace = true
fj-operations.workspace = true
fj-viewer.workspace = true
fj-window.workspace = true
include_dir = "0.7.3"

[dependencies.clap]
version = "4.0.23"
Expand All @@ -45,7 +38,3 @@ features = ["derive"]
[dependencies.tracing-subscriber]
version = "0.3.16"
features = ["env-filter", "fmt"]

[dependencies.tar]
version = "0.4.35"
default-features = false
36 changes: 0 additions & 36 deletions crates/fj-app/build.rs

This file was deleted.

11 changes: 9 additions & 2 deletions crates/fj-app/model-template/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# Fornjot - Model Template
# Model Template

This template is compiled into the `fj-app` binary, where it is used to generate new models.
This is a Fornjot model that has been freshly generated! [**Fornjot**][Fornjot] is a next-generation, code-first CAD application. [**Check out the website**][Fornjot] to learn more!

Fornjot models are written in Rust, and a Fornjot model is just a Cargo package. If you don't fully understand what's going on here, check out the Rust documentation: [**https://www.rust-lang.org/learn**](https://www.rust-lang.org/learn)

Once you feel ready to dive in, get your favorite editor and check out `src/lib.rs`, which contains the source code for this model.


[Fornjot]: https://www.fornjot.app/
17 changes: 10 additions & 7 deletions crates/fj-app/src/model_crate.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
use include_dir::{include_dir, Dir};
use std::{fs, path::Path};
use tar::Archive;

static NEW_MODEL_TAR: &[u8] =
include_bytes!(concat!(env!("OUT_DIR"), "/new_model.tar"));
static MODEL_TEMPLATE: Dir = include_dir!("$CARGO_MANIFEST_DIR/model-template");

pub fn create(model_name: &str) -> anyhow::Result<()> {
let path = Path::new(model_name);
Archive::new(NEW_MODEL_TAR).unpack(path)?;
postprocess_model_files(path, model_name)?;
fs::create_dir_all(path)?;
MODEL_TEMPLATE.extract(path)?;
post_process_model_files(path, model_name)?;
println!("Model '{model_name}' created");
Ok(())
}

fn postprocess_model_files(
fn post_process_model_files(
path: &Path,
model_name: &str,
) -> anyhow::Result<()> {
Expand All @@ -30,7 +30,10 @@ fn postprocess_model_files(
),
],
)?;
fs::write(path.join("README.md"), format!("# {model_name}\n"))?;
replace_in_file(
&path.join("README.md"),
[("# Model Template".to_string(), format!("# {model_name}"))],
)?;
Ok(())
}

Expand Down