improved code quality
This commit is contained in:
@@ -65,6 +65,22 @@ pub class Module {
|
||||
self.children.push(new Module(child_name, child_path, child_output));
|
||||
}
|
||||
}
|
||||
|
||||
pub PathBuf output_dir(self*, PathBuf* parent_dir) {
|
||||
if (self.path.is_dir() || Some("package.mist") == self.path.file_name().unwrap().to_str()) {
|
||||
parent_dir.join(&self.name)
|
||||
} else {
|
||||
parent_dir.clone()
|
||||
}
|
||||
}
|
||||
|
||||
pub PathBuf output_path(self*, PathBuf* parent_dir) {
|
||||
if (self.path.is_dir() || Some("package.mist") == self.path.file_name().unwrap().to_str()) {
|
||||
parent_dir.join(&self.name).join("mod.rs")
|
||||
} else {
|
||||
parent_dir.join(&self.name).with_extension("rs")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub Module master_package(PathBuf mist_path, PathBuf rust_path) {
|
||||
|
||||
@@ -32,9 +32,10 @@ pub PathBuf build(bool force) {
|
||||
|
||||
impl modules::Module {
|
||||
String transpile(self*, PathBuf* parent_dir) {
|
||||
if (self.path.is_dir()) {
|
||||
PathBuf dir = parent_dir.join(&self.name);
|
||||
PathBuf output_file = dir.join("mod.rs");
|
||||
PathBuf dir = self.output_dir(&parent_dir);
|
||||
PathBuf output_file = self.output_path(&parent_dir);
|
||||
|
||||
var _ = fs::create_dir_all(&dir);
|
||||
|
||||
String mut output = String::new();
|
||||
|
||||
@@ -42,6 +43,7 @@ impl modules::Module {
|
||||
output.push_str(&child.transpile(&dir));
|
||||
}
|
||||
|
||||
if (self.path.is_dir()) {
|
||||
var res = fs::write(&output_file, output);
|
||||
|
||||
if (res.is_err()) {
|
||||
@@ -54,28 +56,7 @@ impl modules::Module {
|
||||
process::exit(1);
|
||||
}
|
||||
} else {
|
||||
if (Some("package.mist") == self.path.file_name().unwrap().to_str()) {
|
||||
PathBuf dir = parent_dir.join(&self.name);
|
||||
PathBuf output_file = dir.join("mod.rs");
|
||||
|
||||
String mut output = String::new();
|
||||
|
||||
for (child : &self.children) {
|
||||
output.push_str(&child.transpile(&dir));
|
||||
}
|
||||
|
||||
transpile_file(&self.path, &output_file, &output);
|
||||
} else {
|
||||
PathBuf output_file = parent_dir.join(&self.name).with_extension("rs");
|
||||
|
||||
String mut output = String::new();
|
||||
|
||||
for (child : &self.children) {
|
||||
output.push_str(&child.transpile(&parent_dir));
|
||||
}
|
||||
|
||||
transpile_file(&self.path, &output_file, &output);
|
||||
}
|
||||
}
|
||||
|
||||
format!("pub mod {};\n", self.name)
|
||||
@@ -139,16 +120,3 @@ void transpile_file(PathBuf* path, PathBuf* output_file, str* mod_decl) {
|
||||
}
|
||||
}
|
||||
|
||||
bool should_skip(Path* source, Path* output) {
|
||||
var src_time = fs::metadata(source)
|
||||
.ok()
|
||||
.and_then(|var v| v.modified().ok());
|
||||
|
||||
var out_time = fs::metadata(output)
|
||||
.ok()
|
||||
.and_then(|var v| v.modified().ok());
|
||||
|
||||
out_time
|
||||
.map(|var out_time| out_time >= src_time.unwrap())
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
@@ -1,9 +1,3 @@
|
||||
pub mod app;
|
||||
pub mod task;
|
||||
pub mod plugin;
|
||||
pub mod logger;
|
||||
pub mod event;
|
||||
|
||||
void main() {
|
||||
var mut app_instance = new app::Application("mist-app");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user