4 files changed
+41
-4
crates/cli/src/deploy/config.rs
+5
-4
@@ -34,10 +34,11 @@ pub(crate) async fn check_config(env: Environment) -> Result<Config, ErrorRespon
34
}
35
36
// Parse toml file
37
- let config_content = fs::read_to_string(config_path).map_err(|_| ErrorResponse::Error {
38
- error_code: ErrorCode::MissingConfig,
39
- message: ErrorCode::MissingConfig.message(None).to_string(),
40
- })?;
37
+ let config_content: String =
38
+ fs::read_to_string(config_path).map_err(|_| ErrorResponse::Error {
39
+ error_code: ErrorCode::MissingConfig,
40
+ message: ErrorCode::MissingConfig.message(None).to_string(),
41
+ })?;
42
43
let config: Config = match toml::from_str(&config_content) {
44
Ok(value) => value,
crates/cli/src/deploy/mod.rs
+4
@@ -7,6 +7,7 @@ use crate::{
7
account::{lib::is_logged_in, login::process_login, me::me},
8
cli::CommandResult,
9
deploy::config::check_project,
10
+ project::runner::detect_runner,
11
ui::{fail_message, succeed_message, succeed_symbol},
12
};
13
use anyhow::{anyhow, Result};
@@ -36,6 +37,9 @@ pub async fn process_deploy(env: Environment) -> Result<CommandResult> {
37
// Check config.
38
let config = check_config(env).await?;
39
40
+ // Check runner.
41
+ detect_runner().await?;
42
+
43
// Validate config with project.
44
check_project(env, &access_token, config.project.id).await?;
45
crates/cli/src/project/mod.rs
+1
@@ -5,3 +5,4 @@ pub mod crud_read;
5
pub mod crud_update;
6
mod deployment;
7
pub mod process;
8
+pub(crate) mod runner;
crates/cli/src/project/runner.rs
new
+31
@@ -0,0 +1,31 @@
1
+use crate::ui::{fail_message, fail_symbol, succeed_message, succeed_symbol};
2
+use anyhow::{Ok, Result};
3
+use spinners::Spinner;
4
+use std::path::Path;
5
+
6
+pub(crate) enum Runner {
7
+ NodeJs,
8
+ Ruby,
9
+}
10
+
11
+pub(crate) async fn detect_runner() -> Result<Runner> {
12
+ let mut spinner: Spinner = Spinner::new(
13
+ spinners::Spinners::SimpleDotsScrolling,
14
+ succeed_message("Checking runner"),
15
+ );
16
+
17
+ if Path::new("package.json").exists() {
18
+ spinner.stop_and_persist(&succeed_symbol(), succeed_message("Detected NodeJs runner"));
19
+ return Ok(Runner::NodeJs);
20
+ }
21
+ if Path::new("Gemfile").exists() {
22
+ spinner.stop_and_persist(&succeed_symbol(), succeed_message("Detected Ruby runner"));
23
+ return Ok(Runner::Ruby);
24
+ }
25
+
26
+ spinner.stop_and_persist(
27
+ &fail_symbol(),
28
+ fail_message("Could not detect project runner: no package.json or Gemfile found"),
29
+ );
30
+ anyhow::bail!("Could not detect project runner: no package.json or Gemfile found");
31
+}