Skip to content

Commit

Permalink
Format
Browse files Browse the repository at this point in the history
  • Loading branch information
WilliamRagstad committed Sep 13, 2023
1 parent 7c6ad4c commit cdd7048
Show file tree
Hide file tree
Showing 5 changed files with 302 additions and 110 deletions.
41 changes: 30 additions & 11 deletions src/engine/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ use std::path::Path;

use crate::file::parser::parse_webx_file;
use crate::file::webx::WebXFile;
use crate::project::{locate_webx_files, load_project_config, construct_dependency_tree, detect_circular_dependencies};
use crate::reporting::error::{exit_error, ERROR_READ_WEBX_FILES, ERROR_CIRCULAR_DEPENDENCY};
use crate::project::{
construct_dependency_tree, detect_circular_dependencies, load_project_config, locate_webx_files,
};
use crate::reporting::error::{exit_error, ERROR_CIRCULAR_DEPENDENCY, ERROR_READ_WEBX_FILES};

const PROJECT_CONFIG_FILE_NAME: &str = "webx.config.json";

Expand All @@ -13,21 +15,28 @@ pub fn run(root: &Path, prod: bool) {
let source_root = root.join(&config.src);
let files = match locate_webx_files(&source_root) {
Ok(files) => files,
Err(err) => exit_error(format!("Failed to locate webx program files due to, {}", err), ERROR_READ_WEBX_FILES),
Err(err) => exit_error(
format!("Failed to locate webx program files due to, {}", err),
ERROR_READ_WEBX_FILES,
),
};

let webx_modules = files.iter().map(|f| parse_webx_file(f)).collect::<Vec<_>>();
let errors = webx_modules.iter().filter(|m| m.is_err()).map(|m| m.as_ref().unwrap_err()).collect::<Vec<_>>();
let errors = webx_modules
.iter()
.filter(|m| m.is_err())
.map(|m| m.as_ref().unwrap_err())
.collect::<Vec<_>>();
if !errors.is_empty() {
exit_error(
format!(
"Failed to parse webx files:\n{:?}",
errors
),
format!("Failed to parse webx files:\n{:?}", errors),
ERROR_READ_WEBX_FILES,
);
}
let webx_modules = webx_modules.into_iter().map(|m| m.unwrap()).collect::<Vec<_>>();
let webx_modules = webx_modules
.into_iter()
.map(|m| m.unwrap())
.collect::<Vec<_>>();
let dependency_tree = construct_dependency_tree(&webx_modules);
let circular_dependencies = detect_circular_dependencies(&dependency_tree);
if !circular_dependencies.is_empty() {
Expand All @@ -40,7 +49,17 @@ pub fn run(root: &Path, prod: bool) {
);
}

println!("Webx modules: {:?}", webx_modules.iter().map(WebXFile::module_name).collect::<Vec<_>>().join(", "));
println!("Running web server in {} mode", if prod { "production" } else { "development" });
println!(
"Webx modules: {:?}",
webx_modules
.iter()
.map(WebXFile::module_name)
.collect::<Vec<_>>()
.join(", ")
);
println!(
"Running web server in {} mode",
if prod { "production" } else { "development" }
);
println!("Directory: {}", root.display());
}
2 changes: 1 addition & 1 deletion src/engine/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ mod tests {
fn test_example_todo() {
run(&Path::new("examples/todo"), false);
}
}
}
Loading

0 comments on commit cdd7048

Please sign in to comment.