Skip to content

Commit

Permalink
feat: add spinner to commands that install dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
Rickard Natt och Dag committed Nov 20, 2020
1 parent dd1ecd4 commit 4ced519
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 1 deletion.
19 changes: 19 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@ handlebars = "3.5.1"
dialoguer = "0.7.1"
colored = "2.0.0"
include-dir-macro = "0.2"
indicatif = "0.15.0"

25 changes: 24 additions & 1 deletion src/commands/add.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::utils::{helpers, template};
use crate::utils::{helpers, progressbar::Spinner, template};
use helpers::Result;
use serde_json::json;
use std::fs;
Expand All @@ -24,15 +24,25 @@ pub fn nvm() -> Result<()> {
}

pub fn husky() -> Result<()> {
let spinner = Spinner::new();

spinner.set_message("Installing dependencies");

helpers::install_dev("husky");
helpers::install_dev("pretty-quick");

template::render_file(include_str!("../templates/.huskyrc"), ".huskyrc", None)?;

spinner.success("Husky setup complete");

Ok(())
}

pub fn prettier() -> Result<()> {
let spinner = Spinner::new();

spinner.set_message("Installing dependencies");

helpers::install_dev("prettier");

template::render_file(
Expand All @@ -41,10 +51,16 @@ pub fn prettier() -> Result<()> {
None,
)?;

spinner.success("Prettier setup complete");

Ok(())
}

pub fn jest() -> Result<()> {
let spinner = Spinner::new();

spinner.set_message("Installing dependencies");

helpers::install_dev("jest");
helpers::install_dev("jest-watch-typeahead");

Expand All @@ -54,17 +70,22 @@ pub fn jest() -> Result<()> {
None,
)?;

spinner.success("Jest setup complete");

Ok(())
}

pub fn config() -> Result<()> {
let spinner = Spinner::new();
let is_typescript = fs::metadata("tsconfig.json").is_ok();
let folder = if fs::metadata("./src").is_ok() {
"src"
} else {
"lib"
};

spinner.set_message("Installing dependencies");

helpers::install_dev("@iteam/config");

if is_typescript {
Expand All @@ -87,5 +108,7 @@ pub fn config() -> Result<()> {
None,
)?;

spinner.success("Config setup complete");

Ok(())
}
1 change: 1 addition & 0 deletions src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pub mod helpers;
pub mod progressbar;
pub mod template;
25 changes: 25 additions & 0 deletions src/utils/progressbar.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use indicatif::{ProgressBar, ProgressStyle};

pub struct Spinner {
spinner: ProgressBar,
}

impl Spinner {
pub fn new() -> Spinner {
let spinner = ProgressBar::new_spinner();

spinner.enable_steady_tick(120);

Spinner { spinner }
}

pub fn set_message(&self, msg: &str) {
self.spinner.set_message(msg);
}

pub fn success(&self, msg: &str) {
self.spinner
.set_style(ProgressStyle::default_spinner().template("{msg:.green}"));
self.spinner.finish_with_message(msg);
}
}

0 comments on commit 4ced519

Please sign in to comment.