1 file changed
+33
-12
crates/cli/src/project/runner.rs
+33
-12
@@ -1,6 +1,7 @@
1
use crate::ui::{fail_message, fail_symbol, succeed_message, succeed_symbol};
2
-use anyhow::{Ok, Result};
2
+use anyhow::Result;
3
use spinners::Spinner;
4
+use std::fs;
5
use std::path::Path;
6
7
pub(crate) enum Runner {
@@ -22,24 +23,44 @@ impl Runner {
23
}
24
}
25
26
+// Helper function to detect any next.config.* file
27
+fn next_config_exists() -> bool {
28
+ if let Ok(entries) = fs::read_dir(".") {
29
+ for entry in entries.flatten() {
30
+ let filename = entry.file_name();
31
+ let filename_str = filename.to_string_lossy();
32
+ if filename_str.starts_with("next.config.") {
33
+ return true;
34
+ }
35
+ }
36
+ }
37
+ false
38
+}
39
+
40
+// Helper function to detect any astro.config.* file
41
+fn astro_config_exists() -> bool {
42
+ if let Ok(entries) = fs::read_dir(".") {
43
+ for entry in entries.flatten() {
44
+ let filename = entry.file_name();
45
+ let filename_str = filename.to_string_lossy();
46
+ if filename_str.starts_with("astro.config.") {
47
+ return true;
48
+ }
49
+ }
50
+ }
51
+ false
52
+}
53
+
54
pub(crate) async fn detect_runner() -> Result<Runner> {
55
let mut spinner: Spinner = Spinner::new(
56
spinners::Spinners::SimpleDotsScrolling,
57
succeed_message("Checking runner"),
58
);
59
31
- if Path::new("package.json").exists()
32
- && (Path::new("next.config.js").exists()
33
- || Path::new("next.config.ts").exists()
34
- || Path::new("next.config.mjs").exists()
35
- || Path::new("astro.config.mjs").exists())
36
- {
37
- let app_string = if Path::new("next.config.js").exists()
38
- || Path::new("next.config.ts").exists()
39
- || Path::new("next.config.mjs").exists()
40
- {
60
+ if Path::new("package.json").exists() && (next_config_exists() || astro_config_exists()) {
61
+ let app_string = if next_config_exists() {
62
"Next.js app"
42
- } else if Path::new("astro.config.mjs").exists() {
63
+ } else if astro_config_exists() {
64
"Astro app"
65
} else {
66
panic!("Unsupported app.")