Skip to content

Commit

Permalink
feat: make e2e can works
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Oct 10, 2022
1 parent 7fe4926 commit a814a00
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 14 deletions.
2 changes: 1 addition & 1 deletion fkl_cli/src/e2e.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ mod tests {
let mut input_path = d.clone();
input_path.push(format!("spring.fkl"));

code_gen_exec::code_gen_exec(Some(&input_path), Some(&"HelloGot".to_string()), &base_path);
code_gen_exec::code_gen_exec(&input_path, Some(&"HelloGot".to_string()), &base_path);

let controller = "test_data/spring/src/main/java/com/feakin/demo/rest/HelloController.java";
let output = fs::read_to_string(controller).expect("Something went wrong reading the file");
Expand Down
16 changes: 6 additions & 10 deletions fkl_cli/src/exec/code_gen_exec.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::fs;
use std::path::PathBuf;

use log::error;
use log::{error, info};

use fkl_codegen_java::gen_http_api;
use fkl_parser::mir::{ContextMap, Implementation};
Expand All @@ -25,14 +25,8 @@ pub enum DddLayer {
Infrastructure,
}

pub fn code_gen_exec(feakin_path: Option<&PathBuf>, filter_impl: Option<&String>, base_path: &PathBuf) {
if feakin_path.is_none() {
error!("Please provide a path to a manifest file");
return;
}

let path = feakin_path.unwrap();
let feakin = fs::read_to_string(path).unwrap();
pub fn code_gen_exec(input_path: &PathBuf, filter_impl: Option<&String>, base_path: &PathBuf) {
let feakin = fs::read_to_string(input_path).unwrap();
let mir: ContextMap = parse(&feakin).or_else(|e| {
error!("{}", e);
Err(e)
Expand Down Expand Up @@ -60,8 +54,10 @@ pub fn code_gen_exec(feakin_path: Option<&PathBuf>, filter_impl: Option<&String>
let first_class = &code_file.classes[0];

let lines: Vec<String> = code_block.code.split("\n").map(|s| s.to_string()).collect();
JavaInserter::insert(&path, first_class, lines)
JavaInserter::insert(&path, first_class, &lines)
.expect("TODO: panic message");

info!("inserted code to {}, {:?}", path, &lines);
});
}
}
Expand Down
4 changes: 2 additions & 2 deletions fkl_cli/src/inserter/inserter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::line_separator::line_separator;
pub struct JavaInserter {}

impl JavaInserter {
pub fn insert(path: &str, clazz: &CodeClass, lines: Vec<String>) -> Result<(), String> {
pub fn insert(path: &str, clazz: &CodeClass, lines: &Vec<String>) -> Result<(), String> {
let file_path = PathBuf::from(path);
if !file_path.exists() {
return Err(format!("path {} not exists", path));
Expand Down Expand Up @@ -61,7 +61,7 @@ mod tests {
let code = "public class Test {\n}";
let path = "test.java";
fs::write(path, code).unwrap();
JavaInserter::insert(path, &clazz, vec![
JavaInserter::insert(path, &clazz, &vec![
" public void demo() {".to_string(),
" }".to_string(),
]).unwrap();
Expand Down
11 changes: 10 additions & 1 deletion fkl_cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::io::Write;
use std::path::PathBuf;

use clap::ArgMatches;
use log::error;

use fkl_parser::parse;

Expand Down Expand Up @@ -55,7 +56,15 @@ fn main() {
let feakin_path = matches.get_one::<PathBuf>("path");
let filter_impl = matches.get_one::<String>("impl");

code_gen_exec::code_gen_exec(feakin_path, filter_impl, &PathBuf::from("."));
if feakin_path.is_none() {
error!("Please provide a path to a manifest file");
return;
}

let path = feakin_path.unwrap();
let base_path = path.parent().unwrap().to_path_buf();

code_gen_exec::code_gen_exec(path, filter_impl, &base_path);
}
Some(("dot", matches)) => {
let manifest_path = matches.get_one::<PathBuf>("path");
Expand Down
1 change: 1 addition & 0 deletions fkl_cli/test_data/spring/spring.fkl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ impl HelloGot {
}

layered DDD {
// by default
dependency {
"interface" -> "application"
"interface" -> "domain"
Expand Down

0 comments on commit a814a00

Please sign in to comment.