Rewriting mist project structure

This commit is contained in:
2026-05-21 05:26:52 +02:00
parent 812fa5d540
commit 856c9dfdfa
4 changed files with 13 additions and 25 deletions
+2 -4
View File
@@ -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<String>, config: Config, root: PathBuf) -> bool {
pub fn build(mut args: Vec<String>, root: PathBuf) -> bool {
args.remove(0);
args.insert(1, "--message-format=json".to_string());
@@ -55,7 +53,7 @@ pub fn build(mut args: Vec<String>, 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);
+5 -2
View File
@@ -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");
+4 -19
View File
@@ -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<PathBuf> {
}
}
}
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")
}