-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from metacall/metassr-create
feat: metassr-create
- Loading branch information
Showing
45 changed files
with
1,603 additions
and
29 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
/target | ||
node_modules | ||
dist | ||
/node_modules | ||
/dist | ||
.vscode |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,10 @@ | ||
[package] | ||
name = "metassr-create" | ||
version = "0.1.0" | ||
edition = "2021" | ||
build = "build.rs" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[build-dependencies] | ||
walkdir = "2.5.0" |
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,45 @@ | ||
use std::env; | ||
use std::fs; | ||
use std::path::PathBuf; | ||
use walkdir::WalkDir; | ||
|
||
fn main() { | ||
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap()); | ||
let dest_path = out_dir.join("templates.rs"); | ||
println!("==> {dest_path:#?}"); | ||
let templates_dir = "templates"; | ||
let mut generated_code = String::new(); | ||
|
||
generated_code.push_str("use std::collections::HashMap;\n\n"); | ||
generated_code | ||
.push_str("pub fn load_templates() -> HashMap<String, HashMap<String, String>> {\n"); | ||
generated_code.push_str(" let mut templates = HashMap::new();\n"); | ||
|
||
for entry in WalkDir::new(templates_dir) | ||
.into_iter() | ||
.filter_map(Result::ok) | ||
.filter(|e| e.file_type().is_file()) | ||
{ | ||
let path = entry.path(); | ||
let relative_path = path.strip_prefix(templates_dir).unwrap().to_str().unwrap(); | ||
let template_name = relative_path.split('/').next().unwrap(); | ||
let file_name = relative_path | ||
.split('/') | ||
.skip(1) | ||
.collect::<Vec<_>>() | ||
.join("/"); | ||
|
||
generated_code.push_str(&format!( | ||
" templates.entry(\"{}\".to_string()).or_insert_with(HashMap::new).insert(\"{}\".to_string(), include_str!(r#\"{}\"#).to_string());\n", | ||
template_name, | ||
file_name, | ||
path.display() | ||
)); | ||
} | ||
|
||
generated_code.push_str(" templates\n"); | ||
generated_code.push_str("}\n"); | ||
|
||
fs::write(&dest_path, generated_code).unwrap(); | ||
println!("cargo:rerun-if-changed={}", templates_dir); | ||
} |
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,14 @@ | ||
pub fn add(left: usize, right: usize) -> usize { | ||
left + right | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
#[test] | ||
fn it_works() { | ||
let result = add(2, 2); | ||
assert_eq!(result, 4); | ||
} | ||
} |
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,27 @@ | ||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. | ||
|
||
# dependencies | ||
/node_modules | ||
/.pnp | ||
.pnp.js | ||
.yarn/install-state.gz | ||
|
||
# testing | ||
/coverage | ||
|
||
# metassr | ||
/dist | ||
|
||
|
||
# misc | ||
.DS_Store | ||
*.pem | ||
|
||
# debug | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
metassr.log* | ||
|
||
# local env files | ||
.env*.local |
Oops, something went wrong.