Updated boostrap
This commit is contained in:
+19
-36
@@ -1,23 +1,24 @@
|
||||
use std::process;
|
||||
|
||||
use std::env;
|
||||
|
||||
use std::fs;
|
||||
|
||||
use mist_api::builder;
|
||||
|
||||
use mist_api::transpiler;
|
||||
|
||||
void main() {
|
||||
void main()
|
||||
{
|
||||
Vec<String> args = env::args().collect();
|
||||
|
||||
if args.len() < 2 {
|
||||
print_usage();
|
||||
process::exit(1);
|
||||
}
|
||||
|
||||
match args[1].as_str() {
|
||||
"run" | "build" | "check" | "r" | "b" | "c" => {
|
||||
let root = transpiler::transpile();
|
||||
|
||||
println!("");
|
||||
|
||||
if builder::build(args, root) {
|
||||
println!("\x1b[32m\nBuild successful\x1b[0m");
|
||||
} else {
|
||||
@@ -44,41 +45,26 @@ void main() {
|
||||
}
|
||||
}
|
||||
|
||||
void print_usage() {
|
||||
void print_usage()
|
||||
{
|
||||
println!("Mist - the mist compiler\n");
|
||||
println!(" View our documentation! \x1b[35mhttps://mist.selimaj.dev\x1b[0m");
|
||||
println!(" Follow us on github! \x1b[35mhttps://github.com/mist-go\x1b[0m\n");
|
||||
println!("usage:");
|
||||
println!(" \x1b[36m mist run\x1b[0m,\x1b[36m r\x1b[0m run the project in the current directory\n");
|
||||
println!(
|
||||
" \x1b[36m mist build\x1b[0m,\x1b[36m b\x1b[0m build the project in the current directory\n"
|
||||
);
|
||||
println!(
|
||||
" \x1b[36m mist transpile\x1b[0m,\x1b[36m t\x1b[0m transpile the project in the current directory\n"
|
||||
);
|
||||
println!(
|
||||
" \x1b[36m mist check\x1b[0m,\x1b[36m c\x1b[0m check the project in the current directory\n"
|
||||
);
|
||||
println!(
|
||||
" \x1b[36m mist init\x1b[0m initialize a project in the current folder\n"
|
||||
);
|
||||
println!(" \x1b[36m mist build\x1b[0m,\x1b[36m b\x1b[0m build the project in the current directory\n");
|
||||
println!(" \x1b[36m mist transpile\x1b[0m,\x1b[36m t\x1b[0m transpile the project in the current directory\n");
|
||||
println!(" \x1b[36m mist check\x1b[0m,\x1b[36m c\x1b[0m check the project in the current directory\n");
|
||||
println!(" \x1b[36m mist init\x1b[0m initialize a project in the current folder\n");
|
||||
println!(" \x1b[36m mist version \x1b[0m print the compiler version\n");
|
||||
println!(" \x1b[36m mist help\x1b[0m print this message\n");
|
||||
}
|
||||
|
||||
void init_project(Vec<String> mut args) {
|
||||
void init_project(Vec<String> mut args)
|
||||
{
|
||||
args.remove(0);
|
||||
|
||||
process::Command::new("cargo")
|
||||
.args(args)
|
||||
.stdout(process::Stdio::inherit())
|
||||
.stderr(process::Stdio::inherit())
|
||||
.stdin(process::Stdio::inherit())
|
||||
.spawn()
|
||||
.expect("Failed to run cargo").wait().expect("Unable to wait");
|
||||
|
||||
process::Command::new("cargo").args(args).stdout(process::Stdio::inherit()).stderr(process::Stdio::inherit()).stdin(process::Stdio::inherit()).spawn().expect("Failed to run cargo").wait().expect("Unable to wait");
|
||||
bool is_lib = fs::metadata("src/lib.rs").is_ok();
|
||||
|
||||
if is_lib {
|
||||
fs::remove_file("src/lib.rs").expect("Failed to remove src/lib.rs");
|
||||
fs::write("src/lib.mist", "fn test() {\n}").expect("Failed to create src/lib.mist");
|
||||
@@ -86,20 +72,17 @@ void init_project(Vec<String> mut args) {
|
||||
fs::remove_file("src/main.rs").expect("Failed to remove src/main.rs");
|
||||
fs::write("src/main.mist", "fn main() {\n println!(\"Hello, World!\");\n}\n").expect("Failed to create src/main.mist");
|
||||
}
|
||||
|
||||
inject_mist_target(is_lib);
|
||||
|
||||
println!("\n\x1b[34minfo\x1b[0m: Please open Cargo.toml and adjust `\x1b[35mname\x1b[0m = ` as needed, Thank you for using Mist!\n");
|
||||
}
|
||||
|
||||
void inject_mist_target(bool is_lib) {
|
||||
void inject_mist_target(bool is_lib)
|
||||
{
|
||||
String toml_content = fs::read_to_string("Cargo.toml").expect("Failed to read Cargo.toml");
|
||||
|
||||
str& inject = if is_lib {
|
||||
"\n[lib]\nname = \"my_lib\"\npath = \".mist/src/lib.rs\"\n"
|
||||
} else {
|
||||
"\n[[bin]]\nname = \"my_bin\"\npath = \".mist/src/main.rs\"\n"
|
||||
};
|
||||
|
||||
fs::write("Cargo.toml", toml_content+inject).expect("Failed to inject to Cargo.toml");
|
||||
}
|
||||
fs::write("Cargo.toml", toml_content + inject).expect("Failed to inject to Cargo.toml");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user