Skip to content

Commit

Permalink
rebase main
Browse files Browse the repository at this point in the history
  • Loading branch information
kariy committed Oct 25, 2023
1 parent 147872b commit 1ed3903
Showing 1 changed file with 24 additions and 12 deletions.
36 changes: 24 additions & 12 deletions crates/dojo-lang/src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,18 +104,30 @@ impl Compiler for DojoCompiler {
let contract_name = decl.submodule_id.name(db.upcast_mut());
let contract_name_snake = contract_name.to_case(Case::Snake);

let is_model = match class.abi.clone() {
Some(abii) => abii.items.iter().any(|i| match i {
abi::Item::Struct(s) => s.name == "dojo::database::schema::Struct",
_ => false,
}),
None => false,
};

let separator = if is_model { "model" } else { "contract" };
let file_name = format!("{target_name}-{separator}-{contract_name_snake}.json");

let mut file = target_dir.open_rw(file_name.clone(), "output file", ws.config())?;
println!("{}", target_name);
println!("{}", contract_name);
println!("{}", contract_name_snake);

if let Ok(Some(ModuleItemId::Struct(_))) =
db.module_item_by_name(decl.module_id(), contract_name.clone())
{
println!("is a model?");
}

// let is_model = match &class.abi {
// Some(abi) => abi.items.iter().any(|i| match i {
// abi::Item::Struct(s) => s.name == "dojo::database::schema::Struct",
// _ => false,
// }),

// None => false,
// };

// let separator = if is_model { "model" } else { "contract" };
// let file_name = format!("{target_name}-{separator}-{contract_name_snake}.json");

let mut file =
target_dir.open_rw(contract_name_snake.clone(), "output file", ws.config())?;
serde_json::to_writer_pretty(file.deref_mut(), &class)
.with_context(|| format!("failed to serialize contract: {contract_name}"))?;

Expand Down

0 comments on commit 1ed3903

Please sign in to comment.