Skip to content

Commit

Permalink
feat(export): make export json works
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Mar 1, 2021
1 parent a19277b commit 92e6308
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
28 changes: 22 additions & 6 deletions src/app/visual/output_static.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use core_model::Settings;
use rust_embed::RustEmbed;
use std::fs;
use std::path::Path;
Expand All @@ -6,9 +7,7 @@ use std::path::Path;
#[folder = "web/"]
struct Asset;

pub fn run<P: AsRef<Path>>(path: P) {
copy_reporter_to(&path.as_ref());

pub fn run<P: AsRef<Path>>(path: P, project: String) {
for file in Asset::iter() {
let file_name = format!("{}", file.as_ref());
let file_path = &path.as_ref().join(file.as_ref());
Expand All @@ -19,8 +18,25 @@ pub fn run<P: AsRef<Path>>(path: P) {
println!("write to file: {}", file_path.display());
fs::write(file_path, content).expect("cannot write file");
}
}

pub fn copy_reporter_to(_path: &Path) {
// todo: make reporter copy
let git = Settings::git().join(format!("{}.json", project));
let _ = fs::copy(git, &path.as_ref().join("data").join("git.json"));

let commits = Settings::git().join(format!("{}-commits.json", project).as_str());
let _ = fs::copy(
commits,
&path.as_ref().join("data").join("git-commits.json"),
);

let tags = Settings::git().join(format!("{}-tags.json", project));
let _ = fs::copy(tags, &path.as_ref().join("data").join("git-tags.json"));

let cloc = Settings::cloc().join(format!("{}.json", project));
let _ = fs::copy(cloc, &path.as_ref().join("data").join("cloc.json"));

let structs = Settings::struct_analysis().join(format!("{}.json", project));
let _ = fs::copy(
structs,
&path.as_ref().join("data").join("struct-analysis.json"),
);
}
6 changes: 3 additions & 3 deletions src/bin/visual.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ async fn main() -> std::io::Result<()> {
};

if let Some(ref matches) = matches.subcommand_matches("export") {
start_export_reporter(matches);
start_export_reporter(matches, project);
return Ok(());
}

Expand All @@ -63,14 +63,14 @@ async fn main() -> std::io::Result<()> {
return start_local_server(project, port).await;
}

fn start_export_reporter(matches: &&ArgMatches) {
fn start_export_reporter(matches: &&ArgMatches, project_name: String) {
let mut path = "coco_static";
if let Some(input) = matches.value_of("path") {
path = input
}

// todo: make really output
output_static::run(path);
output_static::run(path, project_name);
}

async fn start_local_server(project: String, port: &str) -> std::io::Result<()> {
Expand Down

0 comments on commit 92e6308

Please sign in to comment.