Skip to content

Commit

Permalink
feat(cli.rs): framework and bundler on info cmd, closes #1681 (#1682
Browse files Browse the repository at this point in the history
)
  • Loading branch information
lucasfernog authored May 3, 2021
1 parent 82a580e commit 152c755
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changes/tauri-info-framework-bundler.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"cli.rs": patch
---

Show `framework` and `bundler` on the `info` command by reading the `package.json` file and matching known dependencies.
37 changes: 37 additions & 0 deletions tooling/cli.rs/src/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,43 @@ impl Info {
.value(config.build.dev_path.clone())
.display();
}
if let Ok(package_json) = read_to_string(app_dir.join("package.json")) {
let framework_map = [
("svelte", "Svelte", None),
("@angular", "Angular", Some("Webpack")),
(r#""next""#, "React (Next.js)", Some("Webpack")),
("gatsby", "React (Gatsby)", Some("Webpack")),
("react", "React", None),
("nuxt", "Vue.js (Nuxt)", Some("Webpack")),
("quasar", "Vue.js (Quasar)", Some("Webpack")),
("@vue/cli", "Vue.js (Vue CLI)", Some("Webpack")),
("vue", "Vue.js", None),
];
let bundler_map = [("webpack", "Webpack"), ("rollup", "Rollup")];

let (framework, framework_bundler) = framework_map
.iter()
.find(|(keyword, _, _)| package_json.contains(keyword))
.map(|(_, framework, bundler)| {
(Some(framework.to_string()), bundler.map(|b| b.to_string()))
})
.unwrap_or((None, None));

let bundler = bundler_map
.iter()
.find(|(keyword, _)| package_json.contains(keyword))
.map(|(_, bundler)| bundler.to_string())
.or(framework_bundler);

if let Some(framework) = framework {
InfoBlock::new("framework").value(framework).display();
}
if let Some(bundler) = bundler {
InfoBlock::new("bundler").value(bundler).display();
}
} else {
println!("package.json not found");
}
}

Ok(())
Expand Down

0 comments on commit 152c755

Please sign in to comment.