Init project
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
use <std::process>;
|
||||
use <std::env>;
|
||||
use <std::fs>;
|
||||
|
||||
pub mod builder;
|
||||
pub mod codegen;
|
||||
@@ -29,6 +30,9 @@ void main() {
|
||||
"transpile" | "t" => {
|
||||
transpiler::build();
|
||||
}
|
||||
"init" => {
|
||||
init_project();
|
||||
}
|
||||
"version" | "--version" | "-v" => {
|
||||
println!("mist {}", env!("CARGO_PKG_VERSION"));
|
||||
}
|
||||
@@ -61,3 +65,17 @@ void print_usage() {
|
||||
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> args) {
|
||||
new process::Command("cargo")
|
||||
.args(args)
|
||||
.stdout(process::Stdio::piped())
|
||||
.stderr(process::Stdio::piped())
|
||||
.stdin(process::Stdio::piped())
|
||||
.spawn()
|
||||
.expect("Failed to run cargo");
|
||||
|
||||
fs::remove("src/main.rs").expect("Failed to remove src/main.rs");
|
||||
|
||||
fs::write("src/main.mist", "void main() {\n println!(\"Hello, World!\")\n}").expect("Failed to create src/main.mist");
|
||||
}
|
||||
|
||||
+3
-17
@@ -10,9 +10,9 @@ use mist_parser::error::ParseError;
|
||||
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 root = std::env::current_dir()
|
||||
.ok()
|
||||
.expect("Unable to find project root");
|
||||
|
||||
let src_dir = root.join("src");
|
||||
let out_dir = root.join(".mist/src");
|
||||
@@ -164,17 +164,3 @@ fn should_skip(source: &Path, output: &Path) -> bool {
|
||||
}
|
||||
false
|
||||
}
|
||||
|
||||
pub fn find_project_root() -> Option<PathBuf> {
|
||||
let mut dir = std::env::current_dir().ok()?;
|
||||
|
||||
loop {
|
||||
if dir.join("mist.json").exists() {
|
||||
return Some(dir);
|
||||
}
|
||||
|
||||
if !dir.pop() {
|
||||
return None;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user