From 856c9dfdfaa9112c07e8415bfa5ba10956e99699 Mon Sep 17 00:00:00 2001 From: Selimaj Dev Date: Thu, 21 May 2026 05:26:52 +0200 Subject: [PATCH] Rewriting mist project structure --- .gitignore | 2 ++ src/builder.rs | 6 ++---- src/main.mist | 7 +++++-- src/transpiler.rs | 23 ++++------------------- 4 files changed, 13 insertions(+), 25 deletions(-) diff --git a/.gitignore b/.gitignore index e4cd9b8..6351270 100644 --- a/.gitignore +++ b/.gitignore @@ -27,3 +27,5 @@ target /target **/build + +.mist/ diff --git a/src/builder.rs b/src/builder.rs index a65983a..34afc8a 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -8,8 +8,6 @@ use std::{ use cargo_metadata::{CompilerMessage, Message}; use mist_parser::rev_mapper::{RustMap, find_mapping, get_mapping}; -use crate::transpiler::Config; - #[derive(Debug, Clone)] pub struct MistDiagnosticMessage { pub message: String, @@ -26,7 +24,7 @@ pub enum MistDiagnostic { Rust(CompilerMessage), } -pub fn build(mut args: Vec, config: Config, root: PathBuf) -> bool { +pub fn build(mut args: Vec, root: PathBuf) -> bool { args.remove(0); args.insert(1, "--message-format=json".to_string()); @@ -55,7 +53,7 @@ pub fn build(mut args: Vec, config: Config, root: PathBuf) -> bool { let mist_file = span .file_name - .replacen(&config.output, &config.src, 1) + .replacen(".mist/src", "src", 1) .replace(".rs", ".mist"); let mist_path = root.join(&mist_file); diff --git a/src/main.mist b/src/main.mist index 8171d3b..48b47c6 100644 --- a/src/main.mist +++ b/src/main.mist @@ -15,9 +15,12 @@ void main() { match (args[1].as_str()) { "run" | "build" | "check" | "r" | "b" | "c" => { - var (config, root) = transpiler::build(); + + var root = transpiler::build(); + println!(""); - if (builder::build(args, config, root)) { + + if (builder::build(args, root)) { println!("\x1b[32m\nBuild successful\x1b[0m"); } else { println!("\x1b[31m\nBuild failed\x1b[0m"); diff --git a/src/transpiler.rs b/src/transpiler.rs index ec282c2..e1abf52 100644 --- a/src/transpiler.rs +++ b/src/transpiler.rs @@ -6,25 +6,16 @@ use std::{ }; use mist_parser::error::ParseError; -use serde::Deserialize; -#[derive(Deserialize)] -pub struct Config { - pub src: String, - pub output: String, -} - -pub fn build() -> (Config, PathBuf) { +pub fn build() -> PathBuf { let start = Instant::now(); let root = find_project_root().unwrap_or_else(|| { panic!("error: could not find project root (mist.json)"); }); - let config = load_config(&root); - - let src_dir = root.join(&config.src); - let out_dir = root.join(&config.output); + let src_dir = root.join("src"); + let out_dir = root.join(".mist/src"); build_dir(&root, &src_dir, &src_dir, &out_dir); @@ -35,7 +26,7 @@ pub fn build() -> (Config, PathBuf) { elapsed ); - (config, root) + root } fn build_dir(root: &Path, base_src: &Path, current_dir: &Path, out_dir: &Path) { @@ -187,9 +178,3 @@ pub fn find_project_root() -> Option { } } } - -fn load_config(root: &Path) -> Config { - let content = fs::read_to_string(root.join("mist.json")).expect("failed to read mist.json"); - - serde_json::from_str(&content).expect("invalid mist.json format") -}