Skip to content

Commit

Permalink
feat(cli): design & UX overhaul (#840)
Browse files Browse the repository at this point in the history
  • Loading branch information
QuiiBz committed May 8, 2023
1 parent 76f8260 commit 9eada33
Show file tree
Hide file tree
Showing 25 changed files with 356 additions and 320 deletions.
5 changes: 5 additions & 0 deletions .changeset/funny-waves-confess.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@lagon/cli': minor
---

Introduce a brand new design
5 changes: 5 additions & 0 deletions .changeset/great-cars-design.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@lagon/cli': patch
---

Pre-select confirmation inputs
5 changes: 5 additions & 0 deletions .changeset/tame-planets-wave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@lagon/cli': patch
---

Improve UX by showing file errors instead of exiting immediately
45 changes: 6 additions & 39 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions crates/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ lagon-runtime-http = { path = "../runtime_http" }
lagon-runtime-isolate = { path = "../runtime_isolate" }
lagon-runtime-utils = { path = "../runtime_utils" }
clap = { version = "4.2.7", features = ["derive"] }
dialoguer = "0.10.4"
dialoguer = { version = "0.10.4", features = ["password"] }
indicatif = "0.17.3"
colored = "2.0.0"
dirs = "5.0.1"
webbrowser = "0.8.9"
tokio = { version = "1", features = ["rt-multi-thread", "macros", "sync"] }
Expand All @@ -27,3 +26,4 @@ notify = "5.1.0"
envfile = "0.2.1"
anyhow = "1.0.71"
urlencoding = "2.1.2"
once_cell = "1.17.1"
33 changes: 14 additions & 19 deletions crates/cli/src/commands/build.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use std::{fs, path::PathBuf};

use crate::utils::{bundle_function, print_progress, resolve_path};
use anyhow::{anyhow, Result};

use crate::utils::{bundle_function, debug, print_progress, resolve_path, success};
use dialoguer::console::style;
use std::{fs, path::PathBuf};

pub fn build(
path: Option<PathBuf>,
Expand All @@ -12,33 +11,29 @@ pub fn build(
let (root, function_config) = resolve_path(path, client, public_dir)?;
let (index, assets) = bundle_function(&function_config, &root, true)?;

let end_progress = print_progress("Writting index.js...");

fs::create_dir_all(root.join(".lagon"))?;
fs::write(root.join(".lagon").join("index.js"), index)?;
let end_progress = print_progress("Writting files");
let root = root.join(".lagon");

end_progress();
fs::create_dir_all(&root)?;
fs::write(root.join("index.js"), index)?;

for (path, content) in assets {
let message = format!("Writting {path}...");
let end_progress = print_progress(&message);

let dir = root.join(".lagon").join("public").join(
let dir = root.join("public").join(
PathBuf::from(&path)
.parent()
.ok_or_else(|| anyhow!("Could not find parent of {}", path))?,
);
fs::create_dir_all(dir)?;
fs::write(root.join(".lagon").join("public").join(path), content)?;

end_progress();
fs::write(root.join("public").join(path), content)?;
}

end_progress();

println!();
println!(" {} Build successful!", style("◼").magenta());
println!(
"{} {}",
success("Build successful!"),
debug("You can find it in .lagon folder.")
" {}",
style(format!("You can find it in {:?}", root)).black().bright()
);

Ok(())
Expand Down
37 changes: 19 additions & 18 deletions crates/cli/src/commands/deploy.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
use crate::utils::{create_deployment, print_progress, resolve_path, Config, TrpcClient, THEME};
use anyhow::{anyhow, Result};
use dialoguer::{console::style, Confirm, Input, Select};
use serde::{Deserialize, Serialize};
use std::{
fmt::{Display, Formatter},
path::PathBuf,
};

use anyhow::{anyhow, Result};
use dialoguer::{Confirm, Input, Select};
use serde::{Deserialize, Serialize};

use crate::utils::{
create_deployment, debug, info, print_progress, resolve_path, Config, TrpcClient,
};

#[derive(Deserialize, Debug)]
pub struct Organization {
pub name: String,
Expand Down Expand Up @@ -69,7 +65,10 @@ pub async fn deploy(
let (root, mut function_config) = resolve_path(path, client, public_dir)?;

if function_config.function_id.is_empty() {
println!("{}", debug("No deployment config found..."));
println!(
"{}",
style("No previous Deployment found...").black().bright()
);
println!();

let trpc_client = TrpcClient::new(config.clone());
Expand All @@ -78,15 +77,16 @@ pub async fn deploy(
.await?;
let organizations = response.result.data;

let index = Select::new()
let index = Select::with_theme(&*THEME)
.items(&organizations)
.default(0)
.with_prompt(info("Select an Organization to deploy to"))
.with_prompt("Which Organization would you like to deploy to?")
.interact()?;
let organization = &organizations[index];

match Confirm::new()
.with_prompt(info("Link to an existing Function?"))
match Confirm::with_theme(&*THEME)
.with_prompt("Link to an existing Function?")
.default(false)
.interact()?
{
true => {
Expand All @@ -95,26 +95,27 @@ pub async fn deploy(
.await?;
let functions = response.result.data;

let index = Select::new()
let index = Select::with_theme(&*THEME)
.items(&functions)
.default(0)
.with_prompt(info("Select a Function to link from"))
.with_prompt("Which Function would you like to link?")
.interact()?;
let function = &functions[index];

function_config.function_id = function.id.clone();
function_config.organization_id = organization.id.clone();
function_config.write(&root)?;

println!();
create_deployment(config, &function_config, is_production, &root, true).await?;
}
false => {
let name = Input::<String>::new()
.with_prompt(info("What is the name of this new Function?"))
let name = Input::<String>::with_theme(&*THEME)
.with_prompt("What's the name of this new Function?")
.interact_text()?;

println!();
let message = format!("Creating Function {name}...");
let message = format!("Creating Function {name}");
let end_progress = print_progress(&message);

let response = trpc_client
Expand Down
Loading

0 comments on commit 9eada33

Please sign in to comment.