Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ node_modules/
/packages/playwright-report/
/packages/playwright/.cache/

# Zed
.zed/

# ignore the output of tmps
tmp/
Expand Down
21 changes: 18 additions & 3 deletions packages/cli/src/cli/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use super::*;
use crate::TraceSrc;
use anyhow::{bail, Context};
use cargo_generate::{GenerateArgs, TemplatePath, Vcs};
use std::path::Path;
use std::{fs, path::Path};

pub(crate) static DEFAULT_TEMPLATE: &str = "gh:dioxuslabs/dioxus-template";

Expand Down Expand Up @@ -61,9 +61,11 @@ impl Create {
self.name = Some(create::name_from_path(&self.path)?);
}

check_path(&self.path).await?;

// Perform a connectivity check so we just don't it around doing nothing if there's a network error
if self.template.is_none() {
connectivity_check().await?;
check_connectivity().await?;
}

// If no template is specified, use the default one and set the branch to the latest release.
Expand Down Expand Up @@ -232,9 +234,22 @@ fn remove_triple_newlines(string: &str) -> String {
new_string
}

/// Check if the requested project can be created in the filesystem
pub(crate) async fn check_path(path: &std::path::PathBuf) -> Result<()> {
match fs::metadata(path) {
Ok(_metadata) => {
bail!(
"A file or directory with the given project name \"{}\" already exists.",
path.to_string_lossy()
)
}
Err(_err) => Ok(()),
}
}

/// Perform a health check against github itself before we attempt to download any templates hosted
/// on github.
pub(crate) async fn connectivity_check() -> Result<()> {
pub(crate) async fn check_connectivity() -> Result<()> {
if crate::VERBOSITY
.get()
.map(|f| f.offline)
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/cli/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl Init {

// Perform a connectivity check so we just don't it around doing nothing if there's a network error
if self.template.is_none() {
create::connectivity_check().await?;
create::check_connectivity().await?;
}

// If no template is specified, use the default one and set the branch to the latest release.
Expand Down
Loading