-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #63 from DarrenBaldwin07/build-command
Build command
- Loading branch information
Showing
12 changed files
with
196 additions
and
26 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
use super::RapidCommand; | ||
use crate::{cli::Config, tui::logo, rapid_config::config::find_rapid_config, util::{NEXTJS_ROUTE_PATH, REMIX_ROUTE_PATH, get_routes_dir, get_bindings_directory}, tui::chevrons}; | ||
use clap::{ArgMatches, Command}; | ||
use rapid_web::shift::generate::create_typescript_types; | ||
use std::env::current_dir; | ||
|
||
pub struct Build {} | ||
|
||
impl RapidCommand for Build { | ||
fn cmd() -> clap::Command { | ||
Command::new("build").about("Trigger a traditional rapid build for generating types and validating handlers") | ||
} | ||
|
||
fn execute(_: &Config, _args: &ArgMatches) -> Result<(), crate::cli::CliError<'static>> { | ||
println!("{}", logo()); | ||
// TODO: this command could also run a `cargo build` (only issue is that we would have to support all the args that cargo allows) | ||
|
||
let config = find_rapid_config(); | ||
let routes_dir = match config.app_type.as_str() { | ||
"server" => get_routes_dir(config.server.as_ref()), | ||
"remix" => REMIX_ROUTE_PATH.to_owned(), | ||
_ => NEXTJS_ROUTE_PATH.to_owned(), | ||
}; | ||
|
||
let every_dir_types_gen = match config.clone().app_type.as_str() { | ||
"server" => match config.clone().server { | ||
Some(server) => match server.typescript_generation_directory { | ||
Some(value) => value, | ||
None => "".to_string(), | ||
}, | ||
None => "".to_string(), | ||
}, | ||
"remix" => match config.clone().remix { | ||
Some(remix) => match remix.typescript_generation_directory { | ||
Some(value) => value, | ||
None => "".to_string(), | ||
}, | ||
None => "".to_string(), | ||
}, | ||
_ => match config.clone().nextjs { | ||
Some(nextjs) => match nextjs.typescript_generation_directory { | ||
Some(value) => value, | ||
None => "".to_string(), | ||
}, | ||
None => "".to_string(), | ||
}, | ||
}; | ||
|
||
let routes_directory = current_dir() | ||
.expect("Could not parse routes direcory path found in rapid config file.") | ||
.join(std::path::PathBuf::from(routes_dir.clone())); | ||
|
||
let type_generation_directory = if every_dir_types_gen != "" { | ||
current_dir() | ||
.expect("Could not parse current directory while executing type generation!") | ||
.join(every_dir_types_gen) | ||
} else { | ||
// If the typegen directory was not defined by the user, simply fallback to only doing handler types in the routes directorys | ||
routes_directory.clone() | ||
}; | ||
|
||
create_typescript_types(get_bindings_directory(config), routes_directory, type_generation_directory); | ||
|
||
println!("{} Rapid build completed!", chevrons()); | ||
|
||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ pub mod commands; | |
pub mod constants; | ||
pub mod rapid_config; | ||
pub mod tui; | ||
mod util; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
use crate::rapid_config::config::{ServerConfig, RapidConfig}; | ||
use std::{path::PathBuf, env::current_dir}; | ||
|
||
pub const REMIX_ROUTE_PATH: &'static str = "app/api/routes"; | ||
pub const NEXTJS_ROUTE_PATH: &'static str = "pages/api/routes"; | ||
|
||
pub fn get_routes_dir(rapid_server_config: Option<&ServerConfig>) -> String { | ||
match rapid_server_config { | ||
Some(server) => match server.routes_directory.clone() { | ||
Some(dir) => match dir == "/" { | ||
true => panic!("The 'routes_directory' variable cannot be set to a base path. Please use something nested!"), | ||
false => dir, | ||
}, | ||
None => panic!("Error: the 'routes_directory' variable must be set in your rapid config file!"), | ||
}, | ||
None => panic!("You must have a valid rapid config file in the base project directory!"), | ||
} | ||
} | ||
|
||
pub fn get_bindings_directory(config: RapidConfig) -> PathBuf { | ||
match config.app_type.as_str() { | ||
"server" => match config.server.as_ref() { | ||
Some(server) => match server.bindings_export_path.clone() { | ||
Some(dir) => match dir == "/" { | ||
true => current_dir().expect("Could not parse bindings export path found in rapid config file."), | ||
false => current_dir() | ||
.expect("Could not parse bindings export path found in rapid config file.") | ||
.join(PathBuf::from(dir)), | ||
}, | ||
None => panic!("Error: the 'bindings_export_path' variable must be set in your rapid config file!"), | ||
}, | ||
None => panic!("You must have a valid rapid config file in the base project directory!"), | ||
}, | ||
"remix" => match config.remix.as_ref() { | ||
Some(remix) => match remix.bindings_export_path.clone() { | ||
Some(dir) => match dir == "/" { | ||
true => current_dir().expect("Could not parse bindings export path found in rapid config file."), | ||
false => current_dir() | ||
.expect("Could not parse bindings export path found in rapid config file.") | ||
.join(PathBuf::from(dir)), | ||
}, | ||
None => panic!("Error: the 'bindings_export_path' variable must be set in your rapid config file!"), | ||
}, | ||
None => panic!("You must have a valid rapid config file in the base project directory!"), | ||
}, | ||
_ => match config.nextjs.as_ref() { | ||
Some(nextjs) => match nextjs.bindings_export_path.clone() { | ||
Some(dir) => match dir == "/" { | ||
true => current_dir().expect("Could not parse bindings export path found in rapid config file."), | ||
false => current_dir() | ||
.expect("Could not parse bindings export path found in rapid config file.") | ||
.join(PathBuf::from(dir)), | ||
}, | ||
None => panic!("Error: the 'bindings_export_path' variable must be set in your rapid config file!"), | ||
}, | ||
None => panic!("You must have a valid rapid config file in the base project directory!"), | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.