Gitignore, and mist new
This commit is contained in:
@@ -35,6 +35,9 @@ void main()
|
|||||||
"init" => {
|
"init" => {
|
||||||
init_project(args);
|
init_project(args);
|
||||||
}
|
}
|
||||||
|
"new" => {
|
||||||
|
new_project(args);
|
||||||
|
}
|
||||||
"version" | "--version" | "-v" => {
|
"version" | "--version" | "-v" => {
|
||||||
println!("mist {}", env!("CARGO_PKG_VERSION"));
|
println!("mist {}", env!("CARGO_PKG_VERSION"));
|
||||||
}
|
}
|
||||||
@@ -75,6 +78,7 @@ void print_usage()
|
|||||||
println!(" \x1b[36m mist transpile\x1b[0m,\x1b[36m t\x1b[0m transpile 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 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 init\x1b[0m initialize a project in the current folder\n");
|
||||||
|
println!(" \x1b[36m mist new\x1b[0m create a new project\n");
|
||||||
println!(" \x1b[36m mist version \x1b[0m print the compiler version\n");
|
println!(" \x1b[36m mist version \x1b[0m print the compiler version\n");
|
||||||
println!(" \x1b[36m mist help\x1b[0m print this message\n");
|
println!(" \x1b[36m mist help\x1b[0m print this message\n");
|
||||||
}
|
}
|
||||||
@@ -96,6 +100,36 @@ void init_project(Vec<String> mut args)
|
|||||||
}
|
}
|
||||||
inject_mist_target(is_lib);
|
inject_mist_target(is_lib);
|
||||||
add_mist_toml(is_lib);
|
add_mist_toml(is_lib);
|
||||||
|
add_gitignore();
|
||||||
|
println!("Thank you for using Mist!\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
void new_project(Vec<String> mut args)
|
||||||
|
{
|
||||||
|
args.remove(0);
|
||||||
|
if args.len() < 2 {
|
||||||
|
eprintln!("error: missing project name\n");
|
||||||
|
print_usage();
|
||||||
|
process::exit(1);
|
||||||
|
}
|
||||||
|
String project_name = args[1].clone();
|
||||||
|
let status = 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");
|
||||||
|
if !status.success() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
std::path::PathBuf project_path = env::current_dir().expect("Unable to find project root").join(&project_name);
|
||||||
|
env::set_current_dir(&project_path).expect("Failed to change to project directory");
|
||||||
|
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", "void test() {\n}").expect("Failed to create src/lib.mist");
|
||||||
|
} else {
|
||||||
|
fs::remove_file("src/main.rs").expect("Failed to remove src/main.rs");
|
||||||
|
fs::write("src/main.mist", "void main() {\n println!(\"Hello, World!\");\n}\n").expect("Failed to create src/main.mist");
|
||||||
|
}
|
||||||
|
inject_mist_target(is_lib);
|
||||||
|
add_mist_toml(is_lib);
|
||||||
|
add_gitignore();
|
||||||
println!("Thank you for using Mist!\n");
|
println!("Thank you for using Mist!\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -121,3 +155,13 @@ void add_mist_toml(bool is_lib)
|
|||||||
};
|
};
|
||||||
fs::write("Mist.toml", content).expect("Failed to add Mist.toml");
|
fs::write("Mist.toml", content).expect("Failed to add Mist.toml");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void add_gitignore()
|
||||||
|
{
|
||||||
|
if fs::metadata(".gitignore").is_ok() {
|
||||||
|
String content = fs::read_to_string(".gitignore").expect("Failed to read .gitignore");
|
||||||
|
if !content.contains(".mist") {
|
||||||
|
fs::write(".gitignore", content + "\n.mist\n").expect("Failed to write .gitignore");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user